Mercurial > MadButterfly
annotate nodejs/mbapp.js @ 1404:ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 04 Apr 2011 12:43:29 +0800 |
parents | 0efa20061d70 |
children | 05e8d3ffa703 |
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; |
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
|
51 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
|
52 coord.add_shape = function(shape) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
53 var coord; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
54 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
55 this._mbapp_saved_add_shape(shape); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
56 shape.parent = this; |
884
6c8e4e1f3a39
Maintain a list of children
Thinker K.F. Li <thinker@codemud.net>
parents:
874
diff
changeset
|
57 this.children.push(shape); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
58 } |
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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 // 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
|
64 // 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
|
65 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
|
66 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
|
67 } |
884
6c8e4e1f3a39
Maintain a list of children
Thinker K.F. Li <thinker@codemud.net>
parents:
874
diff
changeset
|
68 |
6c8e4e1f3a39
Maintain a list of children
Thinker K.F. Li <thinker@codemud.net>
parents:
874
diff
changeset
|
69 parent.children.push(coord); |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
70 |
853
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
71 return coord; |
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
72 }; |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
73 |
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 * Decorate root 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 coord = mb_rt.root; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
78 coord.type = "coord"; |
884
6c8e4e1f3a39
Maintain a list of children
Thinker K.F. Li <thinker@codemud.net>
parents:
874
diff
changeset
|
79 coord.children = []; |
854
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
80 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
|
81 coord[3], coord[4], coord[5]]; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
82 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
|
83 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
|
84 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
|
85 coord.add_shape = function(shape) { |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
86 var coord; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
87 |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
88 this._mbapp_saved_add_shape(shape); |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
89 shape.parent = this; |
eff2f580b536
Use accessor to return bbox values
Thinker K.F. Li <thinker@codemud.net>
parents:
853
diff
changeset
|
90 } |
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
|
91 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
|
92 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
|
93 |
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
|
94 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
|
95 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
|
96 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
|
97 // 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
|
98 // 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
|
99 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
|
100 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
|
101 } |
853
13e0953c3fb3
backup transform matrix when create a new coord
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
102 } |
784
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
103 |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
104 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
|
105 var self = this; |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
106 var mb_rt; |
716 | 107 |
784
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
108 if(typeof display == "undefined") |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
109 display = ":0.0"; |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
110 if(typeof w == "undefined") |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
111 w = 720; |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
112 if(typeof h == "undefined") |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
113 h = 480; |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
114 |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
115 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
|
116 _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
|
117 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
|
118 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
|
119 paint.fill(background); |
37a1bd3e3ce1
mbapp accept arguments for display, width and height
Thinker K.F. Li <thinker@codemud.net>
parents:
762
diff
changeset
|
120 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
|
121 |
909 | 122 this.mb_rt.kbevents.add_event_observer(exports.EVT_KB_PRESS, function(evt) { self.KeyPress(evt);}); |
123 this.keymap={}; | |
124 this.onKeyPress = null; | |
914 | 125 this.svg = new svg.loadSVG(this.mb_rt,this.mb_rt.root,null); |
1402 | 126 this.frame_interval = 1000/24; // 12 frame per second |
127 this.timer = null; | |
716 | 128 } |
129 app.prototype.loadSVG=function(fname) { | |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
130 this.svg.load(this.mb_rt,this.mb_rt.root,fname); |
1391 | 131 this.changeScene(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
|
132 sys.puts("xxxx"); |
716 | 133 } |
134 | |
730 | 135 app.prototype.KeyPress = function(evt) { |
136 if (this.onKeyPress) this.onKeyPress(evt.sym); | |
911 | 137 if (evt.sym in this.keymap) { |
138 this.keymap[evt.sym](); | |
139 } | |
730 | 140 } |
141 | |
716 | 142 app.prototype.loop=function() { |
721
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
143 this.mb_rt.redraw_all(); |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
144 this.mb_rt.flush(); |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
145 } |
762 | 146 app.prototype.update=function() { |
147 this.mb_rt.redraw_all(); | |
148 this.mb_rt.flush(); | |
149 } | |
721
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
150 app.prototype.get=function(name) { |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
151 return this.mb_rt.mbnames[name]; |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
152 } |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
153 app.prototype.addKeyboardListener=function(type,f) { |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
154 return this.mb_rt.kbevents.add_event_observer(type,f); |
716 | 155 } |
724 | 156 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
|
157 this.mb_rt.redraw_changed(); |
724 | 158 this.mb_rt.flush(); |
159 } | |
730 | 160 app.prototype.dump=function() { |
161 sys.puts(this.onKeyPress); | |
162 } | |
163 | |
164 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
|
165 if (typeof(key) == 'number') |
1719484ed15d
Make the argument key can be an array to register multiple keys.
wycc
parents:
730
diff
changeset
|
166 this.keymap[key] = f; |
911 | 167 else { |
168 for(k in key) { | |
169 this.keymap[k] = f; | |
731
1719484ed15d
Make the argument key can be an array to register multiple keys.
wycc
parents:
730
diff
changeset
|
170 } |
911 | 171 } |
730 | 172 } |
716 | 173 |
1376 | 174 app.prototype.generateScaleTween=function(src,dest,p) { |
1391 | 175 sys.puts("p="+ p); |
1376 | 176 src.hide(); |
177 // 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
|
178 var nodes = src.children; |
1376 | 179 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
|
180 var dup = this.mb_rt.coord_new(src.parent); |
1379 | 181 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
|
182 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
|
183 var ng = this.mb_rt.coord_new(dup); |
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
|
184 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
|
185 c.dup = k; |
1379 | 186 } |
1376 | 187 src.dup = dup; |
188 } else { | |
189 dup = src.dup; | |
1379 | 190 src.dup.show(); |
1376 | 191 } |
1379 | 192 //dup.hide(); |
193 //dest.hide(); | |
194 //sys.puts(dup); | |
1376 | 195 |
1379 | 196 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
|
197 coord= 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
|
198 if (coord.target) |
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
|
199 this.generateScaleTweenObject(coord.dup,coord,coord.target,p,''); |
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
|
200 else { |
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
|
201 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 } |
1379 | 209 } |
210 } | |
211 function printcoord(s) | |
212 { | |
213 sys.puts(s[0]+" "+s[1]+" "+s[2]+" "+s[3]+" "+s[4]+" "+s[5]); | |
214 } | |
215 | |
216 function mul(a,b) | |
217 { | |
218 return [a[0]*b[0]+a[1]*b[3], a[0]*b[1]+a[1]*b[4], a[0]*b[2]+a[1]*b[5]+a[2], | |
219 a[3]*b[0]+a[4]*b[3], a[3]*b[1]+a[4]*b[4], a[3]*b[2]+a[4]*b[5]+a[5]]; | |
220 } | |
1376 | 221 |
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
|
222 app.prototype.generateScaleTweenObject=function(coord,src,dest,p,id) { |
1402 | 223 //sys.puts("xxxxxxx"); |
224 //sys.puts("dest="+dest); | |
225 // sys.puts("src=["+src.sx+","+src.sy+","+src.r+","+src.tx+","+src.ty); | |
226 //sys.puts("id="+id+" dest=["+dest.sx+","+dest.sy+","+dest.r+","+dest.tx+","+dest.ty); | |
227 //sys.puts("src.center="+src.center); | |
228 //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
|
229 if (src == null) return; |
1379 | 230 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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 |
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
|
236 // 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 var mt = [1, 0, -x1, 0, 1, -y1]; |
1382 | 244 var opacity; |
1379 | 245 var ms; |
1382 | 246 |
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
|
247 opacity = src.opacity*p1 + dest.opacity*p; |
1382 | 248 coord.opacity = opacity; |
249 | |
1379 | 250 if (r == 0) { |
251 m = mt; | |
252 } else { | |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
253 ms= [Math.cos(r), Math.sin(r),0,-Math.sin(r), Math.cos(r),0]; |
1379 | 254 m = mul(ms,mt); |
1376 | 255 } |
1379 | 256 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
|
257 m = mul([1,0,x1,0,1,y1],m); |
1379 | 258 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
|
259 //m[2] = -m[2]; |
1379 | 260 coord[0] = m[0]; |
261 coord[1] = m[1]; | |
262 coord[2] = m[2]; | |
263 coord[3] = m[3]; | |
264 coord[4] = m[4]; | |
265 coord[5] = m[5]; | |
1402 | 266 //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 | 267 } |
978 | 268 |
269 app.prototype.changeScene=function(s) { | |
270 var nth; | |
1391 | 271 sys.puts(s); |
272 sys.puts(typeof(s)); | |
978 | 273 if (typeof(s)=='number') { |
274 var i; | |
275 nth = s; | |
276 } else { | |
277 nth = this.svg.getFrameNumber(s); | |
278 if (nth == -1) return; | |
279 } | |
1391 | 280 sys.puts("goto to scene "+nth); |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
281 this.currentScene = nth; |
978 | 282 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
|
283 if (scenes == null) return; |
1376 | 284 for(i=0;i<scenes.length-1;i++) { |
978 | 285 try { |
1397 | 286 this.get(scenes[i].ref).hide(); |
978 | 287 if (nth >=scenes[i].start && nth <=scenes[i].end) { |
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
|
288 this.get(scenes[i].ref).show(); |
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
|
289 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
|
290 this.get(scenes[i].ref).dup.show(); |
1376 | 291 if (scenes[i].type == 'normal' || i == scenes.length-1) { |
292 this.get(scenes[i].ref).show(); | |
293 } else if (scenes[i].type == 'scale') { | |
294 if (scenes[i].end == (scenes[i+1].start-1)) { | |
1379 | 295 var p = 1-(nth-scenes[i].start)/(scenes[i].end-scenes[i].start+1); |
1376 | 296 this.generateScaleTween(this.get(scenes[i].ref),this.get(scenes[i+1].ref),p); |
297 } else { | |
298 // If there is no second key frame defined, fall back to the normal | |
299 this.get(scenes[i].ref).show(); | |
300 } | |
1379 | 301 this.get(scenes[i+1].ref).hide(); |
1376 | 302 } |
303 | |
978 | 304 } else { |
305 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
|
306 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
|
307 this.get(scenes[i].ref).dup.hide(); |
978 | 308 } |
309 } catch(e) { | |
310 sys.puts(e); | |
311 sys.puts(scenes[i].ref); | |
312 } | |
313 } | |
1397 | 314 this.get(scenes[i].ref).hide(); |
1379 | 315 this.refresh(); |
978 | 316 } |
1138 | 317 |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
318 app.prototype.runToScene=function(s) { |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
319 if (typeof(s)=='number') { |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
320 var i; |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
321 nth = s; |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
322 } else { |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
323 nth = this.svg.getFrameNumber(s); |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
324 if (nth == -1) return; |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
325 } |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
326 var self = this; |
1391 | 327 sys.puts(this.currentScene+","+nth); |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
328 if (nth > this.currentScene) { |
1402 | 329 this.skipdir = 1; |
330 } else { | |
331 this.skipdir = -1; | |
332 } | |
333 this.targetScene = nth; | |
334 this.startScene = this.currentScene; | |
335 this.starttime = Date.now(); | |
336 if (this.timer == null) { | |
337 this.timer = setTimeout(function() { | |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
338 self.skipFrame() |
1402 | 339 }, this.frame_interval); |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
340 } |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
341 } |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
342 |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
343 app.prototype.skipFrame=function() { |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
344 var self = this; |
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
345 if (this.currentScene != this.targetScene) { |
1402 | 346 var step = Math.round((Date.now() - this.starttime)/this.frame_interval)*this.skipdir; |
347 nextframe = this.startScene + step | |
348 if (this.skipdir>0) { | |
349 if (nextframe > this.targetScene) | |
350 nextframe = this.targetScene; | |
351 } else { | |
352 if (nextframe < this.targetScene) | |
353 nextframe = this.targetScene; | |
354 } | |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
355 this.changeScene(nextframe); |
1402 | 356 if (nextframe != this.targetScene) { |
357 this.timer = setTimeout(function() { | |
358 self.skipFrame() | |
359 }, this.frame_interval); | |
360 } else { | |
361 this.timer = null; | |
362 } | |
1380
76d2aad5da35
Implement runToScene method for the Flash-like animation.
wycc
parents:
1379
diff
changeset
|
363 } |
1138 | 364 } |
365 | |
978 | 366 app.prototype.addSceneListener=function(n, cb) { |
367 sys.puts("This is not implemented yet") | |
368 } | |
369 | |
872
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
370 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
|
371 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
|
372 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
|
373 var background; |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
374 var paint; |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
375 |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
376 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
|
377 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
|
378 |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
379 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
|
380 _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
|
381 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
|
382 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
|
383 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
|
384 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
|
385 |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
386 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
|
387 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
|
388 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
|
389 this.keymap = {}; |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
390 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
|
391 } |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
392 |
bcc63b20d5c6
mbapp.js support to create an application with existed window
Thinker K.F. Li <thinker@codemud.net>
parents:
827
diff
changeset
|
393 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
|
394 |
716 | 395 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
|
396 exports.app_with_win = app_with_win; |
721
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
397 |
01d02382dea7
Refactory the mbapp and testsvg to use keyboard events
wycc
parents:
716
diff
changeset
|
398 // Put all key definition here |
820 | 399 exports.KEY_LEFT = 0xff51; |
729
299ed9319dc6
Use key symbols instead of keycodes.
Thinker K.F. Li <thinker@branda.to>
parents:
724
diff
changeset
|
400 exports.KEY_UP = 0xff52; |
820 | 401 exports.KEY_RIGHT = 0xff53; |
729
299ed9319dc6
Use key symbols instead of keycodes.
Thinker K.F. Li <thinker@branda.to>
parents:
724
diff
changeset
|
402 exports.KEY_DOWN = 0xff54; |
820 | 403 exports.KEY_ENTER = 0xff0d; |
724 | 404 exports.EVT_ANY=0; |
405 exports.EVT_MOUSE_OVER=1; | |
406 exports.EVT_MOUSE_OUT=2; | |
407 exports.EVT_MOUSE_MOVE=3; | |
408 exports.EVT_MOUSE_BUT_PRESS4; | |
409 exports.EVT_MOUSE_BUT_RELEASE=5 | |
410 exports.EVT_KB_PRESS=6; | |
411 exports.EVT_KB_RELEASE=7; | |
412 exports.EVT_PROGM_COMPLETE=8; | |
413 exports.EVT_RDMAN_REDRAW=9; | |
414 exports.EVT_MONITOR_ADD=10; | |
415 exports.EVT_MONITOR_REMOVE=11; | |
416 exports.EVT_MONITOR_FREE=12; | |
417 exports.EVT_MOUSE_MOVE_RAW=13; | |
827 | 418 exports.ldr = ldr; |