Note that there are some explanatory texts on larger screens.

plurals
  1. PODraw an Inset NSShadow and Inset Stroke
    primarykey
    data
    text
    <p>I have an <code>NSBezierPath</code> and I want to draw in inset shadow (similar to Photoshop) inside the path.</p> <p>Is there anyway to do this? Also, I know you can <code>-stroke</code> paths, but can you stroke inside a path (similar to Stroke Inside in Photoshop)?</p> <h2>Update 3</h2> <pre><code>static NSImage * graydient = nil; if (!graydient) { graydient = [[NSImage alloc] initWithSize: NSMakeSize(22, 22)]; [graydient lockFocus]; NSGradient * gradient = [[NSGradient alloc] initWithColorsAndLocations: clr(@"#262729"), 0.0f, clr(@"#37383a"), 0.43f, clr(@"#37383a"), 1.0f, nil]; [gradient drawInRect: NSMakeRect(0, 4.179, 22, 13.578) angle: 90.0f]; [gradient release]; [graydient unlockFocus]; } NSColor * gcolor = [NSColor colorWithPatternImage: graydient]; [gcolor set]; NSShadow * shadow = [NSShadow new]; [shadow setShadowColor: [NSColor colorWithDeviceWhite: 1.0f alpha: 1.0f]]; [shadow setShadowBlurRadius: 0.0f]; [shadow setShadowOffset: NSMakeSize(0, 1)]; [shadow set]; [path fill]; [NSGraphicsContext saveGraphicsState]; [[path pathFromIntersectionWithPath: [NSBezierPath bezierPathWithRect: NSInsetRect([path bounds], 0.6, 0)]] setClip]; [gcolor set]; [shadow setShadowOffset: NSMakeSize(0, 1)]; [shadow setShadowColor: [NSColor blackColor]]; [shadow set]; [outer stroke]; [NSGraphicsContext restoreGraphicsState]; [NSGraphicsContext saveGraphicsState]; [[NSGraphicsContext currentContext] setCompositingOperation: NSCompositeSourceOut]; [shadow set]; [[NSColor whiteColor] set]; [inner fill]; [shadow set]; [inner fill]; [NSGraphicsContext restoreGraphicsState]; </code></pre> <p><img src="https://i.stack.imgur.com/lyn2J.png" alt="Final Result"> This is my final result. It looks pretty good. I had to change the shadow to White @ 1.0 Alpha to make it work. Even though the shadow alpha norm for menu bar items is 0.5, it doesn't look half bad.</p> <p>Many thanks go out to <a href="https://stackoverflow.com/users/201199/joshua-nozzi">Joshua Nozzi</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload