Mercurial > MadButterfly
comparison nodejs/mbapp.js @ 1401:2fc1f54a1a3b
Mainly fix the clone_from_subtree to update the children of the parent node. We need to clearify all related codes in the future to make the logic more clear.
author | wycc |
---|---|
date | Sun, 03 Apr 2011 18:12:42 +0800 |
parents | 9cebe429508c |
children | 0efa20061d70 |
comparison
equal
deleted
inserted
replaced
1400:18215e577fe0 | 1401:2fc1f54a1a3b |
---|---|
54 | 54 |
55 this._mbapp_saved_add_shape(shape); | 55 this._mbapp_saved_add_shape(shape); |
56 shape.parent = this; | 56 shape.parent = this; |
57 this.children.push(shape); | 57 this.children.push(shape); |
58 } | 58 } |
59 coord.clone_from_subtree = function(coord) { | 59 coord.clone_from_subtree = function(c) { |
60 var newcoord = this._mbapp_saved_clone_from_subtree(coord); | 60 var newcoord = this._mbapp_saved_clone_from_subtree(c); |
61 newcoord.parent = this; | 61 newcoord.parent = this; |
62 this.children.push(newcoord); | |
62 // FIXME: This is incorrect. However, we have no way to fix it for now. | 63 // FIXME: This is incorrect. However, we have no way to fix it for now. |
63 // We need to implement a function which can get coord for a coord_t. | 64 // We need to implement a function which can get coord for a coord_t. |
64 newcoord.children=coord.children; | 65 newcoord.children=c.children; |
65 return newcoord; | 66 return newcoord; |
66 } | 67 } |
67 | 68 |
68 parent.children.push(coord); | 69 parent.children.push(coord); |
69 | 70 |
85 var coord; | 86 var coord; |
86 | 87 |
87 this._mbapp_saved_add_shape(shape); | 88 this._mbapp_saved_add_shape(shape); |
88 shape.parent = this; | 89 shape.parent = this; |
89 } | 90 } |
90 coord.clone_from_subtree = function(coord) { | 91 coord.clone_from_subtree = function(c) { |
91 var newcoord; | 92 var newcoord; |
92 | 93 |
93 newcoord = this._mbapp_saved_clone_from_subtree(coord); | 94 newcoord = this._mbapp_saved_clone_from_subtree(c); |
94 newcoord.parent = this; | 95 newcoord.parent = this; |
96 this.children.push(newcoord); | |
95 // FIXME: This is incorrect. However, we have no way to fix it for now. | 97 // FIXME: This is incorrect. However, we have no way to fix it for now. |
96 // We need to implement a function which can get coord for a coord_t. | 98 // We need to implement a function which can get coord for a coord_t. |
97 newcoord.children=coord.children; | 99 newcoord.children=c.children; |
98 return newcoord; | 100 return newcoord; |
99 } | 101 } |
100 } | 102 } |
101 | 103 |
102 app=function(display, w, h) { | 104 app=function(display, w, h) { |
171 app.prototype.generateScaleTween=function(src,dest,p) { | 173 app.prototype.generateScaleTween=function(src,dest,p) { |
172 sys.puts("p="+ p); | 174 sys.puts("p="+ p); |
173 src.hide(); | 175 src.hide(); |
174 // Duplicate the group | 176 // Duplicate the group |
175 var nodes = src.children; | 177 var nodes = src.children; |
176 sys.puts(src.node); | |
177 sys.puts(src.children); | |
178 if (src.dup == null) { | 178 if (src.dup == null) { |
179 var dup = this.mb_rt.coord_new(src.parent); | 179 var dup = this.mb_rt.coord_new(src.parent); |
180 for (i in nodes) { | 180 for (i in nodes) { |
181 var child_dup = this.mb_rt.coord_new(dup); | |
182 var c = nodes[i]; | 181 var c = nodes[i]; |
183 var n = c.node; | 182 var ng = this.mb_rt.coord_new(dup); |
184 var k = child_dup.clone_from_subtree(c); | 183 var k = dup.clone_from_subtree(c); |
185 n.coord.dup = child_dup; | 184 c.dup = k; |
186 sys.puts(n); | |
187 sys.puts("c[0] = "+c[0]+" c[1]="+c[1]+" c[2]="+c[2]+" c[3]="+c[3]+" c[4]="+c[4]+" c[5]="+c[5]); | |
188 k[0] = c[0]; | |
189 k[1] = c[1]; | |
190 k[2] = c[2]; | |
191 k[3] = c[3]; | |
192 k[4] = c[4]; | |
193 k[5] = c[5]; | |
194 } | 185 } |
195 src.dup = dup; | 186 src.dup = dup; |
196 } else { | 187 } else { |
197 dup = src.dup; | 188 dup = src.dup; |
198 src.dup.show(); | 189 src.dup.show(); |
199 } | 190 } |
200 //dup.hide(); | 191 //dup.hide(); |
201 //dest.hide(); | 192 //dest.hide(); |
202 //sys.puts(dup); | 193 //sys.puts(dup); |
194 sys.puts("src.id="+ src.id); | |
203 | 195 |
204 for(i in nodes) { | 196 for(i in nodes) { |
205 coord= nodes[i]; | 197 coord= nodes[i]; |
206 n = coord.node; | 198 sys.puts("coord="+coord+" coord.target=",coord.target); |
207 var attr = n.attr('id'); | 199 if (coord.target) |
208 if (attr == null) continue; | 200 this.generateScaleTweenObject(coord.dup,coord,coord.target,p,''); |
209 var id = attr.value(); | 201 else { |
210 sys.puts("id="+id); | 202 sys.puts(coord.id); |
211 this.generateScaleTweenObject(coord.dup,coord,coord.target,p,id); | 203 sys.puts(coord[0]); |
204 sys.puts(coord[1]); | |
205 sys.puts(coord[2]); | |
206 sys.puts(coord[3]); | |
207 sys.puts(coord[4]); | |
208 sys.puts(coord[5]); | |
209 } | |
212 } | 210 } |
213 } | 211 } |
214 function printcoord(s) | 212 function printcoord(s) |
215 { | 213 { |
216 sys.puts(s[0]+" "+s[1]+" "+s[2]+" "+s[3]+" "+s[4]+" "+s[5]); | 214 sys.puts(s[0]+" "+s[1]+" "+s[2]+" "+s[3]+" "+s[4]+" "+s[5]); |
221 return [a[0]*b[0]+a[1]*b[3], a[0]*b[1]+a[1]*b[4], a[0]*b[2]+a[1]*b[5]+a[2], | 219 return [a[0]*b[0]+a[1]*b[3], a[0]*b[1]+a[1]*b[4], a[0]*b[2]+a[1]*b[5]+a[2], |
222 a[3]*b[0]+a[4]*b[3], a[3]*b[1]+a[4]*b[4], a[3]*b[2]+a[4]*b[5]+a[5]]; | 220 a[3]*b[0]+a[4]*b[3], a[3]*b[1]+a[4]*b[4], a[3]*b[2]+a[4]*b[5]+a[5]]; |
223 } | 221 } |
224 | 222 |
225 app.prototype.generateScaleTweenObject=function(coord,src,dest,p,id) { | 223 app.prototype.generateScaleTweenObject=function(coord,src,dest,p,id) { |
226 sys.puts(dest.node); | 224 sys.puts("xxxxxxx"); |
225 sys.puts("dest="+dest); | |
227 sys.puts("src=["+src.sx+","+src.sy+","+src.r+","+src.tx+","+src.ty); | 226 sys.puts("src=["+src.sx+","+src.sy+","+src.r+","+src.tx+","+src.ty); |
228 sys.puts("id="+dest.node.attr('id')+" dest=["+dest.sx+","+dest.sy+","+dest.r+","+dest.tx+","+dest.ty); | 227 sys.puts("id="+id+" dest=["+dest.sx+","+dest.sy+","+dest.r+","+dest.tx+","+dest.ty); |
229 sys.puts("src.center="+src.center); | 228 sys.puts("src.center="+src.center); |
230 sys.puts("src.center.x="+src.center.x+" src.center.y="+src.center.y); | 229 sys.puts("src.center.x="+src.center.x+" src.center.y="+src.center.y); |
231 if (src == null) return; | 230 if (src == null) return; |
232 var p1 = 1-p; | 231 var p1 = 1-p; |
233 var x1 = src.center.x; | 232 var x1 = src.center.x; |
235 var y1 = 0; | 234 var y1 = 0; |
236 x1 = 0; | 235 x1 = 0; |
237 | 236 |
238 // For the svg:use, the transform matrix is the transform of teh svg:use and the elements inside it | 237 // For the svg:use, the transform matrix is the transform of teh svg:use and the elements inside it |
239 var d,sx,sy,r,tx,ty; | 238 var d,sx,sy,r,tx,ty; |
240 if (dest.isuse) { | 239 sx = src.sx*p+dest.sx*p1; |
241 sx = 1+(dest.sx-1)*p1; | 240 sy = src.sy*p+dest.sy*p1; |
242 sy = 1+(dest.sy-1)*p1; | 241 r = src.r*p+dest.r*p1; |
243 r = dest.r*p1; | 242 tx = src.tx*p+dest.tx*p1; |
244 tx = dest.tx*p1; | 243 ty = src.ty*p+dest.ty*p1; |
245 ty = dest.ty*p1; | |
246 } else { | |
247 sx = src.sx*p+dest.sx*p1; | |
248 sy = src.sy*p+dest.sy*p1; | |
249 r = src.r*p+dest.r*p1; | |
250 tx = src.tx*p+dest.tx*p1; | |
251 ty = src.ty*p+dest.ty*p1; | |
252 } | |
253 var mt = [1, 0, -x1, 0, 1, -y1]; | 244 var mt = [1, 0, -x1, 0, 1, -y1]; |
254 var opacity; | 245 var opacity; |
255 var ms; | 246 var ms; |
256 | 247 |
257 opacity = src.opacity*p1 + dest.opacity*p; | 248 opacity = src.opacity*p1 + dest.opacity*p; |
261 m = mt; | 252 m = mt; |
262 } else { | 253 } else { |
263 ms= [Math.cos(r), Math.sin(r),0,-Math.sin(r), Math.cos(r),0]; | 254 ms= [Math.cos(r), Math.sin(r),0,-Math.sin(r), Math.cos(r),0]; |
264 m = mul(ms,mt); | 255 m = mul(ms,mt); |
265 } | 256 } |
266 sys.puts("x1="+x1); | 257 sys.puts("tx="+tx); |
267 sys.puts("y1="+y1); | 258 sys.puts("ty="+ty); |
268 m = mul([sx,0,0,0,sy,0],m); | 259 m = mul([sx,0,0,0,sy,0],m); |
269 m = mul([1,0,x1,0,1,y1],m); | 260 m = mul([1,0,x1,0,1,y1],m); |
270 m = mul([1,0,tx,0,1,ty],m); | 261 m = mul([1,0,tx,0,1,ty],m); |
271 //m[2] = -m[2]; | 262 //m[2] = -m[2]; |
272 coord[0] = m[0]; | 263 coord[0] = m[0]; |