Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSWindow Shadow Outline

I am drawing a custom window by setting a custom content view for the window. When I draw the custom view I give it rounded corners and a nice outline to mimic a proper window.

However, I see another 1 px outline around the window which strays from the edge at the corners. I have found that if I turn off the shadow it goes away, but obviously as this wants to act like a window I need the shadow. Here's what I mean about the 1px outline:

enter image description here

How can I prevent this?


EDIT

Code for drawing the custom window's content view:

    NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:[self bounds] cornerRadius:5];

    NSGradient* aGradient = [[[NSGradient alloc] initWithColorsAndLocations:
                              [NSColor colorWithDeviceRed:0.5569 green:0.5137 blue:0.4588 alpha:1.0000], 0.0,
                              [NSColor colorWithDeviceRed:0.5569 green:0.5137 blue:0.4588 alpha:1.0000], 1.0,
                              nil] autorelease];

    [aGradient drawInBezierPath:path angle:90];

    [path setLineWidth:4];
    [[NSColor colorWithDeviceRed:0.4235 green:0.3922 blue:0.3451 alpha:0.9000] setStroke];
    [path strokeInside];

    [path setLineWidth:3];
    [[NSColor colorWithDeviceRed:0.8431 green:0.8314 blue:0.8078 alpha:1.0000] setStroke];
    [path strokeInside];

    [path setLineWidth:1];
    [[NSColor colorWithDeviceRed:0.4235 green:0.3922 blue:0.3451 alpha:0.9000] setStroke];
    [path strokeInside];
like image 653
Joshua Avatar asked May 29 '11 12:05

Joshua


1 Answers

Don't ask me how I got this, but this will solve your problem.

Define a category for NSWindow with the following content:

@implementation NSWindow(NoShadowRim)

- (id)_shadowRimInfo {
  return @{
    @"kCUIMeasureWindowFrameRimDensity": [NSNumber numberWithInt:0]
  };
}

@end

DISCLAIMER: This overrides the internal method of NSWindow, so use it at your own risk. It may break with any OS X update.

like image 63
Mihhail Lapushkin Avatar answered Oct 03 '22 09:10

Mihhail Lapushkin