Mercurial > MadButterfly
annotate nodejs/mbapp.js @ 1392:cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
author | wycc |
---|---|
date | Sun, 27 Mar 2011 08:27:03 +0800 |
parents | ff8122c59648 |
children | a5672125e515 |
rev | line source |
---|---|
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
820
diff
changeset
|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- |
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
820
diff
changeset
|
2 // vim: sw=4:ts=8:sts=4 |
716 | 3 var mbfly = require("mbfly"); |
4 var svg = require("./svg"); | |
730 | 5 var sys = require("sys"); |
716 | 6 var ldr = mbfly.img_ldr_new("."); |
784
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
7 |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
8 function _reverse(m1) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
9 var rev = new Array(1, 0, 0, 0, 1, 0); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
10 var m = new Array(m1[0], m1[1], m1[2], m1[3], m1[4], m1[5]); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
11 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
12 rev[3] = -m[3] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
13 m[3] = 0; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
14 m[4] += rev[3] * m[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
15 m[5] += rev[3] * m[2]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
16 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
17 rev[1] = -m[1] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
18 rev[0] += rev[1] * rev[3]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
19 m[1] = 0; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
20 m[2] += rev[1] * m[5]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
21 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
22 rev[2] = -m[2]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
23 rev[5] = -m[5]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
24 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
25 rev[0] = rev[0] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
26 rev[1] = rev[1] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
27 rev[2] = rev[2] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
28 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
29 rev[3] = rev[3] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
30 rev[4] = rev[4] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
31 rev[5] = rev[5] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
32 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
33 return rev; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
34 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
35 |
853
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
36 function _decorate_mb_rt(mb_rt) { |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
37 var coord; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
38 |
853
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
39 mb_rt._mbapp_saved_coord_new = mb_rt.coord_new; |
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
40 mb_rt.coord_new = function(parent) { |
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
41 var coord; |
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
42 |
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
43 coord = this._mbapp_saved_coord_new(parent); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
44 coord.type = "coord"; |
884
6c8e4e1f3a39
Maintain a list of children
Thinker K.F. Li <thinker@codemud.net>
parents:
874
diff
changeset
|
45 coord.children = []; |
853
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
46 coord._mbapp_saved_mtx = [coord[0], coord[1], coord[2], |
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
47 coord[3], coord[4], coord[5]]; |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
48 coord._mbapp_saved_rev_mtx = _reverse(coord._mbapp_saved_mtx); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
49 coord.parent = parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
50 coord._mbapp_saved_add_shape = coord.add_shape; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
51 coord.add_shape = function(shape) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
52 var coord; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
53 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
54 this._mbapp_saved_add_shape(shape); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
55 shape.parent = this; |
884
6c8e4e1f3a39
Maintain a list of children
Thinker K.F. Li <thinker@codemud.net>
parents:
874
diff
changeset
|
56 this.children.push(shape); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
57 } |
884
6c8e4e1f3a39
Maintain a list of children
Thinker K.F. Li <thinker@codemud.net>
parents:
874
diff
changeset
|
58 |
6c8e4e1f3a39
Maintain a list of children
Thinker K.F. Li <thinker@codemud.net>
parents:
874
diff
changeset
|
59 parent.children.push(coord); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
60 |
853
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
61 return coord; |
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
62 }; |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
63 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
64 /* |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
65 * Decorate root coord |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
66 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
67 coord = mb_rt.root; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
68 coord.type = "coord"; |
884
6c8e4e1f3a39
Maintain a list of children
Thinker K.F. Li <thinker@codemud.net>
parents:
874
diff
changeset
|
69 coord.children = []; |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
70 coord._mbapp_saved_mtx = [coord[0], coord[1], coord[2], |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
71 coord[3], coord[4], coord[5]]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
72 coord._mbapp_saved_rev_mtx = _reverse(coord._mbapp_saved_mtx); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
73 coord._mbapp_saved_add_shape = coord.add_shape; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
74 coord.add_shape = function(shape) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
75 var coord; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
76 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
77 this._mbapp_saved_add_shape(shape); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
78 shape.parent = this; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
79 } |
853
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
80 } |
784
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
81 |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
82 app=function(display, w, h) { |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
83 var self = this; |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
84 var mb_rt; |
716 | 85 |
784
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
86 if(typeof display == "undefined") |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
87 display = ":0.0"; |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
88 if(typeof w == "undefined") |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
89 w = 720; |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
90 if(typeof h == "undefined") |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
91 h = 480; |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
92 |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
93 mb_rt = this.mb_rt = new mbfly.mb_rt(display, w, h); |
853
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
94 _decorate_mb_rt(mb_rt); |
784
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
95 var background = mb_rt.rect_new(0, 0, 720, 480, 0, 0); |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
96 var paint = mb_rt.paint_color_new(1, 1, 1, 1); |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
97 paint.fill(background); |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
98 mb_rt.root.add_shape(background); |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
99 |
909 | 100 this.mb_rt.kbevents.add_event_observer(exports.EVT_KB_PRESS, function(evt) { self.KeyPress(evt);}); |
101 this.keymap={}; | |
102 this.onKeyPress = null; | |
914 | 103 this.svg = new svg.loadSVG(this.mb_rt,this.mb_rt.root,null); |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
104 this.frame_interval = 1000/12; // 12 frame per second |
716 | 105 } |
106 app.prototype.loadSVG=function(fname) { | |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
107 this.svg.load(this.mb_rt,this.mb_rt.root,fname); |
1391 | 108 this.changeScene(0); |
716 | 109 } |
110 | |
730 | 111 app.prototype.KeyPress = function(evt) { |
112 if (this.onKeyPress) this.onKeyPress(evt.sym); | |
911 | 113 if (evt.sym in this.keymap) { |
114 this.keymap[evt.sym](); | |
115 } | |
730 | 116 } |
117 | |
716 | 118 app.prototype.loop=function() { |
721
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
119 this.mb_rt.redraw_all(); |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
120 this.mb_rt.flush(); |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
121 } |
762 | 122 app.prototype.update=function() { |
123 this.mb_rt.redraw_all(); | |
124 this.mb_rt.flush(); | |
125 } | |
721
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
126 app.prototype.get=function(name) { |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
127 return this.mb_rt.mbnames[name]; |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
128 } |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
129 app.prototype.addKeyboardListener=function(type,f) { |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
130 return this.mb_rt.kbevents.add_event_observer(type,f); |
716 | 131 } |
724 | 132 app.prototype.refresh=function() { |
886
3457f2d8b0b8
Only redraw changed when calling app.refresh() in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
884
diff
changeset
|
133 this.mb_rt.redraw_changed(); |
724 | 134 this.mb_rt.flush(); |
135 } | |
730 | 136 app.prototype.dump=function() { |
137 sys.puts(this.onKeyPress); | |
138 } | |
139 | |
140 app.prototype.addKeyListener=function(key,f) { | |
731
1719484ed15d
Make the argument key can be an array to register multiple keys.
wycc
parents:
730
diff
changeset
|
141 if (typeof(key) == 'number') |
1719484ed15d
Make the argument key can be an array to register multiple keys.
wycc
parents:
730
diff
changeset
|
142 this.keymap[key] = f; |
911 | 143 else { |
144 for(k in key) { | |
145 this.keymap[k] = f; | |
731
1719484ed15d
Make the argument key can be an array to register multiple keys.
wycc
parents:
730
diff
changeset
|
146 } |
911 | 147 } |
730 | 148 } |
716 | 149 |
1376 | 150 app.prototype.generateScaleTween=function(src,dest,p) { |
1391 | 151 sys.puts("p="+ p); |
1376 | 152 src.hide(); |
153 // Duplicate the group | |
1379 | 154 var nodes = src.node.childNodes(); |
1376 | 155 if (src.dup == null) { |
1379 | 156 dup = this.mb_rt.coord_new(src.parent); |
157 for (i in nodes) { | |
158 n = nodes[i]; | |
159 g = dup.clone_from_subtree(n.coord); | |
160 n.coord.dup = g; | |
161 } | |
1376 | 162 src.dup = dup; |
163 } else { | |
164 dup = src.dup; | |
1379 | 165 src.dup.show(); |
1376 | 166 } |
1379 | 167 //dup.hide(); |
168 //dest.hide(); | |
169 //sys.puts(dup); | |
1376 | 170 |
1379 | 171 for(i in nodes) { |
172 n= nodes[i]; | |
173 coord = n.coord; | |
174 var attr = n.attr('id'); | |
175 if (attr == null) continue; | |
176 var id = attr.value(); | |
1391 | 177 sys.puts("id="+id); |
1379 | 178 this.generateScaleTweenObject(coord.dup,coord,coord.target,p); |
179 } | |
180 } | |
181 function printcoord(s) | |
182 { | |
183 sys.puts(s[0]+" "+s[1]+" "+s[2]+" "+s[3]+" "+s[4]+" "+s[5]); | |
184 } | |
185 | |
186 function mul(a,b) | |
187 { | |
188 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], | |
189 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]]; | |
190 } | |
1376 | 191 |
1379 | 192 app.prototype.generateScaleTweenObject=function(coord,src,dest,p) { |
1391 | 193 sys.puts("src=["+src.sx+","+src.sy+","+src.r+","+src.tx+","+src.ty); |
194 sys.puts("dest=["+dest.sx+","+dest.sy+","+dest.r+","+dest.tx+","+dest.ty); | |
1392
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1391
diff
changeset
|
195 if (src == null) return; |
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1391
diff
changeset
|
196 sys.puts("src.center="+src.center); |
1379 | 197 var p1 = 1-p; |
1392
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1391
diff
changeset
|
198 var x1 = src.center.x; |
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1391
diff
changeset
|
199 var y1 = src.center.y; |
1379 | 200 var sx = src.sx*p+dest.sx*p1; |
201 var sy = src.sy*p+dest.sy*p1; | |
202 var r = src.r*p+dest.r*p1; | |
1392
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1391
diff
changeset
|
203 var tx = src.tx*p+dest.tx*p1-src.tx; |
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1391
diff
changeset
|
204 var ty = src.ty*p+dest.ty*p1-src.ty; |
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1391
diff
changeset
|
205 var mt = [1, 0, -x1, 0, 1, -y1]; |
1382 | 206 var opacity; |
1379 | 207 var ms; |
1382 | 208 |
1383 | 209 opacity = src.opacity*p + dest.opacity*p1; |
1382 | 210 coord.opacity = opacity; |
211 | |
1379 | 212 if (r == 0) { |
213 m = mt; | |
214 } else { | |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
215 ms= [Math.cos(r), Math.sin(r),0,-Math.sin(r), Math.cos(r),0]; |
1379 | 216 m = mul(ms,mt); |
1376 | 217 } |
1392
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1391
diff
changeset
|
218 sys.puts("x1="+x1); |
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1391
diff
changeset
|
219 sys.puts("y1="+y1); |
1379 | 220 m = mul([sx,0,0,0,sy,0],m); |
1392
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1391
diff
changeset
|
221 m = mul([1,0,x1,0,1,y1],m); |
1379 | 222 m = mul([1,0,tx,0,1,ty],m); |
1392
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1391
diff
changeset
|
223 //m[2] = -m[2]; |
1379 | 224 coord[0] = m[0]; |
225 coord[1] = m[1]; | |
226 coord[2] = m[2]; | |
227 coord[3] = m[3]; | |
228 coord[4] = m[4]; | |
229 coord[5] = m[5]; | |
230 //sys.puts(coord); | |
1392
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1391
diff
changeset
|
231 sys.puts("p="+p+" "+m[0]+","+m[1]+","+m[2]+","+m[3]+","+m[4]+","+m[5]); |
1376 | 232 } |
978 | 233 |
234 app.prototype.changeScene=function(s) { | |
235 var nth; | |
1391 | 236 sys.puts(s); |
237 sys.puts(typeof(s)); | |
978 | 238 if (typeof(s)=='number') { |
239 var i; | |
240 nth = s; | |
241 } else { | |
242 nth = this.svg.getFrameNumber(s); | |
243 if (nth == -1) return; | |
244 } | |
1391 | 245 sys.puts("goto to scene "+nth); |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
246 this.currentScene = nth; |
978 | 247 var scenes = this.svg.scenes; |
1392
cd5fb45bc247
Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
wycc
parents:
1391
diff
changeset
|
248 if (scenes == null) return; |
1376 | 249 for(i=0;i<scenes.length-1;i++) { |
978 | 250 try { |
251 if (nth >=scenes[i].start && nth <=scenes[i].end) { | |
1391 | 252 sys.puts("find"); |
1376 | 253 if (scenes[i].type == 'normal' || i == scenes.length-1) { |
254 this.get(scenes[i].ref).show(); | |
255 } else if (scenes[i].type == 'scale') { | |
1391 | 256 sys.puts(i+","+scenes[i+1].start+","+scenes[i].end); |
1376 | 257 if (scenes[i].end == (scenes[i+1].start-1)) { |
1379 | 258 var p = 1-(nth-scenes[i].start)/(scenes[i].end-scenes[i].start+1); |
1376 | 259 this.generateScaleTween(this.get(scenes[i].ref),this.get(scenes[i+1].ref),p); |
260 } else { | |
261 // If there is no second key frame defined, fall back to the normal | |
262 this.get(scenes[i].ref).show(); | |
263 } | |
1379 | 264 this.get(scenes[i+1].ref).hide(); |
1376 | 265 } |
266 | |
978 | 267 } else { |
1391 | 268 sys.puts("hide "+scenes[i].ref); |
978 | 269 this.get(scenes[i].ref).hide(); |
270 } | |
271 } catch(e) { | |
272 sys.puts(e); | |
273 sys.puts(scenes[i].ref); | |
274 } | |
275 } | |
1379 | 276 this.refresh(); |
978 | 277 } |
1138 | 278 |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
279 app.prototype.runToScene=function(s) { |
1391 | 280 sys.puts(s); |
281 sys.puts(typeof(s)); | |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
282 if (typeof(s)=='number') { |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
283 var i; |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
284 nth = s; |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
285 } else { |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
286 nth = this.svg.getFrameNumber(s); |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
287 if (nth == -1) return; |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
288 } |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
289 var self = this; |
1391 | 290 sys.puts(this.currentScene+","+nth); |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
291 if (nth > this.currentScene) { |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
292 this.targetScene = nth; |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
293 this.startScene = this.currentScene; |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
294 this.starttime = Date.now(); |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
295 setTimeout(function() { |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
296 self.skipFrame() |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
297 }, this.frame_interval); |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
298 } else { |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
299 this.changeScene(nth); |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
300 } |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
301 } |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
302 |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
303 app.prototype.skipFrame=function() { |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
304 var self = this; |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
305 sys.puts("n="+this.currentScene); |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
306 if (this.currentScene != this.targetScene) { |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
307 nextframe = this.startScene + Math.round((Date.now() - this.starttime)/this.frame_interval); |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
308 if (nextframe > this.targetScene) |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
309 nextframe = this.targetScene; |
1391 | 310 sys.puts("change to scene "+nextframe); |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
311 this.changeScene(nextframe); |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
312 setTimeout(function() { |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
313 self.skipFrame() |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
314 }, this.frame_interval); |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
315 } |
1138 | 316 } |
317 | |
978 | 318 app.prototype.addSceneListener=function(n, cb) { |
319 sys.puts("This is not implemented yet") | |
320 } | |
321 | |
872
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
322 var app_with_win = function(display, win) { |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
323 var self = this; |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
324 var mb_rt; |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
325 var background; |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
326 var paint; |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
327 |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
328 if(typeof display == "undefined" || typeof win == "undefined") |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
329 throw "Invalid argument"; |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
330 |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
331 mb_rt = this.mb_rt = new mbfly.mb_rt_with_win(display, win); |
874
ec8d7e9c9642
Decorate mb_rt created by mb_rt_with_win()
Thinker K.F. Li <thinker@codemud.net>
parents:
873
diff
changeset
|
332 _decorate_mb_rt(mb_rt); |
872
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
333 background = mb_rt.rect_new(0, 0, 720, 480, 0, 0); |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
334 paint = mb_rt.paint_color_new(1, 1, 1, 1); |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
335 paint.fill(background); |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
336 mb_rt.root.add_shape(background); |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
337 |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
338 this.mb_rt.kbevents. |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
339 add_event_observer(exports.EVT_KB_PRESS, |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
340 function(evt) { self.KeyPress(evt); }); |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
341 this.keymap = {}; |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
342 this.onKeyPress = null; |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
343 } |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
344 |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
345 app_with_win.prototype = app.prototype; |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
346 |
716 | 347 exports.app=app; |
872
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
348 exports.app_with_win = app_with_win; |
721
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
349 |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
350 // Put all key definition here |
820 | 351 exports.KEY_LEFT = 0xff51; |
729
299ed9319dc6
Use key symbols instead of keycodes.
Thinker K.F. Li <thinker@branda.to>
parents:
724
diff
changeset
|
352 exports.KEY_UP = 0xff52; |
820 | 353 exports.KEY_RIGHT = 0xff53; |
729
299ed9319dc6
Use key symbols instead of keycodes.
Thinker K.F. Li <thinker@branda.to>
parents:
724
diff
changeset
|
354 exports.KEY_DOWN = 0xff54; |
820 | 355 exports.KEY_ENTER = 0xff0d; |
724 | 356 exports.EVT_ANY=0; |
357 exports.EVT_MOUSE_OVER=1; | |
358 exports.EVT_MOUSE_OUT=2; | |
359 exports.EVT_MOUSE_MOVE=3; | |
360 exports.EVT_MOUSE_BUT_PRESS4; | |
361 exports.EVT_MOUSE_BUT_RELEASE=5 | |
362 exports.EVT_KB_PRESS=6; | |
363 exports.EVT_KB_RELEASE=7; | |
364 exports.EVT_PROGM_COMPLETE=8; | |
365 exports.EVT_RDMAN_REDRAW=9; | |
366 exports.EVT_MONITOR_ADD=10; | |
367 exports.EVT_MONITOR_REMOVE=11; | |
368 exports.EVT_MONITOR_FREE=12; | |
369 exports.EVT_MOUSE_MOVE_RAW=13; | |
827 | 370 exports.ldr = ldr; |