Last active
May 5, 2025 21:08
-
-
Save connordavenport/22ece008d6ee3c363224da39fe2db24b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 mojo.subscriber import Subscriber, registerGlyphEditorSubscriber, unregisterGlyphEditorSubscriber, listRegisteredSubscribers | |
from mojo.UI import inDarkMode | |
class anchor_scrubber(Subscriber): | |
debug = False | |
def build(self): | |
editor = self.getGlyphEditor() | |
foregroundLayer = editor.extensionContainer( | |
identifier="com.scrubber.foreground", | |
location='foreground', | |
clear=True | |
) | |
self.pointInsertionLayer = foregroundLayer.appendBaseSublayer() | |
glyphDidChangeAnchorsDelay = 0 | |
def glyphDidChangeAnchors(self, info): | |
glyph = info['glyph'] | |
delNames = [] | |
ignore = [] | |
rev = list(glyph.anchors) | |
rev.reverse() | |
d = False | |
for ar in rev: | |
if ar.name in ignore: | |
delNames.append(ar.name) | |
glyph.removeAnchor(ar) | |
rev.remove(ar) | |
d = True | |
else: | |
ignore.append(ar.name) | |
if d: | |
for anc in glyph.anchors: | |
if anc.name in delNames: | |
anc.selected = False | |
color = anc.color or (1,0,0,1) | |
self.playPointAnimation(anc.position, 15, color) | |
def playPointAnimation(self, location, size, color): | |
x, y = location | |
pathLayer = self.pointInsertionLayer.appendBaseSublayer( | |
position=((x-size/2, y-size/2)), | |
size=(size, size), | |
) | |
circle = pathLayer.appendOvalSublayer( | |
size=(size, size), | |
fillColor=None, | |
strokeColor=color, | |
strokeWidth=2, | |
strokeCap="round") | |
size *= 2.2 | |
with circle.propertyGroup(duration=1): | |
circle.setStrokeWidth(1) | |
circle.setSize((size,size)) | |
with pathLayer.propertyGroup( | |
duration=1, | |
animationFinishedCallback=self.removePointAnimation | |
): | |
pathLayer.setOpacity(0) | |
pathLayer.setPosition((x-size/2, y-size/2)) | |
def removePointAnimation(self, layer): | |
self.pointInsertionLayer.removeSublayer(layer) | |
if __name__ == '__main__': | |
registerGlyphEditorSubscriber(anchor_scrubber) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment