//----------------------------------------------------------------------------- void CGDrawContext::drawRect (const CRect &rect, const CDrawStyle drawStyle) { CGContextRef context = beginCGContext (true, currentState.drawMode.integralMode ()); if (context) { CGPathDrawingMode m; switch (drawStyle) { case kDrawFilled : m = kCGPathFill; break; case kDrawFilledAndStroked : m = kCGPathFillStroke; break; default : m = kCGPathStroke; break; } applyLineStyle (context); CGRect r; if (currentState.drawMode.integralMode ()) { r = CGRectMake (round (rect.left), round (rect.top + 1), round (rect.width () - 1), round (rect.height () - 1)); } else { r = CGRectMake (rect.left, rect.top + 1, rect.width () - 1, rect.height () - 1); } if ((((int32_t)currentState.frameWidth) % 2)) CGContextTranslateCTM (context, 0.5f, -0.5f); CGContextBeginPath (context); CGContextAddRect (context, r); CGContextDrawPath (context, m); releaseCGContext (context); } }
//----------------------------------------------------------------------------- void CGDrawContext::drawLines (const CPoint* points, const int32_t& numLines) { CGContextRef context = beginCGContext (true, currentState.drawMode.integralMode ()); if (context) { applyLineStyle (context); if ((((int32_t)currentState.frameWidth) % 2)) CGContextTranslateCTM (context, 0.5f, -0.5f); CGPoint* cgPoints = new CGPoint[numLines*2]; for (int32_t i = 0; i < numLines * 2; i += 2) { if (currentState.drawMode.integralMode ()) { cgPoints[i].x = round (points[i].x); cgPoints[i+1].x = round (points[i+1].x); cgPoints[i].y = round (points[i].y); cgPoints[i+1].y = round (points[i+1].y); } else { cgPoints[i].x = points[i].x; cgPoints[i+1].x = points[i+1].x; cgPoints[i].y = points[i].y; cgPoints[i+1].y = points[i+1].y; } } CGContextStrokeLineSegments (context, cgPoints, numLines*2); delete [] cgPoints; releaseCGContext (context); } }
//----------------------------------------------------------------------------- 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); } }
//----------------------------------------------------------------------------- void CGDrawContext::lineTo (const CPoint& point) { CGContextRef context = beginCGContext (true, currentState.drawMode.integralMode ()); if (context) { applyLineStyle (context); if ((((int32_t)currentState.frameWidth) % 2)) CGContextTranslateCTM (context, 0.5f, -0.5f); CGContextBeginPath (context); if (currentState.drawMode.integralMode ()) { CGContextMoveToPoint (context, round (currentState.penLoc.h), round (currentState.penLoc.v)); CGContextAddLineToPoint (context, round (point.h), round (point.v)); } else { CGContextMoveToPoint (context, currentState.penLoc.h, currentState.penLoc.v); CGContextAddLineToPoint (context, point.h, point.v); } CGContextDrawPath (context, kCGPathStroke); releaseCGContext (context); } currentState.penLoc = point; }
//----------------------------------------------------------------------------- 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); } }
//----------------------------------------------------------------------------- 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); } }
//----------------------------------------------------------------------------- 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); } }
//----------------------------------------------------------------------------- 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); } }
//----------------------------------------------------------------------------- void CGDrawContext::drawEllipse (const CRect &rect, const CDrawStyle drawStyle) { CGContextRef context = beginCGContext (true, currentState.drawMode.integralMode ()); if (context) { CGPathDrawingMode m; switch (drawStyle) { case kDrawFilled : m = kCGPathFill; break; case kDrawFilledAndStroked : m = kCGPathFillStroke; break; default : m = kCGPathStroke; break; } applyLineStyle (context); if (rect.width () != rect.height ()) { CGContextSaveGState (context); CGContextBeginPath (context); CGRect cgRect = CGRectMake (rect.left, rect.top, rect.width (), rect.height ()); CGPoint center = CGPointMake (CGRectGetMidX (cgRect), CGRectGetMidY (cgRect)); CGFloat a = CGRectGetWidth (cgRect) / 2.; CGFloat b = CGRectGetHeight (cgRect) / 2.; CGContextTranslateCTM (context, center.x, center.y); CGContextScaleCTM (context, a, b); CGContextMoveToPoint (context, 1, 0); CGContextAddArc (context, 0, 0, 1, radians (0), radians (360), 0); CGContextClosePath (context); CGContextRestoreGState (context); CGContextDrawPath (context, m); } else { CGFloat radius = rect.width () * 0.5; CGContextBeginPath (context); CGContextAddArc (context, rect.left + radius, rect.top + radius, radius, radians (0), radians (360), 0); CGContextClosePath (context); CGContextDrawPath (context, m); } releaseCGContext (context); } }
//----------------------------------------------------------------------------- void CGDrawContext::drawArc (const CRect &rect, const float _startAngle, const float _endAngle, const CDrawStyle drawStyle) // in degree { CGContextRef context = beginCGContext (true, currentState.drawMode.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); addOvalToPath (context, CPoint (rect.left + rect.width () / 2, rect.top + rect.height () / 2), rect.width () / 2, rect.height () / 2, -_startAngle, -_endAngle); if (drawStyle == kDrawFilled || kDrawFilledAndStroked) CGContextAddLineToPoint (context, rect.left + rect.width () / 2, rect.top + rect.height () / 2); CGContextDrawPath (context, m); releaseCGContext (context); } }
//----------------------------------------------------------------------------- void CGDrawContext::drawPolygon (const CPoint* pPoints, int32_t numberOfPoints, const CDrawStyle drawStyle) { CGContextRef context = beginCGContext (true, currentState.drawMode.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); CGContextMoveToPoint (context, pPoints[0].h, pPoints[0].v); for (int32_t i = 1; i < numberOfPoints; i++) CGContextAddLineToPoint (context, pPoints[i].h, pPoints[i].v); CGContextDrawPath (context, m); releaseCGContext (context); } }
//----------------------------------------------------------------------------- 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); } }