Created
April 24, 2015 20:54
-
-
Save venkatperi/6bf53091af5c5a54a30b to your computer and use it in GitHub Desktop.
CGContext Syntactic Sugar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CGContextABCD(context!, ...) becomes context?.ABCD(...) | |
import Cocoa | |
extension CGContext { | |
func saveGState() { CGContextSaveGState(self) } | |
func restoreGState() { CGContextRestoreGState(self) } | |
func scaleCTM( sx: CGFloat, sy: CGFloat) { CGContextScaleCTM(self, sx, sy) } | |
func translateCTM( tx: CGFloat, ty: CGFloat) { CGContextTranslateCTM(self, tx, ty) } | |
func rotateCTM( angle: CGFloat) { CGContextRotateCTM(self, angle) } | |
func concatCTM( transform: CGAffineTransform) { CGContextConcatCTM(self, transform) } | |
func getCTM() -> CGAffineTransform { return CGContextGetCTM(self) } | |
func setLineWidth( width: CGFloat) { CGContextSetLineWidth(self, width) } | |
func setLineCap( cap: CGLineCap) { CGContextSetLineCap(self, cap) } | |
func setLineJoin( join: CGLineJoin) { CGContextSetLineJoin(self, join) } | |
func setMiterLimit( limit: CGFloat) { CGContextSetMiterLimit(self, limit) } | |
func setLineDash( phase: CGFloat, lengths: UnsafePointer<CGFloat>, count: Int) { CGContextSetLineDash(self, phase, lengths, count) } | |
func setFlatness( flatness: CGFloat) { CGContextSetFlatness(self, flatness) } | |
func setAlpha( alpha: CGFloat) { CGContextSetAlpha(self, alpha) } | |
func setBlendMode( mode: CGBlendMode) { CGContextSetBlendMode(self, mode) } | |
func beginPath() { CGContextBeginPath(self) } | |
func moveToPoint( x: CGFloat, y: CGFloat) { CGContextMoveToPoint(self, x, y) } | |
func addLineToPoint( x: CGFloat, y: CGFloat) { CGContextAddLineToPoint(self, x, y) } | |
func addCurveToPoint( cp1x: CGFloat, cp1y: CGFloat, cp2x: CGFloat, cp2y: CGFloat, x: CGFloat, y: CGFloat) { CGContextAddCurveToPoint(self, cp1x, cp1y, cp2x, cp2y, x, y) } | |
func addQuadCurveToPoint( cpx: CGFloat, cpy: CGFloat, x: CGFloat, y: CGFloat) { CGContextAddQuadCurveToPoint(self, cpx, cpy, x, y) } | |
func closePath() { CGContextClosePath(self) } | |
func addRect( rect: CGRect) { CGContextAddRect(self, rect) } | |
func addRects( rects: UnsafePointer<CGRect>, count: Int) { CGContextAddRects(self, rects, count) } | |
func addLines( points: UnsafePointer<CGPoint>, count: Int) { CGContextAddLines(self, points, count) } | |
func addEllipseInRect( rect: CGRect) { CGContextAddEllipseInRect(self, rect) } | |
func addArc( x: CGFloat, y: CGFloat, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat, clockwise: Int32) { CGContextAddArc(self, x, y, radius, startAngle, endAngle, clockwise) } | |
func addArcToPoint( x1: CGFloat, y1: CGFloat, x2: CGFloat, y2: CGFloat, radius: CGFloat) { CGContextAddArcToPoint(self, x1, y1, x2, y2, radius) } | |
func addPath( path: CGPath!) { CGContextAddPath(self, path) } | |
func replacePathWithStrokedPath() { CGContextReplacePathWithStrokedPath(self) } | |
func isPathEmpty() -> Bool { return CGContextIsPathEmpty(self) } | |
func getPathCurrentPoint() -> CGPoint { return CGContextGetPathCurrentPoint(self) } | |
func getPathBoundingBox() -> CGRect { return CGContextGetPathBoundingBox(self) } | |
func copyPath() -> CGPath! { return CGContextCopyPath(self) } | |
func pathContainsPoint( point: CGPoint, mode: CGPathDrawingMode) -> Bool { return CGContextPathContainsPoint(self, point, mode) } | |
func drawPath( mode: CGPathDrawingMode) { CGContextDrawPath(self, mode) } | |
func fillPath() { CGContextFillPath(self) } | |
func eOFillPath() { CGContextEOFillPath(self) } | |
func strokePath() { CGContextStrokePath(self) } | |
func fillRect( rect: CGRect) { CGContextFillRect(self, rect) } | |
func fillRects( rects: UnsafePointer<CGRect>, count: Int) { CGContextFillRects(self, rects, count) } | |
func strokeRect( rect: CGRect) { CGContextStrokeRect(self, rect) } | |
func strokeRectWithWidth( rect: CGRect, width: CGFloat) { CGContextStrokeRectWithWidth(self, rect, width) } | |
func clearRect( rect: CGRect) { CGContextClearRect(self, rect) } | |
func fillEllipseInRect( rect: CGRect) { CGContextFillEllipseInRect(self, rect) } | |
func strokeEllipseInRect( rect: CGRect) { CGContextStrokeEllipseInRect(self, rect) } | |
func strokeLineSegments( points: UnsafePointer<CGPoint>, count: Int) { CGContextStrokeLineSegments(self, points, count) } | |
func clip() { CGContextClip(self) } | |
func eOClip() { CGContextEOClip(self) } | |
func clipToMask( rect: CGRect, mask: CGImage!) { CGContextClipToMask(self, rect, mask) } | |
func getClipBoundingBox() -> CGRect { return CGContextGetClipBoundingBox(self) } | |
func clipToRect( rect: CGRect) { CGContextClipToRect(self, rect) } | |
func clipToRects( rects: UnsafePointer<CGRect>, count: Int) { CGContextClipToRects(self, rects, count) } | |
func setFillColorWithColor( color: CGColor!) { CGContextSetFillColorWithColor(self, color) } | |
func setStrokeColorWithColor( color: CGColor!) { CGContextSetStrokeColorWithColor(self, color) } | |
func setFillColorSpace( space: CGColorSpace!) { CGContextSetFillColorSpace(self, space) } | |
func setStrokeColorSpace( space: CGColorSpace!) { CGContextSetStrokeColorSpace(self, space) } | |
func setFillColor( components: UnsafePointer<CGFloat>) { CGContextSetFillColor(self, components) } | |
func setStrokeColor( components: UnsafePointer<CGFloat>) { CGContextSetStrokeColor(self, components) } | |
func setFillPattern( pattern: CGPattern!, components: UnsafePointer<CGFloat>) { CGContextSetFillPattern(self, pattern, components) } | |
func setStrokePattern( pattern: CGPattern!, components: UnsafePointer<CGFloat>) { CGContextSetStrokePattern(self, pattern, components) } | |
func setPatternPhase( phase: CGSize) { CGContextSetPatternPhase(self, phase) } | |
func setGrayFillColor( gray: CGFloat, alpha: CGFloat) { CGContextSetGrayFillColor(self, gray, alpha) } | |
func setGrayStrokeColor( gray: CGFloat, alpha: CGFloat) { CGContextSetGrayStrokeColor(self, gray, alpha) } | |
func setRGBFillColor( red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) { CGContextSetRGBFillColor(self, red, green, blue, alpha) } | |
func setRGBStrokeColor( red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) { CGContextSetRGBStrokeColor(self, red, green, blue, alpha) } | |
func setCMYKFillColor( cyan: CGFloat, magenta: CGFloat, yellow: CGFloat, black: CGFloat, alpha: CGFloat) { CGContextSetCMYKFillColor(self, cyan, magenta, yellow, black, alpha) } | |
func setCMYKStrokeColor( cyan: CGFloat, magenta: CGFloat, yellow: CGFloat, black: CGFloat, alpha: CGFloat) { CGContextSetCMYKStrokeColor(self, cyan, magenta, yellow, black, alpha) } | |
func setRenderingIntent( intent: CGColorRenderingIntent) { CGContextSetRenderingIntent(self, intent) } | |
func drawImage( rect: CGRect, image: CGImage!) { CGContextDrawImage(self, rect, image) } | |
func drawTiledImage( rect: CGRect, image: CGImage!) { CGContextDrawTiledImage(self, rect, image) } | |
func getInterpolationQuality() -> CGInterpolationQuality { return CGContextGetInterpolationQuality(self) } | |
func setInterpolationQuality( quality: CGInterpolationQuality) { CGContextSetInterpolationQuality(self, quality) } | |
func setShadowWithColor( offset: CGSize, blur: CGFloat, color: CGColor!) { CGContextSetShadowWithColor(self, offset, blur, color) } | |
func setShadow( offset: CGSize, blur: CGFloat) { CGContextSetShadow(self, offset, blur) } | |
func drawLinearGradient( gradient: CGGradient!, startPoint: CGPoint, endPoint: CGPoint, options: CGGradientDrawingOptions) { CGContextDrawLinearGradient(self, gradient, startPoint, endPoint, options) } | |
func drawRadialGradient( gradient: CGGradient!, startCenter: CGPoint, startRadius: CGFloat, endCenter: CGPoint, endRadius: CGFloat, options: CGGradientDrawingOptions) { CGContextDrawRadialGradient(self, gradient, startCenter, startRadius, endCenter, endRadius, options) } | |
func drawShading( shading: CGShading!) { CGContextDrawShading(self, shading) } | |
func setCharacterSpacing( spacing: CGFloat) { CGContextSetCharacterSpacing(self, spacing) } | |
func setTextPosition( x: CGFloat, y: CGFloat) { CGContextSetTextPosition(self, x, y) } | |
func getTextPosition() -> CGPoint { return CGContextGetTextPosition(self) } | |
func setTextMatrix( t: CGAffineTransform) { CGContextSetTextMatrix(self, t) } | |
func getTextMatrix() -> CGAffineTransform { return CGContextGetTextMatrix(self) } | |
func setTextDrawingMode( mode: CGTextDrawingMode) { CGContextSetTextDrawingMode(self, mode) } | |
func setFont( font: CGFont!) { CGContextSetFont(self, font) } | |
func setFontSize( size: CGFloat) { CGContextSetFontSize(self, size) } | |
func showGlyphsAtPositions( glyphs: UnsafePointer<CGGlyph>, positions: UnsafePointer<CGPoint>, count: Int) { CGContextShowGlyphsAtPositions(self, glyphs, positions, count) } | |
func drawPDFPage( page: CGPDFPage!) { CGContextDrawPDFPage(self, page) } | |
func beginPage( mediaBox: UnsafePointer<CGRect>) { CGContextBeginPage(self, mediaBox) } | |
func endPage() { CGContextEndPage(self) } | |
func flush() { CGContextFlush(self) } | |
func synchronize() { CGContextSynchronize(self) } | |
func setShouldAntialias( shouldAntialias: Bool) { CGContextSetShouldAntialias(self, shouldAntialias) } | |
func setAllowsAntialiasing( allowsAntialiasing: Bool) { CGContextSetAllowsAntialiasing(self, allowsAntialiasing) } | |
func setShouldSmoothFonts( shouldSmoothFonts: Bool) { CGContextSetShouldSmoothFonts(self, shouldSmoothFonts) } | |
func setAllowsFontSmoothing( allowsFontSmoothing: Bool) { CGContextSetAllowsFontSmoothing(self, allowsFontSmoothing) } | |
func setShouldSubpixelPositionFonts( shouldSubpixelPositionFonts: Bool) { CGContextSetShouldSubpixelPositionFonts(self, shouldSubpixelPositionFonts) } | |
func setAllowsFontSubpixelPositioning( allowsFontSubpixelPositioning: Bool) { CGContextSetAllowsFontSubpixelPositioning(self, allowsFontSubpixelPositioning) } | |
func setShouldSubpixelQuantizeFonts( shouldSubpixelQuantizeFonts: Bool) { CGContextSetShouldSubpixelQuantizeFonts(self, shouldSubpixelQuantizeFonts) } | |
func setAllowsFontSubpixelQuantization( allowsFontSubpixelQuantization: Bool) { CGContextSetAllowsFontSubpixelQuantization(self, allowsFontSubpixelQuantization) } | |
func beginTransparencyLayer( auxiliaryInfo: CFDictionary!) { CGContextBeginTransparencyLayer(self, auxiliaryInfo) } | |
func beginTransparencyLayerWithRect( rect: CGRect, auxiliaryInfo: CFDictionary!) { CGContextBeginTransparencyLayerWithRect(self, rect, auxiliaryInfo) } | |
func endTransparencyLayer() { CGContextEndTransparencyLayer(self) } | |
func getUserSpaceToDeviceSpaceTransform() -> CGAffineTransform { return CGContextGetUserSpaceToDeviceSpaceTransform(self) } | |
func convertPointToDeviceSpace( point: CGPoint) -> CGPoint { return CGContextConvertPointToDeviceSpace(self, point) } | |
func convertPointToUserSpace( point: CGPoint) -> CGPoint { return CGContextConvertPointToUserSpace(self, point) } | |
func convertSizeToDeviceSpace( size: CGSize) -> CGSize { return CGContextConvertSizeToDeviceSpace(self, size) } | |
func convertSizeToUserSpace( size: CGSize) -> CGSize { return CGContextConvertSizeToUserSpace(self, size) } | |
func convertRectToDeviceSpace( rect: CGRect) -> CGRect { return CGContextConvertRectToDeviceSpace(self, rect) } | |
func convertRectToUserSpace( rect: CGRect) -> CGRect { return CGContextConvertRectToUserSpace(self, rect) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment