本文整理匯總了C++中CGContextBeginPath函數的典型用法代碼示例。如果您正苦於以下問題:C++ CGContextBeginPath函數的具體用法?C++ CGContextBeginPath怎麽用?C++ CGContextBeginPath使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CGContextBeginPath函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: doStrokeWithCTM
void doStrokeWithCTM(CGContextRef context)
{
CGContextTranslateCTM(context, 150., 180.);
CGContextSetLineWidth(context, 10);
// Draw ellipse 1 with a uniform stroke.
CGContextSaveGState(context);
// Scale the CTM so the circular arc will be elliptical.
CGContextScaleCTM(context, 2, 1);
CGContextBeginPath(context);
// Create an arc that is a circle.
CGContextAddArc(context, 0., 0., 45., 0., 2*M_PI, 0);
// Restore the context parameters prior to stroking the path.
// CGContextRestoreGState does not affect the path in the context.
CGContextRestoreGState(context);
CGContextStrokePath(context);
// *** was 0, -120
CGContextTranslateCTM(context, 220., 0.);
// Draw ellipse 2 with non-uniform stroke.
CGContextSaveGState(context);
// Scale the CTM so the circular arc will be elliptical.
CGContextScaleCTM(context, 2, 1);
CGContextBeginPath(context);
// Create an arc that is a circle.
CGContextAddArc(context, 0., 0., 45., 0., 2*M_PI, 0);
// Stroke the path with the scaled coordinate system in effect.
CGContextStrokePath(context);
CGContextRestoreGState(context);
}
示例2: RestoreApplicationDockTileImage
void MacDock::overlay(const QString& text)
{
if (text.isEmpty()) {
overlayed = false;
RestoreApplicationDockTileImage();
return;
}
// Create the context
CGContextRef context = BeginCGContextForApplicationDockTile();
if (!overlayed) {
overlayed = true;
// Add some subtle drop down shadow
// FIXME: Disabled because 10.2 doesn't support it
//CGSize s = { 2.0, -4.0 };
//CGContextSetShadow(context,s,5.0);
}
// Draw a circle
CGContextBeginPath(context);
CGContextAddArc(context, 95.0, 95.0, 25.0, 0.0, 2 * M_PI, true);
CGContextClosePath(context);
CGContextSetRGBFillColor(context, 1, 0.0, 0.0, 1);
CGContextFillPath(context);
// Set the clipping path to the same circle
CGContextBeginPath(context);
CGContextAddArc(context, 95.0, 95.0, 25.0, 0.0, 2 * M_PI, true);
CGContextClip(context);
// Remove drop shadow
// FIXME: Disabled because 10.2 doesn't support it
//CGSize s = { 0.0, -0.0 };
//CGContextSetShadowWithColor(context, s, 0, NULL);
// Select the appropriate font
CGContextSelectFont(context,DOCK_FONT_NAME, DOCK_FONT_SIZE, kCGEncodingMacRoman);
CGContextSetRGBFillColor(context, 1, 1, 1, 1);
// Draw the text invisible
CGPoint begin = CGContextGetTextPosition(context);
CGContextSetTextDrawingMode(context, kCGTextInvisible);
CGContextShowTextAtPoint(context, begin.x, begin.y, text.toStdString().c_str(), text.length());
CGPoint end = CGContextGetTextPosition(context);
// Draw the text
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextShowTextAtPoint(context, 95 - (end.x - begin.x)/2, 95 - 8, text.toStdString().c_str(), text.length());
// Cleanup
CGContextFlush(context);
EndCGContextForApplicationDockTile(context);
}
示例3: doIndexedColorDrawGraphics
void doIndexedColorDrawGraphics(CGContextRef context)
{
CGColorSpaceRef theBaseRGBSpace = getTheCalibratedRGBColorSpace();
CGColorSpaceRef theIndexedSpace = NULL;
unsigned char lookupTable[6];
float opaqueRed[] = { 0, 1 }; // index, alpha
float aBlue[] = { 1, 1 }; // index, alpha
// Set the first 3 values in the lookup table to a red of
// 169/255 = 0.663, no green, and blue = 8/255 = 0.031. This makes
// the first entry in the lookup table a shade of red.
lookupTable[0] = 169; lookupTable[1] = 0; lookupTable[2] = 8;
// Set the second 3 values in the lookup table to a red value
// of 123/255 = 0.482, a green value of 158/255 = 0.62, and
// a blue value of 222/255 = 0.871. This makes the second entry
// in the lookup table a shade of blue.
lookupTable[3] = 123; lookupTable[4] = 158; lookupTable[5] = 222;
// Create the indexed color space with this color lookup table,
// using the RGB color space as the base color space and a 2 element
// color lookup table to characterize the indexed color space.
theIndexedSpace = CGColorSpaceCreateIndexed(theBaseRGBSpace, 1, lookupTable);
if(theIndexedSpace != NULL){
CGContextSetStrokeColorSpace(context, theIndexedSpace);
CGContextSetFillColorSpace(context, theIndexedSpace);
// Release the color space this code created since it is no
// longer needed in this routine.
CGColorSpaceRelease(theIndexedSpace);
// Set the stroke color to an opaque blue.
CGContextSetStrokeColor(context, aBlue);
// Set the fill color to an opaque red.
CGContextSetFillColor(context, opaqueRed);
CGContextSetLineWidth(context, 8.);
// Draw the first rectangle.
CGContextBeginPath(context);
CGContextAddRect(context, CGRectMake(20., 20., 100., 100.));
CGContextDrawPath(context, kCGPathFillStroke);
// Continue to use the stroke colorspace already set
// but change the stroke alpha value to a semitransparent value
// while leaving the index value unchanged.
aBlue[1] = 0.5;
CGContextSetStrokeColor(context, aBlue);
// Draw another rectangle to the right of the first one.
CGContextBeginPath(context);
CGContextAddRect(context, CGRectMake(140., 20., 100., 100.));
CGContextDrawPath(context, kCGPathFillStroke);
}else
fprintf(stderr, "Couldn't make the indexed color space!\n");
}
示例4: Quartz_Circle
static void Quartz_Circle(double x, double y, double r,
R_GE_gcontext *gc,
NewDevDesc *dd)
{
QuartzDesc *xd = (QuartzDesc*)dd->deviceSpecific;
CGContextSaveGState( GetContext(xd) );
CGContextBeginPath( GetContext(xd) );
Quartz_SetLineProperties(gc, dd);
CGContextAddArc( GetContext(xd), (float)x , (float)y, (float)r, 3.141592654 * 2.0, 0.0, 0);
Quartz_SetFill( gc->fill, gc->gamma, dd);
CGContextFillPath( GetContext(xd) );
Quartz_SetStroke( gc->col, gc->gamma, dd);
CGContextAddArc( GetContext(xd), (float)x , (float)y, (float)r, 3.141592654 * 2.0, 0.0, 0);
CGContextStrokePath( GetContext(xd) );
CGContextRestoreGState( GetContext(xd) );
}
示例5: ScratchContext
bool
PathCG::StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
const Point &aPoint,
const Matrix &aTransform) const
{
Matrix inverse = aTransform;
inverse.Invert();
Point transformedPoint = inverse*aPoint;
// We could probably drop the input transform and just transform the point at the caller?
CGPoint point = {transformedPoint.x, transformedPoint.y};
CGContextRef cg = ScratchContext();
CGContextSaveGState(cg);
CGContextBeginPath(cg);
CGContextAddPath(cg, mPath);
SetStrokeOptions(cg, aStrokeOptions);
CGContextReplacePathWithStrokedPath(cg);
CGContextRestoreGState(cg);
CGPathRef sPath = CGContextCopyPath(cg);
bool inStroke = CGPathContainsPoint(sPath, nullptr, point, false);
CGPathRelease(sPath);
return inStroke;
}
示例6: beginCGContext
//-----------------------------------------------------------------------------
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);
}
}
示例7: CGContextBeginPath
void CFX_QuartzDeviceDriver::setPathToContext(const CFX_PathData* pathData)
{
FX_INT32 count = pathData->GetPointCount();
FX_PATHPOINT* points = pathData->GetPoints();
CGContextBeginPath(_context);
for (FX_INT32 i = 0; i < count; i ++) {
switch (points[i].m_Flag & FXPT_TYPE) {
case FXPT_MOVETO:
CGContextMoveToPoint(_context, points[i].m_PointX, points[i].m_PointY);
break;
case FXPT_LINETO:
CGContextAddLineToPoint(_context, points[i].m_PointX, points[i].m_PointY);
break;
case FXPT_BEZIERTO: {
CGContextAddCurveToPoint(_context,
points[i].m_PointX, points[i].m_PointY,
points[i + 1].m_PointX, points[i + 1].m_PointY,
points[i + 2].m_PointX, points[i + 2].m_PointY);
i += 2;
}
}
if (points[i].m_Flag & FXPT_CLOSEFIGURE) {
CGContextClosePath(_context);
}
}
}
示例8: beginCGContext
//-----------------------------------------------------------------------------
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);
}
}
示例9: doRotatedEllipses
void doRotatedEllipses(CGContextRef context)
{
int i, totreps = 144;
float tint = 1.0, tintIncrement = 1.0/totreps;
// Create a new transform consisting of a 45 degrees rotation.
CGAffineTransform theTransform = CGAffineTransformMakeRotation(M_PI/4);
// Apply a scale to the transform just created.
theTransform = CGAffineTransformScale(theTransform, 1, 2);
// Place the first ellipse at a good location.
CGContextTranslateCTM(context, 100., 100.);
for(i=0 ; i < totreps ; i++){
// Make a snapshot the coordinate system.
CGContextSaveGState(context);
// Set up the coordinate system for the rotated ellipse.
CGContextConcatCTM(context, theTransform);
CGContextBeginPath(context);
CGContextAddArc(context, 0., 0., 45., 0., 2*M_PI, 0);
// Set the fill color for this instance of the ellipse.
CGContextSetRGBFillColor(context, tint, 0., 0., 1.0);
CGContextDrawPath(context, kCGPathFill);
// Restore the coordinate system to that of the snapshot.
CGContextRestoreGState(context);
// Compute the next tint color.
tint -= tintIncrement;
// Move over by 1 unit in x for the next ellipse.
CGContextTranslateCTM(context, 1.0, 0.0);
}
}
示例10: Quartz_Polyline
static void Quartz_Polyline(int n, double *x, double *y,
R_GE_gcontext *gc,
NewDevDesc *dd)
{
CGPoint *lines;
int i;
CGrafPtr savedPort, port;
QuartzDesc *xd = (QuartzDesc*)dd->deviceSpecific;
lines = (CGPoint *)malloc(sizeof(CGPoint)*n);
if(lines == NULL)
return;
for (i = 0; i < n; i++) {
lines[i].x = (float)x[i];
lines[i].y = (float)y[i];
}
CGContextSaveGState( GetContext(xd) );
CGContextBeginPath( GetContext(xd) );
Quartz_SetLineProperties(gc, dd);
CGContextAddLines( GetContext(xd), &lines[0], n );
Quartz_SetStroke( gc->col, gc->gamma, dd);
CGContextStrokePath( GetContext(xd) );
CGContextRestoreGState( GetContext(xd) );
}
示例11: Quartz_Line
static void Quartz_Line(double x1, double y1, double x2, double y2,
R_GE_gcontext *gc,
NewDevDesc *dd)
{
QuartzDesc *xd = (QuartzDesc*)dd->deviceSpecific;
CGPoint lines[ 2 ];
Rect rect;
CGContextSaveGState( GetContext(xd) );
CGContextBeginPath( GetContext(xd) );
lines[0].x = (float)x1;
lines[0].y = (float)y1;
lines[1].x = (float)x2;
lines[1].y = (float)y2;
Quartz_SetLineProperties(gc, dd);
CGContextAddLines( GetContext(xd), &lines[0], 2 );
Quartz_SetStroke( gc->col, gc->gamma, dd);
CGContextStrokePath( GetContext(xd) );
CGContextRestoreGState( GetContext(xd) );
}
示例12: addOvalToPath
void addOvalToPath(CGContextRef context, CGRect r)
{
CGAffineTransform matrix;
// Save the context's state because we are going to transform and scale it
CGContextSaveGState(context);
// Create a transform to scale the context so that a radius of 1
// is equal to the bounds of the rectangle, and transform the origin
// of the context to the center of the bounding rectangle. The
// center of the bounding rectangle will now be the center of
// the oval.
matrix = CGAffineTransformMake((r.size.width)/2, 0,
0, (r.size.height)/2,
r.origin.x + (r.size.width)/2,
r.origin.y + (r.size.height)/2);
// Apply the transform to the context
CGContextConcatCTM(context, matrix);
// Signal the start of a path
CGContextBeginPath(context);
// Add a circle to the path. After the circle is transformed by the
// context's transformation matrix, it will become an oval lying
// just inside the bounding rectangle.
CGContextAddArc(context, 0, 0, 1, 0, 2*pi, true);
// Restore the context's state. This removes the translation and scaling but leaves
// the path, since the path is not part of the graphics state.
CGContextRestoreGState(context);
}
示例13: platformContext
void GraphicsContext::drawPath(const Path& path)
{
if (paintingDisabled())
return;
CGContextRef context = platformContext();
const GraphicsContextState& state = m_state;
if (state.fillGradient || state.strokeGradient) {
// We don't have any optimized way to fill & stroke a path using gradients
// FIXME: Be smarter about this.
fillPath(path);
strokePath(path);
return;
}
CGContextBeginPath(context);
CGContextAddPath(context, path.platformPath());
if (state.fillPattern)
applyFillPattern();
if (state.strokePattern)
applyStrokePattern();
CGPathDrawingMode drawingMode;
if (calculateDrawingMode(state, drawingMode))
CGContextDrawPath(context, drawingMode);
}
示例14: focusRingOffset
void GraphicsContext::drawFocusRing(const Color& color)
{
if (paintingDisabled())
return;
float radius = (focusRingWidth() - 1) / 2.0f;
int offset = radius + focusRingOffset();
CGColorRef colorRef = color.isValid() ? cgColor(color) : 0;
CGMutablePathRef focusRingPath = CGPathCreateMutable();
const Vector<IntRect>& rects = focusRingRects();
unsigned rectCount = rects.size();
for (unsigned i = 0; i < rectCount; i++)
CGPathAddRect(focusRingPath, 0, CGRectInset(rects[i], -offset, -offset));
CGContextRef context = platformContext();
CGContextSaveGState(context);
CGContextBeginPath(context);
CGContextAddPath(context, focusRingPath);
wkDrawFocusRing(context, colorRef, radius);
CGColorRelease(colorRef);
CGPathRelease(focusRingPath);
CGContextRestoreGState(context);
}
示例15: drawRoundedRect
void drawRoundedRect(CGContextRef context, int x, int y){
struct CGRect cgRect;
struct CGPoint cgPoint;
cgRect.size.width = 640;
cgRect.size.height = y+30;
cgPoint.x = 0;
cgPoint.y = 5;
cgRect.origin = cgPoint;
//printf("Drawing %f, %f, %f, %f", cgPoint.x, cgPoint.y, cgRect.size.width, cgRect.size.height);
CGContextBeginPath(context);
float ovalWidth = 10;
float ovalHeight = 10;
float fw, fh;
// If the width or height of the corner oval is zero, then it reduces to a right angle,
// so instead of a rounded rectangle we have an ordinary one.
if (ovalWidth == 0 || ovalHeight == 0) {
CGContextAddRect(context, cgRect);
return;
}
// Save the context's state so that the translate and scale can be undone with a call
// to CGContextRestoreGState.
CGContextSaveGState(context);
// Translate the origin of the contex to the lower left corner of the rectangle.
CGContextTranslateCTM(context, CGRectGetMinX(cgRect), CGRectGetMinY(cgRect));
//Normalize the scale of the context so that the width and height of the arcs are 1.0
CGContextScaleCTM(context, ovalWidth, ovalHeight);
// Calculate the width and height of the rectangle in the new coordinate system.
fw = CGRectGetWidth(cgRect) / ovalWidth;
fh = CGRectGetHeight(cgRect) / ovalHeight;
// CGContextAddArcToPoint adds an arc of a circle to the context's path (creating the rounded
// corners). It also adds a line from the path's last point to the begining of the arc, making
// the sides of the rectangle.
CGContextMoveToPoint(context, fw, fh/2); // Start at lower right corner
CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1); // Top right corner
CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1); // Top left corner
CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1); // Lower left corner
CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1); // Back to lower right
// Close the path
CGContextClosePath(context);
CGContextSetRGBFillColor (context, 1, 1, 1, 0.7);
CGContextFillPath(context);
CGContextRestoreGState(context);
}