Mercurial > MadButterfly
annotate pyink/tween.py @ 1284:cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
author | wycc |
---|---|
date | Sat, 15 Jan 2011 02:43:20 +0800 |
parents | ccbf0c5d01d1 |
children | 7f0a16125eeb |
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 |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
39 class TweenObject(object): |
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 |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
44 def __init__(self, doc, root): |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
45 super(TweenObject, self).__init__() |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
46 self._doc = doc |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
47 self._root = root |
1141 | 48 try: |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
49 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
|
50 self.height = float(root.getAttribute("height")) |
1141 | 51 except: |
52 self.width = 640 | |
53 self.height = 480 | |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
54 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
55 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
56 |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
57 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
|
58 start_scene_group, stop_scene_group, percent): |
1140 | 59 """ |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
60 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
|
61 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
|
62 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
|
63 specified. |
1140 | 64 """ |
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
|
65 # 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
|
66 node = duplicate_group.firstChild() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
67 dup_nodes = {} |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
68 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
|
69 try: |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
70 ref = node.getAttribute("ref") |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
71 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
|
72 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
|
73 ref = None |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
74 pass |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
75 node = node.next() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
76 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
|
77 |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
78 # 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
|
79 stop_nodes = {} |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
80 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
|
81 while node: |
1140 | 82 try: |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
83 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
|
84 stop_nodes[node_label] = node |
1140 | 85 except: |
86 pass | |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
87 node = node.next() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
88 pass |
1199
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1172
diff
changeset
|
89 |
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
|
90 # 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 pass |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
101 |
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
|
102 # 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
110 # |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
111 # 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
|
112 # '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
|
113 # 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
|
114 # 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
|
115 # |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
116 # 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
|
117 # 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
|
118 # 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
|
119 # |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
120 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
|
121 while start_node: |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
122 start_node_id = start_node.getAttribute('id') |
1163 | 123 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
|
124 try: |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
125 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
|
126 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
|
127 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
|
128 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
|
129 percent, dup_node) |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
130 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
|
131 continue |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
132 |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
133 |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
134 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
|
135 start_node, stop_node, |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
136 percent, dup_node) |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
137 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
|
138 pass |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
139 pass |
1140 | 140 |
141 def parseTransform(self,obj): | |
142 """ | |
143 Return the transform matrix of an object | |
144 """ | |
145 try: | |
1141 | 146 t = obj.getAttribute("transform") |
1140 | 147 if t[0:9] == 'translate': |
148 fields = t[10:].split(',') | |
149 x = float(fields[0]) | |
150 fields = fields[1].split(')') | |
151 y = float(fields[0]) | |
152 return [1,0,0,1,x,y] | |
153 elif t[0:6] == 'matrix': | |
154 fields=t[7:].split(')') | |
155 fields = fields[0].split(',') | |
156 return [float(fields[0]),float(fields[1]),float(fields[2]),float(fields[3]),float(fields[4]),float(fields[5])] | |
157 except: | |
158 #traceback.print_exc() | |
159 return [1,0,0,1,0,0] | |
160 | |
161 def invA(self,m): | |
162 d = m[0]*m[3]-m[2]*m[1] | |
163 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] | |
164 | |
165 def mulA(self,a,b): | |
166 return [a[0]*b[0]+a[1]*b[2], | |
167 a[0]*b[1]+a[1]*b[3], | |
168 a[2]*b[0]+a[3]*b[2], | |
169 a[2]*b[1]+a[3]*b[3], | |
170 a[0]*b[4]+a[1]*b[5]+a[4], | |
171 a[2]*b[4]+a[3]*b[5]+a[5]] | |
172 | |
173 def decomposition(self,m): | |
174 """ | |
175 Decompose the affine matrix into production of translation,rotation,shear and scale. | |
176 The algorithm is documented at http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html | |
177 """ | |
178 if m[0]*m[3] == m[1]*m[2]: | |
179 print "The affine matrix is singular" | |
180 return [1,0,0,1,0,0] | |
181 A=m[0] | |
182 B=m[2] | |
183 C=m[1] | |
184 D=m[3] | |
185 E=m[4] | |
186 F=m[5] | |
187 sx = math.sqrt(A*A+B*B) | |
188 A = A/sx | |
189 B = B/sx | |
190 shear = m[0]*m[1]+m[2]*m[3] | |
191 C = C - A*shear | |
192 D = D - B*shear | |
193 sy = math.sqrt(C*C+D*D) | |
194 C = C/sy | |
195 D = D/sy | |
196 r = A*D-B*C | |
197 if r == -1: | |
198 shear = -shear | |
199 sy = -sy | |
200 R = math.atan2(B,A) | |
201 return [sx,sy, R, E,F] | |
202 | |
203 | |
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
|
204 def updateTweenObject(self,obj,typ,s,d,p,newobj): |
1140 | 205 """ |
206 Generate tweened object in the @obj by using s and d in the @p percent | |
207 http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html | |
208 """ | |
1157
3a891dccabd8
Remove the locate tween. It is a special case for the scale tween
wycc
parents:
1156
diff
changeset
|
209 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
|
210 self.updateTweenObjectScale(obj,s,d,p,newobj) |
1140 | 211 pass |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
212 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
|
213 if newobj == None: |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
214 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
|
215 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
|
216 obj.appendChild(newobj) |
1140 | 217 pass |
218 | |
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
|
219 def updateTweenObjectScale(self,obj,s,d,p,newobj): |
1140 | 220 """ |
221 Generate a new group which contains the original group and then | |
222 add the transform matrix to generate a tween frame between the | |
223 origin and destination scene group. | |
224 | |
225 We will parse the transform matrix of the @s and @d and then | |
226 generate the matrix which is (1-p) of @s and p percent of @d. | |
227 """ | |
1239
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
228 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
|
229 # 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
|
230 # |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
231 # 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
|
232 # 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
|
233 # 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
|
234 newobj.parent().removeChild(newobj) |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
235 newobj = None |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
236 pass |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
237 |
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
|
238 if newobj == None: |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
239 newobj = s.duplicate(self._doc) |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 top = newobj |
1239
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
246 newobj = newobj.firstChild() |
447cd3359cf2
Fix bug of mal-structured dup group
Thinker K.F. Li <thinker@codemud.net>
parents:
1227
diff
changeset
|
247 pass |
1284
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
248 print s.name() |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
249 if s.name() == 'svg:g' or s.name() == 'svg:use': |
1140 | 250 # Parse the translate or matrix |
251 # | |
252 # D = B inv(A) | |
253 try: | |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
254 (ox,oy) = s.spitem.getCenter() |
1140 | 255 except: |
256 ox = 0 | |
257 oy = 0 | |
258 try: | |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
259 (dx,dy) = d.spitem.getCenter() |
1140 | 260 except: |
261 dx = 0 | |
262 dy = 0 | |
1225
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
263 try: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
264 start_opacity = parse_opacity(s) |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
265 except: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
266 start_opacity = 1 |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
267 |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
268 try: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
269 end_opacity =parse_opacity( d) |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
270 except: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
271 end_opacity = 1 |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
272 |
1140 | 273 |
1225
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
274 cur_opacity = start_opacity*(1-p)+end_opacity*p |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
275 change_opacity(newobj,cur_opacity) |
1140 | 276 sm = self.parseTransform(s) |
277 ss = self.decomposition(sm) | |
278 dm = self.parseTransform(d) | |
279 dd = self.decomposition(dm) | |
280 sx = (ss[0]*(1-p)+dd[0]*p)/ss[0] | |
1284
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
281 sy = (ss[1]*(1-p)+dd[1]*p)/ss[1] |
1140 | 282 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
|
283 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
|
284 ty = oy*(1-p)+dy*p |
1140 | 285 m = [math.cos(a),math.sin(a),-math.sin(a),math.cos(a),0,0] |
286 m = self.mulA([sx,0,0,sy,0,0],m) | |
287 m = self.mulA(m,[1,0,0,1,-ox,oy-self.height]) | |
288 m = self.mulA([1,0,0,1,tx,self.height-ty],m) | |
289 | |
290 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5])) | |
291 else: | |
292 try: | |
1284
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
293 if d.name() == "svg:use": |
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
|
294 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
|
295 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
|
296 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
|
297 dh = 1 |
1284
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
298 else: |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
299 try: |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
300 sw = float(s.getAttribute("width")) |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
301 except: |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
302 sw = 1 |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
303 try: |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
304 sh = float(s.getAttribute("height")) |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
305 except: |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
306 sh = 1 |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
307 |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
308 try: |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
309 dw = float(d.getAttribute("width")) |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
310 except: |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
311 dw = 1 |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
312 try: |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
313 dh = float(d.getAttribute("height")) |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
314 except: |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
315 dh = 1 |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
316 pass |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
317 |
1225
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
318 try: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
319 start_opacity = parse_opacity(s) |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
320 except: |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
321 start_opacity = 1 |
1284
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
322 pass |
1225
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) |
1284
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
326 if d.name() == "svg:use": |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
327 end_opacity = end_opacity * start_opacity |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
328 pass |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
329 pass |
1225
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
330 except: |
1284
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
331 if d.name() == "svg:use": |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
332 end_opacity = start_opacity |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
333 else: |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
334 end_opacity = 1 |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
335 pass |
cbcb91b196fa
Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
wycc
parents:
1245
diff
changeset
|
336 |
1225
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
337 cur_opacity = start_opacity*(1-p)+end_opacity*p |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
338 change_opacity(newobj,cur_opacity) |
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
339 |
1140 | 340 try: |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
341 (ox,oy) = s.spitem.getCenter() |
1140 | 342 except: |
343 ox = 0 | |
344 oy = 0 | |
345 try: | |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
346 (dx,dy) = d.spitem.getCenter() |
1140 | 347 except: |
348 dx = 0 | |
349 dy = 0 | |
350 try: | |
351 sm = self.parseTransform(s) | |
352 ss = self.decomposition(sm) | |
353 except: | |
354 ss = [1,1,0,0,0] | |
355 pass | |
356 try: | |
357 dm = self.parseTransform(d) | |
358 dd = self.decomposition(dm) | |
359 except: | |
360 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
|
361 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
|
362 dd[1] = dd[1]*dh/sh |
1140 | 363 sx = (ss[0]*(1-p)+dd[0]*p)/ss[0] |
364 sy = (ss[1]*(1-p)+dd[1]*p)/ss[1] | |
365 a = ss[2]*(1-p)+dd[2]*p-ss[2] | |
366 tx = ox*(1-p)+dx*p | |
367 ty = oy*(1-p)+dy*p | |
368 m = [math.cos(a),math.sin(a),-math.sin(a),math.cos(a),0,0] | |
369 m = self.mulA([sx,0,0,sy,0,0],m) | |
370 m = self.mulA(m,[1,0,0,1,-ox,oy-self.height]) | |
371 m = self.mulA([1,0,0,1,tx,self.height-ty],m) | |
372 | |
373 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5])) | |
374 except: | |
375 traceback.print_exc() | |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
376 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
377 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
378 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
379 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
380 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
381 ## \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
|
382 # |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
383 # 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
|
384 # 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
|
385 # 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
|
386 # 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
|
387 # domview_ui. |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
388 # |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
389 class scenes_director(object): |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
390 _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
|
391 TweenObject.TWEEN_TYPE_SCALE) |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
392 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
393 def __init__(self, domview_ui): |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
394 super(scenes_director, self).__init__() |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
395 self._domview = domview_ui |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
396 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
|
397 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
398 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
399 def show_scene(self, idx): |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
400 """ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
401 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
|
402 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
|
403 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
|
404 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
|
405 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
|
406 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
|
407 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
|
408 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
|
409 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
|
410 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
|
411 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
412 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
|
413 group whose name as dup. |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
414 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
|
415 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
|
416 available. |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
417 """ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
418 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
|
419 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
|
420 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
|
421 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
422 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
|
423 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
|
424 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
|
425 scene_group = \ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
426 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
|
427 scene_group.setAttribute('style', '') |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
428 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
|
429 dup_group.setAttribute('style', '') |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
430 scene_group = \ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
431 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
|
432 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
|
433 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
434 try: |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
435 next_scene_group = \ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
436 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
|
437 except: # no next key frame |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
438 next_scene_group = scene_group |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
439 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
440 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
441 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
|
442 nframes = end - start + 1 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
443 percent = float(idx - start) / nframes |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
444 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
|
445 tween_obj_type, |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
446 scene_group, |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
447 next_scene_group, |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
448 percent) |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
449 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
450 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
|
451 scene_group = \ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
452 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
|
453 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
|
454 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
455 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
456 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
457 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
458 pass |