From b2e6b88f5e0ae5dccbd70f7140880c8aa0aab95d Mon Sep 17 00:00:00 2001 From: Skyler Lehmkuhl Date: Fri, 4 Jan 2013 16:56:44 -0500 Subject: [PATCH] Can now move keyframes. --- lightningbeam.py | 27 +++++++++- svlgui.py | 138 +++++++++++++++++++++++++++-------------------- todo.txt | 4 +- 3 files changed, 108 insertions(+), 61 deletions(-) diff --git a/lightningbeam.py b/lightningbeam.py index 634607e..464b7b0 100755 --- a/lightningbeam.py +++ b/lightningbeam.py @@ -82,6 +82,7 @@ def onLoadFrames(self): j = box(i*16,0,16,32,svlgui.Color([1,1,1])) self.add(j)''' def onClickFrame(self, x, y,button=1,clicks=1): + self.clicks = clicks root.descendItem().activelayer.frames[root.descendItem().activelayer.currentframe].actions = MainWindow.scriptwindow.text root.descendItem().activeframe = int(x/16) print ">>>>>> ", x, y @@ -164,6 +165,8 @@ def onMouseDownText(self,x,y,button=1,clicks=1): self.obj.editing = True def onMouseDownFrame(self, x, y,button=1,clicks=1): pass +def onMouseDownMC(self, x, y, button=1, clicks=1): + print clicks def onMouseUpGroup(self, x, y,button=1,clicks=1): self.clicked = False if svlgui.MODE in ["r", "e"]: @@ -199,6 +202,22 @@ def onMouseUpObj(self, x, y,button=1,clicks=1): del undo_stack[-1] def onMouseUpText(self, x, y,button=1,clicks=1): self.clicked = False +def onMouseUpFrame(self, x, y, button=1, clicks=1): + self.x = None + if root.descendItem().activeframe==root.descendItem().activelayer.currentframe: + index = int(x/16) + if index>len(root.descendItem().activelayer.frames): + [root.descendItem().activelayer.frames.append(None) for i in xrange(len(root.descendItem().activelayer.frames),index+1)] + if index>root.descendItem().activeframe: + print "bigger" + root.descendItem().activelayer.frames.insert(index, root.descendItem().activelayer.frames.pop(root.descendItem().activeframe)) + else: + root.descendItem().activelayer.frames.insert(index, root.descendItem().activelayer.frames.pop(root.descendItem().activeframe)) + if not any(root.activelayer.frames[index+1:]): + root.descendItem().activelayer.frames = root.descendItem().activelayer.frames[:index+1] + root.descendItem().currentframe = index + print root.descendItem().activelayer.frames + def onMouseMoveGroup(self, x, y,button=1): pass #This is for testing rotation. Comment out before any commit! @@ -251,7 +270,9 @@ def onMouseDragObj(self, x, y,button=1,clicks=1): def onMouseDragText(self, x, y,button=1,clicks=1): self.x = x-self.initx self.y = y-self.inity - +def onMouseDragFrame(self, x, y, button=1, clicks=1): + if root.descendItem().activeframe==root.descendItem().activelayer.currentframe: + self.x = x def onKeyDownGroup(self, key): if not svlgui.EDITING: if key in [" ", "s", "r", "e", "b", "p"]: @@ -482,6 +503,8 @@ MainWindow.layerbox.add(layers,0,0) #MainWindow.timelinebox.add(frames,0,0) MainWindow.timelinebox.root = root MainWindow.timelinebox.onMouseDown = onClickFrame +MainWindow.timelinebox.onMouseDrag = onMouseDragFrame +MainWindow.timelinebox.onMouseUp = onMouseUpFrame def new_file(widget=None): @@ -764,7 +787,7 @@ def convert_to_symbol(widget=None): svlgui.alert("No object selected!") return else: - svlgui.ConvertToSymbolWindow(root) + svlgui.ConvertToSymbolWindow(root, onMouseDownMC) MainWindow.stage.draw() def about(widget=None): diff --git a/svlgui.py b/svlgui.py index 438a334..db012bf 100644 --- a/svlgui.py +++ b/svlgui.py @@ -3121,8 +3121,9 @@ class PublishSettingsWindow: self.win.ok() class ConvertToSymbolWindow: - def __init__(self,root): + def __init__(self,root,onMouseDown): self.root = root + self.onMouseDown = onMouseDown if SYSTEM=="osx": self.win = ModalDialog(closable=True,width=400,height=150) self.win.title = "Convert to symbol" @@ -3154,81 +3155,104 @@ class ConvertToSymbolWindow: self.root.descendItem().activelayer.delete(self.root.descendItem().activelayer.currentselect) print self.root.descendItem().activelayer.currentFrame() self.root.descendItem().activelayer.add(symbol) + symbol.onMouseDown = self.onMouseDown self.win.ok() class FramesCanvas(Canvas): def __init__(self,w,h): Canvas.__init__(self,w,h) self.pointer = 1 + self.x = None if SYSTEM == 'osx': self.canvas.draw = self._draw self.canvas.mouse_down = self.mouse_down + self.canvas.mouse_drag = self.mouse_drag + self.canvas.mouse_up = self.mouse_up self.ackfr = GUI.Image(file = media_path+"media/keyframe_active.png") self.inackfr = GUI.Image(file = media_path+"media/keyframe_inactive.png") self.acfr = GUI.Image(file = media_path+"media/frame_active_tween.png") self.inacfr = GUI.Image(file = media_path+"media/frame_inactive_tween.png") def _draw(self,cr,update_rect): - for k in xrange(len(self.root.descendItem().layers)): - FRAMES = self.root.descendItem().layers[k].frames - for i in xrange(len(FRAMES)): - cr.gsave() - #cr.translate(i*16,k*32) - if FRAMES[i]: - if self.root.descendItem().currentframe == i: - src_rect = self.ackfr.bounds - src_rect = [0,0,(16)*(self.pointer%17),32] - dst_rect = [i*16, k*32, 16+i*16, 32+k*32] - # print dst_rect - self.ackfr.draw(cr, src_rect, dst_rect) + try: + for k in xrange(len(self.root.descendItem().layers)): + FRAMES = self.root.descendItem().layers[k].frames + for i in xrange(len(FRAMES)): + cr.gsave() + #cr.translate(i*16,k*32) + if FRAMES[i]: + if self.root.descendItem().currentframe == i: + src_rect = self.ackfr.bounds + src_rect = [0,0,(16)*(self.pointer%17),32] + dst_rect = [i*16, k*32, 16+i*16, 32+k*32] + # print dst_rect + self.ackfr.draw(cr, src_rect, dst_rect) + else: + src_rect = self.inackfr.bounds + dst_rect = [i*16, k*32, 16+i*16, 32+k*32] + self.inackfr.draw(cr, src_rect, dst_rect) else: - src_rect = self.inackfr.bounds - dst_rect = [i*16, k*32, 16+i*16, 32+k*32] - self.inackfr.draw(cr, src_rect, dst_rect) - else: - if self.root.descendItem() == i: - src_rect = self.acfr.bounds - dst_rect = [i*16, k*32, 16+i*16, 32+k*32] - self.acfr.draw(cr, src_rect, dst_rect) - else: - src_rect = self.inacfr.bounds - dst_rect = [i*16, k*32, 16+i*16, 32+k*32] - self.inacfr.draw(cr, src_rect, dst_rect) - cr.grestore() - for i in xrange(len(FRAMES)): - if FRAMES[i]: - try: - cr.gsave() - cr.translate(i*16,0) - sounds = [i.obj for i in FRAMES[i].objs if isinstance(i.obj, Sound)] - [i.draw_frame(cr, None) for i in sounds] - cr.grestore() - except: - traceback.print_exc() - # print max(len(FRAMES),int(update_rect[0]/16-1)),int(update_rect[2]/16+1) - for i in xrange(max(len(FRAMES),int(update_rect[0]/16-1)),int(update_rect[2]/16+1)): - cr.newpath() - cr.rect([i*16,k*32,i*16+16,k*32+32]) - if self.root.descendItem().activeframe==i: - cr.fillcolor = Color([0.5,0.5,0.5]).pygui - cr.fill() - elif i%5==0: - cr.fillcolor = Color([0.8,0.8,0.8]).pygui - cr.fill() - # print i - else: - cr.fillcolor = Color([1.0,1.0,1.0]).pygui - cr.fill() + if self.root.descendItem() == i: + src_rect = self.acfr.bounds + dst_rect = [i*16, k*32, 16+i*16, 32+k*32] + self.acfr.draw(cr, src_rect, dst_rect) + else: + src_rect = self.inacfr.bounds + dst_rect = [i*16, k*32, 16+i*16, 32+k*32] + self.inacfr.draw(cr, src_rect, dst_rect) + cr.grestore() + for i in xrange(len(FRAMES)): + if FRAMES[i]: + try: + cr.gsave() + cr.translate(i*16,0) + sounds = [i.obj for i in FRAMES[i].objs if isinstance(i.obj, Sound)] + [i.draw_frame(cr, None) for i in sounds] + cr.grestore() + except: + traceback.print_exc() + # print max(len(FRAMES),int(update_rect[0]/16-1)),int(update_rect[2]/16+1) + for i in xrange(max(len(FRAMES),int(update_rect[0]/16-1)),int(update_rect[2]/16+1)): cr.newpath() - cr.fillcolor = Color([0.1,0.1,0.1]).pygui - cr.rect([i*16+15,k*32,i*16+16,k*32+32]) - cr.fill() - + cr.rect([i*16,k*32,i*16+16,k*32+32]) + if self.root.descendItem().activeframe==i: + cr.fillcolor = Color([0.5,0.5,0.5]).pygui + cr.fill() + elif i%5==0: + cr.fillcolor = Color([0.8,0.8,0.8]).pygui + cr.fill() + # print i + else: + cr.fillcolor = Color([1.0,1.0,1.0]).pygui + cr.fill() + cr.newpath() + cr.fillcolor = Color([0.1,0.1,0.1]).pygui + cr.rect([i*16+15,k*32,i*16+16,k*32+32]) + cr.fill() + if self.x: + src_rect = [0,0,16,32] + dst_rect = [self.x-8, 0, self.x+8, 32] + self.ackfr.draw(cr,src_rect,dst_rect) + except: + traceback.print_exc() def mouse_down(self, event): x, y = event.position - self.onMouseDown(self,x, y) + clicks = event.num_clicks + self.onMouseDown(self,x, y, clicks) self.canvas.invalidate_rect([0,0,self.canvas.extent[0],self.canvas.extent[1]]) - def onMouseDown(self,self1,x, y): - print "Nananana" + def mouse_drag(self, event): + x, y = event.position + self.onMouseDrag(self,x, y) + self.canvas.invalidate_rect([0,0,self.canvas.extent[0],self.canvas.extent[1]]) + def mouse_up(self, event): + x, y = event.position + self.onMouseUp(self,x, y) + self.canvas.invalidate_rect([0,0,self.canvas.extent[0],self.canvas.extent[1]]) + def onMouseDown(self,self1,x, y, button=1, clicks=1): + pass + def onMouseDrag(self, self1, x, y, button=1, clicks=1): + pass + def onMouseUp(self, self1, x, y, button=1, clicks=1): + pass def main(): diff --git a/todo.txt b/todo.txt index ce9377b..74c5460 100644 --- a/todo.txt +++ b/todo.txt @@ -2,8 +2,8 @@ + text + undo + scale -scaling of images -moving keyframes ++ scaling of images ++ moving keyframes + sound + moving an object with arrow keys movie clips \ No newline at end of file