Created
March 6, 2012 20:02
-
-
Save peyton/1988678 to your computer and use it in GitHub Desktop.
Block-based helpers for CGContexts
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
/** | |
* CGContextBlocks.h | |
* | |
* Block-based convenience methods for organizing Core Graphics-heavy code. | |
* | |
* See https://gist.github.com/gists/1988678 for the latest version. | |
* | |
* Idea stolen from http://www.natestedman.com/post/improving-cgcontext-with-blocks/ | |
*/ | |
typedef void(^CGStateBlock)(); | |
void CGContextState(CGContextRef ctx, CGStateBlock actions) | |
{ | |
CGContextSaveGState(ctx); | |
actions(); | |
CGContextRestoreGState(ctx); | |
} | |
void CGContextTransparencyLayer(CGContextRef ctx, CGStateBlock actions) | |
{ | |
CGContextBeginTransparencyLayer(ctx, NULL); | |
actions(); | |
CGContextEndTransparencyLayer(ctx); | |
} | |
// End CGContextBlocks.h // |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment