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); }
FloatRect strokeBoundingBox(const Path& path, RenderStyle* style, const RenderObject* object) { // the bbox might grow if the path is stroked. // and CGPathGetBoundingBox doesn't support that, so we'll have // to make an alternative call... // FIXME: since this is mainly used to decide what to repaint, // perhaps it would be sufficient to just outset the fill bbox by // the stroke width - that should be way cheaper and simpler than // what we do here. CGPathRef cgPath = path.platformPath(); CGContextRef context = scratchContext(); CGContextSaveGState(context); CGContextBeginPath(context); CGContextAddPath(context, cgPath); GraphicsContext gc(context); applyStrokeStyleToContext(&gc, style, object); CGContextReplacePathWithStrokedPath(context); if (CGContextIsPathEmpty(context)) { // CGContextReplacePathWithStrokedPath seems to fail to create a path sometimes, this is not well understood. // returning here prevents CG from logging to the console from CGContextGetPathBoundingBox CGContextRestoreGState(context); return FloatRect(); } CGRect box = CGContextGetPathBoundingBox(context); CGContextRestoreGState(context); return FloatRect(box); }
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); }
CFX_QuartzDeviceDriver::~CFX_QuartzDeviceDriver() { CGContextRestoreGState(_context); m_saveCount--; for (int i = 0; i < m_saveCount; ++i) { CGContextRestoreGState(_context); } if (_context) { CGContextRelease(_context); } }
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; }
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); }
//----------------------------------------------------------------------------- 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); } }
void drawRoundedRect(CGContextRef context, int x, int y){ struct CGRect cgRect; struct CGPoint cgPoint; cgRect.size.width = 640; cgRect.size.height = y+30; cgPoint.x = 0; cgPoint.y = 5; cgRect.origin = cgPoint; //printf("Drawing %f, %f, %f, %f", cgPoint.x, cgPoint.y, cgRect.size.width, cgRect.size.height); CGContextBeginPath(context); float ovalWidth = 10; float ovalHeight = 10; float fw, fh; // If the width or height of the corner oval is zero, then it reduces to a right angle, // so instead of a rounded rectangle we have an ordinary one. if (ovalWidth == 0 || ovalHeight == 0) { CGContextAddRect(context, cgRect); return; } // Save the context's state so that the translate and scale can be undone with a call // to CGContextRestoreGState. CGContextSaveGState(context); // Translate the origin of the contex to the lower left corner of the rectangle. CGContextTranslateCTM(context, CGRectGetMinX(cgRect), CGRectGetMinY(cgRect)); //Normalize the scale of the context so that the width and height of the arcs are 1.0 CGContextScaleCTM(context, ovalWidth, ovalHeight); // Calculate the width and height of the rectangle in the new coordinate system. fw = CGRectGetWidth(cgRect) / ovalWidth; fh = CGRectGetHeight(cgRect) / ovalHeight; // CGContextAddArcToPoint adds an arc of a circle to the context's path (creating the rounded // corners). It also adds a line from the path's last point to the begining of the arc, making // the sides of the rectangle. CGContextMoveToPoint(context, fw, fh/2); // Start at lower right corner CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1); // Top right corner CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1); // Top left corner CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1); // Lower left corner CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1); // Back to lower right // Close the path CGContextClosePath(context); CGContextSetRGBFillColor (context, 1, 1, 1, 0.7); CGContextFillPath(context); CGContextRestoreGState(context); }
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); }
void pathForArc(CGContextRef context, CGRect r, int startAngle, int arcAngle) { float start, end; CGAffineTransform matrix; // Save the context's state because we are going to scale it CGContextSaveGState(context); // Create a transform to scale the context so that a radius of 1 maps to the bounds // of the rectangle, and transform the origin of the context to the center of // the bounding rectangle. matrix = CGAffineTransformMake(r.size.width/2, 0, 0, r.size.height/2, r.origin.x + r.size.width/2, r.origin.y + r.size.height/2); // Apply the transform to the context CGContextConcatCTM(context, matrix); // Calculate the start and ending angles if (arcAngle > 0) { start = (90 - startAngle - arcAngle) * M_PI / 180; end = (90 - startAngle) * M_PI / 180; } else { start = (90 - startAngle) * M_PI / 180; end = (90 - startAngle - arcAngle) * M_PI / 180; } // Add the Arc to the path CGContextAddArc(context, 0, 0, 1, start, end, false); // Restore the context's state. This removes the translation and scaling // but leaves the path, since the path is not part of the graphics state. CGContextRestoreGState(context); }
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; }
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); }
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); }
bool PathCG::StrokeContainsPoint(const StrokeOptions &aStrokeOptions, const Point &aPoint, const Matrix &aTransform) const { Matrix inverse = aTransform; inverse.Invert(); Point transformedPoint = inverse*aPoint; // We could probably drop the input transform and just transform the point at the caller? CGPoint point = {transformedPoint.x, transformedPoint.y}; CGContextRef cg = ScratchContext(); CGContextSaveGState(cg); CGContextBeginPath(cg); CGContextAddPath(cg, mPath); SetStrokeOptions(cg, aStrokeOptions); CGContextReplacePathWithStrokedPath(cg); CGContextRestoreGState(cg); CGPathRef sPath = CGContextCopyPath(cg); bool inStroke = CGPathContainsPoint(sPath, nullptr, point, false); CGPathRelease(sPath); return inStroke; }
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); }
//----------------------------------------------------------------------------- void CGDrawContext::releaseCGContext (CGContextRef context) { if (context) { CGContextRestoreGState (context); } }
void GraphicsContext::restorePlatformState() { // Note: Do not use this function within this class implementation, since we want to avoid the extra // restore of the secondary context (in GraphicsContextPlatformPrivate.h). CGContextRestoreGState(platformContext()); m_data->restore(); }
void SkOSWindow::doPaint(void* ctx) { #if 0 this->update(NULL); const SkBitmap& bm = this->getBitmap(); CGImageRef img = SkCreateCGImageRef(bm); if (img) { CGRect r = CGRectMake(0, 0, bm.width(), bm.height()); CGContextRef cg = reinterpret_cast<CGContextRef>(ctx); CGContextSaveGState(cg); CGContextTranslateCTM(cg, 0, r.size.height); CGContextScaleCTM(cg, 1, -1); CGContextDrawImage(cg, r, img); CGContextRestoreGState(cg); CGImageRelease(img); } #endif }
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); }
bool wxMetaFile::Play(wxDC *dc) { if (!m_refData) return false; if (!dc->Ok() ) return false; { #if wxMAC_USE_CORE_GRAPHICS QDPictRef cgPictRef = M_METAFILEDATA->m_qdPictRef ; CGContextRef cg = ((wxMacCGContext*)(dc->GetGraphicContext()))->GetNativeContext() ; CGRect bounds = QDPictGetBounds( cgPictRef ) ; CGContextSaveGState(cg); CGContextTranslateCTM(cg, 0 , bounds.size.width ); CGContextScaleCTM(cg, 1, -1); QDPictDrawToCGContext( cg , bounds , cgPictRef ) ; CGContextRestoreGState( cg ) ; #else PicHandle pict = (PicHandle) GetHMETAFILE() ; wxMacPortSetter helper( dc ) ; DrawPicture( pict , &(**pict).picFrame ) ; #endif } return true; }
void GraphicsContext::restorePlatformState() { if (m_data->context) { #if USE(WXGC) wxGraphicsContext* gc = m_data->context->GetGraphicsContext(); gc->PopState(); #else #if __WXMAC__ CGContextRef context; wxGraphicsContext* gc = m_data->context->GetGraphicsContext(); if (gc) context = (CGContextRef)gc->GetNativeContext(); if (context) CGContextRestoreGState(context); #elif __WXMSW__ HDC dc = (HDC)m_data->context->GetHDC(); ::RestoreDC(dc, m_data->mswDCStateID); #elif __WXGTK__ m_data->context->m_currentClippingRegion = m_data->gtkCurrentClipRgn; m_data->context->m_paintClippingRegion = m_data->gtkPaintClipRgn; #endif #endif // USE_WXGC } }
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()); }
static void _cairo_quartz_surface_release_dest_image(void *abstract_surface, cairo_rectangle_int16_t *intersect_rect, cairo_image_surface_t *image, cairo_rectangle_int16_t *image_rect, void *image_extra) { cairo_quartz_surface_t *surface = abstract_surface; CGImageRef image_ref; CGRect rect; image_ref = create_image_from_surface (image, image_extra); rect = CGRectMake (image_rect->x, image_rect->y, image_rect->width, image_rect->height); if (surface->y_grows_down) { CGContextSaveGState (surface->context); CGContextTranslateCTM (surface->context, 0, image_rect->height + 2 * image_rect->y); CGContextScaleCTM (surface->context, 1, -1); } CGContextDrawImage(surface->context, rect, image_ref); CFRelease (image_ref); if (surface->y_grows_down) { CGContextRestoreGState (surface->context); } cairo_surface_destroy ((cairo_surface_t *)image); free (image_extra); }
void ImageBuffer::putByteArray(Multiply multiplied, ByteArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint) { if (!m_context->isAcceleratedContext()) { m_data.putData(source, sourceSize, sourceRect, destPoint, internalSize(), m_context->isAcceleratedContext(), multiplied == Unmultiplied); return; } #if USE(IOSURFACE_CANVAS_BACKING_STORE) // Make a copy of the source to ensure the bits don't change before being drawn IntSize sourceCopySize(sourceRect.width(), sourceRect.height()); OwnPtr<ImageBuffer> sourceCopy = ImageBuffer::create(sourceCopySize, 1, ColorSpaceDeviceRGB, Unaccelerated); if (!sourceCopy) return; sourceCopy->m_data.putData(source, sourceSize, sourceRect, IntPoint(-sourceRect.x(), -sourceRect.y()), sourceCopy->internalSize(), sourceCopy->context()->isAcceleratedContext(), multiplied == Unmultiplied); // Set up context for using drawImage as a direct bit copy CGContextRef destContext = context()->platformContext(); CGContextSaveGState(destContext); CGContextConcatCTM(destContext, AffineTransform(CGContextGetCTM(destContext)).inverse()); wkCGContextResetClip(destContext); CGContextSetInterpolationQuality(destContext, kCGInterpolationNone); CGContextSetAlpha(destContext, 1.0); CGContextSetBlendMode(destContext, kCGBlendModeCopy); CGContextSetShadowWithColor(destContext, CGSizeZero, 0, 0); // Draw the image in CG coordinate space IntPoint destPointInCGCoords(destPoint.x() + sourceRect.x(), internalSize().height() - (destPoint.y()+sourceRect.y()) - sourceRect.height()); IntRect destRectInCGCoords(destPointInCGCoords, sourceCopySize); RetainPtr<CGImageRef> sourceCopyImage(AdoptCF, sourceCopy->copyNativeImage()); CGContextDrawImage(destContext, destRectInCGCoords, sourceCopyImage.get()); CGContextRestoreGState(destContext); #endif }
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); }
void TileGrid::drawTileMapContents(CGContextRef context, CGRect layerBounds) const { CGContextSetRGBFillColor(context, 0.3, 0.3, 0.3, 1); CGContextFillRect(context, layerBounds); CGFloat scaleFactor = layerBounds.size.width / m_controller.bounds().width(); CGFloat contextScale = scaleFactor / m_scale; CGContextScaleCTM(context, contextScale, contextScale); for (TileMap::const_iterator it = m_tiles.begin(), end = m_tiles.end(); it != end; ++it) { const TileInfo& tileInfo = it->value; PlatformCALayer* tileLayer = tileInfo.layer.get(); CGFloat red = 1; CGFloat green = 1; CGFloat blue = 1; CGFloat alpha = 1; if (tileInfo.hasStaleContent) { red = 0.25; green = 0.125; blue = 0; } else if (m_controller.shouldAggressivelyRetainTiles() && tileInfo.cohort != VisibleTileCohort) { red = 0.8; green = 0.8; blue = 0.8; } TileCohort newestCohort = newestTileCohort(); TileCohort oldestCohort = oldestTileCohort(); if (!m_controller.shouldAggressivelyRetainTiles() && tileInfo.cohort != VisibleTileCohort && newestCohort > oldestCohort) alpha = 1 - (static_cast<float>((newestCohort - tileInfo.cohort)) / (newestCohort - oldestCohort)); CGContextSetRGBFillColor(context, red, green, blue, alpha); if (tileLayer->superlayer()) { CGContextSetLineWidth(context, 0.5 / contextScale); CGContextSetRGBStrokeColor(context, 0, 0, 0, 1); } else { CGContextSetLineWidth(context, 1 / contextScale); CGContextSetRGBStrokeColor(context, 0.2, 0.1, 0.9, 1); } CGRect frame = CGRectMake(tileLayer->position().x(), tileLayer->position().y(), tileLayer->bounds().size().width(), tileLayer->bounds().size().height()); CGContextFillRect(context, frame); CGContextStrokeRect(context, frame); CGContextSetRGBFillColor(context, 0, 0, 0, 0.5); String repaintCount = String::number(m_tileRepaintCounts.get(tileLayer)); CGContextSaveGState(context); tileLayer->drawTextAtPoint(context, frame.origin.x + 64, frame.origin.y + 192, CGSizeMake(3, -3), 58, repaintCount.ascii().data(), repaintCount.length()); CGContextRestoreGState(context); } }
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); }
static void addRoundedRectToPath(CGContextRef context, CGRect rect, float ovalWidth, float ovalHeight) { float fw, fh; // If either ovalWidth or ovalHeight is 0, draw a regular rectangle. if (ovalWidth == 0 || ovalHeight == 0) { CGContextAddRect(context, rect); }else{ CGContextSaveGState(context); // Translate to lower-left corner of rectangle. CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect)); // Scale by the oval width and height so that // each rounded corner is 0.5 units in radius. CGContextScaleCTM(context, ovalWidth, ovalHeight); // Unscale the rectangle width by the amount of the X scaling. fw = CGRectGetWidth(rect) / ovalWidth; // Unscale the rectangle height by the amount of the Y scaling. fh = CGRectGetHeight(rect) / ovalHeight; // Start at the right edge of the rect, at the midpoint in Y. CGContextMoveToPoint(context, fw, fh/2); // Segment 1 CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 0.5); // Segment 2 CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 0.5); // Segment 3 CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 0.5); // Segment 4 CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 0.5); // Closing the path adds the last segment. CGContextClosePath(context); CGContextRestoreGState(context); } }
static void quartzgen_end_page(GVJ_t *job) { /* end the page (if this is a paged context) and graphics state */ CGContextRef context = (CGContextRef)job->context; CGContextRestoreGState(context); CGContextEndPage(context); }
void doRotatedEllipses(CGContextRef context) { int i, totreps = 144; float tint = 1.0, tintIncrement = 1.0/totreps; // Create a new transform consisting of a 45 degrees rotation. CGAffineTransform theTransform = CGAffineTransformMakeRotation(M_PI/4); // Apply a scale to the transform just created. theTransform = CGAffineTransformScale(theTransform, 1, 2); // Place the first ellipse at a good location. CGContextTranslateCTM(context, 100., 100.); for(i=0 ; i < totreps ; i++){ // Make a snapshot the coordinate system. CGContextSaveGState(context); // Set up the coordinate system for the rotated ellipse. CGContextConcatCTM(context, theTransform); CGContextBeginPath(context); CGContextAddArc(context, 0., 0., 45., 0., 2*M_PI, 0); // Set the fill color for this instance of the ellipse. CGContextSetRGBFillColor(context, tint, 0., 0., 1.0); CGContextDrawPath(context, kCGPathFill); // Restore the coordinate system to that of the snapshot. CGContextRestoreGState(context); // Compute the next tint color. tint -= tintIncrement; // Move over by 1 unit in x for the next ellipse. CGContextTranslateCTM(context, 1.0, 0.0); } }