From 284a77b10f501e293d82e6d30e03416eae8cf574 Mon Sep 17 00:00:00 2001 From: Skyler Lehmkuhl Date: Wed, 18 Jan 2012 13:23:24 -0500 Subject: [PATCH] Added basic text --- lightningbeam.py | 43 ++++++++++++---- svlgui.py | 125 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 154 insertions(+), 14 deletions(-) diff --git a/lightningbeam.py b/lightningbeam.py index 1d4cc8f..3b23abf 100755 --- a/lightningbeam.py +++ b/lightningbeam.py @@ -69,6 +69,7 @@ def onMouseDownGroup(self, x, y): self.clicked = True elif svlgui.MODE in ["r", "e", "p"]: if svlgui.MODE=="r": + #I can't remember what the 'c' stands for... self.cshape = box(x, y, 0, 0) elif svlgui.MODE=="e": self.cshape = ellipse(x, y, 0, 0) @@ -84,6 +85,13 @@ def onMouseDownGroup(self, x, y): self.cshape.onKeyDown = onKeyDownObj self.clicked = True MainWindow.scriptwindow.text = self.activelayer.frames[self.activelayer.currentframe].actions + elif svlgui.MODE in ["t"]: + self.ctext = svlgui.Text("Mimimi",x,y) + self.ctext.onMouseDown = onMouseDownText + self.ctext.onMouseDrag = onMouseDragText + self.ctext.onMouseUp = onMouseUpText + self.add(self.ctext) + self.ctext = None def onMouseDownObj(self, x, y): MainWindow.scriptwindow.text = root.descendItem().activelayer.frames[root.descendItem().activelayer.currentframe].actions self.clicked = True @@ -91,6 +99,11 @@ def onMouseDownObj(self, x, y): if svlgui.MODE == "b": self.filled = True self.fillcolor = svlgui.FILLCOLOR +def onMouseDownText(self,x,y): + MainWindow.scriptwindow.text = root.descendItem().activelayer.frames[root.descendItem().activelayer.currentframe].actions + self.clicked = True + self.initx, self.inity = x-self.x, y-self.y + #svlgui.alert('235') def onMouseDownFrame(self, x, y): pass def onMouseUpGroup(self, x, y): @@ -105,6 +118,8 @@ def onMouseUpGroup(self, x, y): MainWindow.stage.draw() def onMouseUpObj(self, x, y): self.clicked = False +def onMouseUpText(self, x, y): + self.clicked = False def onMouseMoveGroup(self, x, y): pass #This is for testing rotation. Comment out before any commit! @@ -130,18 +145,26 @@ def onMouseDragGroup(self, x, y): def onMouseDragObj(self, x, y): self.x = x-self.initx self.y = y-self.inity +def onMouseDragText(self, x, y): + self.x = x-self.initx + self.y = y-self.inity def onKeyDownGroup(self, key): - pass - if key in [" ", "s", "r", "e", "b", "p"]: - svlgui.MODE=key - svlgui.set_cursor({" ":"arrow","s":"arrow","r":"crosshair","e":"crosshair", - "b":"arrow","p":"arrow"}[key], MainWindow.stage) - misc_funcs.update_tooloptions() - elif key=="F6": - add_keyframe() - elif key=="F8": - convert_to_symbol() + if not svlgui.EDITING: + if key in [" ", "s", "r", "e", "b", "p"]: + svlgui.MODE=key + svlgui.set_cursor({" ":"arrow","s":"arrow","r":"crosshair","e":"crosshair", + "b":"arrow","p":"arrow"}[key], MainWindow.stage) + misc_funcs.update_tooloptions() + elif key=="F6": + add_keyframe() + elif key=="F8": + convert_to_symbol() + else: + if not key=="escape": + pass + else: + svlgui.EDITING=False def onKeyDownObj(self, key): if key in ("delete", "backspace"): del self.parent[self.parent.index(self)] # Need to clean up deletion diff --git a/svlgui.py b/svlgui.py index d9adfdb..9e225fe 100644 --- a/svlgui.py +++ b/svlgui.py @@ -46,6 +46,8 @@ FOCUS = None #Options for export EXPORT_OPTS = {"swf":False,"html5":False,"basehtml":False,"fallback":False,"pack":False} +#Editing - whether the user is editing text +EDITING = True #Library. Contatins all objects whether displayed or not. Library = [] @@ -125,7 +127,8 @@ def hex2rgb(hex): LINECOLOR = Color("#990099") -FILLCOLOR = Color("#000000") +FILLCOLOR = Color("#00FF00") +TEXTCOLOR = Color("#000000") #Magic. Detect platform and select appropriate toolkit. To be used throughout code. if sys.platform=="linux2": @@ -216,6 +219,10 @@ elif sys.platform=="darwin": from GUI.StdButtons import DefaultButton, CancelButton from GUI.Files import FileType from GUI.Geometry import offset_rect, rect_sized + import Cocoa + SYSTEM_FONTS = list(Cocoa.NSFontManager.sharedFontManager().availableFontFamilies()) + FONT_PATH = "/Library/Fonts/" + FONT = u'Times New Roman' #app = GUI.application() SYSTEM="osx" TEMPDIR="/tmp" @@ -762,7 +769,7 @@ class Canvas(Widget): keydict = {127:"backspace",63272:"delete",63232:"up_arrow",63233:"down_arrow", 63235:"right_arrow",63234:"left_arrow",13:"enter",9:"tab", 63236:"F1",63237:"F2",63238:"F3",63239:"F4",63240:"F5", - 63241:"F6",63242:"F7",63243:"F8",} + 63241:"F6",63242:"F7",63243:"F8",27:"escape"} if not event.unichars=='': if ord(event.unichars) in keydict: key = keydict[ord(event.unichars)] @@ -1251,6 +1258,116 @@ class Shape (object): retval += self.name+".filled = "+str(self.filled).lower()+";\n" return retval +class Text (object): + def __init__(self,text="",x=0,y=0): + global SITER + global Library + Library.append(self) + self.text = text + self.x = x + self.y = y + self.rotation = 0 + self.xscale = 1 + self.yscale = 1 + self.fill = TEXTCOLOR + self.font = Font(FONT,24) + self.dynamic = False + self.variable = None + self.password = False + self.wordwrap = False + self.multiline = False + self.html = False + self.editable = False + self.selectable = True + self.border = False + self.width = self.font.width(self.text) + self.height = self.font.height + self.type="Text" + self.name = "t"+str(int(random.random()*10000))+str(SITER) + SITER+=1 + def draw(self,cr=None,parent=None,rect=None): + if SYSTEM=="osx": + cr.font = self.font + cr.textcolor = self.fill.pygui + cr.gsave() + #cr.moveto(self.x,self.y) + if sep=="\\": + # Very ugly hack for Windows. :( + # Windows doesn't respect coordinate transformations + # with respect to translation, so we have to do this + # bit ourselves. + + # Rotation in radians + radrot = parent.group.rotation*math.pi/180 + # Coordinate transform: multiplication by a rotation matrix + cr.translate(self.x*math.cos(radrot)-self.y*math.sin(radrot), self.x*math.sin(radrot)+self.y*math.cos(radrot)) + else: + cr.translate(self.x,self.y) + cr.newpath() + cr.moveto(0,0) + cr.show_text(self.text) + cr.grestore() + def hitTest(self, x, y): + self.width = self.font.width(self.text) + self.height = self.font.height + if 0