changeset 1120:214e1f628d63

Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
author wycc
date Tue, 07 Dec 2010 07:52:47 +0800
parents 9d52dda8d49f
children e030c9d4b79b
files pyink/MBScene.py pyink/frameline.py pyink/mbtest.svg
diffstat 3 files changed, 136 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/pyink/MBScene.py	Sun Dec 05 14:27:17 2010 +0800
+++ b/pyink/MBScene.py	Tue Dec 07 07:52:47 2010 +0800
@@ -48,10 +48,11 @@
     pass
 
 class Scene:
-    def __init__(self, node, start,end):
+    def __init__(self, node, start,end,typ):
 	self.node = node
 	self.start = int(start)
 	self.end = int(end)
+	self.type = typ
 	pass
     pass
 
@@ -168,10 +169,15 @@
 			except:
 			    end = start
 			    pass
+			try:
+			    typ = s.repr.attribute('type')
+			    if typ == None:
+				typ = 'normal'
+			except:
+			    traceback.print_exc()
+			    typ = 'normal'
 			link = s.repr.attribute("ref")
-			self.scenemap[link] = [int(start),int(end)]
-			print "scene %d to %d" % (self.scenemap[link][0],
-						  self.scenemap[link][1])
+			self.scenemap[link] = [int(start),int(end),typ]
 			if cur >= start and cur <= end:
 			    self.currentscene = link
 			    pass
@@ -234,7 +240,7 @@
 			    lyobj.current_scene.append(scene)
 			    continue
 
-			lyobj.scenes.append(Scene(scene,scmap[0],scmap[1]))
+			lyobj.scenes.append(Scene(scene,scmap[0],scmap[1],scmap[2]))
 			pass
 		    else:
 			lyobj.current_scene.append(scene)
@@ -458,6 +464,7 @@
 	    if s.right_tween is False:
 	        if nth == s.idx+1:
 		    self.enterGroup(s.ref)
+	            self.setTweenType(frameline.get_tween_type(s.idx))
 		    return
 		else:
 		    pass
@@ -466,12 +473,20 @@
 
 	    if nth >= (s.idx+1) and nth <= (frameline._keys[i+1].idx+1):
 	        self.enterGroup(s.ref)
+	        self.setTweenType(frameline.get_tween_type(s.idx))
 		return
 	    else:
 	        pass
 	    i = i + 2
 	    pass
         pass
+    def setTweenType(self,typ):
+        if typ == 'normal':
+	    self.tweenTypeSelector.set_active(0)
+        elif typ == 'relocate':
+	    self.tweenTypeSelector.set_active(1)
+        elif typ == 'scale':
+	    self.tweenTypeSelector.set_active(2)
 
 	
 	
@@ -558,7 +573,7 @@
 		frameline.add_keyframe(scene.start-1,scene.node.repr)
 		if scene.start != scene.end:
 		    frameline.add_keyframe(scene.end-1,scene.node.repr)
-		    frameline.tween(scene.start-1)
+		    frameline.tween(scene.start-1,scene.type)
 		pass
 	    pass
 	pass
@@ -662,7 +677,52 @@
 	btn.connect('clicked', self.doDuplicateKeyScene)
 	hbox.pack_start(btn,expand=False,fill=False)
 	self.addNameEditor(hbox)
+	self.addTweenTypeSelector(hbox)
 	pass
+    def onTweenTypeChange(self,w):
+	n = self.tweenTypeSelector.get_active()
+	if self.last_line == None:
+	    return
+	frameline = self.last_line
+        i = 0
+	found = -1
+        while i < len(frameline._keys):
+	    s = frameline._keys[i]
+	    if s.right_tween is False:
+	        if self.last_frame == s.idx:
+		    found = s.idx
+		    break
+		else:
+		    pass
+		i = i + 1
+		continue
+
+	    if self.last_frame >= s.idx and self.last_frame <= frameline._keys[i+1].idx:
+		found = s.idx
+		break
+	    else:
+	        pass
+	    i = i + 2
+	    pass
+        pass
+	if found == -1: return
+	self.last_line.set_tween_type(found,self.tweenTypeSelector.get_active_text())
+	self.last_line.update()
+	self.update()
+
+    def addTweenTypeSelector(self,hbox):
+	tweenbox = gtk.HBox()
+	label = gtk.Label('Tween Type')
+	tweenbox.pack_start(label)
+	
+        self.tweenTypeSelector = gtk.combo_box_new_text()
+	self.tweenTypeSelector.append_text('normal')
+	self.tweenTypeSelector.append_text('relocate')
+	self.tweenTypeSelector.append_text('scale')
+	self.tweenTypeSelector.set_active(0)
+	tweenbox.pack_start(self.tweenTypeSelector, expand=False,fill=False)
+	hbox.pack_start(tweenbox,expand=False,fill=False)
+	self.tweenTypeSelector.connect('changed', self.onTweenTypeChange)
     
     def onQuit(self, event):
 	self.OK = False
--- a/pyink/frameline.py	Sun Dec 05 14:27:17 2010 +0800
+++ b/pyink/frameline.py	Tue Dec 07 07:52:47 2010 +0800
@@ -116,7 +116,7 @@
     _key_mark_color = 0x000000  # color of marks for key frames.
     _key_mark_sz = 4            # width and height of a key frame mark
     _tween_color = 0x808080     # color of tween line
-    _tween_bgcolors = [0x80ff80, 0xff8080] # bg colors of tween frames
+    _tween_bgcolors = [0x80ff80, 0xff8080,0xffff80] # bg colors of tween frames
     # Colors for normal frames
     _normal_bgcolors = [0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xcccccc]
     _normal_border = 0xaaaaaa   # border color of normal frames.
@@ -124,7 +124,8 @@
     _hover_border_color = 0xa0a0a0 # border when the pointer over a frame
     # tween types
     _tween_type_none=0
-    _tween_type_shape=3
+    _tween_type_move=1
+    _tween_type_shape=2
     
 
     FRAME_BUT_PRESS = 'frame-button-press'
@@ -464,6 +465,24 @@
                 pass
             pass
         pass
+    def set_tween_type(self,frame_idx,typ):
+        found=False
+	for i in range(0,len(self._keys)):
+	    if self._keys[i].idx == frame_idx:
+	        idx = i
+		found = True
+		break
+	if not found: return
+        key = self._keys[idx]
+	if typ == 'normal':
+	    type = self._tween_type_none
+	elif typ == 'relocate':
+	    type = self._tween_type_move
+	elif typ == 'scale':
+	    type = self._tween_type_shape
+	if key.left_tween is False and key.right_tween is True:
+	    key.right_tween_type = type
+    	
 
     ## \brief Show a mark for the pointer for a frame.
     #
@@ -573,7 +592,7 @@
     ## Tween the key frame specified by an index and the key frame at right.
     #
     # \see http://www.entheosweb.com/Flash/shape_tween.asp
-    def tween(self, idx, _type=0):
+    def tween(self, idx, _type='normal'):
         key_indic = [key.idx for key in self._keys]
         pos = key_indic.index(idx)
         key = self._keys[pos]
@@ -585,8 +604,25 @@
 
         key.right_tween = True
         right_key.left_tween = True
-        key.right_tween_type = _type
+	if _type == 'normal':
+            key.right_tween_type = self._tween_type_none
+	elif _type == 'relocate':
+            key.right_tween_type = self._tween_type_move
+	elif _type == 'scale':
+            key.right_tween_type = self._tween_type_shape
         pass
+    def get_tween_type(self,idx):
+        for i in range(0,len(self._keys)):
+	    key = self._keys[i]
+	    if key.left_tween is True: continue
+	    if key.idx == idx:
+	    	if key.right_tween_type == self._tween_type_none:
+		    return 'normal'
+	    	elif key.right_tween_type == self._tween_type_move:
+		    return 'relocate'
+	    	elif key.right_tween_type == self._tween_type_shape:
+		    return 'scale'
+        
 
     ## Set active frame
     #
@@ -626,11 +662,18 @@
 		ss.setAttribute("start", str(key.idx+1),True)
 		ss.setAttribute("ref",key.ref.attribute("id"),True)
 		ss.setAttribute("end", str(self._keys[i+1].idx+1),True)
+		if self._keys[i].right_tween_type == self._tween_type_none:
+		    ss.setAttribute("type", "normal", True)
+		elif self._keys[i].right_tween_type == self._tween_type_move:
+		    ss.setAttribute("type", "relocate", True)
+		elif self._keys[i].right_tween_type == self._tween_type_scale:
+		    ss.setAttribute("type", "scale", True)
 	    else:
 	        ss = rdoc.createElement("ns0:scene")
 		node.appendChild(ss)
 		ss.setAttribute("start", str(key.idx+1),True)
 		ss.setAttribute("ref",key.ref.attribute("id"),True)
+	        ss.setAttribute("type", "normal", True)
 
 	        
     ## \brief Start future drawing actions
--- a/pyink/mbtest.svg	Sun Dec 05 14:27:17 2010 +0800
+++ b/pyink/mbtest.svg	Tue Dec 07 07:52:47 2010 +0800
@@ -15,7 +15,7 @@
    height="480px"
    id="svg2383"
    sodipodi:version="0.32"
-   inkscape:version="0.48+devel r9764 custom"
+   inkscape:version="0.48+devel r9773 custom"
    sodipodi:docname="mbtest.svg"
    inkscape:output_extension="org.inkscape.output.svg.inkscape"
    version="1.1">
@@ -27,13 +27,13 @@
      inkscape:pageopacity="0.0"
      inkscape:pageshadow="2"
      inkscape:zoom="1.6029106"
-     inkscape:cx="69.206233"
+     inkscape:cx="238.58561"
      inkscape:cy="290.40921"
-     inkscape:current-layer="layer2"
+     inkscape:current-layer="g3189"
      inkscape:document-units="px"
      showgrid="false"
      inkscape:window-width="1400"
-     inkscape:window-height="974"
+     inkscape:window-height="973"
      inkscape:window-x="271"
      inkscape:window-y="25"
      inkscape:window-maximized="0" />
@@ -194,21 +194,26 @@
     <ns0:scenes>
       <ns0:scene
          start="1"
-         ref="g3189"
-         end="15" />
-      <ns0:scene
-         start="1"
-         ref="s4427" />
+         ref="s4427"
+         type="normal" />
       <ns0:scene
          start="2"
-         ref="s4159" />
+         ref="s4159"
+         type="normal" />
       <ns0:scene
          start="5"
          ref="s9524"
-         end="10" />
+         end="10"
+         type="normal" />
       <ns0:scene
          start="15"
-         ref="s6546" />
+         ref="s6546"
+         type="normal" />
+      <ns0:scene
+         start="1"
+         ref="g3189"
+         end="15"
+         type="relocate" />
     </ns0:scenes>
   </metadata>
   <g
@@ -237,8 +242,9 @@
          ry="10" />
       <g
          style="display:inline"
-         transform="translate(-11.385541,2.6514388)"
-         id="g3303">
+         transform="translate(-15.128732,2.0275737)"
+         id="g3303"
+         inkscape:label="action1">
         <rect
            y="15.22048"
            x="32.440987"
@@ -283,14 +289,13 @@
       </g>
     </g>
     <g
-       id="s4393"
-       style="" />
+       id="s4393" />
   </g>
   <g
      inkscape:groupmode="layer"
      id="layer3"
      inkscape:label="Buton"
-     style="display:inline">
+     style="display:none">
     <g
        id="s4427"
        style="display:none" />
@@ -362,7 +367,6 @@
          y="0"
          width="100"
          height="100"
-         style="fill:#ff00"
          id="rect3116" />
     </g>
   </g>
@@ -370,5 +374,5 @@
      id="layer1"
      inkscape:label="Layer 1"
      inkscape:groupmode="layer"
-     style="display:inline" />
+     style="display:none" />
 </svg>