Mercurial > MadButterfly
annotate pyink/tween.py @ 1243:d5f70928e9f1
Move MBScene_domview_ui and MBScene_domview to separated modules.
- domview.py is where MBScene_domview and MBScene_domview_monitor are.
- domview_ui.py is where MBScene_domview_ui and MBScene_frameline_stack are.
- keep modules small to make better collaberation.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 10 Jan 2011 16:32:16 +0800 |
parents | 447cd3359cf2 |
children | ccbf0c5d01d1 |
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 def parse_opacity(obj): |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
7 style = obj.getAttribute("style") |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
8 arr = style.split(';') |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
9 for a in arr: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
10 f = a.split(':') |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
11 if f[0] == 'opacity': |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
12 return float(f[1]) |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
13 return 1 |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
14 |
1227 | 15 def change_opacity(obj, opacity): |
16 try: | |
17 style = obj.getAttribute("style") | |
18 except: | |
19 obj.setAttribute("style","opacity:%g" % opacity) | |
20 return | |
1225
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
21 arr = style.split(';') |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
22 s='' |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
23 for a in arr: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
24 f = a.split(':') |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
25 f[0] = f[0].replace(' ','') |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
26 if f[0] == 'opacity': |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
27 if s != '': |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
28 s = s + ('; opacity:%g' % opacity) |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
29 else: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
30 s = 'opacity:%g' % opacity |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
31 elif f[0] != '': |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
32 if s == '': |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
33 s = a |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
34 else: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
35 s = s +';'+ a |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
36 obj.setAttribute("style",s) |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
37 |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
38 |
1140 | 39 class TweenObject: |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
40 TWEEN_TYPE_NORMAL = 0 |
1157
3a891dccabd8
Remove the locate tween. It is a special case for the scale tween
wycc
parents:
1156
diff
changeset
|
41 #TWEEN_TYPE_RELOCATE = 1 |
3a891dccabd8
Remove the locate tween. It is a special case for the scale tween
wycc
parents:
1156
diff
changeset
|
42 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
|
43 |
1140 | 44 def __init__(self,doc,dom): |
45 self.document = doc | |
46 self.dom = dom | |
1141 | 47 try: |
48 self.width = float(dom.getAttribute("width")) | |
49 self.height = float(dom.getAttribute("height")) | |
50 except: | |
51 self.width = 640 | |
52 self.height = 480 | |
1140 | 53 |
54 def updateMapping(self): | |
55 self.nodeToItem={} | |
56 root = self.dom | |
57 self.updateMappingNode(root) | |
58 def updateMappingNode(self,node): | |
59 for c in node.childList(): | |
60 self.updateMappingNode(c) | |
1141 | 61 try: |
62 self.nodeToItem[c.getAttribute("id")] = c | |
63 except: | |
64 pass | |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
65 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
|
66 start_scene_group, stop_scene_group, percent): |
1140 | 67 """ |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
68 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
|
69 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
|
70 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
|
71 specified. |
1140 | 72 """ |
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
|
73 # 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
|
74 node = duplicate_group.firstChild() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
75 dup_nodes = {} |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
76 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
|
77 try: |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
78 ref = node.getAttribute("ref") |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
79 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
|
80 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
|
81 ref = None |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
82 pass |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
83 node = node.next() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
84 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
|
85 |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
86 # 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
|
87 stop_nodes = {} |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
88 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
|
89 while node: |
1140 | 90 try: |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
91 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
|
92 stop_nodes[node_label] = node |
1140 | 93 except: |
94 pass | |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
95 node = node.next() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
96 pass |
1199
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1172
diff
changeset
|
97 |
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
|
98 # 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 pass |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
109 |
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
|
110 # 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
118 # |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
119 # 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
|
120 # '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
|
121 # 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
|
122 # 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
|
123 # |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
124 # 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
|
125 # 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
|
126 # 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
|
127 # |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
128 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
|
129 while start_node: |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
130 start_node_id = start_node.getAttribute('id') |
1163 | 131 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
|
132 try: |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
133 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
|
134 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
|
135 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
|
136 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
|
137 percent, dup_node) |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
138 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
|
139 continue |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
140 |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
141 |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
142 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
|
143 start_node, stop_node, |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
144 percent, dup_node) |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
145 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
|
146 pass |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
147 pass |
1140 | 148 |
149 def parseTransform(self,obj): | |
150 """ | |
151 Return the transform matrix of an object | |
152 """ | |
153 try: | |
1141 | 154 t = obj.getAttribute("transform") |
1140 | 155 if t[0:9] == 'translate': |
156 fields = t[10:].split(',') | |
157 x = float(fields[0]) | |
158 fields = fields[1].split(')') | |
159 y = float(fields[0]) | |
160 return [1,0,0,1,x,y] | |
161 elif t[0:6] == 'matrix': | |
162 fields=t[7:].split(')') | |
163 fields = fields[0].split(',') | |
164 return [float(fields[0]),float(fields[1]),float(fields[2]),float(fields[3]),float(fields[4]),float(fields[5])] | |
165 except: | |
166 #traceback.print_exc() | |
167 return [1,0,0,1,0,0] | |
168 | |
169 def invA(self,m): | |
170 d = m[0]*m[3]-m[2]*m[1] | |
171 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] | |
172 | |
173 def mulA(self,a,b): | |
174 return [a[0]*b[0]+a[1]*b[2], | |
175 a[0]*b[1]+a[1]*b[3], | |
176 a[2]*b[0]+a[3]*b[2], | |
177 a[2]*b[1]+a[3]*b[3], | |
178 a[0]*b[4]+a[1]*b[5]+a[4], | |
179 a[2]*b[4]+a[3]*b[5]+a[5]] | |
180 | |
181 def decomposition(self,m): | |
182 """ | |
183 Decompose the affine matrix into production of translation,rotation,shear and scale. | |
184 The algorithm is documented at http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html | |
185 """ | |
186 if m[0]*m[3] == m[1]*m[2]: | |
187 print "The affine matrix is singular" | |
188 return [1,0,0,1,0,0] | |
189 A=m[0] | |
190 B=m[2] | |
191 C=m[1] | |
192 D=m[3] | |
193 E=m[4] | |
194 F=m[5] | |
195 sx = math.sqrt(A*A+B*B) | |
196 A = A/sx | |
197 B = B/sx | |
198 shear = m[0]*m[1]+m[2]*m[3] | |
199 C = C - A*shear | |
200 D = D - B*shear | |
201 sy = math.sqrt(C*C+D*D) | |
202 C = C/sy | |
203 D = D/sy | |
204 r = A*D-B*C | |
205 if r == -1: | |
206 shear = -shear | |
207 sy = -sy | |
208 R = math.atan2(B,A) | |
209 return [sx,sy, R, E,F] | |
210 | |
211 | |
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
|
212 def updateTweenObject(self,obj,typ,s,d,p,newobj): |
1140 | 213 """ |
214 Generate tweened object in the @obj by using s and d in the @p percent | |
215 http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html | |
216 """ | |
1157
3a891dccabd8
Remove the locate tween. It is a special case for the scale tween
wycc
parents:
1156
diff
changeset
|
217 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
|
218 self.updateTweenObjectScale(obj,s,d,p,newobj) |
1140 | 219 pass |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
220 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
|
221 if newobj == None: |
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
|
222 newobj = s.duplicate(self.document) |
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
|
223 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
|
224 obj.appendChild(newobj) |
1140 | 225 pass |
226 | |
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
|
227 def updateTweenObjectScale(self,obj,s,d,p,newobj): |
1140 | 228 """ |
229 Generate a new group which contains the original group and then | |
230 add the transform matrix to generate a tween frame between the | |
231 origin and destination scene group. | |
232 | |
233 We will parse the transform matrix of the @s and @d and then | |
234 generate the matrix which is (1-p) of @s and p percent of @d. | |
235 """ | |
1239
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
236 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
|
237 # 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
|
238 # |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
239 # 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
|
240 # 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
|
241 # 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
|
242 newobj.parent().removeChild(newobj) |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
243 newobj = None |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
244 pass |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
245 |
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
|
246 if newobj == None: |
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
|
247 newobj = s.duplicate(self.document) |
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
|
248 top = self.document.createElement("svg:g") |
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
|
249 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
|
250 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
|
251 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
|
252 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
|
253 top = newobj |
1239
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
254 newobj = newobj.firstChild() |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
255 pass |
1140 | 256 |
257 if s.name() == 'svg:g': | |
258 # Parse the translate or matrix | |
259 # | |
260 # D = B inv(A) | |
261 try: | |
1141 | 262 item = self.nodeToItem[s.getAttribute("id")] |
1140 | 263 (ox,oy) = item.getCenter() |
264 except: | |
265 ox = 0 | |
266 oy = 0 | |
267 try: | |
1141 | 268 item = self.nodeToItem[d.getAttribute("id")] |
1140 | 269 (dx,dy) = item.getCenter() |
270 except: | |
271 dx = 0 | |
272 dy = 0 | |
1225
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
273 try: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
274 start_opacity = parse_opacity(s) |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
275 except: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
276 start_opacity = 1 |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
277 |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
278 try: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
279 end_opacity =parse_opacity( d) |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
280 except: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
281 end_opacity = 1 |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
282 |
1140 | 283 |
1225
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
284 cur_opacity = start_opacity*(1-p)+end_opacity*p |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
285 change_opacity(newobj,cur_opacity) |
1140 | 286 sm = self.parseTransform(s) |
287 ss = self.decomposition(sm) | |
288 dm = self.parseTransform(d) | |
289 dd = self.decomposition(dm) | |
290 sx = (ss[0]*(1-p)+dd[0]*p)/ss[0] | |
291 sy = (ss[1]*(1-p)+dd[1]*p)/ss[0] | |
292 a = ss[2]*(1-p)+dd[2]*p-ss[2] | |
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
|
293 tx = ox*(1-p)+dx*p |
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
|
294 ty = oy*(1-p)+dy*p |
1140 | 295 m = [math.cos(a),math.sin(a),-math.sin(a),math.cos(a),0,0] |
296 m = self.mulA([sx,0,0,sy,0,0],m) | |
297 m = self.mulA(m,[1,0,0,1,-ox,oy-self.height]) | |
298 m = self.mulA([1,0,0,1,tx,self.height-ty],m) | |
299 | |
300 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5])) | |
301 else: | |
302 try: | |
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
|
303 try: |
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
|
304 sw = float(s.getAttribute("width")) |
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
|
305 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
|
306 sw = 1 |
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
|
307 try: |
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
|
308 sh = float(s.getAttribute("height")) |
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
|
309 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
|
310 sh = 1 |
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
|
311 try: |
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
|
312 dw = float(d.getAttribute("width")) |
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
|
313 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
|
314 dw = 1 |
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
|
315 try: |
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
|
316 dh = float(d.getAttribute("height")) |
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
|
317 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
|
318 dh = 1 |
1225
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
319 try: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
320 start_opacity = parse_opacity(s) |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
321 except: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
322 start_opacity = 1 |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
323 |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
324 try: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
325 end_opacity =parse_opacity( d) |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
326 except: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
327 end_opacity = 1 |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
328 cur_opacity = start_opacity*(1-p)+end_opacity*p |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
329 change_opacity(newobj,cur_opacity) |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
330 |
1140 | 331 try: |
1141 | 332 item = self.nodeToItem[s.getAttribute("id")] |
1140 | 333 (ox,oy) = item.getCenter() |
334 except: | |
335 ox = 0 | |
336 oy = 0 | |
337 try: | |
1141 | 338 item = self.nodeToItem[d.getAttribute("id")] |
1140 | 339 (dx,dy) = item.getCenter() |
340 except: | |
341 dx = 0 | |
342 dy = 0 | |
343 try: | |
344 sm = self.parseTransform(s) | |
345 ss = self.decomposition(sm) | |
346 except: | |
347 ss = [1,1,0,0,0] | |
348 pass | |
349 try: | |
350 dm = self.parseTransform(d) | |
351 dd = self.decomposition(dm) | |
352 except: | |
353 dd = [1,1,0,0,0] | |
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
|
354 dd[0] = dd[0]*dw/sw |
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
|
355 dd[1] = dd[1]*dh/sh |
1140 | 356 sx = (ss[0]*(1-p)+dd[0]*p)/ss[0] |
357 sy = (ss[1]*(1-p)+dd[1]*p)/ss[1] | |
358 a = ss[2]*(1-p)+dd[2]*p-ss[2] | |
359 tx = ox*(1-p)+dx*p | |
360 ty = oy*(1-p)+dy*p | |
361 m = [math.cos(a),math.sin(a),-math.sin(a),math.cos(a),0,0] | |
362 m = self.mulA([sx,0,0,sy,0,0],m) | |
363 m = self.mulA(m,[1,0,0,1,-ox,oy-self.height]) | |
364 m = self.mulA([1,0,0,1,tx,self.height-ty],m) | |
365 | |
366 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5])) | |
367 except: | |
368 traceback.print_exc() |