annotate nodejs/coord.cc @ 684:b346e4699e55

Add more comment for JS binding
author Thinker K.F. Li <thinker@branda.to>
date Sat, 07 Aug 2010 19:33:42 +0800
parents a588eefd3f04
children 763a4e2bbd85
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
684
b346e4699e55 Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents: 680
diff changeset
19 /*! \defgroup xnjsmb_coord JS binding for coord objects.
b346e4699e55 Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents: 680
diff changeset
20 * \ingroup xnjsmb
b346e4699e55 Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents: 680
diff changeset
21 *
b346e4699e55 Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents: 680
diff changeset
22 * @{
b346e4699e55 Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents: 680
diff changeset
23 */
680
a588eefd3f04 Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents: 667
diff changeset
24 static void
a588eefd3f04 Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents: 667
diff changeset
25 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
26 Persistent<Object> *self_hdl;
a588eefd3f04 Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents: 667
diff changeset
27 subject_t *subject;
a588eefd3f04 Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents: 667
diff changeset
28 Handle<Value> subject_o;
a588eefd3f04 Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents: 667
diff changeset
29
a588eefd3f04 Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents: 667
diff changeset
30 /* 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
31 * later, without create new js object.
a588eefd3f04 Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents: 667
diff changeset
32 */
a588eefd3f04 Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents: 667
diff changeset
33 self_hdl = new Persistent<Object>(self);
a588eefd3f04 Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents: 667
diff changeset
34 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
35
a588eefd3f04 Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents: 667
diff changeset
36 subject = coord->mouse_event;
a588eefd3f04 Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents: 667
diff changeset
37 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
38 SET(self, "mouse_event", subject_o);
a588eefd3f04 Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents: 667
diff changeset
39 }
a588eefd3f04 Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents: 667
diff changeset
40
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
41 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
42 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
43 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
44 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
45 *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
46 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
47 }
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48
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
49 return coord_get_matrix(coord)[idx];
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 }
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51
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 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
53 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
54 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
55 Handle<Object> js_rt;
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 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
57
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 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
59 *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
60 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
61 }
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62
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
63 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
64
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
65 js_rt = GET(self, "mbrt")->ToObject();
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
66 rdman = xnjsmb_rt_rdman(js_rt);
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 rdman_coord_changed(rdman, coord);
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68
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
69 return v;
557
0ca8437a91fa Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 }
560
ce7a35abcb0d Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 557
diff changeset
71
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
72 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
73 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
74 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
75 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
76 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
77 int r;
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
78
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
79 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
80 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
81 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
82 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
83 *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
84 }
6639d386db78 Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
85
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
86 #include "coord-inc.h"
562
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
87
684
b346e4699e55 Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents: 680
diff changeset
88 /*! \brief This function used by \ref xnjsmb_mb_rt to wrap coord object.
b346e4699e55 Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents: 680
diff changeset
89 */
666
b6fb543d69ee Use binding generator to implement mb_rt
Thinker K.F. Li <thinker@branda.to>
parents: 661
diff changeset
90 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
91 xnjsmb_auto_coord_new(coord);
b6fb543d69ee Use binding generator to implement mb_rt
Thinker K.F. Li <thinker@branda.to>
parents: 661
diff changeset
92 }
b6fb543d69ee Use binding generator to implement mb_rt
Thinker K.F. Li <thinker@branda.to>
parents: 661
diff changeset
93
562
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
94 /*! \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
95 *
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
96 * \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
97 *
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
98 * 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
99 * Javascript.
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
100 */
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
101 void
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
102 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
103 redraw_man_t *rdman;
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
104 coord_t *root;
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
105 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
106 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
107
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 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
109 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
110 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
111 }
562
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
112
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
113 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
114 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
115 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
116 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
117
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
118 SET(js_rt, "root", obj);
1b6402f07cd4 Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents: 560
diff changeset
119 }
684
b346e4699e55 Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents: 680
diff changeset
120
b346e4699e55 Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents: 680
diff changeset
121 /* @} */