void GraphicsContext::fillRoundedRect(const RoundedRect& rect, const Color& color, ColorSpace colorSpace) { if (rect.isRounded()) fillRoundedRect(rect.rect(), rect.radii().topLeft(), rect.radii().topRight(), rect.radii().bottomLeft(), rect.radii().bottomRight(), color, colorSpace); else fillRect(rect.rect(), color, colorSpace); }
static void drawAndFillRoundedRect(double x, double y, double width, double height, double r, string color) { gwp->setColor(color); fillRoundedRect(x, y,width, height, r); gwp->setColor("Black"); drawRoundedRect(x, y, width, height, r); }
void GraphicsContext::fillRoundedRect(const RoundedRect& rect, const Color& color, ColorSpace colorSpace, BlendMode blendMode) { if (rect.isRounded()) { setCompositeOperation(compositeOperation(), blendMode); fillRoundedRect(rect.rect(), rect.radii().topLeft(), rect.radii().topRight(), rect.radii().bottomLeft(), rect.radii().bottomRight(), color, colorSpace); setCompositeOperation(compositeOperation()); } else fillRect(rect.rect(), color, colorSpace, compositeOperation(), blendMode); }
/* OvalTeenDrawEventHandler : Handles the draw events for the "Ovalteen" window. Parameter DescriptionsinHandler : A reference to the current handler call chain. This is passed to your handler so that you can call CallNextEventHandler if you need to. inEvent : The event that triggered this call. inUserData : The application-specific data you passed in to InstallEventHandler. */ OSStatus OvalTeenDrawEventHandler (EventHandlerCallRef inHandler, EventRef inEvent, void* inUserData) { OSStatus status = eventNotHandledErr; CGContextRef context; CGRect bounds; double a, b; int count, k; //CallNextEventHandler in order to make sure the default handling of the inEvent // (drawing the white background) happens status = CallNextEventHandler( inHandler, inEvent ); require_noerr(status, CantCallNextEventHandler); // Get the CGContextRef status = GetEventParameter (inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof (CGContextRef), NULL, &context); require_noerr(status, CantGetEventParameter); // Get the bounding rectangle status = HIViewGetBounds ((HIViewRef) inUserData, &bounds); require_noerr(status, CantGetViewBounds); // Calculate the dimensions for an oval inside the bounding box a = 0.9 * bounds.size.width/4; b = 0.3 * bounds.size.height/2; count = 5; // Set the fill color to a partially transparent blue CGContextSetRGBFillColor(context, 0, 0, 1, 0.5); // Set the stroke color to an opaque black CGContextSetRGBStrokeColor(context, 0, 0, 0, 1); // Set the line width to be used, in user space units. CGContextSetLineWidth(context, 3); // Save the conexts state because we are going to be moving the origin and // rotating context for drawing, but we would like to restore the current // state before drawing the next image. CGContextSaveGState(context); // Move the origin to the middle of the first image (left side) to draw. CGContextTranslateCTM(context, bounds.size.width/4, bounds.size.height/2); // Draw "count" ovals, rotating the context around the newly translated origin // 1/count radians after drawing each oval for (k = 0; k < count; k++) { // Paint the oval with the fill color paintOval(context, CGRectMake(-a, -b, 2 * a, 2 * b)); // Frame the oval with the stroke color frameOval(context, CGRectMake(-a, -b, 2 * a, 2 * b)); // Rotate the context around the center of the image CGContextRotateCTM(context, pi / count); } // Restore the saved state to a known state for dawing the next image CGContextRestoreGState(context); // Calculate a bounding box for the rounded rect a = 0.9 * bounds.size.width/4; b = 0.3 * bounds.size.height/2; count = 5; // Set the fill color to a partially transparent red CGContextSetRGBFillColor(context, 1, 0, 0, 0.5); // Set the stroke color to an opaque black CGContextSetRGBStrokeColor(context, 0, 0, 0, 1); // Set the line width to be used, in user space units. CGContextSetLineWidth(context, 3); // Save the conexts state because we are going to be moving the origin and // rotating context for drawing, but we would like to restore the current // state before drawing the next image. CGContextSaveGState(context); // Move the origin to the middle of the second image (right side) to draw. CGContextTranslateCTM(context, bounds.size.width/4 + bounds.size.width/2, bounds.size.height/2); for (k = 0; k < count; k++) { // Fill then stroke the rounding rect, otherwise the fill would cover the stroke fillRoundedRect(context, CGRectMake(-a, -b, 2 * a, 2 * b), 20, 20); strokeRoundedRect(context, CGRectMake(-a, -b, 2 * a, 2 * b), 20, 20); // Rotate the context for the next rounded rect CGContextRotateCTM(context, pi / count); } CGContextRestoreGState(context); CantCallNextEventHandler: CantGetEventParameter: CantGetViewBounds: return status; }