void GraphicsContext::addRoundedRectClip(const IntRect& rect, const IntSize& topLeft, const IntSize& topRight,
    const IntSize& bottomLeft, const IntSize& bottomRight)
{
    if (paintingDisabled())
        return;

    // Need sufficient width and height to contain these curves.  Sanity check our
    // corner radii and our width/height values to make sure the curves can all fit.
    if (static_cast<unsigned>(rect.width()) < static_cast<unsigned>(topLeft.width()) + static_cast<unsigned>(topRight.width()) ||
        static_cast<unsigned>(rect.width()) < static_cast<unsigned>(bottomLeft.width()) + static_cast<unsigned>(bottomRight.width()) ||
        static_cast<unsigned>(rect.height()) < static_cast<unsigned>(topLeft.height()) + static_cast<unsigned>(bottomLeft.height()) ||
        static_cast<unsigned>(rect.height()) < static_cast<unsigned>(topRight.height()) + static_cast<unsigned>(bottomRight.height()))
        return;
 
    // Clip to our rect.
    clip(rect);

    // OK, the curves can fit.
    CGContextRef context = platformContext();
    
    // Add the four ellipses to the path.  Technically this really isn't good enough, since we could end up
    // not clipping the other 3/4 of the ellipse we don't care about.  We're relying on the fact that for
    // normal use cases these ellipses won't overlap one another (or when they do the curvature of one will
    // be subsumed by the other).
    CGContextAddEllipseInRect(context, CGRectMake(rect.x(), rect.y(), topLeft.width() * 2, topLeft.height() * 2));
    CGContextAddEllipseInRect(context, CGRectMake(rect.right() - topRight.width() * 2, rect.y(),
                                                  topRight.width() * 2, topRight.height() * 2));
    CGContextAddEllipseInRect(context, CGRectMake(rect.x(), rect.bottom() - bottomLeft.height() * 2,
                                                  bottomLeft.width() * 2, bottomLeft.height() * 2));
    CGContextAddEllipseInRect(context, CGRectMake(rect.right() - bottomRight.width() * 2,
                                                  rect.bottom() - bottomRight.height() * 2,
                                                  bottomRight.width() * 2, bottomRight.height() * 2));
    
    // Now add five rects (one for each edge rect in between the rounded corners and one for the interior).
    CGContextAddRect(context, CGRectMake(rect.x() + topLeft.width(), rect.y(),
                                         rect.width() - topLeft.width() - topRight.width(),
                                         max(topLeft.height(), topRight.height())));
    CGContextAddRect(context, CGRectMake(rect.x() + bottomLeft.width(), 
                                         rect.bottom() - max(bottomLeft.height(), bottomRight.height()),
                                         rect.width() - bottomLeft.width() - bottomRight.width(),
                                         max(bottomLeft.height(), bottomRight.height())));
    CGContextAddRect(context, CGRectMake(rect.x(), rect.y() + topLeft.height(),
                                         max(topLeft.width(), bottomLeft.width()), rect.height() - topLeft.height() - bottomLeft.height()));
    CGContextAddRect(context, CGRectMake(rect.right() - max(topRight.width(), bottomRight.width()),
                                         rect.y() + topRight.height(),
                                         max(topRight.width(), bottomRight.width()), rect.height() - topRight.height() - bottomRight.height()));
    CGContextAddRect(context, CGRectMake(rect.x() + max(topLeft.width(), bottomLeft.width()),
                                         rect.y() + max(topLeft.height(), topRight.height()),
                                         rect.width() - max(topLeft.width(), bottomLeft.width()) - max(topRight.width(), bottomRight.width()),
                                         rect.height() - max(topLeft.height(), topRight.height()) - max(bottomLeft.height(), bottomRight.height())));
    CGContextClip(context);
}
Beispiel #2
0
void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect, int thickness)
{
    if (paintingDisabled())
        return;

    clip(rect);
    CGContextRef context = platformContext();

    // Add outer ellipse
    CGContextAddEllipseInRect(context, CGRectMake(rect.x(), rect.y(), rect.width(), rect.height()));
    // Add inner ellipse.
    CGContextAddEllipseInRect(context, CGRectMake(rect.x() + thickness, rect.y() + thickness,
        rect.width() - (thickness * 2), rect.height() - (thickness * 2)));

    CGContextEOClip(context);
}
Beispiel #3
0
//-----------------------------------------------------------------------------
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 GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color& color)
{
    if (paintingDisabled() || !color.alpha())
        return;

    CGContextRef context = platformContext();
    Color oldFillColor = fillColor();
    if (oldFillColor != color)
        setCGFillColor(context, color);

    // Add the four ellipses to the path.  Technically this really isn't good enough, since we could end up
    // not clipping the other 3/4 of the ellipse we don't care about.  We're relying on the fact that for
    // normal use cases these ellipses won't overlap one another (or when they do the curvature of one will
    // be subsumed by the other).
    CGContextAddEllipseInRect(context, CGRectMake(rect.x(), rect.y(), topLeft.width() * 2, topLeft.height() * 2));
    CGContextAddEllipseInRect(context, CGRectMake(rect.right() - topRight.width() * 2, rect.y(),
                                                  topRight.width() * 2, topRight.height() * 2));
    CGContextAddEllipseInRect(context, CGRectMake(rect.x(), rect.bottom() - bottomLeft.height() * 2,
                                                  bottomLeft.width() * 2, bottomLeft.height() * 2));
    CGContextAddEllipseInRect(context, CGRectMake(rect.right() - bottomRight.width() * 2,
                                                  rect.bottom() - bottomRight.height() * 2,
                                                  bottomRight.width() * 2, bottomRight.height() * 2));
    
    // Now add five rects (one for each edge rect in between the rounded corners and one for the interior).
    CGContextAddRect(context, CGRectMake(rect.x() + topLeft.width(), rect.y(),
                                         rect.width() - topLeft.width() - topRight.width(),
                                         max(topLeft.height(), topRight.height())));
    CGContextAddRect(context, CGRectMake(rect.x() + bottomLeft.width(), 
                                         rect.bottom() - max(bottomLeft.height(), bottomRight.height()),
                                         rect.width() - bottomLeft.width() - bottomRight.width(),
                                         max(bottomLeft.height(), bottomRight.height())));
    CGContextAddRect(context, CGRectMake(rect.x(), rect.y() + topLeft.height(),
                                         max(topLeft.width(), bottomLeft.width()), rect.height() - topLeft.height() - bottomLeft.height()));
    CGContextAddRect(context, CGRectMake(rect.right() - max(topRight.width(), bottomRight.width()),
                                         rect.y() + topRight.height(),
                                         max(topRight.width(), bottomRight.width()), rect.height() - topRight.height() - bottomRight.height()));
    CGContextAddRect(context, CGRectMake(rect.x() + max(topLeft.width(), bottomLeft.width()),
                                         rect.y() + max(topLeft.height(), topRight.height()),
                                         rect.width() - max(topLeft.width(), bottomLeft.width()) - max(topRight.width(), bottomRight.width()),
                                         rect.height() - max(topLeft.height(), topRight.height()) - max(bottomLeft.height(), bottomRight.height())));
    CGContextFillPath(context);
    if (oldFillColor != color)
        setCGFillColor(context, oldFillColor);
}
void GraphicsContext::clipOutEllipseInRect(const IntRect& rect)
{
    if (paintingDisabled())
        return;
        
    CGContextBeginPath(platformContext());
    CGContextAddRect(platformContext(), CGContextGetClipBoundingBox(platformContext()));
    CGContextAddEllipseInRect(platformContext(), rect);
    CGContextEOClip(platformContext());
}
Beispiel #6
0
static void quartzgen_ellipse(GVJ_t *job, pointf *A, int filled)
{
	/* convert ellipse into the current path */
	CGContextRef context = (CGContextRef)job->context;
	double dx = A[1].x - A[0].x;
	double dy = A[1].y - A[0].y;
	CGContextAddEllipseInRect(context, CGRectMake(A[0].x - dx, A[0].y - dy, dx * 2.0, dy * 2.0));

	/* draw the ellipse */
	quartzgen_path(job, filled);
}
//-----------------------------------------------------------------------------
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