Mercurial > MadButterfly
annotate pyink/tween.py @ 1522:73837e189039
Add diagram of arch of pyink
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sat, 20 Aug 2011 16:17:56 +0800 |
parents | f89d3ee130de |
children |
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 |
1358
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
7 def _shift_matrix(x, y): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
8 return (1, 0, 0, 1, x, y) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
9 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
10 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
11 def _rotate_matrix(a): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
12 return (math.cos(a), math.sin(a), -math.sin(a), math.cos(a), 0, 0) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
13 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
14 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
15 def _scale_matrix(scale_x, scale_y): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
16 return (scale_x, 0, 0, scale_y, 0, 0) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
17 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
18 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
19 _id_matrix = (1, 0, 0, 1, 0, 0) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
20 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
21 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
22 def _mulA(a, b): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
23 return (a[0] * b[0] + a[2] * b[1], |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
24 a[1] * b[0] + a[3] * b[1], |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
25 a[0] * b[2] + a[2] * b[3], |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
26 a[1] * b[2] + a[3] * b[3], |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
27 a[0] * b[4] + a[2] * b[5] + a[4], |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
28 a[1] * b[4] + a[3] * b[5] + a[5]) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
29 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
30 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
31 def _parse_style(style): |
1339
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
32 attrs = {} |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
33 |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
34 style_parts = style.split(';') |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
35 for part in style_parts: |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
36 part = part.strip() |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
37 if not part: |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
38 continue |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
39 nv_pair = part.split(':') |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
40 if len(nv_pair) != 2: |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
41 raise ValueError, 'invalid format for style "%s"' % (style) |
1225
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
42 |
1339
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
43 name = nv_pair[0].strip() |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
44 value = nv_pair[1].strip() |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
45 attrs[name] = value |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
46 pass |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
47 |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
48 return attrs |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
49 |
1358
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
50 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
51 def _gen_style(attrs): |
1339
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
52 parts = [name + ':' + value for name, value in attrs.items()] |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
53 style = ';'.join(parts) |
20cf3e2a0a9d
Fix weir behavior for tweening for opacity.
Thinker K.F. Li <thinker@codemud.net>
parents:
1297
diff
changeset
|
54 return style |
1225
a05c8deb6523
Add opacity support to implement fadein/fadeout effect
wycc
parents:
1199
diff
changeset
|
55 |
1358
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
56 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
57 def _parse_transform_str(txt): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
58 if txt[0:9] == 'translate': |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
59 fields = txt[10:].split(',') |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
60 x = float(fields[0]) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
61 fields = fields[1].split(')') |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
62 y = float(fields[0]) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
63 return [1, 0, 0, 1 , x, y] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
64 elif txt[0:6] == 'matrix': |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
65 fields = txt[7:].split(')') |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
66 fields = fields[0].split(',') |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
67 return [float(field) for field in fields] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
68 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
69 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
70 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
71 ## \brief Parse style attributes about animation. |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
72 # |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
73 def _parse_style_ani(node, ani_attrs): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
74 try: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
75 style = node.getAttribute('style') |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
76 except: # has no style |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
77 style_attrs = {} |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
78 else: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
79 style_attrs = _parse_style(style) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
80 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
81 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
82 if 'opacity' in style_attrs: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
83 ani_attrs['opacity'] = float(style_attrs['opacity']) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
84 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
85 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
86 if 'display' in style_attrs: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
87 ani_attrs['display'] = style_attrs['display'] != 'none' |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
88 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
89 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
90 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
91 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
92 ## \brief Parse all attributes about animation |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
93 # |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
94 def _parse_attr_ani(node, ani_attrs): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
95 def _parse_transform_with_center(attr_value): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
96 value = _parse_transform_str(attr_value) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
97 x, y = node.spitem.getCenter() |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
98 return (value, (x, y)) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
99 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
100 attr_defs = {'x': float, 'y': float, |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
101 'width': float, 'height': float, |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
102 'transform': _parse_transform_with_center} |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
103 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
104 for attrname, parser in attr_defs.items(): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
105 try: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
106 value = node.getAttribute(attrname) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
107 except: # has no this attribute |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
108 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
109 else: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
110 parsed_value = parser(value) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
111 ani_attrs[attrname] = parsed_value |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
112 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
113 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
114 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
115 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
116 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
117 ## \brief Interpolate float values. |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
118 # |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
119 def _interp_float(start_value, stop_value, percent): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
120 if start_value == None or stop_value == None: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
121 if percent == 1: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
122 return stop_value |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
123 return start_value |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
124 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
125 return start_value * (1 - percent) + stop_value * percent |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
126 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
127 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
128 ## \brief Interpolate matric. |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
129 # |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
130 def _interp_transform(start_value, stop_value, percent): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
131 start_matrix = start_value[0] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
132 start_center_x, start_center_y = start_value[1] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
133 stop_matrix = stop_value[0] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
134 stop_center_x, stop_center_y = stop_value[1] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
135 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
136 start_scale_x, start_scale_y, start_ang, start_x, start_y = \ |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
137 _decomposition(start_matrix) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
138 stop_scale_x, stop_scale_y, stop_ang, stop_x, stop_y = \ |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
139 _decomposition(stop_matrix) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
140 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
141 interp = lambda x, y: _interp_float(x, y, percent) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
142 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
143 factor_x = interp(start_scale_x, stop_scale_x) / start_scale_x |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
144 factor_y = interp(start_scale_y, stop_scale_y) / start_scale_y |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
145 angle = interp(start_ang, stop_ang) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
146 shift_x = interp(start_center_x, stop_center_x) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
147 shift_y = interp(start_center_y, stop_center_y) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
148 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
149 # Shift center point back to origin |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
150 matrix = start_matrix |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
151 shift_matrix = _shift_matrix(-start_center_x, -start_center_y) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
152 matrix = _mulA(shift_matrix, matrix) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
153 # Remove rotation |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
154 rotate_matrix = _rotate_matrix(-start_ang) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
155 matrix = _mulA(rotate_matrix, matrix) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
156 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
157 # Apply new scaling |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
158 scale_matrix = _scale_matrix(factor_x, factor_y) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
159 matrix = _mulA(scale_matrix, matrix) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
160 # Rotate to new angle |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
161 rotate_matrix = _rotate_matrix(angle) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
162 matrix = _mulA(rotate_matrix, matrix) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
163 # Shift space to aim center point on new position. |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
164 shift_matrix = _shift_matrix(shift_x, shift_y) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
165 matrix = _mulA(shift_matrix, matrix) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
166 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
167 return matrix |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
168 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
169 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
170 ## \brief Interpolate for value of display style. |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
171 # |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
172 def _interp_display(start_value, stop_value, percent): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
173 if percent < 1: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
174 return start_value |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
175 return stop_value |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
176 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
177 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
178 _interp_funcs = { |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
179 'x': _interp_float, 'y': _interp_float, |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
180 'width': _interp_float, 'height': _interp_float, |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
181 'opacity': _interp_float, 'display': _interp_display, |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
182 'transform': _interp_transform} |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
183 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
184 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
185 def _tween_interpolation(attrname, start_value, stop_value, percent): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
186 interp = _interp_funcs[attrname] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
187 _interp_value = interp(start_value, stop_value, percent) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
188 return _interp_value |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
189 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
190 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
191 def _apply_animation_attrs(ani_attrs, node): |
1359
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
192 for attr in ('x', 'y', 'width', 'height'): |
1358
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
193 if attr in ani_attrs: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
194 node.setAttribute(attr, str(ani_attrs[attr])) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
195 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
196 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
197 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
198 if 'transform' in ani_attrs: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
199 try: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
200 style = node.getAttribute('style') |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
201 except: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
202 style = '' |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
203 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
204 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
205 transform = [str(elm) for elm in ani_attrs['transform']] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
206 transform_str = 'matrix(' + ','.join(transform) + ')' |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
207 node.setAttribute('transform', transform_str) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
208 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
209 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
210 chg_style = [] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
211 for attrname in 'opacity display'.split(): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
212 if attrname in ani_attrs: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
213 chg_style.append((attrname, str(ani_attrs[attrname]))) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
214 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
215 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
216 if chg_style: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
217 try: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
218 style = node.getAttribute('style') |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
219 except: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
220 style_attrs = chg_style |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
221 else: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
222 style_attrs = _parse_style(style) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
223 style_attrs.update(dict(chg_style)) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
224 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
225 style = _gen_style(style_attrs) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
226 node.setAttribute('style', style) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
227 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
228 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
229 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
230 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
231 def _decomposition(m): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
232 """ |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
233 Decompose the affine matrix into production of |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
234 translation,rotation,shear and scale. The algorithm is |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
235 documented at |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
236 http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
237 """ |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
238 if m[0]*m[3] == m[1]*m[2]: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
239 print "The affine matrix is singular" |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
240 return [1,0,0,1,0,0] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
241 A=m[0] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
242 B=m[2] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
243 C=m[1] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
244 D=m[3] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
245 E=m[4] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
246 F=m[5] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
247 sx = math.sqrt(A*A+B*B) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
248 A = A/sx |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
249 B = B/sx |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
250 shear = m[0]*m[1]+m[2]*m[3] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
251 C = C - A*shear |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
252 D = D - B*shear |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
253 sy = math.sqrt(C*C+D*D) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
254 C = C/sy |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
255 D = D/sy |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
256 r = A*D-B*C |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
257 if r == -1: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
258 shear = -shear |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
259 sy = -sy |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
260 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
261 R = math.atan2(-B,A) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
262 return [sx,sy, R, E, F] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
263 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
264 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
265 def _normalize_attrs(node1, attrs1, node2, attrs2): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
266 if node2.name() == 'svg:use': |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
267 for name in 'x y width height'.split(): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
268 if name in attrs1: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
269 del attrs1[name] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
270 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
271 if name in attrs2: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
272 del attrs2[name] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
273 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
274 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
275 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
276 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
277 names = set(attrs1.keys() + attrs2.keys()) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
278 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
279 if 'transform' in names: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
280 if 'transform' not in attrs1: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
281 center = node1.spitem.getCenter() |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
282 attrs1['transform'] = (_id_matrix, center) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
283 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
284 if 'transform' not in attrs2: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
285 center = node2.spitem.getCenter() |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
286 attrs2['transform'] = (_id_matrix, center) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
287 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
288 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
289 root = node1.root() |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
290 try: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
291 root_h = float(root.getAttribute('height')) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
292 except: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
293 root_h = 600 # 800x600 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
294 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
295 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
296 for attrs in (attrs1, attrs2): |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
297 transform = attrs['transform'] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
298 center = (transform[1][0], root_h - transform[1][1]) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
299 attrs['transform'] = (transform[0], center) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
300 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
301 if 'x' in attrs: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
302 del attrs['x'] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
303 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
304 if 'y' in attrs: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
305 del attrs['y'] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
306 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
307 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
308 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
309 |
1359
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
310 defaults = {'x': 0, 'y': 0, |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
311 'width': 0, 'height': 0, |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
312 'opacity': 1.0, 'display': 'inline'} |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
313 |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
314 for attrname in defaults: |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
315 if attrname in names: |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
316 if attrname not in attrs1: |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
317 attrs1[attrname] = defaults[attrname] |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
318 pass |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
319 if attrname not in attrs2: |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
320 attrs2[attrname] = defaults[attrname] |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
321 pass |
1358
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
322 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
323 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
324 |
1359
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
325 if node2.name() == 'svg:use': |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
326 accumulators = {'opacity': |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
327 (lambda attr_v1, attr_v2: attr_v1 * attr_v2), |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
328 'transform': |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
329 (lambda m1, m2: (_mulA(m2[0], m1[0]), m2[1])) |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
330 } |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
331 for attrname in accumulators: |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
332 if attrname not in names: |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
333 continue |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
334 accumulator = accumulators[attrname] |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
335 acc = accumulator(attrs1[attrname], attrs2[attrname]) |
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
336 attrs2[attrname] = acc |
1358
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
337 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
338 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
339 pass |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
340 |
1359
5313bbfafa67
Fix issue of chain of reference for opacity and matrix
Thinker K.F. Li <thinker@codemud.net>
parents:
1358
diff
changeset
|
341 |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
342 class TweenObject(object): |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
343 TWEEN_TYPE_NORMAL = 0 |
1157
3a891dccabd8
Remove the locate tween. It is a special case for the scale tween
wycc
parents:
1156
diff
changeset
|
344 #TWEEN_TYPE_RELOCATE = 1 |
3a891dccabd8
Remove the locate tween. It is a special case for the scale tween
wycc
parents:
1156
diff
changeset
|
345 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
|
346 |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
347 def __init__(self, doc, root): |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
348 super(TweenObject, self).__init__() |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
349 self._doc = doc |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
350 self._root = root |
1141 | 351 try: |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
352 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
|
353 self.height = float(root.getAttribute("height")) |
1141 | 354 except: |
355 self.width = 640 | |
356 self.height = 480 | |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
357 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
358 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
359 |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
360 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
|
361 start_scene_group, stop_scene_group, percent): |
1140 | 362 """ |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
363 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
|
364 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
|
365 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
|
366 specified. |
1140 | 367 """ |
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
|
368 # 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
|
369 node = duplicate_group.firstChild() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
370 dup_nodes = {} |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
371 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
|
372 try: |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
373 ref = node.getAttribute("ref") |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
374 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
|
375 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
|
376 ref = None |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
377 pass |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
378 node = node.next() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
379 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
|
380 |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
381 # 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
|
382 stop_nodes = {} |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
383 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
|
384 while node: |
1140 | 385 try: |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
386 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
|
387 stop_nodes[node_label] = node |
1140 | 388 except: |
389 pass | |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
390 node = node.next() |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
391 pass |
1199
25e1579ed3d1
Fix bug of running animation
Thinker K.F. Li <thinker@codemud.net>
parents:
1172
diff
changeset
|
392 |
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
|
393 # 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
|
394 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
|
395 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
|
396 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
|
397 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
|
398 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
|
399 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
|
400 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
|
401 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
|
402 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
|
403 pass |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
404 |
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
|
405 # 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
|
406 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
|
407 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
|
408 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
|
409 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
|
410 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
|
411 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
|
412 |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
413 # |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
414 # 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
|
415 # '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
|
416 # 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
|
417 # 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
|
418 # |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
419 # 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
|
420 # 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
|
421 # 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
|
422 # |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
423 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
|
424 while start_node: |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
425 start_node_id = start_node.getAttribute('id') |
1163 | 426 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
|
427 try: |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
428 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
|
429 except KeyError: |
1358
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
430 stop_node = start_node |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
431 pass |
1151
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
432 |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
433 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
|
434 start_node, stop_node, |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
435 percent, dup_node) |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
436 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
|
437 pass |
71c72e8d6755
Refactory cod eof TweenObject.updateTweenContent and MBScene.setCurrentScene().
Thinker K.F. Li <thinker@codemud.net>
parents:
1150
diff
changeset
|
438 pass |
1140 | 439 |
440 | |
1358
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
441 def updateTweenObject(self, obj, typ, s, d, p, newobj): |
1140 | 442 """ |
443 Generate tweened object in the @obj by using s and d in the @p percent | |
444 http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html | |
445 """ | |
1157
3a891dccabd8
Remove the locate tween. It is a special case for the scale tween
wycc
parents:
1156
diff
changeset
|
446 if typ == self.TWEEN_TYPE_SCALE: |
1358
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
447 if newobj == None: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
448 newobj = s.duplicate(self._doc) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
449 newobj.setAttribute("ref", s.getAttribute("id")) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
450 obj.appendChild(newobj) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
451 pass |
1360
f89d3ee130de
Remove TweenObject._update_tween_style
Thinker K.F. Li <thinker@codemud.net>
parents:
1359
diff
changeset
|
452 self._update_tween_object_scale(s, d, p, newobj) |
1140 | 453 pass |
1358
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
454 elif typ == self.TWEEN_TYPE_NORMAL and newobj == None: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
455 newobj = s.duplicate(self._doc) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
456 newobj.setAttribute("ref", s.getAttribute("id")) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
457 obj.appendChild(newobj) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
458 pass |
1140 | 459 pass |
460 | |
1360
f89d3ee130de
Remove TweenObject._update_tween_style
Thinker K.F. Li <thinker@codemud.net>
parents:
1359
diff
changeset
|
461 def _update_tween_object_scale(self, start, stop, percent, newobj): |
1358
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
462 start_attrs = {} |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
463 _parse_style_ani(start, start_attrs) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
464 _parse_attr_ani(start, start_attrs) |
1296
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
465 |
1358
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
466 stop_attrs = {} |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
467 _parse_style_ani(stop, stop_attrs) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
468 _parse_attr_ani(stop, stop_attrs) |
1296
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
469 |
1358
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
470 _normalize_attrs(start, start_attrs, stop, stop_attrs) |
1296
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
471 |
1358
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
472 tween_attrs = {} |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
473 attrs = set(start_attrs.keys() + stop_attrs.keys()) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
474 for attr in attrs: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
475 start_v = start_attrs[attr] |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
476 stop_v = stop_attrs[attr] |
1296
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
477 |
1358
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
478 if start_v != stop_v: |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
479 new_v = _tween_interpolation(attr, start_v, stop_v, percent) |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
480 tween_attrs[attr] = new_v |
1296
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
481 pass |
7f0a16125eeb
When we animate from a use, we should not consider its matrix because the matrix of the destination group is apply to the whole <svg:use> include its matrix.
wycc
parents:
1284
diff
changeset
|
482 pass |
1358
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
483 |
cd0c0c7547b4
Simplify tween function
Thinker K.F. Li <thinker@codemud.net>
parents:
1357
diff
changeset
|
484 _apply_animation_attrs(tween_attrs, newobj) |
1245
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
485 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
486 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
487 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
488 ## \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
|
489 # |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
490 # 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
|
491 # 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
|
492 # 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
|
493 # 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
|
494 # domview_ui. |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
495 # |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
496 class scenes_director(object): |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
497 _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
|
498 TweenObject.TWEEN_TYPE_SCALE) |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
499 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
500 def __init__(self, domview_ui): |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
501 super(scenes_director, self).__init__() |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
502 self._domview = domview_ui |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
503 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
|
504 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
505 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
506 def show_scene(self, idx): |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
507 """ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
508 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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 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
|
514 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
|
515 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
|
516 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
|
517 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
|
518 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
519 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
|
520 group whose name as dup. |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
521 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
|
522 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
|
523 available. |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
524 """ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
525 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
|
526 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
|
527 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
|
528 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
529 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
|
530 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
|
531 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
|
532 scene_group = \ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
533 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
|
534 scene_group.setAttribute('style', '') |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
535 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
|
536 dup_group.setAttribute('style', '') |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
537 scene_group = \ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
538 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
|
539 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
|
540 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
541 try: |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
542 next_scene_group = \ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
543 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
|
544 except: # no next key frame |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
545 next_scene_group = scene_group |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
546 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
547 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
548 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
|
549 nframes = end - start + 1 |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
550 percent = float(idx - start) / nframes |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
551 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
|
552 tween_obj_type, |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
553 scene_group, |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
554 next_scene_group, |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
555 percent) |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
556 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
557 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
|
558 scene_group = \ |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
559 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
|
560 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
|
561 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
562 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
563 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
564 pass |
ccbf0c5d01d1
Move code of setCurrentScene to tween.py.
Thinker K.F. Li <thinker@codemud.net>
parents:
1239
diff
changeset
|
565 pass |