Mercurial > MadButterfly
annotate pyink/tween.py @ 1341:599b606c4669
Start to implement HTML5/CSS3 exporter
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 07 Feb 2011 21:54:03 +0800 |
parents | 20cf3e2a0a9d |
children | a48df5d53ddc |
rev | line source |
---|---|
1140 | 1 # -*- indent-tabs-mode: t; tab-width: 8; python-indent: 4; -*- |
2 # vim: sw=4:ts=8:sts=4 | |
3 import traceback | |
4 import math | |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
5 |
1225
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
6 |
1339
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
7 def parse_style(style): |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
8 attrs = {} |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
9 |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
10 style_parts = style.split(';') |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
11 for part in style_parts: |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
12 part = part.strip() |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
13 if not part: |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
14 continue |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
15 nv_pair = part.split(':') |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
16 if len(nv_pair) != 2: |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
17 raise ValueError, 'invalid format for style "%s"' % (style) |
1225
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
18 |
1339
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
19 name = nv_pair[0].strip() |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
20 value = nv_pair[1].strip() |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
21 attrs[name] = value |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
22 pass |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
23 |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
24 return attrs |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
25 |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
26 def gen_style(attrs): |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
27 parts = [name + ':' + value for name, value in attrs.items()] |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
28 style = ';'.join(parts) |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
29 return style |
1225
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
30 |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
31 class TweenObject(object): |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
32 TWEEN_TYPE_NORMAL = 0 |
1157
3a891dccabd8
Remove the locate tween. It is a special case for the scale tween
wycc
parents:
1156
diff
changeset
|
33 #TWEEN_TYPE_RELOCATE = 1 |
3a891dccabd8
Remove the locate tween. It is a special case for the scale tween
wycc
parents:
1156
diff
changeset
|
34 TWEEN_TYPE_SCALE = 1 |
1156
ad9c44a08645
If an object does not exist in the destination group, we should duplicate it.
wycc
parents:
1151
diff
changeset
|
35 |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
36 def __init__(self, doc, root): |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
37 super(TweenObject, self).__init__() |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
38 self._doc = doc |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
39 self._root = root |
1141 | 40 try: |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
41 self.width = float(root.getAttribute("width")) |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
42 self.height = float(root.getAttribute("height")) |
1141 | 43 except: |
44 self.width = 640 | |
45 self.height = 480 | |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
46 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
47 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
48 |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
49 def updateTweenContent(self, duplicate_group, tween_type, |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
50 start_scene_group, stop_scene_group, percent): |
1140 | 51 """ |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
52 Update the content of the duplicate scene group. We will |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
53 use precent, start_scene_group, stop_scene_group to |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
54 compute transform matrix and update duplicate scene group |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
55 specified. |
1140 | 56 """ |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
57 # Collect ref from the obj |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
58 node = duplicate_group.firstChild() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
59 dup_nodes = {} |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
60 while node: |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
61 try: |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
62 ref = node.getAttribute("ref") |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
63 dup_nodes[ref] = node |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
64 except: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
65 ref = None |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
66 pass |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
67 node = node.next() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
68 pass |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
69 |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
70 # Collect all nodes in stop scene |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
71 stop_nodes = {} |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
72 node = stop_scene_group.firstChild() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
73 while node: |
1140 | 74 try: |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
75 node_label = node.getAttribute("ns0:duplicate-src") |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
76 stop_nodes[node_label] = node |
1140 | 77 except: |
78 pass | |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
79 node = node.next() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
80 pass |
1199
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1172
diff
changeset
|
81 |
1172
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
82 # Collect all nodes in start scene |
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
83 start_nodes = {} |
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
84 node = start_scene_group.firstChild() |
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
85 while node: |
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
86 try: |
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
87 node_label = node.getAttribute("id") |
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
88 start_nodes[node_label] = node |
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
89 except: |
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
90 pass |
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
91 node = node.next() |
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
92 pass |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
93 |
1172
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
94 # Remove duplicate nodes that is not in the set of start nodes |
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
95 for node_ref in dup_nodes: |
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
96 if node_ref not in start_nodes: |
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
97 node = dup_nodes[node_ref] |
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
98 duplicate_group.removeChild(node) |
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
99 pass |
178b126edd2c
Implement the correct normal tween. We will duplicate the node in the start scene. Insted of deleting all nodes which is not in the stop scene, we should delete the object which is not in the start scene instead. If we delete objecvt the the stop scene, the object should appear until we reach the stop scene.
wycc
parents:
1170
diff
changeset
|
100 pass |
1160
1a699dc00fa3
Fix the issue of not removing node in old scene when switching scenes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1157
diff
changeset
|
101 |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
102 # |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
103 # Node ID of a node of start scene must be mapped to |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
104 # 'ns0:duplicate-src' attribute of a node of stop scene. The |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
105 # nodes which can not be mapped to a node of stop scene are |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
106 # not manipulated by the tween. |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
107 # |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
108 # When a scene is duplicated, 'ns0:duplicate-src' attribute of |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
109 # nodes, in the new scene, must be setted to ID of respective |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
110 # one in the duplicated scene. |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
111 # |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
112 start_node = start_scene_group.firstChild() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
113 while start_node: |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
114 start_node_id = start_node.getAttribute('id') |
1163 | 115 dup_node = dup_nodes.setdefault(start_node_id, None) |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
116 try: |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
117 stop_node = stop_nodes[start_node_id] |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
118 except KeyError: |
1170
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
119 self.updateTweenObject(duplicate_group, tween_type, |
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
120 start_node, start_node, |
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
121 percent, dup_node) |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
122 start_node = start_node.next() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
123 continue |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
124 |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
125 |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
126 self.updateTweenObject(duplicate_group, tween_type, |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
127 start_node, stop_node, |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
128 percent, dup_node) |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
129 start_node = start_node.next() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
130 pass |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
131 pass |
1140 | 132 |
133 def parseTransform(self,obj): | |
134 """ | |
135 Return the transform matrix of an object | |
136 """ | |
137 try: | |
1141 | 138 t = obj.getAttribute("transform") |
1140 | 139 if t[0:9] == 'translate': |
140 fields = t[10:].split(',') | |
141 x = float(fields[0]) | |
142 fields = fields[1].split(')') | |
143 y = float(fields[0]) | |
144 return [1,0,0,1,x,y] | |
145 elif t[0:6] == 'matrix': | |
146 fields=t[7:].split(')') | |
147 fields = fields[0].split(',') | |
148 return [float(fields[0]),float(fields[1]),float(fields[2]),float(fields[3]),float(fields[4]),float(fields[5])] | |
149 except: | |
150 #traceback.print_exc() | |
151 return [1,0,0,1,0,0] | |
152 | |
153 def invA(self,m): | |
154 d = m[0]*m[3]-m[2]*m[1] | |
155 return [m[3]/d, -m[1]/d, -m[2]/d, m[0]/d, (m[1]*m[5]-m[4]*m[3])/d, (m[4]*m[2]-m[0]*m[5])/d] | |
156 | |
157 def mulA(self,a,b): | |
158 return [a[0]*b[0]+a[1]*b[2], | |
159 a[0]*b[1]+a[1]*b[3], | |
160 a[2]*b[0]+a[3]*b[2], | |
161 a[2]*b[1]+a[3]*b[3], | |
162 a[0]*b[4]+a[1]*b[5]+a[4], | |
163 a[2]*b[4]+a[3]*b[5]+a[5]] | |
164 | |
165 def decomposition(self,m): | |
166 """ | |
167 Decompose the affine matrix into production of translation,rotation,shear and scale. | |
168 The algorithm is documented at http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html | |
169 """ | |
170 if m[0]*m[3] == m[1]*m[2]: | |
171 print "The affine matrix is singular" | |
172 return [1,0,0,1,0,0] | |
173 A=m[0] | |
174 B=m[2] | |
175 C=m[1] | |
176 D=m[3] | |
177 E=m[4] | |
178 F=m[5] | |
179 sx = math.sqrt(A*A+B*B) | |
180 A = A/sx | |
181 B = B/sx | |
182 shear = m[0]*m[1]+m[2]*m[3] | |
183 C = C - A*shear | |
184 D = D - B*shear | |
185 sy = math.sqrt(C*C+D*D) | |
186 C = C/sy | |
187 D = D/sy | |
188 r = A*D-B*C | |
189 if r == -1: | |
190 shear = -shear | |
191 sy = -sy | |
192 R = math.atan2(B,A) | |
193 return [sx,sy, R, E,F] | |
194 | |
195 | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
196 def updateTweenObject(self,obj,typ,s,d,p,newobj): |
1140 | 197 """ |
198 Generate tweened object in the @obj by using s and d in the @p percent | |
199 http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html | |
200 """ | |
1157
3a891dccabd8
Remove the locate tween. It is a special case for the scale tween
wycc
parents:
1156
diff
changeset
|
201 if typ == self.TWEEN_TYPE_SCALE: |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
202 self.updateTweenObjectScale(obj,s,d,p,newobj) |
1140 | 203 pass |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
204 elif typ == self.TWEEN_TYPE_NORMAL: |
1170
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
205 if newobj == None: |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
206 newobj = s.duplicate(self._doc) |
1170
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
207 newobj.setAttribute("ref", s.getAttribute("id")) |
e64b02951627
Fix the issue in the normal tween. We duplicate the object only when the object is not in the duplicated node yet.
wycc
parents:
1167
diff
changeset
|
208 obj.appendChild(newobj) |
1140 | 209 pass |
210 | |
1339
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
211 def _update_tween_style(self, s, d, p, newobj): |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
212 try: |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
213 s_style = s.getAttribute('style') |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
214 except: |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
215 s_attrs = {} |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
216 else: |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
217 s_attrs = parse_style(s_style) |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
218 pass |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
219 |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
220 try: |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
221 d_style = d.getAttribute('style') |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
222 except: |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
223 d_attrs = {} |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
224 else: |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
225 d_attrs = parse_style(d_style) |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
226 pass |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
227 |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
228 attrs = dict(s_attrs) |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
229 |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
230 if s_attrs.has_key('opacity'): |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
231 start_opacity = float(s_attrs['opacity']) |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
232 else: |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
233 start_opacity = 1 |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
234 pass |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
235 |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
236 if d_attrs.has_key('opacity'): |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
237 end_opacity = float(d_attrs['opacity']) |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
238 else: |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
239 end_opacity = 1 |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
240 pass |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
241 |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
242 cur_opacity = start_opacity * (1 - p) + end_opacity * p |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
243 attrs['opacity'] = '%g' % (cur_opacity) |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
244 |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
245 new_style = gen_style(attrs) |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
246 newobj.setAttribute('style', new_style) |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
247 pass |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
248 |
1297 | 249 def updateTweenObjectScale_Group(self, s, d, p, newobj, top): |
1296
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
250 # Parse the translate or matrix |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
251 # |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
252 # D = B inv(A) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
253 try: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
254 (ox,oy) = s.spitem.getCenter() |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
255 except: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
256 ox = 0 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
257 oy = 0 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
258 pass |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
259 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
260 try: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
261 (dx,dy) = d.spitem.getCenter() |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
262 except: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
263 dx = 0 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
264 dy = 0 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
265 pass |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
266 |
1339
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
267 self._update_tween_style(s, d, p, newobj) |
1296
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
268 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
269 sm = self.parseTransform(s) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
270 ss = self.decomposition(sm) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
271 dm = self.parseTransform(d) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
272 dd = self.decomposition(dm) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
273 sx = (ss[0]*(1-p)+dd[0]*p)/ss[0] |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
274 sy = (ss[1]*(1-p)+dd[1]*p)/ss[1] |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
275 a = ss[2]*(1-p)+dd[2]*p-ss[2] |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
276 tx = ox*(1-p)+dx*p |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
277 ty = oy*(1-p)+dy*p |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
278 m = [math.cos(a),math.sin(a),-math.sin(a),math.cos(a),0,0] |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
279 m = self.mulA([sx,0,0,sy,0,0],m) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
280 m = self.mulA(m,[1,0,0,1,-ox,oy-self.height]) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
281 m = self.mulA([1,0,0,1,tx,self.height-ty],m) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
282 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
283 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5])) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
284 pass |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
285 |
1297 | 286 def updateTweenObjectScale_Use(self, s, d, p, newobj, top): |
1296
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
287 # Parse the translate or matrix |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
288 # |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
289 # D = B inv(A) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
290 try: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
291 (ox,oy) = s.spitem.getCenter() |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
292 except: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
293 ox = 0 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
294 oy = 0 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
295 pass |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
296 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
297 try: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
298 (dx,dy) = d.spitem.getCenter() |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
299 except: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
300 dx = 0 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
301 dy = 0 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
302 pass |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
303 |
1339
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
304 self._update_tween_style(s, d, p, newobj) |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
305 |
1296
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
306 dm = self.parseTransform(d) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
307 dd = self.decomposition(dm) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
308 sx = 1-(1-dd[0])*p |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
309 sy = 1-(1-dd[1])*p |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
310 a = dd[2]*p |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
311 tx = ox*(1-p)+dx*p |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
312 ty = oy*(1-p)+dy*p |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
313 m = [math.cos(a),math.sin(a),-math.sin(a),math.cos(a),0,0] |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
314 m = self.mulA([sx,0,0,sy,0,0],m) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
315 m = self.mulA(m,[1,0,0,1,-ox,oy-self.height]) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
316 m = self.mulA([1,0,0,1,tx,self.height-ty],m) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
317 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
318 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5])) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
319 pass |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
320 |
1297 | 321 def updateTweenObjectScale_Primitive(self, s, d, p, newobj, top): |
1296
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
322 try: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
323 if d.name() == "svg:use": |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
324 sw = 1 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
325 sh = 1 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
326 dw = 1 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
327 dh = 1 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
328 else: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
329 try: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
330 sw = float(s.getAttribute("width")) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
331 except: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
332 sw = 1 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
333 try: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
334 sh = float(s.getAttribute("height")) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
335 except: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
336 sh = 1 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
337 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
338 try: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
339 dw = float(d.getAttribute("width")) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
340 except: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
341 dw = 1 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
342 try: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
343 dh = float(d.getAttribute("height")) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
344 except: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
345 dh = 1 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
346 pass |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
347 |
1339
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
348 self._update_tween_style(s, d, p, newobj) |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
349 |
1296
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
350 try: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
351 (ox,oy) = s.spitem.getCenter() |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
352 except: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
353 ox = 0 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
354 oy = 0 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
355 try: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
356 (dx,dy) = d.spitem.getCenter() |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
357 except: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
358 dx = 0 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
359 dy = 0 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
360 try: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
361 sm = self.parseTransform(s) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
362 ss = self.decomposition(sm) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
363 except: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
364 ss = [1,1,0,0,0] |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
365 pass |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
366 try: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
367 dm = self.parseTransform(d) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
368 dd = self.decomposition(dm) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
369 except: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
370 dd = [1,1,0,0,0] |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
371 dd[0] = dd[0]*dw/sw |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
372 dd[1] = dd[1]*dh/sh |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
373 sx = (ss[0]*(1-p)+dd[0]*p)/ss[0] |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
374 sy = (ss[1]*(1-p)+dd[1]*p)/ss[1] |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
375 a = ss[2]*(1-p)+dd[2]*p-ss[2] |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
376 tx = ox*(1-p)+dx*p |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
377 ty = oy*(1-p)+dy*p |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
378 m = [math.cos(a),math.sin(a),-math.sin(a),math.cos(a),0,0] |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
379 m = self.mulA([sx,0,0,sy,0,0],m) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
380 m = self.mulA(m,[1,0,0,1,-ox,oy-self.height]) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
381 m = self.mulA([1,0,0,1,tx,self.height-ty],m) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
382 |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
383 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5])) |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
384 except: |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
385 traceback.print_exc() |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
386 pass |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
387 pass |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
388 |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
389 def updateTweenObjectScale(self,obj,s,d,p,newobj): |
1140 | 390 """ |
391 Generate a new group which contains the original group and then | |
392 add the transform matrix to generate a tween frame between the | |
393 origin and destination scene group. | |
394 | |
395 We will parse the transform matrix of the @s and @d and then | |
396 generate the matrix which is (1-p) of @s and p percent of @d. | |
397 """ | |
1239
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
398 if newobj and not newobj.firstChild(): |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
399 # newobj is not with expect structure. |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
400 # |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
401 # When a user change tween type of a scene, the structure |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
402 # of dup group created by old tween type may not satisfy |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
403 # the requirement of current tween type. |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
404 newobj.parent().removeChild(newobj) |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
405 newobj = None |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
406 pass |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
407 |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
408 if newobj == None: |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
409 newobj = s.duplicate(self._doc) |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
410 top = self._doc.createElement("svg:g") |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
411 top.setAttribute("ref",s.getAttribute("id")) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
412 top.appendChild(newobj) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
413 obj.appendChild(top) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
414 else: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
415 top = newobj |
1239
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
416 newobj = newobj.firstChild() |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
417 pass |
1296
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
418 if s.name() == 'svg:g': |
1297 | 419 self.updateTweenObjectScale_Group(s,d,p,newobj,top) |
1296
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
420 elif s.name() == 'svg:use': |
1297 | 421 self.updateTweenObjectScale_Use(s,d,p,newobj,top) |
1140 | 422 else: |
1297 | 423 self.updateTweenObjectScale_Primitive(s,d,p,newobj,top) |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
424 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
425 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
426 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
427 ## \brief Providing capability of showing scenes. |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
428 # |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
429 # This class computes and shows scenes for a \ref domview_ui. The |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
430 # content of layers and frames are read from domview_ui to generate |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
431 # scenes properly. When caller requests to show a scene 'n', this |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
432 # class compute content of frame 'n' for every layer of the |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
433 # domview_ui. |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
434 # |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
435 class scenes_director(object): |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
436 _tween_obj_tween_types = (TweenObject.TWEEN_TYPE_NORMAL, |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
437 TweenObject.TWEEN_TYPE_SCALE) |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
438 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
439 def __init__(self, domview_ui): |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
440 super(scenes_director, self).__init__() |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
441 self._domview = domview_ui |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
442 self._tween_obj = TweenObject(domview_ui.doc, domview_ui.root) |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
443 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
444 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
445 def show_scene(self, idx): |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
446 """ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
447 Update the scene group according to the curretn scene |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
448 data. There are a couple of cases. |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
449 1. If the type of the scene is normal, we display it when |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
450 it contains the current frame. Otherwise hide it. |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
451 2. If the type of the scene is relocate or scale, we need |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
452 to duplicate the scene group and then modify its |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
453 transform matrix according to the definition of the |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
454 scene. Then, hide the original scenr group and display |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
455 the duplciate scene group. In addition, we may need to |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
456 delete the old duplicated scene group as well. |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
457 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
458 For each layer, we will always use the duplicated scene |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
459 group whose name as dup. |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
460 We will put the duplicated scene group inside it. We will |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
461 create this group if it is not |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
462 available. |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
463 """ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
464 for layer_idx in range(self._domview.get_layer_num()): |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
465 dup_group = self._domview.get_layer_dup_group(layer_idx) |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
466 dup_group.setAttribute('style', 'display: none') |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
467 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
468 all_key_tweens = self._domview.get_layer_keys(layer_idx) |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
469 for start, end, tween_type in all_key_tweens: |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
470 if start == idx: # at key frame |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
471 scene_group = \ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
472 self._domview.get_key_group(layer_idx, start) |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
473 scene_group.setAttribute('style', '') |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
474 elif start < idx and end >= idx: # in Tween |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
475 dup_group.setAttribute('style', '') |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
476 scene_group = \ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
477 self._domview.get_key_group(layer_idx, start) |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
478 scene_group.setAttribute('style', 'display: none') |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
479 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
480 try: |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
481 next_scene_group = \ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
482 self._domview.get_key_group(layer_idx, end + 1) |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
483 except: # no next key frame |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
484 next_scene_group = scene_group |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
485 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
486 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
487 tween_obj_type = self._tween_obj_tween_types[tween_type] |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
488 nframes = end - start + 1 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
489 percent = float(idx - start) / nframes |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
490 self._tween_obj.updateTweenContent(dup_group, |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
491 tween_obj_type, |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
492 scene_group, |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
493 next_scene_group, |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
494 percent) |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
495 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
496 else: # this scene should not be showed. |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
497 scene_group = \ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
498 self._domview.get_key_group(layer_idx, start) |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
499 scene_group.setAttribute('style', 'display: none') |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
500 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
501 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
502 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
503 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
504 pass |