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); }
DRAW_TEST_P(CGContextFillMode, OverlappedEllipses) { CGContextRef context = GetDrawingContext(); CGRect bounds = GetDrawingBounds(); bounds = CGRectInset(bounds, 16.f, 16.f); CGFloat width = bounds.size.width; CGFloat height = bounds.size.height; CGFloat xstart = bounds.origin.x; CGFloat ystart = bounds.origin.y; CGPathDrawingMode fillMode = GetParam(); CGMutablePathRef leftCircles = CGPathCreateMutable(); CGPathMoveToPoint(leftCircles, NULL, xstart + .25 * width + .4 * height, ystart + .5 * height); CGPathAddArc(leftCircles, NULL, xstart + .25 * width, ystart + .5 * height, .4 * height, 0, M_PI, true); CGPathAddArc(leftCircles, NULL, xstart + .25 * width, ystart + .5 * height, .4 * height, M_PI, 0, true); CGPathMoveToPoint(leftCircles, NULL, xstart + .25 * width + .3 * height, ystart + .5 * height); CGPathAddArc(leftCircles, NULL, xstart + .25 * width, ystart + .5 * height, .3 * height, 0, M_PI, true); CGPathAddArc(leftCircles, NULL, xstart + .25 * width, ystart + .5 * height, .3 * height, M_PI, 0, true); CGPathMoveToPoint(leftCircles, NULL, xstart + .25 * width + .2 * height, ystart + .5 * height); CGPathAddArc(leftCircles, NULL, xstart + .25 * width, ystart + .5 * height, .2 * height, 0, M_PI, true); CGPathAddArc(leftCircles, NULL, xstart + .25 * width, ystart + .5 * height, .2 * height, M_PI, 0, true); CGPathMoveToPoint(leftCircles, NULL, xstart + .25 * width + .1 * height, ystart + .5 * height); CGPathAddArc(leftCircles, NULL, xstart + .25 * width, ystart + .5 * height, .1 * height, 0, M_PI, true); CGPathAddArc(leftCircles, NULL, xstart + .25 * width, ystart + .5 * height, .1 * height, M_PI, 0, true); CGPathCloseSubpath(leftCircles); CGMutablePathRef rightCircles = CGPathCreateMutable(); CGPathMoveToPoint(rightCircles, NULL, xstart + .75 * width + .4 * height, ystart + .5 * height); CGPathAddArc(rightCircles, NULL, xstart + .75 * width, ystart + .5 * height, .4 * height, 0, M_PI, false); CGPathAddArc(rightCircles, NULL, xstart + .75 * width, ystart + .5 * height, .4 * height, M_PI, 0, false); CGPathMoveToPoint(rightCircles, NULL, xstart + .75 * width + .3 * height, ystart + .5 * height); CGPathAddArc(rightCircles, NULL, xstart + .75 * width, ystart + .5 * height, .3 * height, 0, M_PI, true); CGPathAddArc(rightCircles, NULL, xstart + .75 * width, ystart + .5 * height, .3 * height, M_PI, 0, true); CGPathMoveToPoint(rightCircles, NULL, xstart + .75 * width + .2 * height, ystart + .5 * height); CGPathAddArc(rightCircles, NULL, xstart + .75 * width, ystart + .5 * height, .2 * height, 0, M_PI, false); CGPathAddArc(rightCircles, NULL, xstart + .75 * width, ystart + .5 * height, .2 * height, M_PI, 0, false); CGPathMoveToPoint(rightCircles, NULL, xstart + .75 * width + .1 * height, ystart + .5 * height); CGPathAddArc(rightCircles, NULL, xstart + .75 * width, ystart + .5 * height, .1 * height, 0, M_PI, true); CGPathAddArc(rightCircles, NULL, xstart + .75 * width, ystart + .5 * height, .1 * height, M_PI, 0, true); CGPathCloseSubpath(rightCircles); CGContextAddPath(context, leftCircles); CGContextAddPath(context, rightCircles); CGContextSetRGBFillColor(context, 0, 0, 1, 1); CGContextSetRGBStrokeColor(context, 1, 0, 0, 1); CGContextDrawPath(context, fillMode); CGPathRelease(leftCircles); CGPathRelease(rightCircles); }
// --------------------------------------------------------------------------- // // ----------- void bToolMove::update(bool global){ if(!global){ clearTempPathContext(false); } if(get_on_drag()){ CGPoint v1,v2; get_clic(&v1); get_cur(&v2); CGFloat dx=v2.x-v1.x; CGFloat dy=v2.y-v1.y; bGenericGeoElement* o; bArray sel(*_gapp->selMgr()->elements()); ivx_rect vr; for(long i=1;i<=sel.count();i++){ sel.get(i,&o); o->getVertices(&_vxs); ivs_bounds(_vxs,&vr); hilite_rect(getTempPathContext(),CGRectOffset(CGRectInset(ivr2cgr(_gapp,vr),-2,-2),dx,dy),true,true); } } if(!global){ validTempPathContext(); } }
OSStatus TRGetBestFontSize(CGContextRef ctx, CGRect r, CFStringRef string, CFStringRef fontName, TRFallbackBehavior fallbackBehavior, CGFloat* oFontSize, CGFloat* oBaseline) { CGFloat fontSize = 0.0f; CGFloat baseline = 0.0f; if (fontName) { r = CGRectInset(r, 0.1f*r.size.width, 0.1f*r.size.height); fontSize = 100.0f; NSUInteger i = 0; while (fontSize > 0.0f) { TRInfo info; OSStatus err = TRGetTextInfo(ctx, r, string, fontName, fontSize, fallbackBehavior, &info); if (err == paramErr) return err; baseline = info.baseline; /*printf("TRGetBestFontSize:{%.2f %.2f} size=%.2fpt w=%.2f h=%.2f asc=%f desc=%f bl=%f\n", r.size.width, r.size.height, fontSize, info.width, info.height, info.ascent, info.descent, baseline);*/ if (info.height < r.size.height && info.width < r.size.width) break; CGFloat pct = __fpmin((r.size.height/info.height), (r.size.width/info.width)); //printf("pct %f\n", pct); if (pct > .99f && pct < 1.01f) break; fontSize *= pct; i++; if (i > 10) break; } } *oFontSize = fontSize; *oBaseline = baseline; return noErr; }
void drawWithColorBlendMode(CGContextRef context, CFURLRef url) { // A pleasant green color. float green[4] = { 0.584, 0.871, 0.318, 1.0 }; CGRect insetRect, pdfRect; // Create a CGPDFDocument object from the URL. CGPDFDocumentRef pdfDoc = CGPDFDocumentCreateWithURL(url); if(pdfDoc == NULL){ fprintf(stderr, "Couldn't create CGPDFDocument from URL!\n"); return; } // Obtain the media box for page 1 of the PDF document. pdfRect = CGPDFDocumentGetMediaBox(pdfDoc, 1); // Set the origin of the rectangle to (0,0). pdfRect.origin.x = pdfRect.origin.y = 0; // Graphic 1, the left portion of the figure. CGContextTranslateCTM(context, 20, 10 + CGRectGetHeight(pdfRect)/2); // Draw the PDF document. CGContextDrawPDFDocument(context, pdfRect, pdfDoc, 1); // Set the fill color space to that returned by getTheCalibratedRGBColorSpace. CGContextSetFillColorSpace(context, getTheCalibratedRGBColorSpace()); // Set the fill color to green. CGContextSetFillColor(context, green); // Graphic 2, the top-right portion of the figure. CGContextTranslateCTM(context, CGRectGetWidth(pdfRect) + 10, CGRectGetHeight(pdfRect)/2 + 10); // Draw the PDF document again. CGContextDrawPDFDocument(context, pdfRect, pdfDoc, 1); // Make a fill rectangle that is the same size as the PDF document // but inset each side by 80 units in x and 20 units in y. insetRect = CGRectInset(pdfRect, 80, 20); // Fill the rectangle with green. Because the fill color is opaque and // the blend mode is Normal, this obscures the drawing underneath. CGContextFillRect(context, insetRect); // Graphic 3, the bottom-right portion of the figure. CGContextTranslateCTM(context, 0, -(10 + CGRectGetHeight(pdfRect))); // Draw the PDF document again. CGContextDrawPDFDocument(context, pdfRect, pdfDoc, 1); // Set the blend mode to kCGBlendModeColor which will // colorize the destination with subsequent drawing. CGContextSetBlendMode(context, kCGBlendModeColor); // Draw the rectangle on top of the PDF document. The portion of the // background that is covered by the rectangle is colorized // with the fill color. CGContextFillRect(context, insetRect); // Release the CGPDFDocumentRef the code created. CGPDFDocumentRelease(pdfDoc); }
void CanvasRenderingContext2D::stroke() { GraphicsContext* c = drawingContext(); if (!c) return; // FIXME: Do this through platform-independent GraphicsContext API. #if PLATFORM(CG) CGContextBeginPath(c->platformContext()); CGContextAddPath(c->platformContext(), state().m_path.platformPath()); if (!state().m_path.isEmpty()) { float lineWidth = state().m_lineWidth; float inset = -lineWidth / 2; CGRect boundingRect = CGRectInset(CGContextGetPathBoundingBox(c->platformContext()), inset, inset); willDraw(boundingRect); } if (state().m_strokeStyle->gradient()) { // Shading works on the entire clip region, so convert the current path to a clip. c->save(); CGContextReplacePathWithStrokedPath(c->platformContext()); CGContextClip(c->platformContext()); CGContextDrawShading(c->platformContext(), state().m_strokeStyle->gradient()->platformShading()); c->restore(); } else { if (state().m_strokeStyle->pattern()) applyStrokePattern(); CGContextStrokePath(c->platformContext()); } #elif PLATFORM(QT) QPainterPath* path = state().m_path.platformPath(); QPainter* p = static_cast<QPainter*>(c->platformContext()); willDraw(path->controlPointRect()); if (state().m_strokeStyle->gradient()) { p->save(); p->setBrush(*(state().m_strokeStyle->gradient()->platformShading())); p->strokePath(*path, p->pen()); p->restore(); } else { if (state().m_strokeStyle->pattern()) applyStrokePattern(); p->strokePath(*path, p->pen()); } #endif clearPathForDashboardBackwardCompatibilityMode(); }
OSStatus ScrollingTextBoxDraw(CGContextRef context, const HIRect * bounds, const ScrollingTextBoxData * myData) { HIRect textBounds = { {kMargin, kMargin}, {bounds->size.width - kMargin - kMargin, myData->height} }; HIRect clipBounds = CGRectInset(*bounds, kMargin + 1.0, kMargin + 1.0); // // If we're building on Panther (or later) then HIThemeDrawTextBox is available, else we use DrawThemeTextBox // #if PANTHER_BUILD // // Furthermore, if we're running on Panther then we can call HIThemeDrawTextBox else we call DrawThemeTextBox // if (GetHIToolboxVersion() >= Panther_HIToolbox_Version) { CGContextClipToRect(context, clipBounds); HIThemeTextInfo textInfo = {0, kThemeStateActive, kScrollingTextBoxFontID, kHIThemeTextHorizontalFlushLeft, kHIThemeTextVerticalFlushTop, kHIThemeTextBoxOptionStronglyVertical, kHIThemeTextTruncationNone, 0, false}; HIThemeDrawTextBox(myData->theText, &textBounds, &textInfo, context, kHIThemeOrientationNormal); } else #endif { Rect QDTextBounds = HI2QDRECT(textBounds); Rect QDClipBounds = HI2QDRECT(clipBounds); RgnHandle saveClip = NewRgn(); GetClip(saveClip); ClipRect(&QDClipBounds); DrawThemeTextBox(myData->theText, kScrollingTextBoxFontID, kThemeStateActive, true, &QDTextBounds, teJustLeft, context); SetClip(saveClip); DisposeRgn(saveClip); } return noErr; }
static pascal OSStatus MultiCartPaneEventHandler (EventHandlerCallRef inHandlerRef, EventRef inEvent, void *inUserData) { OSStatus err, result = eventNotHandledErr; HIViewRef view; DragRef drag; PasteboardRef pasteboard; PasteboardItemID itemID; CFArrayRef array; CFStringRef flavorType; CFIndex numFlavors; ItemCount numItems; int index = *((int *) inUserData); switch (GetEventClass(inEvent)) { case kEventClassControl: { switch (GetEventKind(inEvent)) { case kEventControlDraw: { err = GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &view); if (err == noErr) { CGContextRef ctx; err = GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(CGContextRef), NULL, &ctx); if (err == noErr) { HIThemeFrameDrawInfo info; HIRect bounds, frame; HIViewGetBounds(view, &bounds); CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 1.0f); CGContextFillRect(ctx, bounds); info.version = 0; info.kind = kHIThemeFrameTextFieldSquare; info.state = kThemeStateInactive; info.isFocused = false; err = HIThemeDrawFrame(&bounds, &info, ctx, kHIThemeOrientationNormal); if (multiCartDragHilite == index && systemVersion >= 0x1040) { err = HIThemeSetStroke(kThemeBrushDragHilite, NULL, ctx, kHIThemeOrientationNormal); frame = CGRectInset(bounds, 1, 1); CGContextBeginPath(ctx); CGContextAddRect(ctx, frame); CGContextStrokePath(ctx); } } } result = noErr; break; } case kEventControlDragEnter: { err = GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &view); if (err == noErr) { err = GetEventParameter(inEvent, kEventParamDragRef, typeDragRef, NULL, sizeof(DragRef), NULL, &drag); if (err == noErr) { err = GetDragPasteboard(drag, &pasteboard); if (err == noErr) { err = PasteboardGetItemCount(pasteboard, &numItems); if (err == noErr && numItems == 1) { err = PasteboardGetItemIdentifier(pasteboard, 1, &itemID); if (err == noErr) { err = PasteboardCopyItemFlavors(pasteboard, itemID, &array); if (err == noErr) { numFlavors = CFArrayGetCount(array); for (CFIndex i = 0; i < numFlavors; i++) { flavorType = (CFStringRef) CFArrayGetValueAtIndex(array, i); if (UTTypeConformsTo(flavorType, CFSTR("public.file-url"))) { Boolean accept = true; err = SetEventParameter(inEvent, kEventParamControlWouldAcceptDrop, typeBoolean, sizeof(Boolean), &accept); if (err == noErr) { multiCartDragHilite = index; HIViewSetNeedsDisplay(view, true); result = noErr; } } } CFRelease(array); } } } } } } break; } case kEventControlDragWithin: { result = noErr; break; } case kEventControlDragLeave: { err = GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &view); if (err == noErr) { multiCartDragHilite = -1; HIViewSetNeedsDisplay(view, true); } result = noErr; break; } case kEventControlDragReceive: { err = GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &view); if (err == noErr) { err = GetEventParameter(inEvent, kEventParamDragRef, typeDragRef, NULL, sizeof(DragRef), NULL, &drag); if (err == noErr) { multiCartDragHilite = -1; HIViewSetNeedsDisplay(view, true); err = GetDragPasteboard(drag, &pasteboard); if (err == noErr) { err = PasteboardGetItemIdentifier(pasteboard, 1, &itemID); if (err == noErr) { err = PasteboardCopyItemFlavors(pasteboard, itemID, &array); if (err == noErr) { numFlavors = CFArrayGetCount(array); for (CFIndex i = 0; i < numFlavors; i++) { flavorType = (CFStringRef) CFArrayGetValueAtIndex(array, i); if (UTTypeConformsTo(flavorType, CFSTR("public.file-url"))) { CFDataRef flavorData; err = PasteboardCopyItemFlavorData(pasteboard, itemID, flavorType, &flavorData); if (err == noErr) { CFIndex dataSize; UInt8 *data; dataSize = CFDataGetLength(flavorData); data = (UInt8 *) malloc(dataSize); if (data) { CFDataGetBytes(flavorData, CFRangeMake(0, dataSize), data); HIViewRef ctl; HIViewID cid; CFStringRef str; CFURLRef url; GetControlID(view, &cid); cid.signature = 'MNAM'; HIViewFindByID(view, cid, &ctl); url = CFURLCreateWithBytes(kCFAllocatorDefault, data, dataSize, kCFStringEncodingUTF8, NULL); str = CFURLCopyLastPathComponent(url); SetStaticTextCFString(ctl, str, true); CFRelease(str); str = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); if (multiCartPath[cid.id]) CFRelease(multiCartPath[cid.id]); multiCartPath[cid.id] = str; CFRelease(url); result = noErr; free(data); } CFRelease(flavorData); } } } CFRelease(array); } } } } } } } } } return (result); }
CGRect CGRectResize(CGRect rect, CGSize newSize) { CGFloat dx = (rect.size.width - newSize.width) / 2.0; CGFloat dy = (rect.size.height - newSize.height) / 2.0; return CGRectInset(rect, dx, dy); }
//----------------------------------------------------------------------------- void MadShiftaNumberCircle::draw(DGGraphicsContext * inContext) { // draw the outer edge of the background circle CGContextRef cgContext = inContext->getPlatformGraphicsContext(); CGRect backgroundBounds = getBounds()->convertToCGRect( inContext->getPortHeight() ); CGContextAddEllipseInRect(cgContext, backgroundBounds); inContext->setFillColor(kControlFillColor_alt); inContext->endPath(); inContext->fillPath(); // draw the inner filling of the background circle inContext->beginPath(); inContext->setFillColor(kControlBackgroundColor); const CGFloat backgroundFrameWidth = 1.0f; CGRect fillBounds = CGRectInset(backgroundBounds, backgroundFrameWidth, backgroundFrameWidth); CGContextAddEllipseInRect(cgContext, fillBounds); inContext->endPath(); inContext->fillPath(); // draw the pie portion filling inContext->beginPath(); inContext->setFillColor(kControlFillColor); CGFloat centerX = fillBounds.origin.x + (fillBounds.size.width * 0.5); CGFloat centerY = fillBounds.origin.y + (fillBounds.size.height * 0.5); SInt32 min = GetControl32BitMinimum( getCarbonControl() ); SInt32 max = GetControl32BitMaximum( getCarbonControl() ); SInt32 val = GetControl32BitValue( getCarbonControl() ); if (val <= min) { inContext->setStrokeColor(kControlFillColor_alt); float linePosX = floorf(centerX) + 0.5f; // CoreGraphics lines are positioned between pixels rather than on them float lineStartY = fillBounds.origin.y; float lineEndY = roundf(centerY); inContext->drawLine(linePosX, lineStartY, linePosX, lineEndY, 1.0f); } else if (val >= max) { CGContextAddEllipseInRect(cgContext, fillBounds); inContext->fillPath(); } else { double paramValue_gen = getDfxGuiEditor()->getparameter_f( getParameterID() ); const CAAUParameter auParam = getAUVP(); paramValue_gen = AUParameterValueToLinear(paramValue_gen, &auParam); CGFloat radius = fillBounds.size.width * 0.5; CGFloat startAngle = 0.0; CGFloat angle = paramValue_gen * (kDFX_PI_d * 2.0); startAngle = kDFX_PI_d * 0.5; angle = kDFX_PI_d; CGContextAddArc(cgContext, centerX, centerY, radius, startAngle, angle + startAngle, 0); inContext->endPath(); inContext->fillPath(); inContext->beginPath(); if (paramValue_gen >= 0.5) { startAngle -= (paramValue_gen - 0.5) * (kDFX_PI_d * 2.0); CGContextAddArc(cgContext, centerX, centerY, radius, startAngle, angle + startAngle, 0); } else { inContext->setFillColor(kControlBackgroundColor); radius += backgroundFrameWidth; startAngle -= paramValue_gen * (kDFX_PI_d * 2.0); CGContextAddArc(cgContext, centerX, centerY, radius, startAngle, angle + startAngle, 0); } inContext->endPath(); inContext->fillPath(); } DGTextDisplay::draw(inContext); }
/***************************************************** * * Internal_HICustomViewHandler(inHandlerCallRef, inEvent, inUserData) * * Purpose: Event handler that implements our HICustomView custom view * * Inputs: inHandlerCallRef - reference to the current handler call chain * inEvent - the event * inUserData - app-specified data you passed in the call to InstallEventHandler * * Returns: OSStatus - error code (0 == no error) */ static pascal OSStatus Internal_HICustomViewHandler(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void * inUserData) { OSStatus status = eventNotHandledErr; HICustomViewData * myData = (HICustomViewData *)inUserData; switch (GetEventClass(inEvent)) { case kEventClassHIObject: switch (GetEventKind(inEvent)) { case kEventHIObjectConstruct: { // allocate some instance data myData = (HICustomViewData *) calloc(1, sizeof(HICustomViewData)); require_action(myData != NULL, ConstructExit, status = memFullErr); // get our superclass instance HIViewRef epView; status = GetEventParameter(inEvent, kEventParamHIObjectInstance, typeHIObjectRef, NULL, sizeof(epView), NULL, &epView); require_noerr(status, ConstructExit); // remember our superclass in our instance data myData->view = epView; // store our instance data into the event status = SetEventParameter(inEvent, kEventParamHIObjectInstance, typeVoidPtr, sizeof(myData), &myData); require_noerr(status, ConstructExit); ConstructExit: break; } #pragma mark * kEventHIObjectInitialize case kEventHIObjectInitialize: { // always begin kEventHIObjectInitialize by calling through to the previous handler status = CallNextEventHandler(inHandlerCallRef, inEvent); require_noerr(status, InitializeExit); // if that succeeded, do our own initialization // in this sample code, there is nothing to do InitializeExit: break; } case kEventHIObjectDestruct: { // freeing our storage if (myData != NULL) free(myData); status = noErr; break; } default: break; } break; case kEventClassControl: switch (GetEventKind(inEvent)) { #pragma mark * kEventControlDraw case kEventControlDraw: { CGContextRef context; status = GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(context), NULL, &context); require_noerr(status, ControlDrawExit); HIRect bounds, viewBounds; HIViewGetBounds(myData->view, &viewBounds); // setting our colors according to state: IsControlEnabled, IsControlActive, IsControlHilited if (!IsControlEnabled(myData->view)) { CGContextSetRGBFillColor(context, 0.3, 0.3, 0.3, 0.8); CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.8); } else if (!IsControlActive(myData->view)) { CGContextSetRGBFillColor(context, 0.7, 0.7, 0.7, 0.8); CGContextSetRGBStrokeColor(context, 0.8, 0.8, 0.8, 0.8); } else if (!IsControlHilited(myData->view)) { CGContextSetRGBFillColor(context, 1, 0, 0, 0.8); CGContextSetRGBStrokeColor(context, 0, 0, 1, 0.8); } else { CGContextSetRGBFillColor(context, 0.7, 0, 0, 0.8); CGContextSetRGBStrokeColor(context, 0, 0, 0.7, 0.8); } // using a line thickness of 3 CGContextSetLineWidth(context, 3); bounds = CGRectInset(viewBounds, 3, 3); float minDim = (bounds.size.height < bounds.size.width) ? bounds.size.height / 2 : bounds.size.width / 2; float cx = bounds.origin.x + minDim, cy = bounds.origin.y + minDim; UInt32 i, n = GetControl32BitValue(myData->view); // having some fun with geometric shapes based on the value of the custom view CGContextBeginPath(context); switch (n) { case 0: CGContextAddArc(context, cx, cy, minDim, 0, 2 * pi, true); break; case 1: CGContextAddEllipseInRect(context, CGRectInset(bounds, bounds.size.width * 0.4, 0)); break; default: { float deltangle = pi / n, angle = 0, r = minDim / 2; CGContextMoveToPoint(context, cx + minDim, cy); for (i = 0; i < n; i++) { angle += deltangle; CGContextAddLineToPoint(context, cx + r * cos(angle), cy + r * sin(angle)); angle += deltangle; CGContextAddLineToPoint(context, cx + minDim * cos(angle), cy + minDim * sin(angle)); } CGContextAddLineToPoint(context, cx + minDim, cy); } } CGContextClosePath(context); CGContextDrawPath(context, kCGPathFillStroke); status = noErr; ControlDrawExit: break; } #pragma mark * kEventControl___Changed case kEventControlValueFieldChanged: case kEventControlHiliteChanged: { // just asking for a refresh HIViewSetNeedsDisplay(myData->view, true); break; } default: break; } break; default: break; } return status; } // Internal_HICustomViewHandler
static void TkMacOSXDrawButton( MacButton *mbPtr, /* Mac button. */ GC gc, /* The GC we are drawing into - needed for * the bevel button */ Pixmap pixmap) /* The pixmap we are drawing into - needed * for the bevel button */ { TkButton * butPtr = ( TkButton *)mbPtr; TkWindow * winPtr; HIRect cntrRect; TkMacOSXDrawingContext dc; DrawParams* dpPtr = &mbPtr->drawParams; int useNewerHITools = 1; winPtr = (TkWindow *)butPtr->tkwin; TkMacOSXComputeButtonParams(butPtr, &mbPtr->btnkind, &mbPtr->drawinfo); cntrRect = CGRectMake(winPtr->privatePtr->xOff, winPtr->privatePtr->yOff, Tk_Width(butPtr->tkwin), Tk_Height(butPtr->tkwin)); cntrRect = CGRectInset(cntrRect, butPtr->inset, butPtr->inset); if (useNewerHITools == 1) { HIRect contHIRec; static HIThemeButtonDrawInfo hiinfo; ButtonBackgroundDrawCB(&cntrRect, mbPtr, 32, true); if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) { return; } if (mbPtr->btnkind == kThemePushButton) { /* * For some reason, pushbuttons get drawn a bit * too low, normally. Correct for this. */ if (cntrRect.size.height < 22) { cntrRect.origin.y -= 1; } else if (cntrRect.size.height < 23) { cntrRect.origin.y -= 2; } } hiinfo.version = 0; hiinfo.state = mbPtr->drawinfo.state; hiinfo.kind = mbPtr->btnkind; hiinfo.value = mbPtr->drawinfo.value; hiinfo.adornment = mbPtr->drawinfo.adornment; hiinfo.animation.time.current = CFAbsoluteTimeGetCurrent(); if (hiinfo.animation.time.start == 0) { hiinfo.animation.time.start = hiinfo.animation.time.current; } HIThemeDrawButton(&cntrRect, &hiinfo, dc.context, kHIThemeOrientationNormal, &contHIRec); TkMacOSXRestoreDrawingContext(&dc); ButtonContentDrawCB(&contHIRec, mbPtr->btnkind, &mbPtr->drawinfo, (MacButton *)mbPtr, 32, true); } else { if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) { return; } TkMacOSXRestoreDrawingContext(&dc); } mbPtr->lastdrawinfo = mbPtr->drawinfo; }
void MacWidgetPainter::DrawFocusRect(const OpRect &drawrect) { OpRect opBounds = drawrect; float scale = ((float)vd->GetScale()) / 100.0f; #ifdef VIEWPORTS_SUPPORT opBounds.x += vd->GetTranslationX() - vd->GetRenderingViewX() + vd->ScaleToDoc(vd->GetOffsetX()); opBounds.y += vd->GetTranslationY() - vd->GetRenderingViewY() + vd->ScaleToDoc(vd->GetOffsetY()); #else opBounds.x += vd->GetTranslationX() - vd->GetViewX() + vd->ScaleToDoc(vd->GetOffsetX()); opBounds.y += vd->GetTranslationY() - vd->GetViewY() + vd->ScaleToDoc(vd->GetOffsetY()); #endif CGRect scaledBounds = {{opBounds.x*scale, opBounds.y*scale}, {opBounds.width*scale, opBounds.height*scale}}; OpRect vd_clip = vd->GetClipping(); // Get current cliprect, we need to sync QDclip with that vd_clip = vd->ScaleToScreen(vd_clip); vd_clip.x += vd->GetOffsetX(); vd_clip.y += vd->GetOffsetY(); CGRect clipBounds = {{vd_clip.x, vd_clip.y}, {vd_clip.width, vd_clip.height}}; clipBounds = CGRectInset(clipBounds, -3, -3); // don't quite know why... scaledBounds = CGRectInset(scaledBounds, 4, 4); VEGAOpPainter* painter = (VEGAOpPainter*)m_painter; VEGARenderTarget* target = painter->GetRenderTarget(); CocoaVEGAWindow* window = (CocoaVEGAWindow*)target->getTargetWindow(); if(!window) { return; } int win_height = CGImageGetHeight(window->getImage()); #ifdef PIXEL_SCALE_RENDERING_SUPPORT const PixelScaler& scaler = vd->GetVPScale(); win_height = FROM_DEVICE_PIXEL(scaler, win_height); #endif // PIXEL_SCALE_RENDERING_SUPPORT CGContextRef context = window->getPainter(); if (context) { MacOpView *macview = (MacOpView *)vd->GetOpView(); OpPoint pt; pt = macview->ConvertToScreen(pt); OpWindow* root = macview->GetRootWindow(); INT32 xpos,ypos; root->GetInnerPos(&xpos, &ypos); scaledBounds = CGRectOffset(scaledBounds, pt.x - xpos, pt.y - ypos); clipBounds = CGRectOffset(clipBounds, pt.x - xpos, pt.y - ypos); CGContextSaveGState(context); float scale = 1.0f; #ifdef PIXEL_SCALE_RENDERING_SUPPORT scale = TO_DEVICE_PIXEL(scaler, scale); #endif // PIXEL_SCALE_RENDERING_SUPPORT CGContextScaleCTM(context, scale, -scale); CGContextTranslateCTM(context, 0.0f, -win_height); CGContextClipToRect(context, clipBounds); HIThemeDrawFocusRect(&scaledBounds, true, context, kHIThemeOrientationNormal); CGContextRestoreGState(context); } }