Mercurial > MadButterfly
annotate nodejs/mbapp.js @ 1482:3a671e79429a
Hide/show selection for states
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Fri, 29 Apr 2011 14:59:40 +0800 |
parents | b916bb0dc7ca |
children |
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("."); |
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.
wycc
parents:
1405
diff
changeset
|
7 var component = require("./component"); |
784
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
8 |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
9 function _reverse(m1) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
10 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
|
11 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
|
12 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
13 rev[3] = -m[3] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
14 m[3] = 0; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
15 m[4] += rev[3] * m[1]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
16 m[5] += rev[3] * m[2]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
17 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
18 rev[1] = -m[1] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
19 rev[0] += rev[1] * rev[3]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
20 m[1] = 0; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
21 m[2] += rev[1] * m[5]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
22 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
23 rev[2] = -m[2]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
24 rev[5] = -m[5]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
25 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
26 rev[0] = rev[0] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
27 rev[1] = rev[1] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
28 rev[2] = rev[2] / m[0]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
29 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
30 rev[3] = rev[3] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
31 rev[4] = rev[4] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
32 rev[5] = rev[5] / m[4]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
33 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
34 return rev; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
35 } |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
36 |
853
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
37 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
|
38 var coord; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
39 |
853
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
40 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
|
41 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
|
42 var coord; |
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
43 |
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
44 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
|
45 coord.type = "coord"; |
884
6c8e4e1f3a39
Maintain a list of children
Thinker K.F. Li <thinker@codemud.net>
parents:
874
diff
changeset
|
46 coord.children = []; |
853
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
47 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
|
48 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
|
49 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
|
50 coord.parent = parent; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
51 coord._mbapp_saved_add_shape = coord.add_shape; |
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.
wycc
parents:
1397
diff
changeset
|
52 coord._mbapp_saved_clone_from_subtree = coord.clone_from_subtree; |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
53 coord.add_shape = function(shape) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
54 var coord; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
55 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
56 this._mbapp_saved_add_shape(shape); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
57 shape.parent = this; |
884
6c8e4e1f3a39
Maintain a list of children
Thinker K.F. Li <thinker@codemud.net>
parents:
874
diff
changeset
|
58 this.children.push(shape); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
59 } |
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.
wycc
parents:
1399
diff
changeset
|
60 coord.clone_from_subtree = function(c) { |
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.
wycc
parents:
1399
diff
changeset
|
61 var newcoord = this._mbapp_saved_clone_from_subtree(c); |
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.
wycc
parents:
1397
diff
changeset
|
62 newcoord.parent = this; |
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.
wycc
parents:
1399
diff
changeset
|
63 this.children.push(newcoord); |
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.
wycc
parents:
1397
diff
changeset
|
64 // FIXME: This is incorrect. However, we have no way to fix it for now. |
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.
wycc
parents:
1397
diff
changeset
|
65 // We need to implement a function which can get coord for a coord_t. |
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.
wycc
parents:
1399
diff
changeset
|
66 newcoord.children=c.children; |
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.
wycc
parents:
1397
diff
changeset
|
67 return newcoord; |
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.
wycc
parents:
1397
diff
changeset
|
68 } |
884
6c8e4e1f3a39
Maintain a list of children
Thinker K.F. Li <thinker@codemud.net>
parents:
874
diff
changeset
|
69 |
6c8e4e1f3a39
Maintain a list of children
Thinker K.F. Li <thinker@codemud.net>
parents:
874
diff
changeset
|
70 parent.children.push(coord); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
71 |
853
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
72 return coord; |
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
73 }; |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
74 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
75 /* |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
76 * Decorate root coord |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
77 */ |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
78 coord = mb_rt.root; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
79 coord.type = "coord"; |
884
6c8e4e1f3a39
Maintain a list of children
Thinker K.F. Li <thinker@codemud.net>
parents:
874
diff
changeset
|
80 coord.children = []; |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
81 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
|
82 coord[3], coord[4], coord[5]]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
83 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
|
84 coord._mbapp_saved_add_shape = coord.add_shape; |
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.
wycc
parents:
1397
diff
changeset
|
85 coord._mbapp_saved_clone_from_subtree = coord.clone_from_subtree; |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
86 coord.add_shape = function(shape) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
87 var coord; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
88 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
89 this._mbapp_saved_add_shape(shape); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
90 shape.parent = this; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
91 } |
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.
wycc
parents:
1399
diff
changeset
|
92 coord.clone_from_subtree = function(c) { |
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.
wycc
parents:
1397
diff
changeset
|
93 var newcoord; |
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.
wycc
parents:
1397
diff
changeset
|
94 |
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.
wycc
parents:
1399
diff
changeset
|
95 newcoord = this._mbapp_saved_clone_from_subtree(c); |
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.
wycc
parents:
1397
diff
changeset
|
96 newcoord.parent = this; |
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.
wycc
parents:
1399
diff
changeset
|
97 this.children.push(newcoord); |
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.
wycc
parents:
1397
diff
changeset
|
98 // FIXME: This is incorrect. However, we have no way to fix it for now. |
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.
wycc
parents:
1397
diff
changeset
|
99 // We need to implement a function which can get coord for a coord_t. |
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.
wycc
parents:
1399
diff
changeset
|
100 newcoord.children=c.children; |
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.
wycc
parents:
1397
diff
changeset
|
101 return newcoord; |
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.
wycc
parents:
1397
diff
changeset
|
102 } |
853
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
103 } |
784
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
104 |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
105 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
|
106 var self = this; |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
107 var mb_rt; |
716 | 108 |
784
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
109 if(typeof display == "undefined") |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
110 display = ":0.0"; |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
111 if(typeof w == "undefined") |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
112 w = 720; |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
113 if(typeof h == "undefined") |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
114 h = 480; |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
115 |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
116 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
|
117 _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
|
118 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
|
119 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
|
120 paint.fill(background); |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
121 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
|
122 |
909 | 123 this.mb_rt.kbevents.add_event_observer(exports.EVT_KB_PRESS, function(evt) { self.KeyPress(evt);}); |
124 this.keymap={}; | |
125 this.onKeyPress = null; | |
914 | 126 this.svg = new svg.loadSVG(this.mb_rt,this.mb_rt.root,null); |
1426
5487aaf6f863
Change the algorithm to determine the gap between frames so that the go back can be calculated correctly.
wycc
parents:
1424
diff
changeset
|
127 this.frame_interval = 1000/12; // 12 frame per second |
1402 | 128 this.timer = null; |
1405
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
129 this._time = Date.now(); |
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.
wycc
parents:
1405
diff
changeset
|
130 this._componentmanager = new component.ComponentManager(this); |
1405
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
131 } |
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
132 |
1447 | 133 app.prototype.setFrameRate=function(fps) { |
134 this.frame_interval = 1000/fps; | |
135 } | |
136 | |
1405
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
137 app.prototype.ts=function(m) { |
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
138 var now = Date.now(); |
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
139 var t = now-this._time; |
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
140 sys.puts("["+t+"] "+m); |
716 | 141 } |
142 app.prototype.loadSVG=function(fname) { | |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
143 this.svg.load(this.mb_rt,this.mb_rt.root,fname); |
1391 | 144 this.changeScene(0); |
716 | 145 } |
146 | |
730 | 147 app.prototype.KeyPress = function(evt) { |
148 if (this.onKeyPress) this.onKeyPress(evt.sym); | |
1447 | 149 sys.puts(this.keymap); |
150 if (evt.sym in this.keymap) { | |
151 this.keymap[evt.sym](); | |
152 } | |
730 | 153 } |
154 | |
716 | 155 app.prototype.loop=function() { |
721
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
156 this.mb_rt.redraw_all(); |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
157 this.mb_rt.flush(); |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
158 } |
762 | 159 app.prototype.update=function() { |
160 this.mb_rt.redraw_all(); | |
161 this.mb_rt.flush(); | |
162 } | |
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.
wycc
parents:
1405
diff
changeset
|
163 |
721
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
164 app.prototype.get=function(name) { |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
165 return this.mb_rt.mbnames[name]; |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
166 } |
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.
wycc
parents:
1405
diff
changeset
|
167 |
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.
wycc
parents:
1405
diff
changeset
|
168 |
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.
wycc
parents:
1405
diff
changeset
|
169 app.prototype.getComponent=function(name) { |
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.
wycc
parents:
1405
diff
changeset
|
170 var comp = new component.Component(this,name); |
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.
wycc
parents:
1405
diff
changeset
|
171 this._componentmanager.dump(); |
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.
wycc
parents:
1405
diff
changeset
|
172 comp.realize(); |
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.
wycc
parents:
1405
diff
changeset
|
173 sys.puts("Search for "+name); |
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.
wycc
parents:
1405
diff
changeset
|
174 var obj = comp.toCoord(); |
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.
wycc
parents:
1405
diff
changeset
|
175 return comp; |
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.
wycc
parents:
1405
diff
changeset
|
176 } |
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.
wycc
parents:
1405
diff
changeset
|
177 |
721
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
178 app.prototype.addKeyboardListener=function(type,f) { |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
179 return this.mb_rt.kbevents.add_event_observer(type,f); |
716 | 180 } |
724 | 181 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
|
182 this.mb_rt.redraw_changed(); |
1405
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
183 //this.mb_rt.redraw_all(); |
724 | 184 this.mb_rt.flush(); |
185 } | |
730 | 186 app.prototype.dump=function() { |
187 sys.puts(this.onKeyPress); | |
188 } | |
189 | |
190 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
|
191 if (typeof(key) == 'number') |
1719484ed15d
Make the argument key can be an array to register multiple keys.
wycc
parents:
730
diff
changeset
|
192 this.keymap[key] = f; |
911 | 193 else { |
194 for(k in key) { | |
195 this.keymap[k] = f; | |
731
1719484ed15d
Make the argument key can be an array to register multiple keys.
wycc
parents:
730
diff
changeset
|
196 } |
911 | 197 } |
730 | 198 } |
716 | 199 |
1376 | 200 app.prototype.generateScaleTween=function(src,dest,p) { |
1391 | 201 sys.puts("p="+ p); |
1376 | 202 src.hide(); |
203 // Duplicate the group | |
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.
wycc
parents:
1397
diff
changeset
|
204 var nodes = src.children; |
1422 | 205 //if (src.dup) { |
206 // src.dup.remove(); | |
207 // src.dup = null; | |
208 //} | |
1376 | 209 if (src.dup == null) { |
1396
a5672125e515
Copy the transformation matrix when we clone it. It looks like the MB do not copy the matrix automatically.
wycc
parents:
1392
diff
changeset
|
210 var dup = this.mb_rt.coord_new(src.parent); |
1379 | 211 for (i in nodes) { |
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.
wycc
parents:
1397
diff
changeset
|
212 var c = nodes[i]; |
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.
wycc
parents:
1399
diff
changeset
|
213 var k = dup.clone_from_subtree(c); |
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.
wycc
parents:
1399
diff
changeset
|
214 c.dup = k; |
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.
wycc
parents:
1405
diff
changeset
|
215 c.dup.id = c.id; |
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.
wycc
parents:
1405
diff
changeset
|
216 c.dup.refid = c.refid; |
1436
a9e96291ef0b
Clone the javascrip properties of the object return by clone_from_subtree. This should be relocated to the javascript version of the clone_from_subtree in the future.
wycc
parents:
1426
diff
changeset
|
217 // The following code should be relocated to the javascript wrapper |
a9e96291ef0b
Clone the javascrip properties of the object return by clone_from_subtree. This should be relocated to the javascript version of the clone_from_subtree in the future.
wycc
parents:
1426
diff
changeset
|
218 // the clone_from_subtree in the future. |
a9e96291ef0b
Clone the javascrip properties of the object return by clone_from_subtree. This should be relocated to the javascript version of the clone_from_subtree in the future.
wycc
parents:
1426
diff
changeset
|
219 try { |
a9e96291ef0b
Clone the javascrip properties of the object return by clone_from_subtree. This should be relocated to the javascript version of the clone_from_subtree in the future.
wycc
parents:
1426
diff
changeset
|
220 k.bbox = c.bbox; |
a9e96291ef0b
Clone the javascrip properties of the object return by clone_from_subtree. This should be relocated to the javascript version of the clone_from_subtree in the future.
wycc
parents:
1426
diff
changeset
|
221 k.bbox.owner = k; |
a9e96291ef0b
Clone the javascrip properties of the object return by clone_from_subtree. This should be relocated to the javascript version of the clone_from_subtree in the future.
wycc
parents:
1426
diff
changeset
|
222 } catch(e) { |
a9e96291ef0b
Clone the javascrip properties of the object return by clone_from_subtree. This should be relocated to the javascript version of the clone_from_subtree in the future.
wycc
parents:
1426
diff
changeset
|
223 } |
a9e96291ef0b
Clone the javascrip properties of the object return by clone_from_subtree. This should be relocated to the javascript version of the clone_from_subtree in the future.
wycc
parents:
1426
diff
changeset
|
224 |
a9e96291ef0b
Clone the javascrip properties of the object return by clone_from_subtree. This should be relocated to the javascript version of the clone_from_subtree in the future.
wycc
parents:
1426
diff
changeset
|
225 try { |
a9e96291ef0b
Clone the javascrip properties of the object return by clone_from_subtree. This should be relocated to the javascript version of the clone_from_subtree in the future.
wycc
parents:
1426
diff
changeset
|
226 k.center = c.center; |
a9e96291ef0b
Clone the javascrip properties of the object return by clone_from_subtree. This should be relocated to the javascript version of the clone_from_subtree in the future.
wycc
parents:
1426
diff
changeset
|
227 k.center.owner = c.owner; |
a9e96291ef0b
Clone the javascrip properties of the object return by clone_from_subtree. This should be relocated to the javascript version of the clone_from_subtree in the future.
wycc
parents:
1426
diff
changeset
|
228 } catch(e) { |
a9e96291ef0b
Clone the javascrip properties of the object return by clone_from_subtree. This should be relocated to the javascript version of the clone_from_subtree in the future.
wycc
parents:
1426
diff
changeset
|
229 } |
1379 | 230 } |
1376 | 231 src.dup = dup; |
232 } else { | |
233 dup = src.dup; | |
1379 | 234 src.dup.show(); |
1376 | 235 } |
1379 | 236 //dup.hide(); |
237 //dest.hide(); | |
238 //sys.puts(dup); | |
1376 | 239 |
1379 | 240 for(i in nodes) { |
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.
wycc
parents:
1397
diff
changeset
|
241 coord= nodes[i]; |
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.
wycc
parents:
1405
diff
changeset
|
242 if (coord.target) { |
1437 | 243 this._componentmanager.add(coord,coord.dup); |
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.
wycc
parents:
1399
diff
changeset
|
244 this.generateScaleTweenObject(coord.dup,coord,coord.target,p,''); |
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.
wycc
parents:
1405
diff
changeset
|
245 } else { |
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.
wycc
parents:
1399
diff
changeset
|
246 sys.puts(coord.id); |
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.
wycc
parents:
1399
diff
changeset
|
247 sys.puts(coord[0]); |
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.
wycc
parents:
1399
diff
changeset
|
248 sys.puts(coord[1]); |
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.
wycc
parents:
1399
diff
changeset
|
249 sys.puts(coord[2]); |
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.
wycc
parents:
1399
diff
changeset
|
250 sys.puts(coord[3]); |
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.
wycc
parents:
1399
diff
changeset
|
251 sys.puts(coord[4]); |
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.
wycc
parents:
1399
diff
changeset
|
252 sys.puts(coord[5]); |
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.
wycc
parents:
1399
diff
changeset
|
253 } |
1379 | 254 } |
255 } | |
256 function printcoord(s) | |
257 { | |
258 sys.puts(s[0]+" "+s[1]+" "+s[2]+" "+s[3]+" "+s[4]+" "+s[5]); | |
259 } | |
260 | |
261 function mul(a,b) | |
262 { | |
263 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], | |
264 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]]; | |
265 } | |
1376 | 266 |
1396
a5672125e515
Copy the transformation matrix when we clone it. It looks like the MB do not copy the matrix automatically.
wycc
parents:
1392
diff
changeset
|
267 app.prototype.generateScaleTweenObject=function(coord,src,dest,p,id) { |
1402 | 268 //sys.puts("xxxxxxx"); |
269 //sys.puts("dest="+dest); | |
1422 | 270 sys.puts("src=["+src.sx+","+src.sy+","+src.r+","+src.tx+","+src.ty); |
271 sys.puts("id="+id+" dest=["+dest.sx+","+dest.sy+","+dest.r+","+dest.tx+","+dest.ty); | |
1402 | 272 //sys.puts("src.center="+src.center); |
273 //sys.puts("src.center.x="+src.center.x+" src.center.y="+src.center.y); | |
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
|
274 if (src == null) return; |
1379 | 275 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
|
276 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
|
277 var y1 = src.center.y; |
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.
wycc
parents:
1397
diff
changeset
|
278 var y1 = 0; |
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.
wycc
parents:
1397
diff
changeset
|
279 x1 = 0; |
1396
a5672125e515
Copy the transformation matrix when we clone it. It looks like the MB do not copy the matrix automatically.
wycc
parents:
1392
diff
changeset
|
280 |
a5672125e515
Copy the transformation matrix when we clone it. It looks like the MB do not copy the matrix automatically.
wycc
parents:
1392
diff
changeset
|
281 // For the svg:use, the transform matrix is the transform of teh svg:use and the elements inside it |
a5672125e515
Copy the transformation matrix when we clone it. It looks like the MB do not copy the matrix automatically.
wycc
parents:
1392
diff
changeset
|
282 var d,sx,sy,r,tx,ty; |
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.
wycc
parents:
1399
diff
changeset
|
283 sx = src.sx*p+dest.sx*p1; |
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.
wycc
parents:
1399
diff
changeset
|
284 sy = src.sy*p+dest.sy*p1; |
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.
wycc
parents:
1399
diff
changeset
|
285 r = src.r*p+dest.r*p1; |
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.
wycc
parents:
1399
diff
changeset
|
286 tx = src.tx*p+dest.tx*p1; |
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.
wycc
parents:
1399
diff
changeset
|
287 ty = src.ty*p+dest.ty*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
|
288 var mt = [1, 0, -x1, 0, 1, -y1]; |
1382 | 289 var opacity; |
1379 | 290 var ms; |
1382 | 291 |
1396
a5672125e515
Copy the transformation matrix when we clone it. It looks like the MB do not copy the matrix automatically.
wycc
parents:
1392
diff
changeset
|
292 opacity = src.opacity*p1 + dest.opacity*p; |
1382 | 293 coord.opacity = opacity; |
294 | |
1379 | 295 if (r == 0) { |
296 m = mt; | |
297 } else { | |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
298 ms= [Math.cos(r), Math.sin(r),0,-Math.sin(r), Math.cos(r),0]; |
1379 | 299 m = mul(ms,mt); |
1376 | 300 } |
1379 | 301 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
|
302 m = mul([1,0,x1,0,1,y1],m); |
1379 | 303 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
|
304 //m[2] = -m[2]; |
1379 | 305 coord[0] = m[0]; |
306 coord[1] = m[1]; | |
307 coord[2] = m[2]; | |
308 coord[3] = m[3]; | |
309 coord[4] = m[4]; | |
310 coord[5] = m[5]; | |
1402 | 311 //sys.puts("id="+id+" src.tx="+src.tx+" src.ty="+src.ty+" tx="+tx+" ty="+ty+" r="+r+" x1="+x1+" y1="+y1+" p="+p+" "+m[0]+","+m[1]+","+m[2]+","+m[3]+","+m[4]+","+m[5]); |
1376 | 312 } |
978 | 313 |
314 app.prototype.changeScene=function(s) { | |
315 var nth; | |
1391 | 316 sys.puts(s); |
317 sys.puts(typeof(s)); | |
978 | 318 if (typeof(s)=='number') { |
319 var i; | |
320 nth = s; | |
321 } else { | |
322 nth = this.svg.getFrameNumber(s); | |
323 if (nth == -1) return; | |
324 } | |
1405
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
325 this.ts("goto to scene "+nth); |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
326 this.currentScene = nth; |
978 | 327 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
|
328 if (scenes == null) return; |
1376 | 329 for(i=0;i<scenes.length-1;i++) { |
978 | 330 try { |
1397 | 331 this.get(scenes[i].ref).hide(); |
978 | 332 if (nth >=scenes[i].start && nth <=scenes[i].end) { |
1424 | 333 //this.get(scenes[i].ref).show(); |
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.
wycc
parents:
1397
diff
changeset
|
334 if (this.get(scenes[i].ref).dup) |
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.
wycc
parents:
1397
diff
changeset
|
335 this.get(scenes[i].ref).dup.show(); |
1376 | 336 if (scenes[i].type == 'normal' || i == scenes.length-1) { |
337 this.get(scenes[i].ref).show(); | |
338 } else if (scenes[i].type == 'scale') { | |
339 if (scenes[i].end == (scenes[i+1].start-1)) { | |
1379 | 340 var p = 1-(nth-scenes[i].start)/(scenes[i].end-scenes[i].start+1); |
1376 | 341 this.generateScaleTween(this.get(scenes[i].ref),this.get(scenes[i+1].ref),p); |
342 } else { | |
343 // If there is no second key frame defined, fall back to the normal | |
344 this.get(scenes[i].ref).show(); | |
345 } | |
1424 | 346 //this.get(scenes[i+1].ref).hide(); |
1376 | 347 } |
348 | |
978 | 349 } else { |
350 this.get(scenes[i].ref).hide(); | |
1396
a5672125e515
Copy the transformation matrix when we clone it. It looks like the MB do not copy the matrix automatically.
wycc
parents:
1392
diff
changeset
|
351 if (this.get(scenes[i].ref).dup) |
a5672125e515
Copy the transformation matrix when we clone it. It looks like the MB do not copy the matrix automatically.
wycc
parents:
1392
diff
changeset
|
352 this.get(scenes[i].ref).dup.hide(); |
978 | 353 } |
354 } catch(e) { | |
355 sys.puts(e); | |
356 sys.puts(scenes[i].ref); | |
357 } | |
358 } | |
1397 | 359 this.get(scenes[i].ref).hide(); |
1405
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
360 this.ts("refresh"); |
1379 | 361 this.refresh(); |
1405
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
362 this.ts("refresh done"); |
978 | 363 } |
1138 | 364 |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
365 app.prototype.runToScene=function(s) { |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
366 if (typeof(s)=='number') { |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
367 var i; |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
368 nth = s; |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
369 } else { |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
370 nth = this.svg.getFrameNumber(s); |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
371 if (nth == -1) return; |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
372 } |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
373 var self = this; |
1391 | 374 sys.puts(this.currentScene+","+nth); |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
375 if (nth > this.currentScene) { |
1402 | 376 this.skipdir = 1; |
377 } else { | |
378 this.skipdir = -1; | |
379 } | |
380 this.targetScene = nth; | |
381 this.startScene = this.currentScene; | |
382 this.starttime = Date.now(); | |
383 if (this.timer == null) { | |
1405
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
384 this.skipFrame(); |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
385 } |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
386 } |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
387 |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
388 app.prototype.skipFrame=function() { |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
389 var self = this; |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
390 if (this.currentScene != this.targetScene) { |
1405
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
391 var now = Date.now(); |
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
392 var step = Math.round((now - this.starttime)/this.frame_interval)*this.skipdir; |
1402 | 393 nextframe = this.startScene + step |
1405
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
394 //nextframe = this.currentScene + this.skipdir; |
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
395 this.ts("goto begin"); |
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
396 |
1402 | 397 if (this.skipdir>0) { |
398 if (nextframe > this.targetScene) | |
399 nextframe = this.targetScene; | |
400 } else { | |
401 if (nextframe < this.targetScene) | |
402 nextframe = this.targetScene; | |
403 } | |
1426
5487aaf6f863
Change the algorithm to determine the gap between frames so that the go back can be calculated correctly.
wycc
parents:
1424
diff
changeset
|
404 this.changeScene(nextframe); |
1402 | 405 if (nextframe != this.targetScene) { |
1426
5487aaf6f863
Change the algorithm to determine the gap between frames so that the go back can be calculated correctly.
wycc
parents:
1424
diff
changeset
|
406 var timegap = this.frame_interval - (Date.now()-now); |
5487aaf6f863
Change the algorithm to determine the gap between frames so that the go back can be calculated correctly.
wycc
parents:
1424
diff
changeset
|
407 if (timegap < 0) timegap = 0; |
5487aaf6f863
Change the algorithm to determine the gap between frames so that the go back can be calculated correctly.
wycc
parents:
1424
diff
changeset
|
408 |
1402 | 409 this.timer = setTimeout(function() { |
410 self.skipFrame() | |
1426
5487aaf6f863
Change the algorithm to determine the gap between frames so that the go back can be calculated correctly.
wycc
parents:
1424
diff
changeset
|
411 }, timegap ); |
1402 | 412 } else { |
413 this.timer = null; | |
414 } | |
1405
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
415 now = Date.now(); |
05e8d3ffa703
Change the changeScene to sleep less when the render speed is too slow.
wycc
parents:
1402
diff
changeset
|
416 this.ts("goto end"); |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
417 } |
1138 | 418 } |
419 | |
978 | 420 app.prototype.addSceneListener=function(n, cb) { |
421 sys.puts("This is not implemented yet") | |
422 } | |
423 | |
872
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
424 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
|
425 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
|
426 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
|
427 var background; |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
428 var paint; |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
429 |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
430 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
|
431 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
|
432 |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
433 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
|
434 _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
|
435 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
|
436 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
|
437 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
|
438 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
|
439 |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
440 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
|
441 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
|
442 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
|
443 this.keymap = {}; |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
444 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
|
445 } |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
446 |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
447 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
|
448 |
716 | 449 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
|
450 exports.app_with_win = app_with_win; |
721
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
451 |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
452 // Put all key definition here |
820 | 453 exports.KEY_LEFT = 0xff51; |
729
299ed9319dc6
Use key symbols instead of keycodes.
Thinker K.F. Li <thinker@branda.to>
parents:
724
diff
changeset
|
454 exports.KEY_UP = 0xff52; |
820 | 455 exports.KEY_RIGHT = 0xff53; |
729
299ed9319dc6
Use key symbols instead of keycodes.
Thinker K.F. Li <thinker@branda.to>
parents:
724
diff
changeset
|
456 exports.KEY_DOWN = 0xff54; |
820 | 457 exports.KEY_ENTER = 0xff0d; |
724 | 458 exports.EVT_ANY=0; |
459 exports.EVT_MOUSE_OVER=1; | |
460 exports.EVT_MOUSE_OUT=2; | |
461 exports.EVT_MOUSE_MOVE=3; | |
462 exports.EVT_MOUSE_BUT_PRESS4; | |
463 exports.EVT_MOUSE_BUT_RELEASE=5 | |
464 exports.EVT_KB_PRESS=6; | |
465 exports.EVT_KB_RELEASE=7; | |
466 exports.EVT_PROGM_COMPLETE=8; | |
467 exports.EVT_RDMAN_REDRAW=9; | |
468 exports.EVT_MONITOR_ADD=10; | |
469 exports.EVT_MONITOR_REMOVE=11; | |
470 exports.EVT_MONITOR_FREE=12; | |
471 exports.EVT_MOUSE_MOVE_RAW=13; | |
827 | 472 exports.ldr = ldr; |