绘制 Inset NSShadow 和 Inset Stroke
我有一个 NSBezierPath,我想在路径内绘制插图阴影(类似于 Photoshop)。
有办法做到这一点吗?另外,我知道您可以-描边
路径,但是您可以在路径内部描边(类似于Photoshop中的描边内部)吗?
更新 3
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];
这是我的最终结果。看起来不错。我必须将阴影更改为 White @ 1.0 Alpha 才能使其正常工作。尽管菜单栏项目的阴影 alpha 范数是 0.5,但它看起来还不错。
非常感谢 Joshua Nozzi。
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 3
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];
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.
Many thanks go out to Joshua Nozzi.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可以通过在贝塞尔曲线路径上设置剪辑以将其用作蒙版并抚摸阴影来实现此目的,然后根据需要添加正常描边。
根据更新的代码进行更新:
就这样。今晚我感觉自己有点拖延。 :-)
I think you can do this by setting clip on the bezier path to use it as a mask and stroking the shadow, then adding a normal stroke if desired.
Update based on updated code:
Here you go. I'm feeling procrastinate-y tonight. :-)