FROM : Jerry Krinock
DATE : Fri Feb 01 22:18:27 2008
On 2008 Feb, 01, at 12:47, glenn andreas wrote:
> What circumstances are you running into that not having an explicit
> drawing context parameter is a problem?
Drawing a focus ring, in -drawRect of a custom control...
[NSGraphicsContext saveGraphicsState];
NSSetFocusRingStyle(NSFocusRingOnly);
[[NSColor keyboardFocusIndicatorColor] set];
NSFrameRect([self visibleRect]);
[NSGraphicsContext restoreGraphicsState];
In the Cocoa Drawing Guide I read that:
"Important: Saving and restoring the current graphics state is an
expensive operation and should done as little as possible. With the
exception of clipping paths, most state attributes can be undone
manually in your code without saving and restoring the entire state."
They seem to be suggesting that instead of -saveGraphicsState and -
restoreGraphicsState, I should manually "get" the color and the
FocusRingStyle before "setting", so I can set them back to their
original values after I am done. But I can't do that because there
are no getters for these.
As far as the rest of your reply, OK I understand that there are many
other methods that use the drawing context as an implied "object",
that this is done for convenience, and I should orient my thinking
into this paradigm. Thanks for the explanation.
DATE : Fri Feb 01 22:18:27 2008
On 2008 Feb, 01, at 12:47, glenn andreas wrote:
> What circumstances are you running into that not having an explicit
> drawing context parameter is a problem?
Drawing a focus ring, in -drawRect of a custom control...
[NSGraphicsContext saveGraphicsState];
NSSetFocusRingStyle(NSFocusRingOnly);
[[NSColor keyboardFocusIndicatorColor] set];
NSFrameRect([self visibleRect]);
[NSGraphicsContext restoreGraphicsState];
In the Cocoa Drawing Guide I read that:
"Important: Saving and restoring the current graphics state is an
expensive operation and should done as little as possible. With the
exception of clipping paths, most state attributes can be undone
manually in your code without saving and restoring the entire state."
They seem to be suggesting that instead of -saveGraphicsState and -
restoreGraphicsState, I should manually "get" the color and the
FocusRingStyle before "setting", so I can set them back to their
original values after I am done. But I can't do that because there
are no getters for these.
As far as the rest of your reply, OK I understand that there are many
other methods that use the drawing context as an implied "object",
that this is done for convenience, and I should orient my thinking
into this paradigm. Thanks for the explanation.
| Related mails | Author | Date |
|---|---|---|
| Jerry Krinock | Feb 1, 20:41 | |
| glenn andreas | Feb 1, 21:47 | |
| Jerry Krinock | Feb 1, 22:18 | |
| glenn andreas | Feb 1, 22:44 | |
| Erik Buck | Feb 1, 23:49 | |
| Peter Ammon | Feb 2, 01:23 | |
| Erik Buck | Feb 2, 03:29 | |
| Ricky Sharp | Feb 2, 16:04 | |
| Jerry Krinock | Feb 4, 19:59 |






Cocoa mail archive

