Mercurial > MadButterfly
comparison nodejs/mbapp.js @ 1408:c918b79892ab
Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
author | wycc |
---|---|
date | Wed, 06 Apr 2011 07:51:06 +0800 |
parents | 05e8d3ffa703 |
children | 6fa411fd9549 bd3d5ac8e748 |
comparison
equal
deleted
inserted
replaced
1407:f19121bd6a6c | 1408:c918b79892ab |
---|---|
2 // vim: sw=4:ts=8:sts=4 | 2 // vim: sw=4:ts=8:sts=4 |
3 var mbfly = require("mbfly"); | 3 var mbfly = require("mbfly"); |
4 var svg = require("./svg"); | 4 var svg = require("./svg"); |
5 var sys = require("sys"); | 5 var sys = require("sys"); |
6 var ldr = mbfly.img_ldr_new("."); | 6 var ldr = mbfly.img_ldr_new("."); |
7 var component = require("./component"); | |
7 | 8 |
8 function _reverse(m1) { | 9 function _reverse(m1) { |
9 var rev = new Array(1, 0, 0, 0, 1, 0); | 10 var rev = new Array(1, 0, 0, 0, 1, 0); |
10 var m = new Array(m1[0], m1[1], m1[2], m1[3], m1[4], m1[5]); | 11 var m = new Array(m1[0], m1[1], m1[2], m1[3], m1[4], m1[5]); |
11 | 12 |
124 this.onKeyPress = null; | 125 this.onKeyPress = null; |
125 this.svg = new svg.loadSVG(this.mb_rt,this.mb_rt.root,null); | 126 this.svg = new svg.loadSVG(this.mb_rt,this.mb_rt.root,null); |
126 this.frame_interval = 1000/30; // 12 frame per second | 127 this.frame_interval = 1000/30; // 12 frame per second |
127 this.timer = null; | 128 this.timer = null; |
128 this._time = Date.now(); | 129 this._time = Date.now(); |
130 this._componentmanager = new component.ComponentManager(this); | |
129 } | 131 } |
130 | 132 |
131 app.prototype.ts=function(m) { | 133 app.prototype.ts=function(m) { |
132 var now = Date.now(); | 134 var now = Date.now(); |
133 var t = now-this._time; | 135 var t = now-this._time; |
152 } | 154 } |
153 app.prototype.update=function() { | 155 app.prototype.update=function() { |
154 this.mb_rt.redraw_all(); | 156 this.mb_rt.redraw_all(); |
155 this.mb_rt.flush(); | 157 this.mb_rt.flush(); |
156 } | 158 } |
159 | |
157 app.prototype.get=function(name) { | 160 app.prototype.get=function(name) { |
158 return this.mb_rt.mbnames[name]; | 161 return this.mb_rt.mbnames[name]; |
159 } | 162 } |
163 | |
164 | |
165 app.prototype.getComponent=function(name) { | |
166 var comp = new component.Component(this,name); | |
167 this._componentmanager.dump(); | |
168 comp.realize(); | |
169 sys.puts("Search for "+name); | |
170 var obj = comp.toCoord(); | |
171 sys.puts("obj="+obj+" id="+obj.id+" refid="+obj.refid); | |
172 return comp; | |
173 } | |
174 | |
160 app.prototype.addKeyboardListener=function(type,f) { | 175 app.prototype.addKeyboardListener=function(type,f) { |
161 return this.mb_rt.kbevents.add_event_observer(type,f); | 176 return this.mb_rt.kbevents.add_event_observer(type,f); |
162 } | 177 } |
163 app.prototype.refresh=function() { | 178 app.prototype.refresh=function() { |
164 this.mb_rt.redraw_changed(); | 179 this.mb_rt.redraw_changed(); |
183 sys.puts("p="+ p); | 198 sys.puts("p="+ p); |
184 src.hide(); | 199 src.hide(); |
185 // Duplicate the group | 200 // Duplicate the group |
186 var nodes = src.children; | 201 var nodes = src.children; |
187 if (src.dup) { | 202 if (src.dup) { |
188 //src.dup.remove(); | 203 src.dup.remove(); |
189 //src.dup = null; | 204 src.dup = null; |
190 } | 205 } |
191 if (src.dup == null) { | 206 if (src.dup == null) { |
192 var dup = this.mb_rt.coord_new(src.parent); | 207 var dup = this.mb_rt.coord_new(src.parent); |
193 for (i in nodes) { | 208 for (i in nodes) { |
194 var c = nodes[i]; | 209 var c = nodes[i]; |
195 var ng = this.mb_rt.coord_new(dup); | 210 var ng = this.mb_rt.coord_new(dup); |
196 var k = dup.clone_from_subtree(c); | 211 var k = dup.clone_from_subtree(c); |
197 c.dup = k; | 212 c.dup = k; |
213 c.dup.id = c.id; | |
214 c.dup.refid = c.refid; | |
198 } | 215 } |
199 src.dup = dup; | 216 src.dup = dup; |
200 } else { | 217 } else { |
201 dup = src.dup; | 218 dup = src.dup; |
202 src.dup.show(); | 219 src.dup.show(); |
205 //dest.hide(); | 222 //dest.hide(); |
206 //sys.puts(dup); | 223 //sys.puts(dup); |
207 | 224 |
208 for(i in nodes) { | 225 for(i in nodes) { |
209 coord= nodes[i]; | 226 coord= nodes[i]; |
210 if (coord.target) | 227 if (coord.target) { |
211 this.generateScaleTweenObject(coord.dup,coord,coord.target,p,''); | 228 this.generateScaleTweenObject(coord.dup,coord,coord.target,p,''); |
212 else { | 229 this._componentmanager.add(coord,coord.dup); |
230 } else { | |
213 sys.puts(coord.id); | 231 sys.puts(coord.id); |
214 sys.puts(coord[0]); | 232 sys.puts(coord[0]); |
215 sys.puts(coord[1]); | 233 sys.puts(coord[1]); |
216 sys.puts(coord[2]); | 234 sys.puts(coord[2]); |
217 sys.puts(coord[3]); | 235 sys.puts(coord[3]); |