Can now move keyframes.

This commit is contained in:
Skyler Lehmkuhl 2013-01-04 16:56:44 -05:00
parent 58b3abe5dd
commit b2e6b88f5e
3 changed files with 108 additions and 61 deletions

View File

@ -82,6 +82,7 @@ def onLoadFrames(self):
j = box(i*16,0,16,32,svlgui.Color([1,1,1])) j = box(i*16,0,16,32,svlgui.Color([1,1,1]))
self.add(j)''' self.add(j)'''
def onClickFrame(self, x, y,button=1,clicks=1): 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().activelayer.frames[root.descendItem().activelayer.currentframe].actions = MainWindow.scriptwindow.text
root.descendItem().activeframe = int(x/16) root.descendItem().activeframe = int(x/16)
print ">>>>>> ", x, y print ">>>>>> ", x, y
@ -164,6 +165,8 @@ def onMouseDownText(self,x,y,button=1,clicks=1):
self.obj.editing = True self.obj.editing = True
def onMouseDownFrame(self, x, y,button=1,clicks=1): def onMouseDownFrame(self, x, y,button=1,clicks=1):
pass pass
def onMouseDownMC(self, x, y, button=1, clicks=1):
print clicks
def onMouseUpGroup(self, x, y,button=1,clicks=1): def onMouseUpGroup(self, x, y,button=1,clicks=1):
self.clicked = False self.clicked = False
if svlgui.MODE in ["r", "e"]: if svlgui.MODE in ["r", "e"]:
@ -199,6 +202,22 @@ def onMouseUpObj(self, x, y,button=1,clicks=1):
del undo_stack[-1] del undo_stack[-1]
def onMouseUpText(self, x, y,button=1,clicks=1): def onMouseUpText(self, x, y,button=1,clicks=1):
self.clicked = False 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): def onMouseMoveGroup(self, x, y,button=1):
pass pass
#This is for testing rotation. Comment out before any commit! #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): def onMouseDragText(self, x, y,button=1,clicks=1):
self.x = x-self.initx self.x = x-self.initx
self.y = y-self.inity 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): def onKeyDownGroup(self, key):
if not svlgui.EDITING: if not svlgui.EDITING:
if key in [" ", "s", "r", "e", "b", "p"]: 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.add(frames,0,0)
MainWindow.timelinebox.root = root MainWindow.timelinebox.root = root
MainWindow.timelinebox.onMouseDown = onClickFrame MainWindow.timelinebox.onMouseDown = onClickFrame
MainWindow.timelinebox.onMouseDrag = onMouseDragFrame
MainWindow.timelinebox.onMouseUp = onMouseUpFrame
def new_file(widget=None): def new_file(widget=None):
@ -764,7 +787,7 @@ def convert_to_symbol(widget=None):
svlgui.alert("No object selected!") svlgui.alert("No object selected!")
return return
else: else:
svlgui.ConvertToSymbolWindow(root) svlgui.ConvertToSymbolWindow(root, onMouseDownMC)
MainWindow.stage.draw() MainWindow.stage.draw()
def about(widget=None): def about(widget=None):

138
svlgui.py
View File

@ -3121,8 +3121,9 @@ class PublishSettingsWindow:
self.win.ok() self.win.ok()
class ConvertToSymbolWindow: class ConvertToSymbolWindow:
def __init__(self,root): def __init__(self,root,onMouseDown):
self.root = root self.root = root
self.onMouseDown = onMouseDown
if SYSTEM=="osx": if SYSTEM=="osx":
self.win = ModalDialog(closable=True,width=400,height=150) self.win = ModalDialog(closable=True,width=400,height=150)
self.win.title = "Convert to symbol" self.win.title = "Convert to symbol"
@ -3154,81 +3155,104 @@ class ConvertToSymbolWindow:
self.root.descendItem().activelayer.delete(self.root.descendItem().activelayer.currentselect) self.root.descendItem().activelayer.delete(self.root.descendItem().activelayer.currentselect)
print self.root.descendItem().activelayer.currentFrame() print self.root.descendItem().activelayer.currentFrame()
self.root.descendItem().activelayer.add(symbol) self.root.descendItem().activelayer.add(symbol)
symbol.onMouseDown = self.onMouseDown
self.win.ok() self.win.ok()
class FramesCanvas(Canvas): class FramesCanvas(Canvas):
def __init__(self,w,h): def __init__(self,w,h):
Canvas.__init__(self,w,h) Canvas.__init__(self,w,h)
self.pointer = 1 self.pointer = 1
self.x = None
if SYSTEM == 'osx': if SYSTEM == 'osx':
self.canvas.draw = self._draw self.canvas.draw = self._draw
self.canvas.mouse_down = self.mouse_down 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.ackfr = GUI.Image(file = media_path+"media/keyframe_active.png")
self.inackfr = GUI.Image(file = media_path+"media/keyframe_inactive.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.acfr = GUI.Image(file = media_path+"media/frame_active_tween.png")
self.inacfr = GUI.Image(file = media_path+"media/frame_inactive_tween.png") self.inacfr = GUI.Image(file = media_path+"media/frame_inactive_tween.png")
def _draw(self,cr,update_rect): def _draw(self,cr,update_rect):
for k in xrange(len(self.root.descendItem().layers)): try:
FRAMES = self.root.descendItem().layers[k].frames for k in xrange(len(self.root.descendItem().layers)):
for i in xrange(len(FRAMES)): FRAMES = self.root.descendItem().layers[k].frames
cr.gsave() for i in xrange(len(FRAMES)):
#cr.translate(i*16,k*32) cr.gsave()
if FRAMES[i]: #cr.translate(i*16,k*32)
if self.root.descendItem().currentframe == i: if FRAMES[i]:
src_rect = self.ackfr.bounds if self.root.descendItem().currentframe == i:
src_rect = [0,0,(16)*(self.pointer%17),32] src_rect = self.ackfr.bounds
dst_rect = [i*16, k*32, 16+i*16, 32+k*32] src_rect = [0,0,(16)*(self.pointer%17),32]
# print dst_rect dst_rect = [i*16, k*32, 16+i*16, 32+k*32]
self.ackfr.draw(cr, src_rect, dst_rect) # 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: else:
src_rect = self.inackfr.bounds if self.root.descendItem() == i:
dst_rect = [i*16, k*32, 16+i*16, 32+k*32] src_rect = self.acfr.bounds
self.inackfr.draw(cr, src_rect, dst_rect) dst_rect = [i*16, k*32, 16+i*16, 32+k*32]
else: self.acfr.draw(cr, src_rect, dst_rect)
if self.root.descendItem() == i: else:
src_rect = self.acfr.bounds src_rect = self.inacfr.bounds
dst_rect = [i*16, k*32, 16+i*16, 32+k*32] dst_rect = [i*16, k*32, 16+i*16, 32+k*32]
self.acfr.draw(cr, src_rect, dst_rect) self.inacfr.draw(cr, src_rect, dst_rect)
else: cr.grestore()
src_rect = self.inacfr.bounds for i in xrange(len(FRAMES)):
dst_rect = [i*16, k*32, 16+i*16, 32+k*32] if FRAMES[i]:
self.inacfr.draw(cr, src_rect, dst_rect) try:
cr.grestore() cr.gsave()
for i in xrange(len(FRAMES)): cr.translate(i*16,0)
if FRAMES[i]: sounds = [i.obj for i in FRAMES[i].objs if isinstance(i.obj, Sound)]
try: [i.draw_frame(cr, None) for i in sounds]
cr.gsave() cr.grestore()
cr.translate(i*16,0) except:
sounds = [i.obj for i in FRAMES[i].objs if isinstance(i.obj, Sound)] traceback.print_exc()
[i.draw_frame(cr, None) for i in sounds] # print max(len(FRAMES),int(update_rect[0]/16-1)),int(update_rect[2]/16+1)
cr.grestore() for i in xrange(max(len(FRAMES),int(update_rect[0]/16-1)),int(update_rect[2]/16+1)):
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()
cr.newpath() cr.newpath()
cr.fillcolor = Color([0.1,0.1,0.1]).pygui cr.rect([i*16,k*32,i*16+16,k*32+32])
cr.rect([i*16+15,k*32,i*16+16,k*32+32]) if self.root.descendItem().activeframe==i:
cr.fill() 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): def mouse_down(self, event):
x, y = event.position 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]]) self.canvas.invalidate_rect([0,0,self.canvas.extent[0],self.canvas.extent[1]])
def onMouseDown(self,self1,x, y): def mouse_drag(self, event):
print "Nananana" 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(): def main():

View File

@ -2,8 +2,8 @@
+ text + text
+ undo + undo
+ scale + scale
scaling of images + scaling of images
moving keyframes + moving keyframes
+ sound + sound
+ moving an object with arrow keys + moving an object with arrow keys
movie clips movie clips