changeset 1164:2cb5047d8f2b

Add support to insert key frame in the middle of the tween.
author wycc
date Wed, 29 Dec 2010 00:33:48 +0800
parents c23593881507
children 9f2b5a1a0d84 6160e6282252
files pyink/MBScene.py pyink/frameline.py
diffstat 2 files changed, 50 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/pyink/MBScene.py	Tue Dec 28 22:26:11 2010 +0800
+++ b/pyink/MBScene.py	Wed Dec 29 00:33:48 2010 +0800
@@ -418,13 +418,30 @@
 	y = self.last_line
 	rdoc = self.document
 	ns = rdoc.createElement("svg:g")
-	txt = rdoc.createElement("svg:rect")
-	txt.setAttribute("x","0")
-	txt.setAttribute("y","0")
-	txt.setAttribute("width","100")
-	txt.setAttribute("height","100")
-	txt.setAttribute("style","fill:#ff00")
-	ns.appendChild(txt)
+	found = False
+	for node in self.last_line.node.childList():
+	    try:
+		label = node.getAttribute("inkscape:label")
+	    except:
+		continue
+	    if label == "dup":
+		for n in node.childList():
+		    ns.appendChild(n.duplicate(self.document))
+		found = True
+		node.setAttribute("style","display:none")
+		break
+	    pass
+	pass
+
+	if found == False:
+	    txt = rdoc.createElement("svg:rect")
+	    txt.setAttribute("x","0")
+	    txt.setAttribute("y","0")
+	    txt.setAttribute("width","100")
+	    txt.setAttribute("height","100")
+	    txt.setAttribute("style","fill:#ff00")
+	    ns.appendChild(txt)
+
 	gid = self.last_line.node.getAttribute('inkscape:label')+self.newID()
 	self.ID[gid]=1
 	ns.setAttribute("id",gid)
@@ -749,8 +766,13 @@
 	        frameline.label.set_text('???')
 	    else:
 	        frameline.label.set_text(frameline.node.getAttribute("inkscape:label"))
+	    last_scene = None
 	    for scene in layer.scenes:
-		frameline.add_keyframe(scene.start-1,scene.node)
+		if last_scene and last_scene.end == scene.start:
+		    frameline.setRightTween(last_scene.end)
+		else:
+		    frameline.add_keyframe(scene.start-1,scene.node)
+		last_scene = scene
 		if scene.start != scene.end:
 		    frameline.add_keyframe(scene.end-1,scene.node)
 		    tween_type_idx = self._tween_type_names.index(scene.type)
@@ -816,6 +838,7 @@
 	old_nodes = _travel_DOM(orig)
 	new_nodes = _travel_DOM(ns)
 	for old_node in old_nodes:
+	    print old_node
 	    old_node_id = old_node.getAttribute('id')
 	    new_node = new_nodes.next()
 	    new_node.setAttribute('ns0:duplicate-src', old_node_id)
--- a/pyink/frameline.py	Tue Dec 28 22:26:11 2010 +0800
+++ b/pyink/frameline.py	Wed Dec 29 00:33:48 2010 +0800
@@ -633,18 +633,33 @@
         
         key = keyframe(idx)
 	key.ref = ref
-        self._keys[insert_pos:insert_pos] = [key]
         if insert_pos > 0 and self._keys[insert_pos - 1].right_tween:
-            key.left_tween = True
-	    key.right_tween = True
-	    key.right_tween_type = self._keys[insert_pos - 1].right_tween_type
+	    if self._keys[insert_pos-1].idx == idx-1:
+		self._keys[insert_pos-1].right_tween = False
+                self._keys[insert_pos:insert_pos] = [key]
+		return
+	    else:
+		key2 = keyframe(idx-1)
+		key2.ref = self._keys[insert_pos-1].ref
+		key2.left_tween = True
+		self._keys[insert_pos:insert_pos] = [key2,key]
+		key.left_tween = False
+		key.right_tween = True
+		key.right_tween_type = self._keys[insert_pos - 1].right_tween_type
             pass
+	else:
+            self._keys[insert_pos:insert_pos] = [key]
 
 	if self._drawing:
 	    self._draw_keyframe(idx)
 	    pass
         pass
 
+    ## Set the frame @idx as the right of a tween
+    def set_right_tween(self,idx):
+	pos = self._find_keyframe(idx)
+	self._keys[pos].right_tween = TRue
+
     def rm_keyframe(self, idx):
 	key_pos = self._find_keyframe(idx)
         key = self._keys[key_pos]