1

I'm trying to recreate a menu that looks like the contextual menu of the Dock.

I'm drawing a background using a NSBezierPath. As you might see, the border of the Dock's menu has 3 semi-transparent colors on the border.

From the inside to the outside :

  • HSB 0;0;7% Op 91% (Black) 1px width
  • HSB 0;0;53% Op 38% (Grey) 2px width
  • HSB 0;0;0 Op 41% (Black) 1px width

How could I draw these borders to my NSBezierPath ?

PS: Using a pattern ([NSColor colorWithPatternImage:]) does not work.

Monolo
  • 18,205
  • 17
  • 69
  • 103
Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134
  • 1
    Instead of trying to stroke 1 bezier path with 3 colors, why not have 3 bezier paths, and use them as a clipping mask on an NSWindow? Also, this may be related: http://stackoverflow.com/questions/15379410/customize-nsmenu-like-apples-dock-right-click-menu. NSMenu already includes private support for a [dark menu](https://github.com/swillits/NSMenu-Dark) like you're looking for. – CodaFi Mar 31 '13 at 02:37
  • It's a nice thing your dark menu. Do you think it's possible to get an arrow like in the dock ? – Matthieu Riegler Mar 31 '13 at 14:00

1 Answers1

1

Paths are just geometry. They don't have color. Color is part of the graphics context and affects the stroke or fill operations.

So, yes, one options is to stroke several paths instead of one.

Another possible approach is to use NSDrawNinePartImage() with pre-rendered images (bitmap or vector/PDF).

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154