Draw an Inset NSShadow and Inset Stroke
Posted
by
Alexsander Akers
on Stack Overflow
See other posts from Stack Overflow
or by Alexsander Akers
Published on 2010-11-17T14:59:50Z
Indexed on
2010/12/31
21:53 UTC
Read the original article
Hit count: 425
I have an NSBezierPath
and I want to draw in inset shadow (similar to Photoshop) inside the path.
Is there anyway to do this? Also, I know you can -stroke
paths, but can you stroke inside a path (similar to Stroke Inside in Photoshop)?
Update
This is the code I'm using. The first part makes a white shadow downwards. The second part draws the gray gradient. The third part draws the black inset shadow. Assume path
is an NSBezierPath
instance and that clr(...)
returns an NSColor
from a hex string.
NSShadow * shadow = [NSShadow new];
[shadow setShadowColor: [NSColor colorWithDeviceWhite: 1.0f alpha: 0.5f]];
[shadow setShadowBlurRadius: 0.0f];
[shadow setShadowOffset: NSMakeSize(0, 1)];
[shadow set];
[shadow release];
NSGradient * gradient = [[NSGradient alloc] initWithColorsAndLocations: clr(@"#262729"), 0.0f, clr(@"#37383a"), 0.43f, clr(@"#37383a"), 1.0f, nil];
[gradient drawInBezierPath: path angle: 90.0f];
[gradient release];
[NSGraphicsContext saveGraphicsState];
[path setClip];
shadow = [NSShadow new];
[shadow setShadowColor: [NSColor redColor]];
[shadow setShadowBlurRadius: 0.0f];
[shadow setShadowOffset: NSMakeSize(0, -1)];
[shadow set];
[shadow release];
[path stroke];
[NSGraphicsContext restoreGraphicsState];
Here you can see a gradient fill, a white drop shadow downwards, and a black inner shadow downwards.
© Stack Overflow or respective owner