I have an odd issue related to the answer to this question:
Draw an installation of NSShadow and Inset Stroke
I use this code in the drawRect method of a user view. I have exactly this:
- (void)drawRect:(NSRect)rect { // Create and fill the shown path NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:[self bounds] xRadius:4.0f yRadius:4.0f]; [[NSColor colorWithCalibratedWhite:0.8f alpha:0.2f] set]; [path fill]; // Save the graphics state for shadow [NSGraphicsContext saveGraphicsState]; // Set the shown path as the clip [path setClip]; // Create and stroke the shadow NSShadow * shadow = [[[NSShadow alloc] init] autorelease]; [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0.0f alpha:0.8f]]; [shadow setShadowBlurRadius:2.0]; [shadow set]; [path stroke]; // Restore the graphics state [NSGraphicsContext restoreGraphicsState]; if ( highlight && [[self window] firstResponder] == self ) { NSSetFocusRingStyle(NSFocusRingOnly); [[NSBezierPath bezierPathWithRect:[self bounds]] fill]; } }
The problem occurs when I add a multi-line shortcut (either the native or the child of my custom view).
When my program window loses focus and I return to it, my inner shadow / stroke becomes darker. The shadows seem to overlap. This is strange because, as said, if only this user view is in my window, it will be fine.
If I comment the line
[path setClip]
the shadow no longer overlaps, but I donβt get the desired effect of rounded corners (similar to NSBox).
I tried what happens with the Push button, and not with the Multiline Label, and, losing / gaining the focus of the window, it has no problems, but when I press the button, the shadow overlaps.
I believe the problem is similar than here, but in Cocoa instead of Java:
Java setClip seems to redraw
Thank you for your help!
source share