Ejemplo n.º 1
0
void JBGStrokePathByLines(CGContextRef ctx, CGPathRef path, CGColorRef color_1, CGFloat width_1, CGColorRef color_2, CGFloat width_2, CGColorRef color_3, CGFloat width_3)
{
    if (width_1 > 0.0f)
    {
        CGContextSetLineWidth(ctx, width_1);
        CGContextAddPath(ctx, path);
        CGContextSetStrokeColorWithColor(ctx, color_1);
        CGContextStrokePath(ctx);
    }

    if (width_2 > 0.0f)
    {
        CGContextAddPath(ctx, path);
        CGContextSetStrokeColorWithColor(ctx, color_2);
        CGContextSetLineWidth(ctx, width_2);
        CGContextStrokePath(ctx);
    }
    
    if (width_3 > 0.0f)
    {
        CGContextAddPath(ctx, path);
        CGContextSetStrokeColorWithColor(ctx, color_3);
        CGContextSetLineWidth(ctx, width_3);
        CGContextStrokePath(ctx);
    }
}
void drawWithColorRefs(CGContextRef context)
{
	static CGColorRef opaqueRedColor = NULL, opaqueBlueColor = NULL, transparentBlueColor = NULL;

	// Initialize the CGColorRefs if necessary
	if(opaqueRedColor == NULL){
		// Initialize the color array to an opaque red 
		// in the generic calibrated RGB color space.
		float color[4] = { 0.663, 0.0, 0.031, 1.0 };
		CGColorSpaceRef theColorSpace = getTheCalibratedRGBColorSpace();
		// Create a CGColorRef for opaque red.
		opaqueRedColor = CGColorCreate(theColorSpace, color);
		// Make the color array correspond to an opaque blue color.
		color[0] = 0.482; color[1] = 0.62; color[2] = 0.871;
		// Create another CGColorRef for opaque blue.
		opaqueBlueColor = CGColorCreate(theColorSpace, color);
		// Create a new CGColorRef from the opaqueBlue CGColorRef 
		// but with a different alpha value.
		transparentBlueColor = CGColorCreateCopyWithAlpha(opaqueBlueColor, 0.5);
		if(!(opaqueRedColor && opaqueBlueColor && transparentBlueColor)){
		    fprintf(stderr, "Couldn't create one of the CGColorRefs!!!\n");
		    return;
		}
	}

	// Set the fill color to the opaque red CGColor object.
	CGContextSetFillColorWithColor(context, opaqueRedColor);
	// Set the stroke color to the opaque blue CGColor object.
	CGContextSetStrokeColorWithColor(context, opaqueBlueColor);
	
	CGContextSetLineWidth(context, 8.);
	// Draw the first rectangle.
	CGContextBeginPath(context);
	CGContextAddRect(context, CGRectMake(20., 20., 100., 100.));
	CGContextDrawPath(context, kCGPathFillStroke);
    
	// Set the stroke color to be that of the transparent blue 
	// CGColor object.
	CGContextSetStrokeColorWithColor(context, transparentBlueColor);	
	// Draw a second rectangle to the right of the first one.
	CGContextBeginPath(context);
 	CGContextAddRect(context, CGRectMake(140., 20., 100., 100.));
	CGContextDrawPath(context, kCGPathFillStroke);
}
Ejemplo n.º 3
0
//-----------------------------------------------------------------------------
void CGDrawContext::setFrameColor (const CColor& color)
{
    if (currentState.frameColor == color)
        return;

    if (cgContext)
        CGContextSetStrokeColorWithColor (cgContext, getCGColor (color));

    CDrawContext::setFrameColor (color);
}
Ejemplo n.º 4
0
void JBGFillGradientCircle(CGContextRef ctx, CGPoint center_1, CGFloat r_1, CGPoint center_2, CGFloat r_2, CGGradientRef fill_gradient, CGColorRef stroke_color)
{
    if (fill_gradient)
    {
        CGGradientDrawingOptions options = kCGGradientDrawsBeforeStartLocation;
        CGContextDrawRadialGradient(ctx, fill_gradient, center_1, r_1, center_2, r_2, options);
    }
    
    if (stroke_color)
    {
        CGContextSetStrokeColorWithColor(ctx, stroke_color);
        CGContextAddArc(ctx, center_2.x, center_2.y, r_2, 0, M_PI * 2, false);
        CGContextStrokePath(ctx);
    }
}
Ejemplo n.º 5
0
static void setCGStrokeColor(CGContextRef context, const Color& color, ColorSpace colorSpace)
{
    CGContextSetStrokeColorWithColor(context, cachedCGColor(color, colorSpace));
}
Ejemplo n.º 6
0
void QuartzWindow::set_color(int c) { 
  CGContextSetFillColorWithColor(   myContext, (CGColorRef)c );
  CGContextSetStrokeColorWithColor( myContext, (CGColorRef)c );
}
void doClippedEllipse(CGContextRef context)
{
    CGPoint theCenterPoint = { 120., 120. };
    CGSize theEllipseSize = { 100., 200. };
    float dash[1] = { 2 };
    static CGColorRef opaqueBrownColor = NULL, opaqueOrangeColor = NULL;
    // Initialize the CGColorRefs if necessary.
    if(opaqueBrownColor == NULL){
		// The initial value of the color array is an 
		// opaque brown in an RGB color space.
		float color[4] = { 0.325, 0.208, 0.157, 1.0 };
		CGColorSpaceRef theColorSpace = getTheCalibratedRGBColorSpace();
		// Create a CGColorRef for opaque brown.
		opaqueBrownColor = CGColorCreate(theColorSpace, color);
		// Make the color array correspond to an opaque orange.
		color[0] = 0.965 ; color[1] = 0.584; color[2] = 0.059;
		// Create another CGColorRef for opaque orange.
		opaqueOrangeColor = CGColorCreate(theColorSpace, color);
	}
	// Draw two ellipses centered about the same point, one
	// rotated 45 degrees from the other.
	CGContextSaveGState(context);
		// Ellipse 1
		createEllipsePath(context, theCenterPoint, theEllipseSize);
		CGContextSetFillColorWithColor(context, opaqueBrownColor);
		CGContextFillPath(context);
		// Translate and rotate about the center point of the ellipse.
		CGContextTranslateCTM(context, theCenterPoint.x, theCenterPoint.y);
		// Rotate by 45 degrees.
		CGContextRotateCTM(context, DEGREES_TO_RADIANS(45));
		// Ellipse 2
		// CGPointZero is a pre-defined Quartz point corresponding to 
		// the coordinate (0,0).
		createEllipsePath(context, CGPointZero, theEllipseSize);
		CGContextSetFillColorWithColor(context, opaqueOrangeColor);
		CGContextFillPath(context);
	CGContextRestoreGState(context);
	
	CGContextTranslateCTM(context, 170., 0.);
	// Now use the first ellipse as a clipping area prior to
	// painting the second ellipse.
	CGContextSaveGState(context);
		// Ellipse 3
		createEllipsePath(context, theCenterPoint, theEllipseSize);
		CGContextSetStrokeColorWithColor(context, opaqueBrownColor);
		CGContextSetLineDash(context, 0, dash, 1);
		// Stroke the path with a dash.
		CGContextStrokePath(context);
		// Ellipse 4
		createEllipsePath(context, theCenterPoint, theEllipseSize);
		// Clip to the elliptical path.
		CGContextClip(context);
		CGContextTranslateCTM(context, theCenterPoint.x, theCenterPoint.y);
		// Rotate by 45 degrees.
		CGContextRotateCTM(context, DEGREES_TO_RADIANS(45));
		// Ellipse 5
		createEllipsePath(context, CGPointZero, theEllipseSize);
		CGContextSetFillColorWithColor(context, opaqueOrangeColor);
		CGContextFillPath(context);
	CGContextRestoreGState(context);
}