示例#1
0
void InitButton(unsigned w, unsigned h)
{
    CGColorSpaceRef colorspace;
    CGContextRef  gc;
    unsigned char *data;
    float cx, cy;

    data = (unsigned char *)malloc(w * h * 4);

    colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
    gc = CGBitmapContextCreate(data, w, h, 8, w * 4, colorspace,
                               kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);

    cx = CENTERX * w;
    cy = CENTERY * h;

    // background
    CGContextTranslateCTM(gc, 0.0, h);
    CGContextScaleCTM(gc, 1.0, -1.0);
    CGContextClearRect(gc, CGRectMake(0, 0, w, h));
    CGContextSetRGBFillColor(gc, 0.0, 0.0, 0.0, 0.8);

    AddRoundedRectToPath(gc, CGRectMake(w*0.05, h*0.5 - 32, w*0.9, 64), 32, 32);
    CGContextFillPath(gc);

    CGGradientRef gradient;
    size_t num_locations = 2;
    CGFloat locations[2] = { 0.0, 1.0 };
    CGFloat components[8] = { 1.0, 1.0, 1.0, 0.5,  // Start color
                              0.0, 0.0, 0.0, 0.0
                            }; // End color

    gradient = CGGradientCreateWithColorComponents (colorspace, components,
               locations, num_locations);
    // top bevel
    CGContextSaveGState(gc);
    AddRoundedRectToPath(gc, CGRectMake(w*0.05, h*0.5 - 32, w*0.9, 64), 32, 32);
    CGContextEOClip(gc);
    CGContextDrawLinearGradient (gc, gradient,
                                 CGPointMake(cx, cy + 32),
                                 CGPointMake(cx, cy), 0);
    CGContextDrawLinearGradient (gc, gradient,
                                 CGPointMake(cx, cy - 32),
                                 CGPointMake(cx, cy - 16), 0);

    glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);

    CGContextRelease(gc);
    CGColorSpaceRelease(colorspace);
    free(data);
}
示例#2
0
//-----------------------------------------------------------------------------
void CGDrawContext::fillLinearGradient (CGraphicsPath* _path, const CGradient& gradient, const CPoint& startPoint, const CPoint& endPoint, bool evenOdd, CGraphicsTransform* t)
{
	QuartzGraphicsPath* path = dynamic_cast<QuartzGraphicsPath*> (_path);
	if (path == 0)
		return;

	const QuartzGradient* cgGradient = dynamic_cast<const QuartzGradient*> (&gradient);
	if (cgGradient == 0)
		return;

	CGContextRef cgContext = beginCGContext (true, currentState.drawMode.integralMode ());
	if (cgContext)
	{
		if (t)
		{
			CGContextSaveGState (cgContext);
			CGAffineTransform transform = QuartzGraphicsPath::createCGAfflineTransform (*t);
			CGContextConcatCTM (cgContext, transform);
			CGContextAddPath (cgContext, path->getCGPathRef ());
			CGContextRestoreGState (cgContext);
		}
		else
			CGContextAddPath (cgContext, path->getCGPathRef ());

		if (evenOdd)
			CGContextEOClip (cgContext);
		else
			CGContextClip (cgContext);

		CGContextDrawLinearGradient (cgContext, *cgGradient, CGPointMake (startPoint.x, startPoint.y), CGPointMake (endPoint.x, endPoint.y), kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
		
		releaseCGContext (cgContext);
	}
}
示例#3
0
void Gradient::paint(GraphicsContext* context)
{
#ifdef BUILDING_ON_TIGER
    CGContextDrawShading(context->platformContext(), platformGradient());
#else
    CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation;
    if (m_radial)
        CGContextDrawRadialGradient(context->platformContext(), platformGradient(), m_p0, m_r0, m_p1, m_r1, extendOptions);
    else
        CGContextDrawLinearGradient(context->platformContext(), platformGradient(), m_p0, m_p1, extendOptions);
#endif
}
示例#4
0
//-----------------------------------------------------------------------------
void CGDrawContext::fillLinearGradient (CGraphicsPath* _path, const CGradient& gradient, const CPoint& startPoint, const CPoint& endPoint, bool evenOdd, CGraphicsTransform* t)
{
    QuartzGraphicsPath* path = dynamic_cast<QuartzGraphicsPath*> (_path);
    if (path == 0)
        return;

    const QuartzGradient* cgGradient = dynamic_cast<const QuartzGradient*> (&gradient);
    if (cgGradient == 0)
        return;

    CGContextRef context = beginCGContext (true, getDrawMode ().integralMode ());
    if (context)
    {
        CGPoint start = CGPointFromCPoint (startPoint);
        CGPoint end = CGPointFromCPoint (endPoint);
        if (getDrawMode ().integralMode ())
        {
            path->pixelAlign (this, t);
            applyLineWidthCTM (context);
            CGContextAddPath (context, path->getCGPathRef ());
            start = pixelAlligned (start);
            end = pixelAlligned (end);
        }
        else if (t)
        {
            CGContextSaveGState (context);
            CGAffineTransform transform = QuartzGraphicsPath::createCGAffineTransform (*t);
            CGContextConcatCTM (context, transform);
            CGContextAddPath (context, path->getCGPathRef ());
            CGContextRestoreGState (context);
        }
        else
            CGContextAddPath (context, path->getCGPathRef ());

        if (evenOdd)
            CGContextEOClip (context);
        else
            CGContextClip (context);

        CGContextDrawLinearGradient (context, *cgGradient, start, end, kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);

        releaseCGContext (context);
    }
}
示例#5
0
void Gradient::paint(CGContextRef context)
{
    CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation;
    if (!m_radial) {
        CGContextDrawLinearGradient(context, platformGradient(), m_p0, m_p1, extendOptions);
        return;
    }

    bool needScaling = aspectRatio() != 1;
    if (needScaling) {
        CGContextSaveGState(context);
        // Scale from the center of the gradient. We only ever scale non-deprecated gradients,
        // for which m_p0 == m_p1.
        ASSERT(m_p0 == m_p1);
        CGContextTranslateCTM(context, m_p0.x(), m_p0.y());
        CGContextScaleCTM(context, 1, 1 / aspectRatio());
        CGContextTranslateCTM(context, -m_p0.x(), -m_p0.y());
    }

    CGContextDrawRadialGradient(context, platformGradient(), m_p0, m_r0, m_p1, m_r1, extendOptions);

    if (needScaling)
        CGContextRestoreGState(context);
}