comparison pyink/MBScene.py @ 1193:0e3a65b7b00c

Simplify extendScened()
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 02 Jan 2011 18:26:30 +0800
parents 79a3f82edaac
children 319414e4d87a
comparison
equal deleted inserted replaced
1192:79a3f82edaac 1193:0e3a65b7b00c
472 scenes_node.appendChild(scene_node) 472 scenes_node.appendChild(scene_node)
473 scene_node.setAttribute("start", str(start_idx + 1)) 473 scene_node.setAttribute("start", str(start_idx + 1))
474 if start_idx != stop_idx: 474 if start_idx != stop_idx:
475 scene_node.setAttribute("end", str(stop_idx + 1)) 475 scene_node.setAttribute("end", str(stop_idx + 1))
476 pass 476 pass
477 scene_node.setAttribute("ref", scene_node.getAttribute("id")) 477 scene_node.setAttribute("ref", scene_node.getAttribute("ref"))
478 scene_node.setAttribute("type", tween_type_name) 478 scene_node.setAttribute("type", tween_type_name)
479 pass 479 pass
480 pass 480 pass
481 481
482 def update_scenes_of_dom(self): 482 def update_scenes_of_dom(self):
657 pass 657 pass
658 658
659 def extendScene(self): 659 def extendScene(self):
660 frame_idx = self.last_frame 660 frame_idx = self.last_frame
661 frameline = self.last_line 661 frameline = self.last_line
662 i = 0 662
663 while i < len(frameline._keys): 663 start, end, scene_type = frameline.get_frame_block_floor(frame_idx)
664 s = frameline._keys[i] 664 if frame_idx <= end:
665 if s.right_tween: 665 return
666 if frame_idx > s.idx: 666
667 if frame_idx <= frameline._keys[i+1].idx: 667 if start < end:
668 return 668 frameline.rm_keyframe(end)
669 try: 669 pass
670 if frame_idx <= frameline._keys[i+2].idx: 670
671 frameline._keys[i+1].idx = frame_idx 671 scene_node = frameline.get_frame_data(start)
672 frameline.draw_all_frames() 672 scene_node.setAttribute('end', str(frame_idx))
673 self.update_scenes_of_dom() 673 frameline.add_keyframe(frame_idx)
674 self.setCurrentScene(frame_idx) 674 frameline.tween(start, scene_type)
675 self.last_line.update()
676 return
677 else:
678 # We may in the next scene
679 i = i + 2
680 pass
681 except:
682 # This is the last keyframe, extend the keyframe by
683 # relocate the location of the keyframe
684 frameline._keys[i+1].idx = frame_idx
685 frameline._draw_all_frames()
686 self.update_scenes_of_dom()
687 self.last_line.update()
688 self.setCurrentScene(frame_idx)
689 return
690 else:
691 # We are in the front of all keyframes
692 return
693 else:
694 # This is a single keyframe
695 if frame_idx < s.idx:
696 return
697 if frame_idx == s.idx:
698 return
699 try:
700 if frame_idx < frameline._keys[i+1].idx:
701 # We are after a single keyframe and no scene is
702 # available here. Create a new tween here
703 idx = frameline._keys[i].idx
704 scene_node = frameline._keys[i].ref
705 frameline.add_keyframe(frame_idx, scene_node)
706 frameline.tween(idx)
707 frameline._draw_all_frames()
708 self.update_scenes_of_dom()
709 self.setCurrentScene(frame_idx)
710 self.last_line.update()
711 return
712 else:
713 # We may in the next scene
714 i = i + 1
715 pass
716 pass
717 except:
718 # This is the last scene, create a new one
719 idx = frameline._keys[i].idx
720 scene_node = frameline._keys[i].ref
721 frameline.add_keyframe(frame_idx, scene_node)
722 frameline.tween(idx)
723 frameline._draw_all_frames()
724 self.update_scenes_of_dom()
725 self.setCurrentScene(frame_idx)
726 self.last_line.update()
727 return
728 pass
729 pass
730 pass 675 pass
731 676
732 def setCurrentScene(self,nth): 677 def setCurrentScene(self,nth):
733 """ 678 """
734 Update the scene group according to the curretn scene 679 Update the scene group according to the curretn scene
935 last_scene = None 880 last_scene = None
936 for scene in layer.scenes: 881 for scene in layer.scenes:
937 if last_scene and last_scene.end == scene.start: 882 if last_scene and last_scene.end == scene.start:
938 frameline.setRightTween(last_scene.end) 883 frameline.setRightTween(last_scene.end)
939 else: 884 else:
940 frameline.add_keyframe(scene.start-1, scene.node) 885 frameline.add_keyframe(scene.start, scene.node)
941 last_scene = scene 886 last_scene = scene
942 if scene.start != scene.end: 887 if scene.start != scene.end:
943 frameline.add_keyframe(scene.end-1, scene.node) 888 frameline.add_keyframe(scene.end, scene.node)
944 tween_type_idx = self._tween_type_names.index(scene.type) 889 tween_type_idx = self._tween_type_names.index(scene.type)
945 tween_type = self._frameline_tween_types[tween_type_idx] 890 tween_type = self._frameline_tween_types[tween_type_idx]
946 frameline.tween(scene.start-1, tween_type) 891 frameline.tween(scene.start-1, tween_type)
947 pass 892 pass
948 pass 893 pass
958 color = cell.get_colormap().alloc_color("green") 903 color = cell.get_colormap().alloc_color("green")
959 cell.modify_bg(gtk.STATE_NORMAL, color) 904 cell.modify_bg(gtk.STATE_NORMAL, color)
960 pass 905 pass
961 906
962 def duplicateKeyScene(self): 907 def duplicateKeyScene(self):
963 self.last_line.add_keyframe(self.last_frame)
964 # Search for the current scene 908 # Search for the current scene
965 i = 0 909 i = 0
966 while i < len(self.last_line._keys): 910 while i < len(self.last_line._keys):
967 key = self.last_line._keys[i] 911 key = self.last_line._keys[i]
968 if key.idx == self.last_frame: 912 if key.idx == self.last_frame:
969 if i == 0: 913 if i == 0:
970 # This is the first frame, we can not duplicate it 914 # This is the first frame, we can not duplicate it
971 self.last_line.rm_keyframe(self.last_frame)
972 return 915 return
973 node = self.duplicateSceneGroup(last_key.ref.getAttribute("id")) 916 self.last_line.add_keyframe(self.last_frame)
974 key.ref = node 917 last_scene_node = last_key.ref
975 self.update_scenes_of_dom() 918 last_scene_group_id = last_scene_node.getAttribute('ref')
976 self.updateUI() 919 scene_group = self.duplicateSceneGroup(last_scene_group_id)
920 scene_node = self._add_scene_node(self.last_frame,
921 self.last_frame,
922 ref=last_scene_group_id)
923 key.ref = scene_node
977 self.doEditScene(None) 924 self.doEditScene(None)
978 return 925 return
979 last_key = key 926 last_key = key
980 i = i + 1 927 i = i + 1
981 pass 928 pass
1012 959
1013 gid = self.last_line.layer_group.getAttribute("inkscape:label")+self.new_id() 960 gid = self.last_line.layer_group.getAttribute("inkscape:label")+self.new_id()
1014 scene_group.setAttribute("id",gid) 961 scene_group.setAttribute("id",gid)
1015 scene_group.setAttribute("inkscape:groupmode","layer") 962 scene_group.setAttribute("inkscape:groupmode","layer")
1016 self.last_line.layer_group.appendChild(scene_group) 963 self.last_line.layer_group.appendChild(scene_group)
1017 return ns 964 return scene_group
1018 965
1019 def doEditScene(self, w): 966 def doEditScene(self, w):
1020 self.setCurrentScene(self.last_frame+1) 967 self.setCurrentScene(self.last_frame+1)
1021 self.selectSceneObject(self.last_line, self.last_frame) 968 self.selectSceneObject(self.last_line, self.last_frame)
1022 pass 969 pass
1043 990
1044 def doExtendScene(self,w): 991 def doExtendScene(self,w):
1045 self._lockui = True 992 self._lockui = True
1046 self.extendScene() 993 self.extendScene()
1047 self._lockui = False 994 self._lockui = False
1048 #self.grid.show_all()
1049 pass 995 pass
1050 996
1051 def changeObjectLabel(self,w): 997 def changeObjectLabel(self,w):
1052 o = self.desktop.selection.list()[0] 998 o = self.desktop.selection.list()[0]
1053 o.setAttribute("inkscape:label", self.nameEditor.get_text()) 999 o.setAttribute("inkscape:label", self.nameEditor.get_text())