From c27a2d52f0acb92949783294eed3bcd371b30f6c Mon Sep 17 00:00:00 2001 From: Skyler Lehmkuhl Date: Thu, 3 Jan 2013 19:07:39 -0500 Subject: [PATCH] Added ability to select multiple objects. --- lightningbeam.py | 11 ++++++ svlgui.py | 92 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 100 insertions(+), 3 deletions(-) diff --git a/lightningbeam.py b/lightningbeam.py index 7aca4da..6327337 100755 --- a/lightningbeam.py +++ b/lightningbeam.py @@ -68,6 +68,11 @@ class maybe: self.edit.to_attrs = to_attrs return self.edit +svlgui.undo_stack = undo_stack +svlgui.edit = edit +svlgui.maybe = maybe +svlgui.clear = clear + def onLoadFrames(self): '''for i in range(2000): if i%5==0: @@ -593,6 +598,9 @@ def undo(widget=None): if e.from_attrs["layer"].currentselect==e.to_attrs["obj"]: e.from_attrs["layer"].currentselect = None del e.from_attrs["layer"].frames[e.from_attrs["frame"]].objs[e.from_attrs["layer"].frames[e.from_attrs["frame"]].objs.index(e.to_attrs["obj"])] + elif e.type=="text": + e.obj.text = e.from_attrs["text"] + e.obj.cursorpos = e.from_attrs["cursorpos"] redo_stack.append(e) MainWindow.stage.draw() @@ -615,6 +623,9 @@ def redo(widget=None): e.obj.fillcolor = e.to_attrs["fillcolor"] elif e.type=="add_object": e.to_attrs["layer"].frames[e.from_attrs["frame"]].objs.append(e.to_attrs["obj"]) + elif e.type=="text": + e.obj.text = e.to_attrs["text"] + e.obj.cursorpos = e.to_attrs["cursorpos"] undo_stack.append(e) MainWindow.stage.draw() diff --git a/svlgui.py b/svlgui.py index 7dc27fc..3909ad0 100644 --- a/svlgui.py +++ b/svlgui.py @@ -1848,6 +1848,20 @@ class Text (object): else: self.text=self.text[:self.cursorpos]+str(key)+self.text[self.cursorpos:] self.cursorpos += 1 + if not key=="enter": + if len(undo_stack)>0: + if isinstance(undo_stack[-1], maybe): + if undo_stack[-1].edit.obj==self: + undo_stack[-1].edit.to_attrs={"text":self.text, "cursorpos":self.cursorpos} + else: + undo_stack.append(maybe("text", self, {"text":self.text, "cursorpos":self.cursorpos})) + else: + undo_stack.append(maybe("text", self, {"text":self.text, "cursorpos":self.cursorpos})) + else: + undo_stack.append(maybe("text", self, {"text":self.text, "cursorpos":self.cursorpos})) + else: + undo_stack[-1] = undo_stack[-1].complete({"text":self.text, "cursorpos":self.cursorpos}) + clear(redo_stack) pass def onKeyUp(self, self1, key): pass @@ -2116,9 +2130,9 @@ class Layer: def getminy(self): return min([i.miny for i in self.currentFrame()]) def getmaxx(self): - return max([i.maxx for i in self.currentFrame()]) + return max([i.maxx+i.x for i in self.currentFrame()]) def getmaxy(self): - return max([i.maxy for i in self.currentFrame()]) + return max([i.maxy+i.y for i in self.currentFrame()]) def onMouseDown(self, self1, x, y, button=1, clicks=1): pass def onMouseDrag(self, self1, x, y, button=1, clicks=1): @@ -2370,6 +2384,14 @@ class Group (object): self.xscale = 1 self.yscale = 1 self.type = "Group" + self.startx = 0 + self.starty = 0 + self.cx = 0 + self.cy = 0 + self.dragging = False + self.selecting = False + self.tempgroup = None + self.name = "g"+str(int(random.random()*10000))+str(SITER) if "onload" in kwargs: kwargs["onload"](self) def draw(self,cr=None,transform=None,rect=None): @@ -2381,6 +2403,12 @@ class Group (object): i.xscale = self.xscale i.yscale = self.yscale i.draw(cr,rect=rect) + if self.dragging and self.selecting and MODE in (" ", "s"): + if SYSTEM=="osx": + cr.newpath() + cr.pencolor = Color([0,0,1]).pygui + cr.stroke_rect([sorted([self.startx,self.cx])[0], sorted([self.starty,self.cy])[0], \ + sorted([self.startx,self.cx])[1], sorted([self.starty,self.cy])[1]]) def add(self, *args): self.activelayer.add(*args) def add_frame(self, populate): @@ -2437,26 +2465,50 @@ class Group (object): test = False for i in reversed(self.currentFrame()): if i.hitTest(x, y): + print i.obj, "is hit" if MODE in [" ", "s"]: self.activelayer.currentselect = i test=True + print 'onmousedowning' i._onMouseDown(x, y, button=button, clicks=clicks) break if not test: + if self.tempgroup: + [self.currentFrame().append(i) for i in self.tempgroup.split()] + del self.currentFrame()[self.currentFrame().index(self.tempgroup)] + self.tempgroup = None self.activelayer.currentselect = None + self.startx, self.starty = x, y + self.selecting = True else: self.onMouseDown(self, x, y, button=button, clicks=clicks) else: + print "HEYY" self.onMouseDown(self, x, y, button=button, clicks=clicks) def onMouseDown(self, self1, x, y, button=1, clicks=1): pass def _onMouseUp(self,x,y, button=1, clicks=1): global SCALING SCALING = False + self.dragging = False + self.selecting = False x, y = self.localtransform(x, y) if self.activelayer.level and MODE in [" ", "s"]: if self.activelayer.currentselect: self.activelayer.currentselect._onMouseUp(x, y, button=button, clicks=clicks) + else: + objs = [] + for i in reversed(self.currentFrame()): + if self.startx