Esempio n. 1
0
//-----------------------------------------------------------------------------
void CGDrawContext::drawEllipse (const CRect &rect, const CDrawStyle drawStyle)
{
    CGContextRef context = beginCGContext (true, getDrawMode ().integralMode ());
    if (context)
    {
        CGRect r = CGRectMake (static_cast<CGFloat> (rect.left), static_cast<CGFloat> (rect.top + 1), static_cast<CGFloat> (rect.getWidth () - 1), static_cast<CGFloat> (rect.getHeight () - 1));

        CGPathDrawingMode m;
        switch (drawStyle)
        {
        case kDrawFilled :
            m = kCGPathFill;
            break;
        case kDrawFilledAndStroked :
            m = kCGPathFillStroke;
            break;
        default :
            m = kCGPathStroke;
            break;
        }
        applyLineStyle (context);
        if (getDrawMode ().integralMode ())
        {
            r = pixelAlligned (r);
            applyLineWidthCTM (context);
        }

        CGContextAddEllipseInRect (context, r);
        CGContextDrawPath (context, m);

        releaseCGContext (context);
    }
}
Esempio n. 2
0
//-----------------------------------------------------------------------------
void CGDrawContext::drawLines (const LineList& lines)
{
    if (lines.size () == 0)
        return;
    CGContextRef context = beginCGContext (true, getDrawMode ().integralMode ());
    if (context)
    {
        applyLineStyle (context);

        CGPoint* cgPoints = new CGPoint[lines.size () * 2];
        uint32_t index = 0;
        VSTGUI_RANGE_BASED_FOR_LOOP(LineList, lines, LinePair, line)
        cgPoints[index] = CGPointFromCPoint (line.first);
        cgPoints[index+1] = CGPointFromCPoint (line.second);
        if (getDrawMode ().integralMode ())
        {
            cgPoints[index] = pixelAlligned (cgPoints[index]);
            cgPoints[index+1] = pixelAlligned (cgPoints[index+1]);
        }
        index += 2;
        VSTGUI_RANGE_BASED_FOR_LOOP_END

        if (getDrawMode ().integralMode ())
        {
            int32_t frameWidth = static_cast<int32_t> (currentState.frameWidth);
            if (frameWidth % 2)
                CGContextTranslateCTM (context, 0.5, 0.5);
        }

        CGContextStrokeLineSegments (context, cgPoints, lines.size () * 2);
        delete [] cgPoints;

        releaseCGContext (context);
    }
}
Esempio n. 3
0
//-----------------------------------------------------------------------------
void CGDrawContext::drawLine (const LinePair& line)
{
    CGContextRef context = beginCGContext (true, getDrawMode ().integralMode ());
    if (context)
    {
        applyLineStyle (context);

        CGContextBeginPath (context);
        CGPoint first = CGPointFromCPoint (line.first);
        CGPoint second = CGPointFromCPoint (line.second);

        if (getDrawMode ().integralMode ())
        {
            first = pixelAlligned (first);
            second = pixelAlligned (second);

            int32_t frameWidth = static_cast<int32_t> (currentState.frameWidth);
            if (frameWidth % 2)
                CGContextTranslateCTM (context, 0.5, 0.5);
        }

        CGContextMoveToPoint (context, first.x, first.y);
        CGContextAddLineToPoint (context, second.x, second.y);

        CGContextDrawPath (context, kCGPathStroke);
        releaseCGContext (context);
    }
}
Esempio n. 4
0
//-----------------------------------------------------------------------------
void CGDrawContext::drawGraphicsPath (CGraphicsPath* _path, PathDrawMode mode, CGraphicsTransform* t)
{
    QuartzGraphicsPath* path = dynamic_cast<QuartzGraphicsPath*> (_path);
    if (path == 0)
        return;

    CGContextRef context = beginCGContext (true, getDrawMode ().integralMode ());
    if (context)
    {
        CGPathDrawingMode cgMode;
        switch (mode)
        {
        case kPathFilledEvenOdd:
        {
            cgMode = kCGPathEOFill;
            break;
        }
        case kPathStroked:
        {
            cgMode = kCGPathStroke;
            applyLineStyle (context);
            break;
        }
        default:
        {
            cgMode = kCGPathFill;
            break;
        }
        }

        if (getDrawMode ().integralMode ())
        {
            applyLineWidthCTM (context);
            path->pixelAlign (this, t);
            CGContextAddPath (context, path->getCGPathRef ());
        }
        else if (t)
        {
            CGContextSaveGState (context);
            CGAffineTransform transform = QuartzGraphicsPath::createCGAffineTransform (*t);
            CGContextConcatCTM (context, transform);
            CGContextAddPath (context, path->getCGPathRef ());
            CGContextRestoreGState (context);
        }
        else
            CGContextAddPath (context, path->getCGPathRef ());

        CGContextDrawPath (context, cgMode);

        releaseCGContext (context);
    }
}
Esempio n. 5
0
//-----------------------------------------------------------------------------
void CGDrawContext::clearRect (const CRect& rect)
{
    CGContextRef context = beginCGContext (true, getDrawMode ().integralMode ());
    if (context)
    {
        CGRect cgRect = CGRectFromCRect (rect);
        if (getDrawMode ().integralMode ())
        {
            cgRect = pixelAlligned (cgRect);
        }
        CGContextClearRect (context, cgRect);
        releaseCGContext (context);
    }
}
Esempio n. 6
0
//-----------------------------------------------------------------------------
void CGDrawContext::drawArc (const CRect &rect, const float _startAngle, const float _endAngle, const CDrawStyle drawStyle) // in degree
{
    CGContextRef context = beginCGContext (true, getDrawMode ().integralMode ());
    if (context)
    {
        CGPathDrawingMode m;
        switch (drawStyle)
        {
        case kDrawFilled :
            m = kCGPathFill;
            break;
        case kDrawFilledAndStroked :
            m = kCGPathFillStroke;
            break;
        default :
            m = kCGPathStroke;
            break;
        }
        applyLineStyle (context);

        CGContextBeginPath (context);
        CGDrawContextInternal::addOvalToPath (context, CPoint (rect.left + rect.getWidth () / 2., rect.top + rect.getHeight () / 2.), static_cast<CGFloat> (rect.getWidth () / 2.), static_cast<CGFloat> (rect.getHeight () / 2.), _startAngle, _endAngle);
        CGContextDrawPath (context, m);
        releaseCGContext (context);
    }
}
Esempio n. 7
0
  void 
  RSphericalParticles::notifyNewColorData()
  {
    switch (getDrawMode())
      {
      case SINGLE_COLOR:
	{
	  for (size_t i(0); i < _N; ++i)
	    for (size_t cc(0); cc < 4; ++cc)
	      _particleColorData[i].s[cc] = _colorFixed.s[cc];
	  break;
	}
      case COLOR_BY_ID:
	{
	  for (size_t i(0); i < _N; ++i)
	    map(_particleColorData[i], ((float)(i)) / _N);
	  break;
	}
      default:
	M_throw() << "Not Implemented";
      }

    CoilRegister::getCoilInstance().getTaskQueue()
      .queueTask(magnet::function::Task::makeTask(&RSphericalParticles::sendColorDataWorker,this));
  }
Esempio n. 8
0
//-----------------------------------------------------------------------------
void CGDrawContext::fillLinearGradient (CGraphicsPath* _path, const CGradient& gradient, const CPoint& startPoint, const CPoint& endPoint, bool evenOdd, CGraphicsTransform* t)
{
    QuartzGraphicsPath* path = dynamic_cast<QuartzGraphicsPath*> (_path);
    if (path == 0)
        return;

    const QuartzGradient* cgGradient = dynamic_cast<const QuartzGradient*> (&gradient);
    if (cgGradient == 0)
        return;

    CGContextRef context = beginCGContext (true, getDrawMode ().integralMode ());
    if (context)
    {
        CGPoint start = CGPointFromCPoint (startPoint);
        CGPoint end = CGPointFromCPoint (endPoint);
        if (getDrawMode ().integralMode ())
        {
            path->pixelAlign (this, t);
            applyLineWidthCTM (context);
            CGContextAddPath (context, path->getCGPathRef ());
            start = pixelAlligned (start);
            end = pixelAlligned (end);
        }
        else if (t)
        {
            CGContextSaveGState (context);
            CGAffineTransform transform = QuartzGraphicsPath::createCGAffineTransform (*t);
            CGContextConcatCTM (context, transform);
            CGContextAddPath (context, path->getCGPathRef ());
            CGContextRestoreGState (context);
        }
        else
            CGContextAddPath (context, path->getCGPathRef ());

        if (evenOdd)
            CGContextEOClip (context);
        else
            CGContextClip (context);

        CGContextDrawLinearGradient (context, *cgGradient, start, end, kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);

        releaseCGContext (context);
    }
}
Esempio n. 9
0
JSONDrawArrayLengths::JSONDrawArrayLengths(osg::DrawArrayLengths& array)
{
    getMaps()["First"] = new JSONValue<int>(array.getFirst());
    getMaps()["Mode"] = getDrawMode(array.getMode());

    JSONArray* jsonArray = new JSONArray;
    for (unsigned int i = 0; i < array.size(); i++) {
        jsonArray->getArray().push_back(new JSONValue<int>(array[i]));
    }
    getMaps()["ArrayLengths"] = jsonArray;
}
Esempio n. 10
0
void Circle::draw(DisplayBuffer &buffer)
{
  int x = m_radius;
  int y = 0;
  int decisionOver2 = 1 - x;
  
  // Draw on a temp buffer and then bring over to the main buffer when done.
  // This is required at the moment since this circle drawing alg has a fair
  // amount of overdraw, and the Toggle drawmode wouldn't work with that.
  DisplayBuffer tempBuffer({ m_radius * 2 + 1, m_radius * 2 + 1 });
  
  // Alg for drawing a circle
  while(y <= x)
  {
    int jump = m_filled ? 1 : (x * 2);
    
    for (int i = -x; i <= x; i += jump)
    {
      tempBuffer.set({ (double)i + m_radius,  (double)y + m_radius  }, DrawMode::Set);
      tempBuffer.set({ (double)i + m_radius,  (double)-y + m_radius }, DrawMode::Set);
      tempBuffer.set({ (double)y + m_radius,  (double)i + m_radius  }, DrawMode::Set);
      tempBuffer.set({ (double)-y + m_radius, (double)i + m_radius  }, DrawMode::Set);
    }
    
    y++;
    
    if (decisionOver2<=0) decisionOver2 += 2 * y + 1;
    
    else
    {
      x--;
      decisionOver2 += 2 * (y - x) + 1;
    }
  }
  
  // Copy the temp buffer over to the main buffer
  for (int x = 0; x < tempBuffer.getViewport().width; ++x)
  {
    for (int y = 0; y < tempBuffer.getViewport().height; ++y)
    {
      if (tempBuffer.get({ (double)x, (double)y }))
      {
        DisplayPoint point
        {
          x - m_radius + getPosition().x,
          y - m_radius + getPosition().y
        };
        
        buffer.set(point, getDrawMode());
      }
    }
  }
}
Esempio n. 11
0
//-----------------------------------------------------------------------------
void CGDrawContext::fillRadialGradient (CGraphicsPath* _path, const CGradient& gradient, const CPoint& center, CCoord radius, const CPoint& originOffset, bool evenOdd, CGraphicsTransform* t)
{
    QuartzGraphicsPath* path = dynamic_cast<QuartzGraphicsPath*> (_path);
    if (path == 0)
        return;

    const QuartzGradient* cgGradient = dynamic_cast<const QuartzGradient*> (&gradient);
    if (cgGradient == 0)
        return;

    CGContextRef context = beginCGContext (true, getDrawMode ().integralMode ());
    if (context)
    {
        if (getDrawMode ().integralMode ())
        {
            path->pixelAlign (this, t);
            CGContextAddPath (context, path->getCGPathRef ());
        }
        else if (t)
        {
            CGContextSaveGState (context);
            CGAffineTransform transform = QuartzGraphicsPath::createCGAffineTransform (*t);
            CGContextConcatCTM (context, transform);
            CGContextAddPath (context, path->getCGPathRef ());
            CGContextRestoreGState (context);
        }
        else
            CGContextAddPath (context, path->getCGPathRef ());

        if (evenOdd)
            CGContextEOClip (context);
        else
            CGContextClip (context);

        CPoint startCenter = center + originOffset;
        CGContextDrawRadialGradient (context, *cgGradient, CGPointFromCPoint (startCenter), 0, CGPointFromCPoint (center), static_cast<CGFloat> (radius), kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);

        releaseCGContext (context);
    }
}
Esempio n. 12
0
//-----------------------------------------------------------------------------
void CGDrawContext::drawPolygon (const PointList& polygonPointList, const CDrawStyle drawStyle)
{
    if (polygonPointList.size () == 0)
        return;
    CGContextRef context = beginCGContext (true, getDrawMode ().integralMode ());
    if (context)
    {
        CGPathDrawingMode m;
        switch (drawStyle)
        {
        case kDrawFilled :
            m = kCGPathFill;
            break;
        case kDrawFilledAndStroked :
            m = kCGPathFillStroke;
            break;
        default :
            m = kCGPathStroke;
            break;
        }
        applyLineStyle (context);

        CGContextBeginPath (context);
        CGPoint p = CGPointFromCPoint(polygonPointList[0]);
        if (getDrawMode ().integralMode ())
            p = pixelAlligned (p);
        CGContextMoveToPoint (context, p.x, p.y);
        for (uint32_t i = 1; i < polygonPointList.size (); i++)
        {
            p = CGPointFromCPoint (polygonPointList[i]);
            if (getDrawMode ().integralMode ())
                p = pixelAlligned (p);
            CGContextAddLineToPoint (context, p.x, p.y);
        }
        CGContextDrawPath (context, m);
        releaseCGContext (context);
    }
}
Esempio n. 13
0
unsigned int nRenderer::drawNode(nRTreeNode *node, unsigned int lev){
	if(node->isNull() || (node->isLeaf() && node->getChildren().size() == 1)) {
		return 0;
	}
	unsigned int nodes = 1;
	unsigned int mod = lev % 7 + 1;
	glColor3d((mod & 0b001) ? 1 : 0, (mod & 0b010) ? 1 : 0, (mod & 0b100) ? 1 : 0);
	DrawMode m = getDrawMode();
	setDrawMode(WireFrame);
	setAttribute(BackFaceCulling, false);
	drawBox(nBoundingBox::create(node->getNegative(), node->getPositive()));
	if(!node->isLeaf()) {
		list<nRTreeNode *> lst = node->getSubNodes();
		for(list<nRTreeNode *>::iterator it = lst.begin(); it != lst.end(); it++) {
			nodes += drawNode(*it, lev + 1);
		}
	}
	setAttribute(BackFaceCulling, true);
	setDrawMode(m);
	nMaterial::release();
	return nodes;
}
Esempio n. 14
0
JSONDrawArray::JSONDrawArray(osg::DrawArrays& array) 
{
    getMaps()["First"] = new JSONValue<int>(array.getFirst());
    getMaps()["Count"] = new JSONValue<int>(array.getCount());
    getMaps()["Mode"] = getDrawMode(array.getMode());
}