One Quickie


Push/pop CGContext state (Graphics->General)
CGContextRef context = ...;
...
CGContextSaveGState (context); {
    [drawable drawWithContext: context
              inRect: bounds
              withMetrics: self.metrics]; // or whatever drawing you're doing
} CGContextRestoreGState (context);
Edit: Gus Meuller of Flying Meat fame has a block-based utility that does this:
void FMCGContextHoldGState (CGContextRef context, void (^block)()) {
    CGContextSaveGState(context); {
        block ();
    } CGContextRestoreGState(context);
}
and if you're wanting to do something similar with NSGraphicsContexts:
void FMNSContextHoldGState (void (^block)()) {
    [NSGraphicsContext saveGraphicsState]; {
        block ();
    } [NSGraphicsContext restoreGraphicsState];
}



borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book

webmonster@borkware.com