コード例 #1
0
ファイル: GraphicsContextCG.cpp プロジェクト: dslab-epfl/warr
void GraphicsContext::fillPath(const Path& path)
{
    if (paintingDisabled())
        return;

    CGContextRef context = platformContext();

    CGContextBeginPath(context);
    CGContextAddPath(context, path.platformPath());

    if (m_state.fillGradient) {
        CGContextSaveGState(context);
        if (fillRule() == RULE_EVENODD)
            CGContextEOClip(context);
        else
            CGContextClip(context);
        CGContextConcatCTM(context, m_state.fillGradient->gradientSpaceTransform());
        m_state.fillGradient->paint(this);
        CGContextRestoreGState(context);
        return;
    }

    if (m_state.fillPattern)
        applyFillPattern();
    fillPathWithFillRule(context, fillRule());
}
コード例 #2
0
ファイル: cgdrawcontext.cpp プロジェクト: DaniM/lyngo
//-----------------------------------------------------------------------------
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 SVGPaintServer::clipToFillPath(CGContextRef context, const RenderPath* path) const
{
    if (path->style()->svgStyle()->fillRule() == RULE_EVENODD)
        CGContextEOClip(context);
    else
        CGContextClip(context);
}
コード例 #4
0
ファイル: GraphicsContextCG.cpp プロジェクト: dslab-epfl/warr
void GraphicsContext::clipOut(const Path& path)
{
    if (paintingDisabled())
        return;

    CGContextBeginPath(platformContext());
    CGContextAddRect(platformContext(), CGContextGetClipBoundingBox(platformContext()));
    CGContextAddPath(platformContext(), path.platformPath());
    CGContextEOClip(platformContext());
}
コード例 #5
0
ファイル: GraphicsContextCG.cpp プロジェクト: dslab-epfl/warr
void GraphicsContext::clipOut(const IntRect& rect)
{
    if (paintingDisabled())
        return;

    CGRect rects[2] = { CGContextGetClipBoundingBox(platformContext()), rect };
    CGContextBeginPath(platformContext());
    CGContextAddRects(platformContext(), rects, 2);
    CGContextEOClip(platformContext());
}
コード例 #6
0
void GraphicsContext::clipOutEllipseInRect(const IntRect& rect)
{
    if (paintingDisabled())
        return;
        
    CGContextBeginPath(platformContext());
    CGContextAddRect(platformContext(), CGContextGetClipBoundingBox(platformContext()));
    CGContextAddEllipseInRect(platformContext(), rect);
    CGContextEOClip(platformContext());
}
コード例 #7
0
ファイル: hud.cpp プロジェクト: AdamDiment/CocoaSampleCode
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);
}
コード例 #8
0
ファイル: GraphicsContextCG.cpp プロジェクト: dslab-epfl/warr
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);
}
コード例 #9
0
ファイル: GraphicsContextCG.cpp プロジェクト: dslab-epfl/warr
void GraphicsContext::clipPath(const Path& path, WindRule clipRule)
{
    if (paintingDisabled())
        return;

    if (path.isEmpty())
        return;

    CGContextRef context = platformContext();

    CGContextBeginPath(platformContext());
    CGContextAddPath(platformContext(), path.platformPath());

    if (clipRule == RULE_EVENODD)
        CGContextEOClip(context);
    else
        CGContextClip(context);
}
コード例 #10
0
ファイル: cgdrawcontext.cpp プロジェクト: UIKit0/vstgui
//-----------------------------------------------------------------------------
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);
    }
}
コード例 #11
0
ファイル: fx_quartz_device.cpp プロジェクト: 151706061/PDFium
FX_BOOL CFX_QuartzDeviceDriver::SetClip_PathFill(const CFX_PathData*    pathData,
        const CFX_AffineMatrix*   matrix,
        int                       fillMode )
{
    SaveState();
    CGAffineTransform m = CGAffineTransformIdentity;
    if (matrix) {
        m = CGAffineTransformMake(matrix->GetA(), matrix->GetB(), matrix->GetC(), matrix->GetD(), matrix->GetE(), matrix->GetF());
    }
    m = CGAffineTransformConcat(m, _foxitDevice2User);
    CGContextConcatCTM(_context, m);
    setPathToContext(pathData);
    RestoreState(FALSE);
    if ((fillMode & 3) == FXFILL_WINDING) {
        CGContextClip(_context);
    } else {
        CGContextEOClip(_context);
    }
    return TRUE;
}
コード例 #12
0
ファイル: GraphicsContextWx.cpp プロジェクト: dog-god/iptv
void GraphicsContext::clipPath(const Path& path, WindRule clipRule)
{
    if (paintingDisabled())
        return;

    // FIXME: Why does this method ignore empty paths?
    if (path.isEmpty())
        return; 

    wxGraphicsContext* gc = m_data->context->GetGraphicsContext();

#if wxUSE_CAIRO
    cairo_t* cr = (cairo_t*)gc->GetNativeContext();
    cairo_path_t* nativePath = (cairo_path_t*)path.platformPath()->GetNativePath();

    cairo_new_path(cr);
    cairo_append_path(cr, nativePath);

    cairo_set_fill_rule(cr, clipRule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
    cairo_clip(cr);
#elif __WXMAC__
    CGContextRef context = (CGContextRef)gc->GetNativeContext();   
    CGPathRef nativePath = (CGPathRef)path.platformPath()->GetNativePath(); 
    
    CGContextBeginPath(context);
    CGContextAddPath(context, nativePath);
    if (clipRule == RULE_EVENODD)
        CGContextEOClip(context);
    else
        CGContextClip(context);
#elif __WXMSW__
    Gdiplus::Graphics* g = (Gdiplus::Graphics*)gc->GetNativeContext();
    Gdiplus::GraphicsPath* nativePath = (Gdiplus::GraphicsPath*)path.platformPath()->GetNativePath();
    if (clipRule == RULE_EVENODD)
        nativePath->SetFillMode(Gdiplus::FillModeAlternate);
    else
        nativePath->SetFillMode(Gdiplus::FillModeWinding);
    g->SetClip(nativePath);
#endif
}
コード例 #13
0
ファイル: cgdrawcontext.cpp プロジェクト: UIKit0/vstgui
//-----------------------------------------------------------------------------
void CGDrawContext::fillRadialGradient (CGraphicsPath* _path, const CGradient& gradient, const CPoint& center, CCoord radius, const CPoint& originOffset, 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)
    {
        if (getDrawMode ().integralMode ())
        {
            path->pixelAlign (this, t);
            CGContextAddPath (context, path->getCGPathRef ());
        }
        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);

        CPoint startCenter = center + originOffset;
        CGContextDrawRadialGradient (context, *cgGradient, CGPointFromCPoint (startCenter), 0, CGPointFromCPoint (center), static_cast<CGFloat> (radius), kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);

        releaseCGContext (context);
    }
}
コード例 #14
0
ファイル: GraphicsContextWx.cpp プロジェクト: Moondee/Artemis
void GraphicsContext::clipOut(const IntRect& rect)
{
    if (paintingDisabled())
        return;

#if USE(WXGC)
    wxGraphicsContext* gc = m_data->context->GetGraphicsContext();

#if wxUSE_CAIRO
    double x1, y1, x2, y2;
    cairo_t* cr = (cairo_t*)gc->GetNativeContext();
    cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
    cairo_rectangle(cr, x1, y1, x2 - x1, y2 - y1);
    cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());
    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
    cairo_clip(cr);
    cairo_set_fill_rule(cr, savedFillRule);

#elif __WXMAC__
    CGContextRef context = (CGContextRef)gc->GetNativeContext();

    CGRect rects[2] = { CGContextGetClipBoundingBox(context), CGRectMake(rect.x(), rect.y(), rect.width(), rect.height()) };
    CGContextBeginPath(context);
    CGContextAddRects(context, rects, 2);
    CGContextEOClip(context);
    return;

#elif __WXMSW__
    Gdiplus::Graphics* g = (Gdiplus::Graphics*)gc->GetNativeContext();
    Gdiplus::Region excludeRegion(Gdiplus::Rect(rect.x(), rect.y(), rect.width(), rect.height()));
    g->ExcludeClip(&excludeRegion);
    return; 
#endif

#endif // USE(WXGC)

    notImplemented();
}
コード例 #15
0
ファイル: hud.cpp プロジェクト: AdamDiment/CocoaSampleCode
static void initNeedle(unsigned w, unsigned h, unsigned max)
{
    CGColorSpaceRef colorspace;
    CGContextRef  gc;
    unsigned char *data;
    float cx, cy;
    float angle, radius, needle;

    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;
    radius = 0.5 * (w > h ? w : h);
    needle = radius * 0.85;

    CGContextTranslateCTM(gc, 0.0, h);
    CGContextScaleCTM(gc, 1.0, -1.0);
    CGContextClearRect(gc, CGRectMake(0, 0, w, h));
    angle = 0;//angleForValue(0, max);

    {
        // draw glow reflecting on inner bevel
        float    dx, dy;
        dx         = -cos(angle) + 1;
        dy         = -sin(angle) + 1;

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

        gradient = CGGradientCreateWithColorComponents (colorspace, components,
                   locations, num_locations);
        CGContextSaveGState(gc);
        CGContextAddArc(gc, cx, cy, needle*1.05, 0, 2*M_PI, false);
        CGContextAddArc(gc, cx, cy, needle*0.96, 0, 2*M_PI, false);
        CGContextEOClip(gc);
        CGContextDrawRadialGradient (gc, gradient,
                                     CGPointMake(cx*dx, cy*dy), radius*0.1,
                                     CGPointMake(cx*1.0, cy*1.0), radius*1.0, 0);
        CGContextRestoreGState(gc);
    }

    CGContextSetRGBFillColor(gc, 0.9, 0.9, 1.0, 1.0);

    // draw several glow passes, with the content offscreen
    CGContextTranslateCTM(gc, 0, OFFSCREEN - 10);
    CGContextSetShadowWithColor(gc, CGSizeMake(0, OFFSCREEN), 48.0, CGColorCreateGenericRGB(0.5, 0.5, 1.0, 0.7));
    drawNeedle(gc, w, h, angle);
    CGContextTranslateCTM(gc, 0, 20);
    CGContextSetShadowWithColor(gc, CGSizeMake(0, OFFSCREEN), 48.0, CGColorCreateGenericRGB(0.5, 0.5, 1.0, 0.7));
    drawNeedle(gc, w, h, angle);
    CGContextTranslateCTM(gc, -10, -10);
    CGContextSetShadowWithColor(gc, CGSizeMake(0, OFFSCREEN), 48.0, CGColorCreateGenericRGB(0.5, 0.5, 1.0, 0.7));
    drawNeedle(gc, w, h, angle);
    CGContextTranslateCTM(gc, 20, 0);
    CGContextSetShadowWithColor(gc, CGSizeMake(0, OFFSCREEN), 48.0, CGColorCreateGenericRGB(0.5, 0.5, 1.0, 0.7));
    drawNeedle(gc, w, h, angle);
    CGContextTranslateCTM(gc, -10, -OFFSCREEN);

    // draw real content
    CGContextSetShadowWithColor(gc, CGSizeMake(0, 1), 6.0, CGColorCreateGenericRGB(0.0, 0.0, 0.5, 0.7));
    drawNeedle(gc, w, h, angle);

    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);
}
コード例 #16
0
ファイル: hud.cpp プロジェクト: AdamDiment/CocoaSampleCode
static void initBackground(unsigned w, unsigned h, unsigned max)
{
    CGColorSpaceRef colorspace;
    CGContextRef  gc;
    unsigned char *data;
    float cx, cy;
    float radius, needle;

    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;
    radius = 0.5 * (w > h ? w : h);
    needle = radius * 0.85;

    // 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.7);
    CGContextAddArc(gc, cx, cy, radius, 0, 2*M_PI, false);
    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 rim light
    CGContextSaveGState(gc);
    CGContextAddArc(gc, cx, cy, radius, 0, 2*M_PI, false);
    CGContextAddArc(gc, cx, cy, needle*1.05, 0, 2*M_PI, false);
    CGContextEOClip(gc);
    CGContextDrawRadialGradient (gc, gradient,
                                 CGPointMake(cx, cy*1.00), radius*1.01,
                                 CGPointMake(cx, cy*0.96), radius*0.98, 0);
    // bottom rim light
    CGContextDrawRadialGradient (gc, gradient,
                                 CGPointMake(cx, cy*1.00), radius*1.01,
                                 CGPointMake(cx, cy*1.04), radius*0.98, 0);
    // top bevel
    CGContextDrawRadialGradient (gc, gradient,
                                 CGPointMake(cx, cy*2.2), radius*0.2,
                                 CGPointMake(cx, cy*1.0), radius*1.0, 0);
    // bottom bevel
    CGContextRestoreGState(gc);
    CGContextSaveGState(gc);
    CGContextAddArc(gc, cx, cy, needle*1.05, 0, 2*M_PI, false);
    CGContextAddArc(gc, cx, cy, needle*0.96, 0, 2*M_PI, false);
    CGContextEOClip(gc);
    CGContextDrawRadialGradient (gc, gradient,
                                 CGPointMake(cx, cy* -.5), radius*0.2,
                                 CGPointMake(cx, cy*1.0), radius*1.0, 0);

    CGGradientRelease(gradient);
    CGContextRestoreGState(gc);

    CGContextSetRGBFillColor(gc, 0.9, 0.9, 1.0, 1.0);
    CGContextSetRGBStrokeColor(gc, 0.9, 0.9, 1.0, 1.0);
    CGContextSetLineCap(gc, kCGLineCapRound);

    // draw several glow passes, with the content offscreen
    CGContextTranslateCTM(gc, 0, OFFSCREEN - 10);
    CGContextSetShadowWithColor(gc, CGSizeMake(0, OFFSCREEN), 48.0, CGColorCreateGenericRGB(0.5, 0.5, 1.0, 0.7));
    drawMarks(gc, w, h, max);
    CGContextTranslateCTM(gc, 0, 20);
    CGContextSetShadowWithColor(gc, CGSizeMake(0, OFFSCREEN), 48.0, CGColorCreateGenericRGB(0.5, 0.5, 1.0, 0.7));
    drawMarks(gc, w, h, max);
    CGContextTranslateCTM(gc, -10, -10);
    CGContextSetShadowWithColor(gc, CGSizeMake(0, OFFSCREEN), 48.0, CGColorCreateGenericRGB(0.5, 0.5, 1.0, 0.7));
    drawMarks(gc, w, h, max);
    CGContextTranslateCTM(gc, 20, 0);
    CGContextSetShadowWithColor(gc, CGSizeMake(0, OFFSCREEN), 48.0, CGColorCreateGenericRGB(0.5, 0.5, 1.0, 0.7));
    drawMarks(gc, w, h, max);
    CGContextTranslateCTM(gc, -10, -OFFSCREEN);

    // draw real content
    CGContextSetShadowWithColor(gc, CGSizeMake(0, 1), 6.0, CGColorCreateGenericRGB(0.7, 0.7, 1.0, 0.9));
    drawMarks(gc, w, h, max);

    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);
}