CGContext Syntactic Sugar

Tired of typing CGContextBlah(context, ...)? There’s an extension for that: context.blah(...)

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

Get CGContextExt.swift.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s