changeset 1293:10bffaffef82

Fix the supporting of removing key tween partially. - For key tween that only middle or right part of the ween being covered by removing range, we shrink the size of the tween and keep the key. - After shrink the size, start removing frames at the frame next to new end frame of the scene after shrinking.
author Thinker K.F. Li <thinker@codemud.net>
date Sat, 15 Jan 2011 22:41:58 +0800
parents 00833f8912a9
children 082fff7e9604
files pyink/domview_ui.py
diffstat 1 files changed, 55 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pyink/domview_ui.py	Sat Jan 15 21:00:56 2011 +0800
+++ b/pyink/domview_ui.py	Sat Jan 15 22:41:58 2011 +0800
@@ -227,7 +227,7 @@
     # The tween can be changed by tweening it again.
     def tween(self, layer_idx, key_frame_idx, tween_len,
 	      tween_type=TweenObject.TWEEN_TYPE_NORMAL):
-	assert tween_len > 0
+	assert tween_len > 1
 	frameline = self._framelines[layer_idx]
 	right_frame_idx = key_frame_idx + tween_len - 1
 	fl_tween_type = self._frameline_tween_types[tween_type]
@@ -243,6 +243,16 @@
 	frameline.tween(start, fl_tween_type)
 	pass
 
+    def untween(self, layer_idx, key_frame_idx):
+	frameline = self._framelines[layer_idx]
+        start, end, tween_type = \
+            frameline.get_frame_block(key_frame_idx)
+        if start < end:
+            frameline.untween(start)
+            frameline.unmark_keyframe(end)
+            pass
+        pass
+
     ## \brief Unmark a key frame.
     #
     # Once a key frame was unmark, the associated tween was also removed
@@ -510,10 +520,53 @@
 
     ## \brief Insert frames at specified position.
     #
-    # All frame at and after given position will shift left, except nearest
+    # All frames at and after given position will shift left, except nearest
     # \ref num frames are removed.
     #
+    #  - For a tween that only right part is covered by removing
+    #    range, its tween length would be shrinked just before
+    #    removing range.
+    #  - For a tween that only left part is covered by removing range,
+    #    key and tween are fully removed.
+    #  - For a tween that only middle part is covered, tween length is
+    #    also shrinked according length of covered part.
+    #
     def rm_frames(self, layer_idx, frame_idx, num):
+        #
+        # Check the key that is partially covered key tween, but not
+        # include key frame.
+        #
+        last_rm_idx = frame_idx + num - 1
+        try:
+            start, end, tween_type = \
+                self._fl_stack.get_left_key_tween(layer_idx, frame_idx)
+        except ValueError:
+            pass                # no key at left
+        else:
+            if start < frame_idx and end >= frame_idx:
+                #
+                # Key frame is not covered, only part of a key tween
+                # is covered.  Shrink its tween length, size of the
+                # covered part, or the key will be unmarked.
+                #
+                shrink_sz = min(end - frame_idx + 1, num)
+                
+                tween_len = end - start + 1 - shrink_sz
+                if tween_len == 1:
+                    self._fl_stack.untween(layer_idx, start)
+                else:
+                    self._fl_stack.tween(layer_idx, start, tween_len,
+                                         tween_type)
+                    pass
+
+                scene_end = end - shrink_sz
+                scene_node = self._fl_stack.get_keyframe_data(layer_idx, start)
+                self._dom.chg_scene_node(scene_node, end=scene_end)
+
+                frame_idx = scene_end + 1 # to shift/remove keys at right side
+                pass
+            pass
+
 	self._fl_stack.rm_frames(layer_idx, frame_idx, num)
 	self._dom.rm_frames(layer_idx, frame_idx, num)
 	pass