Skip to content

Instantly share code, notes, and snippets.

@okay-type
Last active September 12, 2019 10:24
Show Gist options
  • Save okay-type/edead146afbca6be73ba9e985737dce7 to your computer and use it in GitHub Desktop.
Save okay-type/edead146afbca6be73ba9e985737dce7 to your computer and use it in GitHub Desktop.
show the current glyph's mark color in robofont's glyph window
from vanilla import *
import mojo.drawingTools as ctx
from mojo.events import addObserver, removeObserver
from mojo.canvas import CanvasGroup
from mojo.UI import CurrentGlyphWindow
s = 50
class MarkyGlyph(object):
def __init__(self):
self.markview = None
addObserver(self, "observerGlyphWindowWillOpen", "glyphWindowWillOpen")
addObserver(self, "observerDraw", "draw")
addObserver(self, "observerDrawPreview", "drawPreview")
def observerGlyphWindowWillOpen(self, notification):
self.window = notification["window"]
self.markview = CanvasGroup((-s, 0, s, s), delegate=self)
self.window.addGlyphEditorSubview(self.markview)
def observerDraw(self, notification):
if self.markview:
self.markview.show(True)
def observerDrawPreview(self, notification):
# hide the view in Preview mode
if self.markview:
self.markview.show(False)
# canvas delegate callbacks
def opaque(self):
return False
def acceptsFirstResponder(self):
return False
def acceptsMouseMoved(self):
return True
def becomeFirstResponder(self):
return False
def resignFirstResponder(self):
return False
def shouldDrawBackground(self):
return False
def draw(self):
glyph = self.window.getGlyph()
if glyph is None:
return
if glyph.markColor:
r = glyph.markColor.r
g = glyph.markColor.g
b = glyph.markColor.b
a = glyph.markColor.a
else:
r = g = b = 1
a = .1
x, y, w, h = self.window.getVisibleRect()
ctx.fill(r,g,b,a)
ctx.stroke(None)
ctx.newPath()
ctx.moveTo((x+s, y+s))
ctx.lineTo((x+s, y))
ctx.lineTo((x, y+s))
ctx.closePath()
ctx.drawPath()
ctx.fill(None)
MarkyGlyph()
@okay-type
Copy link
Author

Oh, that's easier!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment