Re: What paradigm behind NSColor's drawing methods?
Re: What paradigm behind NSColor's drawing methods?
- Subject: Re: What paradigm behind NSColor's drawing methods?
- From: Erik Buck <email@hidden>
- Date: Fri, 1 Feb 2008 14:49:53 -0800 (PST)
> [NSGraphicsContext saveGraphicsState];
> NSSetFocusRingStyle(NSFocusRingOnly);
> [[NSColor keyboardFocusIndicatorColor] set];
> NSFrameRect([self visibleRect]);
> [NSGraphicsContext restoreGraphicsState];
I this specific case, just don't bother restoring the graphics state. Code it like this:
NSSetFocusRingStyle(NSFocusRingOnly);
[[NSColor keyboardFocusIndicatorColor] set];
NSFrameRect([self visibleRect]);
If you plan to perform any drawing after drawing the focus ring, you can set whatever color you want then. Any other drawing by your classes or framework classes is forced to set the color and other state information it needs because drawing in different drawRect: implementation has no way of knowing what the current graphics state is. Therefore, it doesn't matter what state you leave behind.
Most importantly of all, there is already an implicit [NSGraphicsContext saveGraphicsState]; and [NSGraphicsContext restoreGraphicsState]; pair around drawRect:. That's one of the reasons you shouldn't call -drawRect: directly yourself. Call -display or -setNeedsDisplay: and they will take care of setting up the graphics state and tearing it down.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden