Mercurial > MadButterfly
comparison pyink/tween.py @ 1157:3a891dccabd8
Remove the locate tween. It is a special case for the scale tween
author | wycc |
---|---|
date | Mon, 27 Dec 2010 23:01:48 +0800 |
parents | ad9c44a08645 |
children | 1a699dc00fa3 |
comparison
equal
deleted
inserted
replaced
1156:ad9c44a08645 | 1157:3a891dccabd8 |
---|---|
3 import traceback | 3 import traceback |
4 import math | 4 import math |
5 | 5 |
6 class TweenObject: | 6 class TweenObject: |
7 TWEEN_TYPE_NORMAL = 0 | 7 TWEEN_TYPE_NORMAL = 0 |
8 TWEEN_TYPE_RELOCATE = 1 | 8 #TWEEN_TYPE_RELOCATE = 1 |
9 TWEEN_TYPE_SCALE = 2 | 9 TWEEN_TYPE_SCALE = 1 |
10 | 10 |
11 def __init__(self,doc,dom): | 11 def __init__(self,doc,dom): |
12 self.document = doc | 12 self.document = doc |
13 self.dom = dom | 13 self.dom = dom |
14 try: | 14 try: |
162 def updateTweenObject(self,obj,typ,s,d,p,newobj): | 162 def updateTweenObject(self,obj,typ,s,d,p,newobj): |
163 """ | 163 """ |
164 Generate tweened object in the @obj by using s and d in the @p percent | 164 Generate tweened object in the @obj by using s and d in the @p percent |
165 http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html | 165 http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html |
166 """ | 166 """ |
167 if typ == self.TWEEN_TYPE_RELOCATE: | 167 if typ == self.TWEEN_TYPE_SCALE: |
168 if s.name() == 'svg:g': | |
169 if not newobj: | |
170 newobj = s.duplicate(self.document) | |
171 top = self.document.createElement("svg:g") | |
172 top.setAttribute("ref", s.getAttribute("id")) | |
173 top.appendChild(newobj) | |
174 obj.appendChild(top) | |
175 else: | |
176 top = newobj | |
177 pass | |
178 # Parse the translate or matrix | |
179 sm = self.parseTransform(s) | |
180 dm = self.parseTransform(d) | |
181 top.setAttribute("transform","translate(%g,%g)" % ((dm[2]-sm[2])*p,(dm[5]-sm[5])*p)) | |
182 else: | |
183 if not newobj: | |
184 top = s.duplicate(self.document) | |
185 top.setAttribute('ref', s.getAttribute('id')) | |
186 obj.appendChild(top) | |
187 else: | |
188 top = newobj | |
189 pass | |
190 try: | |
191 sx = float(s.getAttribute("x")) | |
192 sy = float(s.getAttribute("y")) | |
193 dx = float(d.getAttribute("x")) | |
194 dy = float(d.getAttribute("y")) | |
195 tx = (dx-sx)*p | |
196 ty = (dy-sy)*p | |
197 print tx,ty | |
198 top.setAttribute("transform","translate(%g,%g)" % (tx,ty)) | |
199 except: | |
200 traceback.print_exc() | |
201 pass | |
202 pass | |
203 elif typ == self.TWEEN_TYPE_SCALE: | |
204 self.updateTweenObjectScale(obj,s,d,p,newobj) | 168 self.updateTweenObjectScale(obj,s,d,p,newobj) |
205 pass | 169 pass |
206 elif typ == self.TWEEN_TYPE_NORMAL: | 170 elif typ == self.TWEEN_TYPE_NORMAL: |
207 newobj = s.duplicate(self.document) | 171 newobj = s.duplicate(self.document) |
208 newobj.setAttribute("ref", s.getAttribute("id")) | 172 newobj.setAttribute("ref", s.getAttribute("id")) |