Last active
September 12, 2019 10:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh, that's easier!