Drawing in Vanilla

Hi everyone.

I’ve been looking around and testing ways to do this, but with limited success at my current stage of python knowhow.

Can anyone point me to resources/code samples (existing plugins/scripts, or bits in the wrapper etc) that will help me with drawing a shape (not glyph - just a primitive) inside a vanilla window, and preferably inside a group in that window? I’ve found the GlyphView() stuff, but have yet to try and reverse engineer how it works and whether there is an approach in there somewhere (or if this is barking up the wrong tree…)

I’ve no experience with working with AppKit modules as of yet, and have yet to find good documentation.

Thanks!

the GlyphView() is basically a prepared canvas to draw a glyph. If you you want to draw free shapes, you are better off with using the CanvasView() as seen in an example here. … At the line where the example uses NSRectFill(bounds) you can have whatever drawing you want. I’d recommend to check the Apple Documentation in Objective C, search for primitive (or bezierPath) drawing methods and translate them into python syntax. You can find a lot of references when you search for “pyobjc” on the web. It’s not too hard.

Edit:

Additionally to get you another example, you can have a look in to the code I wrote in the Kernkraft Plugin. I made a custom View myself, because a) the GlyphView() didn’t exist back then, and b) I needed to have more functions in the Kernkraft preview, like displaying components.

1 Like

Thanks Mark - This is helpful to start connecting the dots, as it were. I’ll check these out and jump into this further.

I looked into examples mentioned by @Mark but can’t figure out how to add other elements like anchors to GlyphView()?

You simply draw shapes with the NSBezierPath functions. Like you would in a reporter plugin.

1 Like

Also, unless you know how to subclass, you might not be able to customise the GlyphsView(). As I wrote before, it is already prepared to daw a glyph (tile) like in the Font Overview. If you want to draw your own, additional elements you might be faster with using the CanvasView(). And there: just like mekkablue wrote …

1 Like