FROM : Erik Buck
DATE : Fri Feb 01 23:49:53 2008
> [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.
DATE : Fri Feb 01 23:49:53 2008
> [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.
| 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

