Mercurial > MadButterfly
annotate nodejs/coord.cc @ 680:a588eefd3f04
Refactor to xnjsmb_coord_mod().
Move code of initializing attributes of JS coord objects to
xnjsmb_coord_mod().
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 06 Aug 2010 22:56:58 +0800 |
parents | 7315c6e953c3 |
children | b346e4699e55 |
rev | line source |
---|---|
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1 #include <stdio.h> |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
2 #include <v8.h> |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 extern "C" { |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 #include "mb.h" |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
6 #include "mb_X_supp.h" |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 #include "mb_tools.h" |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
8 #include "X_supp_njs.h" |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
9 } |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
10 |
560
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
11 #include "mbfly_njs.h" |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
12 |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
13 #ifndef ASSERT |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
14 #define ASSERT(x) |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
15 #endif |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
16 |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
17 using namespace v8; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
18 |
680
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
19 static void |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
20 xnjsmb_coord_mod(Handle<Object> self, coord_t *coord) { |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
21 Persistent<Object> *self_hdl; |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
22 subject_t *subject; |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
23 Handle<Value> subject_o; |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
24 |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
25 /* Keep associated js object in property store for retrieving, |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
26 * later, without create new js object. |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
27 */ |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
28 self_hdl = new Persistent<Object>(self); |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
29 mb_prop_set(&coord->obj.props, PROP_JSOBJ, self_hdl); |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
30 |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
31 subject = coord->mouse_event; |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
32 subject_o = export_xnjsmb_auto_subject_new(subject); |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
33 SET(self, "mouse_event", subject_o); |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
34 } |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
35 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
36 static float |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
37 coord_get_index(coord_t *coord, Handle<Object> self, int idx, |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
38 const char **err) { |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
39 if(idx < 0 || idx >= 6) { |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
40 *err = "Invalid index: out of range"; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
41 return 0; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
42 } |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
43 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
44 return coord_get_matrix(coord)[idx]; |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
45 } |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
46 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
47 static float |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
48 coord_set_index(coord_t *coord, Handle<Object> self, |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
49 int idx, float v, const char **err) { |
560
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
50 Handle<Object> js_rt; |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
51 redraw_man_t *rdman; |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
52 |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
53 if(idx < 0 || idx >= 6) { |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
54 *err = "Invalid index: out of range"; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
55 return 0; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
56 } |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
57 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
58 coord_get_matrix(coord)[idx] = v; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
59 |
560
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
60 js_rt = GET(self, "mbrt")->ToObject(); |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
61 rdman = xnjsmb_rt_rdman(js_rt); |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
62 rdman_coord_changed(rdman, coord); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
63 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
64 return v; |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
65 } |
560
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
66 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
67 static void |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
68 xnjsmb_coord_add_shape(coord_t *coord, Handle<Object> self, |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
69 shape_t *shape, const char **err) { |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
70 Handle<Object> js_rt; |
566
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
71 redraw_man_t *rdman; |
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
72 int r; |
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
73 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
74 js_rt = GET(self, "mbrt")->ToObject(); |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
75 rdman = xnjsmb_rt_rdman(js_rt); |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
76 r = rdman_add_shape(rdman, shape, coord); |
566
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
77 if(r != 0) |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
78 *err = "Unknown error"; |
566
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
79 } |
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
80 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
81 #include "coord-inc.h" |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
82 |
666
b6fb543d69ee
Use binding generator to implement mb_rt
Thinker K.F. Li <thinker@branda.to>
parents:
661
diff
changeset
|
83 Handle<Value> export_xnjsmb_auto_coord_new(coord_t *coord) { |
b6fb543d69ee
Use binding generator to implement mb_rt
Thinker K.F. Li <thinker@branda.to>
parents:
661
diff
changeset
|
84 xnjsmb_auto_coord_new(coord); |
b6fb543d69ee
Use binding generator to implement mb_rt
Thinker K.F. Li <thinker@branda.to>
parents:
661
diff
changeset
|
85 } |
b6fb543d69ee
Use binding generator to implement mb_rt
Thinker K.F. Li <thinker@branda.to>
parents:
661
diff
changeset
|
86 |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
87 /*! \brief Initialize Javascript object for root coord of a runtime. |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
88 * |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
89 * \param js_rt is the runtime object to create the root object for. |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
90 * |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
91 * After the function, js_rt.root is the object for root coord in |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
92 * Javascript. |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
93 */ |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
94 void |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
95 xnjsmb_coord_mkroot(Handle<Object> js_rt) { |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
96 redraw_man_t *rdman; |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
97 coord_t *root; |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
98 Handle<Object> obj; |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
99 static int init_flag = 0; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
100 |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
101 if(!init_flag) { |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
102 xnjsmb_auto_coord_init(); |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
103 init_flag = 1; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
104 } |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
105 |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
106 rdman = xnjsmb_rt_rdman(js_rt); |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
107 root = rdman_get_root(rdman); |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
108 obj = xnjsmb_auto_coord_new(root).As<Object>(); |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
109 SET(obj, "mbrt", js_rt); |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
110 |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
111 SET(js_rt, "root", obj); |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
112 } |