Mercurial > MadButterfly
comparison nodejs/mbapp.js @ 1399:9cebe429508c
Override the clone_from_subtree to setup the parent and children for the coord object. However, the current children is incorrect since we can not copy it from the origin tree. Instead, we need to get coord_t from the cloned group and then modify all coord objects to include correct parent, children, add_shape and clone_from_subtree.
author | wycc |
---|---|
date | Sun, 03 Apr 2011 11:51:39 +0800 |
parents | a19f6cecf3c8 |
children | 2fc1f54a1a3b |
comparison
equal
deleted
inserted
replaced
1398:6fa4a53c3fca | 1399:9cebe429508c |
---|---|
46 coord._mbapp_saved_mtx = [coord[0], coord[1], coord[2], | 46 coord._mbapp_saved_mtx = [coord[0], coord[1], coord[2], |
47 coord[3], coord[4], coord[5]]; | 47 coord[3], coord[4], coord[5]]; |
48 coord._mbapp_saved_rev_mtx = _reverse(coord._mbapp_saved_mtx); | 48 coord._mbapp_saved_rev_mtx = _reverse(coord._mbapp_saved_mtx); |
49 coord.parent = parent; | 49 coord.parent = parent; |
50 coord._mbapp_saved_add_shape = coord.add_shape; | 50 coord._mbapp_saved_add_shape = coord.add_shape; |
51 coord._mbapp_saved_clone_from_subtree = coord.clone_from_subtree; | |
51 coord.add_shape = function(shape) { | 52 coord.add_shape = function(shape) { |
52 var coord; | 53 var coord; |
53 | 54 |
54 this._mbapp_saved_add_shape(shape); | 55 this._mbapp_saved_add_shape(shape); |
55 shape.parent = this; | 56 shape.parent = this; |
56 this.children.push(shape); | 57 this.children.push(shape); |
58 } | |
59 coord.clone_from_subtree = function(coord) { | |
60 var newcoord = this._mbapp_saved_clone_from_subtree(coord); | |
61 newcoord.parent = this; | |
62 // 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 newcoord.children=coord.children; | |
65 return newcoord; | |
57 } | 66 } |
58 | 67 |
59 parent.children.push(coord); | 68 parent.children.push(coord); |
60 | 69 |
61 return coord; | 70 return coord; |
69 coord.children = []; | 78 coord.children = []; |
70 coord._mbapp_saved_mtx = [coord[0], coord[1], coord[2], | 79 coord._mbapp_saved_mtx = [coord[0], coord[1], coord[2], |
71 coord[3], coord[4], coord[5]]; | 80 coord[3], coord[4], coord[5]]; |
72 coord._mbapp_saved_rev_mtx = _reverse(coord._mbapp_saved_mtx); | 81 coord._mbapp_saved_rev_mtx = _reverse(coord._mbapp_saved_mtx); |
73 coord._mbapp_saved_add_shape = coord.add_shape; | 82 coord._mbapp_saved_add_shape = coord.add_shape; |
83 coord._mbapp_saved_clone_from_subtree = coord.clone_from_subtree; | |
74 coord.add_shape = function(shape) { | 84 coord.add_shape = function(shape) { |
75 var coord; | 85 var coord; |
76 | 86 |
77 this._mbapp_saved_add_shape(shape); | 87 this._mbapp_saved_add_shape(shape); |
78 shape.parent = this; | 88 shape.parent = this; |
89 } | |
90 coord.clone_from_subtree = function(coord) { | |
91 var newcoord; | |
92 | |
93 newcoord = this._mbapp_saved_clone_from_subtree(coord); | |
94 newcoord.parent = this; | |
95 // 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. | |
97 newcoord.children=coord.children; | |
98 return newcoord; | |
79 } | 99 } |
80 } | 100 } |
81 | 101 |
82 app=function(display, w, h) { | 102 app=function(display, w, h) { |
83 var self = this; | 103 var self = this; |
150 | 170 |
151 app.prototype.generateScaleTween=function(src,dest,p) { | 171 app.prototype.generateScaleTween=function(src,dest,p) { |
152 sys.puts("p="+ p); | 172 sys.puts("p="+ p); |
153 src.hide(); | 173 src.hide(); |
154 // Duplicate the group | 174 // Duplicate the group |
155 var nodes = src.node.childNodes(); | 175 var nodes = src.children; |
176 sys.puts(src.node); | |
177 sys.puts(src.children); | |
156 if (src.dup == null) { | 178 if (src.dup == null) { |
157 var dup = this.mb_rt.coord_new(src.parent); | 179 var dup = this.mb_rt.coord_new(src.parent); |
158 for (i in nodes) { | 180 for (i in nodes) { |
159 var child_dup = this.mb_rt.coord_new(dup); | 181 var child_dup = this.mb_rt.coord_new(dup); |
160 var n = nodes[i]; | 182 var c = nodes[i]; |
161 var c = n.coord; | 183 var n = c.node; |
162 var k = child_dup.clone_from_subtree(c); | 184 var k = child_dup.clone_from_subtree(c); |
163 n.coord.dup = child_dup; | 185 n.coord.dup = child_dup; |
164 sys.puts(n); | 186 sys.puts(n); |
165 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]); | 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]); |
166 k[0] = c[0]; | 188 k[0] = c[0]; |
178 //dup.hide(); | 200 //dup.hide(); |
179 //dest.hide(); | 201 //dest.hide(); |
180 //sys.puts(dup); | 202 //sys.puts(dup); |
181 | 203 |
182 for(i in nodes) { | 204 for(i in nodes) { |
183 n= nodes[i]; | 205 coord= nodes[i]; |
184 coord = n.coord; | 206 n = coord.node; |
185 var attr = n.attr('id'); | 207 var attr = n.attr('id'); |
186 if (attr == null) continue; | 208 if (attr == null) continue; |
187 var id = attr.value(); | 209 var id = attr.value(); |
188 sys.puts("id="+id); | 210 sys.puts("id="+id); |
189 this.generateScaleTweenObject(coord.dup,coord,coord.target,p,id); | 211 this.generateScaleTweenObject(coord.dup,coord,coord.target,p,id); |
199 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], | 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], |
200 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]]; | 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]]; |
201 } | 223 } |
202 | 224 |
203 app.prototype.generateScaleTweenObject=function(coord,src,dest,p,id) { | 225 app.prototype.generateScaleTweenObject=function(coord,src,dest,p,id) { |
204 sys.puts(src.node); | 226 sys.puts(dest.node); |
205 sys.puts("src=["+src.sx+","+src.sy+","+src.r+","+src.tx+","+src.ty); | 227 sys.puts("src=["+src.sx+","+src.sy+","+src.r+","+src.tx+","+src.ty); |
206 sys.puts("id="+dest.node.attr('id')+" dest=["+dest.sx+","+dest.sy+","+dest.r+","+dest.tx+","+dest.ty); | 228 sys.puts("id="+dest.node.attr('id')+" dest=["+dest.sx+","+dest.sy+","+dest.r+","+dest.tx+","+dest.ty); |
207 sys.puts("src.center="+src.center); | 229 sys.puts("src.center="+src.center); |
208 sys.puts("src.center.x="+src.center.x+" src.center.y="+src.center.y); | 230 sys.puts("src.center.x="+src.center.x+" src.center.y="+src.center.y); |
209 if (src == null) return; | 231 if (src == null) return; |
210 var p1 = 1-p; | 232 var p1 = 1-p; |
211 var x1 = src.center.x; | 233 var x1 = src.center.x; |
212 var y1 = src.center.y; | 234 var y1 = src.center.y; |
235 var y1 = 0; | |
236 x1 = 0; | |
213 | 237 |
214 // For the svg:use, the transform matrix is the transform of teh svg:use and the elements inside it | 238 // For the svg:use, the transform matrix is the transform of teh svg:use and the elements inside it |
215 var d,sx,sy,r,tx,ty; | 239 var d,sx,sy,r,tx,ty; |
216 if (dest.isuse) { | 240 if (dest.isuse) { |
217 sx = 1+(dest.sx-1)*p1; | 241 sx = 1+(dest.sx-1)*p1; |
271 if (scenes == null) return; | 295 if (scenes == null) return; |
272 for(i=0;i<scenes.length-1;i++) { | 296 for(i=0;i<scenes.length-1;i++) { |
273 try { | 297 try { |
274 this.get(scenes[i].ref).hide(); | 298 this.get(scenes[i].ref).hide(); |
275 if (nth >=scenes[i].start && nth <=scenes[i].end) { | 299 if (nth >=scenes[i].start && nth <=scenes[i].end) { |
300 this.get(scenes[i].ref).show(); | |
301 if (this.get(scenes[i].ref).dup) | |
302 this.get(scenes[i].ref).dup.show(); | |
276 sys.puts("find"); | 303 sys.puts("find"); |
277 if (scenes[i].type == 'normal' || i == scenes.length-1) { | 304 if (scenes[i].type == 'normal' || i == scenes.length-1) { |
278 this.get(scenes[i].ref).show(); | 305 this.get(scenes[i].ref).show(); |
279 } else if (scenes[i].type == 'scale') { | 306 } else if (scenes[i].type == 'scale') { |
280 sys.puts(i+","+scenes[i+1].start+","+scenes[i].end); | 307 sys.puts(i+","+scenes[i+1].start+","+scenes[i].end); |