Skip navigation.
 
mlRe: What paradigm behind NSColor's drawing methods?
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.

Related mailsAuthorDate
mlWhat paradigm behind NSColor's drawing methods? Jerry Krinock Feb 1, 20:41
mlRe: What paradigm behind NSColor's drawing methods? glenn andreas Feb 1, 21:47
mlRe: What paradigm behind NSColor's drawing methods? Jerry Krinock Feb 1, 22:18
mlRe: What paradigm behind NSColor's drawing methods? glenn andreas Feb 1, 22:44
mlRe: What paradigm behind NSColor's drawing methods? Erik Buck Feb 1, 23:49
mlRe: What paradigm behind NSColor's drawing methods? Peter Ammon Feb 2, 01:23
mlRe: What paradigm behind NSColor's drawing methods? Erik Buck Feb 2, 03:29
mlRe: What paradigm behind NSColor's drawing methods? Ricky Sharp Feb 2, 16:04
mlRe: What paradigm behind NSColor's drawing methods? Jerry Krinock Feb 4, 19:59