本文整理匯總了C++中CGContextSaveGState函數的典型用法代碼示例。如果您正苦於以下問題:C++ CGContextSaveGState函數的具體用法?C++ CGContextSaveGState怎麽用?C++ CGContextSaveGState使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CGContextSaveGState函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: doStrokeWithCTM
void doStrokeWithCTM(CGContextRef context)
{
CGContextTranslateCTM(context, 150., 180.);
CGContextSetLineWidth(context, 10);
// Draw ellipse 1 with a uniform stroke.
CGContextSaveGState(context);
// Scale the CTM so the circular arc will be elliptical.
CGContextScaleCTM(context, 2, 1);
CGContextBeginPath(context);
// Create an arc that is a circle.
CGContextAddArc(context, 0., 0., 45., 0., 2*M_PI, 0);
// Restore the context parameters prior to stroking the path.
// CGContextRestoreGState does not affect the path in the context.
CGContextRestoreGState(context);
CGContextStrokePath(context);
// *** was 0, -120
CGContextTranslateCTM(context, 220., 0.);
// Draw ellipse 2 with non-uniform stroke.
CGContextSaveGState(context);
// Scale the CTM so the circular arc will be elliptical.
CGContextScaleCTM(context, 2, 1);
CGContextBeginPath(context);
// Create an arc that is a circle.
CGContextAddArc(context, 0., 0., 45., 0., 2*M_PI, 0);
// Stroke the path with the scaled coordinate system in effect.
CGContextStrokePath(context);
CGContextRestoreGState(context);
}
示例2: CGContextSaveGState
void WKCACFLayer::display(PlatformGraphicsContext* context)
{
if (!m_owner)
return;
CGContextSaveGState(context);
CGRect layerBounds = bounds();
if (m_owner->contentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesTopDown) {
CGContextScaleCTM(context, 1, -1);
CGContextTranslateCTM(context, 0, -layerBounds.size.height);
}
if (m_owner->client()) {
GraphicsContext graphicsContext(context);
// It's important to get the clip from the context, because it may be significantly
// smaller than the layer bounds (e.g. tiled layers)
CGRect clipBounds = CGContextGetClipBoundingBox(context);
IntRect clip(enclosingIntRect(clipBounds));
m_owner->paintGraphicsLayerContents(graphicsContext, clip);
}
#ifndef NDEBUG
else {
ASSERT_NOT_REACHED();
// FIXME: ideally we'd avoid calling -setNeedsDisplay on a layer that is a plain color,
// so CA never makes backing store for it (which is what -setNeedsDisplay will do above).
CGContextSetRGBFillColor(context, 0.0f, 1.0f, 0.0f, 1.0f);
CGContextFillRect(context, layerBounds);
}
#endif
if (m_owner->showRepaintCounter()) {
char text[16]; // that's a lot of repaints
_snprintf(text, sizeof(text), "%d", m_owner->incrementRepaintCount());
CGContextSaveGState(context);
CGContextSetRGBFillColor(context, 1.0f, 0.0f, 0.0f, 0.8f);
CGRect aBounds = layerBounds;
aBounds.size.width = 10 + 12 * strlen(text);
aBounds.size.height = 25;
CGContextFillRect(context, aBounds);
CGContextSetRGBFillColor(context, 0.0f, 0.0f, 0.0f, 1.0f);
CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0f, -1.0f));
CGContextSelectFont(context, "Helvetica", 25, kCGEncodingMacRoman);
CGContextShowTextAtPoint(context, aBounds.origin.x + 3.0f, aBounds.origin.y + 20.0f, text, strlen(text));
CGContextRestoreGState(context);
}
CGContextRestoreGState(context);
}
示例3: CGContextSaveGState
//-----------------------------------------------------------------------------
void CGDrawContext::init ()
{
CGContextSaveGState (cgContext);
CGContextSetShouldAntialias (cgContext, false);
CGContextSetFillColorSpace (cgContext, GetCGColorSpace ());
CGContextSetStrokeColorSpace (cgContext, GetCGColorSpace ());
CGContextSaveGState (cgContext);
CGAffineTransform cgCTM = CGAffineTransformMake (1.0, 0.0, 0.0, -1.0, 0.0, 0.0);
CGContextSetTextMatrix (cgContext, cgCTM);
CDrawContext::init ();
}
示例4: wxRect
wxBitmap wxScreenDCImpl::DoGetAsBitmap(const wxRect *subrect) const
{
wxRect rect = subrect ? *subrect : wxRect(0, 0, m_width, m_height);
wxBitmap bmp(rect.GetSize(), 32);
#if !wxOSX_USE_IPHONE
CGRect srcRect = CGRectMake(rect.x, rect.y, rect.width, rect.height);
CGContextRef context = (CGContextRef)bmp.GetHBITMAP();
CGContextSaveGState(context);
CGContextTranslateCTM( context, 0, m_height );
CGContextScaleCTM( context, 1, -1 );
if ( subrect )
srcRect = CGRectOffset( srcRect, -subrect->x, -subrect->y ) ;
CGImageRef image = grabViaOpenGL(kCGNullDirectDisplay, srcRect);
wxASSERT_MSG(image, wxT("wxScreenDC::GetAsBitmap - unable to get screenshot."));
CGContextDrawImage(context, srcRect, image);
CGImageRelease(image);
CGContextRestoreGState(context);
#else
// TODO implement using UIGetScreenImage, CGImageCreateWithImageInRect, CGContextDrawImage
#endif
return bmp;
}
示例5: paintRepaintRectOverlay
static void paintRepaintRectOverlay(CGContextRef context, WKImageRef image, WKArrayRef repaintRects)
{
WKSize imageSize = WKImageGetSize(image);
CGContextSaveGState(context);
// Using a transparency layer is easier than futzing with clipping.
CGContextBeginTransparencyLayer(context, 0);
// Flip the context.
CGContextScaleCTM(context, 1, -1);
CGContextTranslateCTM(context, 0, -imageSize.height);
CGContextSetRGBFillColor(context, 0, 0, 0, static_cast<CGFloat>(0.66));
CGContextFillRect(context, CGRectMake(0, 0, imageSize.width, imageSize.height));
// Clear the repaint rects.
size_t count = WKArrayGetSize(repaintRects);
for (size_t i = 0; i < count; ++i) {
WKRect rect = WKRectGetValue(static_cast<WKRectRef>(WKArrayGetItemAtIndex(repaintRects, i)));
CGRect cgRect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
CGContextClearRect(context, cgRect);
}
CGContextEndTransparencyLayer(context);
CGContextRestoreGState(context);
}
示例6: MCTileCacheCoreGraphicsCompositor_BeginLayer
bool MCTileCacheCoreGraphicsCompositor_BeginLayer(void *p_context, const MCRectangle& p_clip, uint32_t p_opacity, uint32_t p_ink)
{
MCTileCacheCoreGraphicsCompositorContext *self;
self = (MCTileCacheCoreGraphicsCompositorContext *)p_context;
CGContextSaveGState(self -> cgcontext);
// MW-2012-09-18: [[ Bug 10202 ]] If the ink is no-op then ensure nothing happens.
if (p_ink == GXnoop)
CGContextClipToRect(self -> cgcontext, CGRectZero);
else
{
CGContextClipToRect(self -> cgcontext, CGRectMake(p_clip . x, self -> viewport_height - (p_clip . y + p_clip . height), p_clip . width, p_clip . height));
CGContextSetAlpha(self -> cgcontext, p_opacity / 255.0);
CGBlendMode t_blend_mode;
switch(p_ink)
{
case GXblendMultiply:
t_blend_mode = kCGBlendModeMultiply;
break;
case GXblendScreen:
t_blend_mode = kCGBlendModeScreen;
break;
case GXblendOverlay:
t_blend_mode = kCGBlendModeOverlay;
break;
case GXblendDarken:
t_blend_mode = kCGBlendModeDarken;
break;
case GXblendLighten:
t_blend_mode = kCGBlendModeLighten;
break;
case GXblendDodge:
t_blend_mode = kCGBlendModeColorDodge;
break;
case GXblendBurn:
t_blend_mode = kCGBlendModeColorBurn;
break;
case GXblendSoftLight:
t_blend_mode = kCGBlendModeSoftLight;
break;
case GXblendHardLight:
t_blend_mode = kCGBlendModeHardLight;
break;
case GXblendDifference:
t_blend_mode = kCGBlendModeDifference;
break;
case GXblendExclusion:
t_blend_mode = kCGBlendModeExclusion;
break;
default:
t_blend_mode = kCGBlendModeNormal;
break;
}
CGContextSetBlendMode(self -> cgcontext, t_blend_mode);
}
return true;
}
示例7: platformContext
void GraphicsContext::fillRect(const FloatRect& rect)
{
if (paintingDisabled())
return;
CGContextRef context = platformContext();
if (m_state.fillGradient) {
CGContextSaveGState(context);
CGContextConcatCTM(context, m_state.fillGradient->gradientSpaceTransform());
if (hasShadow()) {
CGLayerRef layer = CGLayerCreateWithContext(context, CGSizeMake(rect.width(), rect.height()), 0);
CGContextRef layerContext = CGLayerGetContext(layer);
m_state.fillGradient->paint(layerContext);
CGContextDrawLayerAtPoint(context, CGPointMake(rect.left(), rect.top()), layer);
CGLayerRelease(layer);
} else {
CGContextClipToRect(context, rect);
m_state.fillGradient->paint(this);
}
CGContextRestoreGState(context);
return;
}
if (m_state.fillPattern)
applyFillPattern();
CGContextFillRect(context, rect);
}
示例8: CGContextSaveGState
void GraphicsContext::savePlatformState()
{
// Note: Do not use this function within this class implementation, since we want to avoid the extra
// save of the secondary context (in GraphicsContextPlatformPrivateCG.h).
CGContextSaveGState(platformContext());
m_data->save();
}
示例9: snprintf
void PlatformCALayer::drawRepaintIndicator(CGContextRef context, PlatformCALayer* platformCALayer, int repaintCount, CGColorRef customBackgroundColor)
{
char text[16]; // that's a lot of repaints
snprintf(text, sizeof(text), "%d", repaintCount);
CGRect indicatorBox = platformCALayer->bounds();
indicatorBox.size.width = 12 + 10 * strlen(text);
indicatorBox.size.height = 27;
CGContextSaveGState(context);
CGContextSetAlpha(context, 0.5f);
CGContextBeginTransparencyLayerWithRect(context, indicatorBox, 0);
if (customBackgroundColor)
CGContextSetFillColorWithColor(context, customBackgroundColor);
else
CGContextSetRGBFillColor(context, 0, 0.5f, 0.25f, 1);
CGContextFillRect(context, indicatorBox);
if (platformCALayer->acceleratesDrawing())
CGContextSetRGBFillColor(context, 1, 0, 0, 1);
else
CGContextSetRGBFillColor(context, 1, 1, 1, 1);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1, -1));
CGContextSelectFont(context, "Helvetica", 22, kCGEncodingMacRoman);
CGContextShowTextAtPoint(context, indicatorBox.origin.x + 5, indicatorBox.origin.y + 22, text, strlen(text));
#pragma clang diagnostic pop
CGContextEndTransparencyLayer(context);
CGContextRestoreGState(context);
}
示例10: beginCGContext
//-----------------------------------------------------------------------------
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);
}
}
示例11: CGRectMake
wxBitmap wxScreenDCImpl::DoGetAsBitmap(const wxRect *subrect) const
{
CGRect srcRect = CGRectMake(0, 0, m_width, m_height);
if (subrect)
{
srcRect.origin.x = subrect->GetX();
srcRect.origin.y = subrect->GetY();
srcRect.size.width = subrect->GetWidth();
srcRect.size.height = subrect->GetHeight();
}
wxBitmap bmp = wxBitmap(srcRect.size.width, srcRect.size.height, 32);
#if wxOSX_USE_IPHONE
#else
CGContextRef context = (CGContextRef)bmp.GetHBITMAP();
CGContextSaveGState(context);
CGContextTranslateCTM( context, 0, m_height );
CGContextScaleCTM( context, 1, -1 );
if ( subrect )
srcRect = CGRectOffset( srcRect, -subrect->x, -subrect->y ) ;
CGImageRef image = grabViaOpenGL(kCGNullDirectDisplay, srcRect);
wxASSERT_MSG(image, wxT("wxScreenDC::GetAsBitmap - unable to get screenshot."));
CGContextDrawImage(context, srcRect, image);
CGContextRestoreGState(context);
#endif
return bmp;
}
示例12: AddRoundedRectToPath
static void AddRoundedRectToPath(CGContextRef context, CGRect rect,
float ovalWidth, float ovalHeight)
{
float fw, fh;
if (ovalWidth == 0 || ovalHeight == 0)
{
CGContextAddRect(context, rect);
return;
}
CGContextSaveGState(context);
CGContextTranslateCTM (context, CGRectGetMinX(rect),
CGRectGetMinY(rect));
CGContextScaleCTM (context, ovalWidth, ovalHeight);
fw = CGRectGetWidth (rect) / ovalWidth;
fh = CGRectGetHeight (rect) / ovalHeight;
CGContextMoveToPoint(context, fw, fh / 2);
CGContextAddArcToPoint(context, fw, fh, fw / 2, fh, 1);
CGContextAddArcToPoint(context, 0, fh, 0, fh / 2, 1);
CGContextAddArcToPoint(context, 0, 0, fw / 2, 0, 1);
CGContextAddArcToPoint(context, fw, 0, fw, fh / 2, 1);
CGContextClosePath(context);
CGContextRestoreGState(context);
}
示例13: ScratchContext
Rect
PathCG::GetStrokedBounds(const StrokeOptions &aStrokeOptions,
const Matrix &aTransform) const
{
// 10.7 has CGPathCreateCopyByStrokingPath which we could use
// instead of this scratch context business
CGContextRef cg = ScratchContext();
CGContextSaveGState(cg);
CGContextBeginPath(cg);
CGContextAddPath(cg, mPath);
SetStrokeOptions(cg, aStrokeOptions);
CGContextReplacePathWithStrokedPath(cg);
Rect bounds = CGRectToRect(CGContextGetPathBoundingBox(cg));
CGContextRestoreGState(cg);
if (!bounds.IsFinite()) {
return Rect();
}
return aTransform.TransformBounds(bounds);
}
示例14: snprintf
void PlatformCALayer::drawRepaintIndicator(CGContextRef context, PlatformCALayer* platformCALayer, int repaintCount, CGColorRef customBackgroundColor)
{
char text[16]; // that's a lot of repaints
snprintf(text, sizeof(text), "%d", repaintCount);
CGRect indicatorBox = platformCALayer->bounds();
CGContextSaveGState(context);
indicatorBox.size.width = 12 + 10 * strlen(text);
indicatorBox.size.height = 27;
CGContextSetAlpha(context, 0.5f);
CGContextBeginTransparencyLayerWithRect(context, indicatorBox, 0);
if (customBackgroundColor)
CGContextSetFillColorWithColor(context, customBackgroundColor);
else
CGContextSetRGBFillColor(context, 0, 0.5f, 0.25f, 1);
CGContextFillRect(context, indicatorBox);
if (platformCALayer->acceleratesDrawing())
CGContextSetRGBFillColor(context, 1, 0, 0, 1);
else
CGContextSetRGBFillColor(context, 1, 1, 1, 1);
platformCALayer->drawTextAtPoint(context, indicatorBox.origin.x + 5, indicatorBox.origin.y + 22, CGSizeMake(1, -1), 22, text, strlen(text));
CGContextEndTransparencyLayer(context);
CGContextRestoreGState(context);
}
示例15: platformContext
void GraphicsContext::drawConvexPolygon(size_t npoints, const FloatPoint* points, bool shouldAntialias)
{
if (paintingDisabled())
return;
if (npoints <= 1)
return;
CGContextRef context = platformContext();
CGContextSaveGState(context);
CGContextSetShouldAntialias(context, shouldAntialias);
CGContextBeginPath(context);
CGContextMoveToPoint(context, points[0].x(), points[0].y());
for (size_t i = 1; i < npoints; i++)
CGContextAddLineToPoint(context, points[i].x(), points[i].y());
CGContextClosePath(context);
if (fillColor().alpha())
CGContextEOFillPath(context);
if (strokeStyle() != NoStroke)
CGContextStrokePath(context);
CGContextRestoreGState(context);
}