Mercurial > MadButterfly
annotate nodejs/coord.cc @ 741:d8764f10e141
Remove a coord from the tree in JS
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 25 Aug 2010 10:40:30 +0800 |
parents | 4916c3a3fe3c |
children | 24038e7a365b |
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 |
739
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
17 /*! \page jsgc How to Manage Life-cycle of Objects for Javascript. |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
18 * |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
19 * The life-cycle of MadButterfly ojects are simple. A object is live |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
20 * when it is created and dead when it is free. When a coord or shape |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
21 * is free, it is also removed from the tree. There is not way to |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
22 * remove a coord or a shape without freeing it. So, if you want to |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
23 * remove a coord or a shape object from the tree, you can only free |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
24 * it. |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
25 * |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
26 * Javascript, in conventional, does not free an object. It has GC, |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
27 * the engine, being used, will free an object if it is no more |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
28 * referenced. So, we had better provide a removing function, but |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
29 * actually free an object. In idea situation, a new MB object would |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
30 * be created for and attached on the JS object, when an object added |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
31 * back to the tree. But, it means we need to keep states of an |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
32 * object and create a new one with the same states later. It is |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
33 * complicated. So, once an object is removed, it is invalidated. |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
34 * |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
35 * I hope someone would implement a higher abstract layer, in JS, to |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
36 * implement the idea model that recreate a new object when an |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
37 * invalidated JS object being added back. |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
38 * |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
39 * An invalid object is the one with NULL internal field and obj.valid |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
40 * == false. The binding of MadButterfly hold a reference to every |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
41 * object added to the tree of a mbrt (runtime object), and remove the |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
42 * reference and invalidate it when it being removed. |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
43 * |
741
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
44 * For coords, they are always attached to the tree when it is valid. |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
45 * So, binding hold a persistent reference to it. The reference is |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
46 * purged when a coord being removed from the tree and being |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
47 * invalidated. |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
48 * |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
49 * For any shape, it is not attached to the tree at begining, but is |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
50 * attached to a tree laterly, or is collected by GC. The binding |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
51 * hold a weak reference for a new shape, and upgrade to a strong |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
52 * reference when the shape being added to the tree. |
739
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
53 */ |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
54 |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
55 using namespace v8; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
56 |
684
b346e4699e55
Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents:
680
diff
changeset
|
57 /*! \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
|
58 * \ingroup xnjsmb |
b346e4699e55
Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents:
680
diff
changeset
|
59 * |
b346e4699e55
Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents:
680
diff
changeset
|
60 * @{ |
b346e4699e55
Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents:
680
diff
changeset
|
61 */ |
741
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
62 /*! \brief Invalidate JS objects for coords and shapes in a subtree. |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
63 * |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
64 * \param self is the object of the root of subtree. |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
65 * |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
66 * \sa \ref jsgc |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
67 */ |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
68 static void |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
69 xnjsmb_coord_invalidate_subtree(Handle<Object> self) { |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
70 Handle<Object> *child_hdl; |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
71 Handle<Object> *mem_hdl; |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
72 redraw_man_t *rdman; |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
73 coord_t *coord, *child; |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
74 shape_t *mem; |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
75 Handle<Value> _false = Boolean::New(0); |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
76 |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
77 if(!GET(self, "valid")->ToBoolean()->Value()) /* Invalidated object */ |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
78 return; |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
79 |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
80 coord = (coord_t *)UNWRAP(self); |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
81 |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
82 /* Invalidate all coords in the subtree */ |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
83 FOR_COORDS_PREORDER(coord, child) { |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
84 child_hdl = (Handle<Object> *)mb_prop_get(&child->obj.props, |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
85 PROP_JSOBJ); |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
86 child = (coord_t *)UNWRAP(*child_hdl); |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
87 WRAP(*child_hdl, NULL); |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
88 SET(*child_hdl, "valid", _false); |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
89 |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
90 /* Invalidate members of a coord */ |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
91 FOR_COORD_SHAPES(child, mem) { |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
92 mem_hdl = (Handle<Object> *)mb_prop_get(&mem->obj.props, |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
93 PROP_JSOBJ); |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
94 WRAP(*mem_hdl, NULL); |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
95 SET(*mem_hdl, "valid", _false); |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
96 } |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
97 } |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
98 } |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
99 |
680
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
100 static void |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
101 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
|
102 Persistent<Object> *self_hdl; |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
103 subject_t *subject; |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
104 Handle<Value> subject_o; |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
105 |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
106 /* 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
|
107 * later, without create new js object. |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
108 */ |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
109 self_hdl = new Persistent<Object>(self); |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
110 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
|
111 |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
112 subject = coord->mouse_event; |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
113 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
|
114 SET(self, "mouse_event", subject_o); |
741
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
115 SET(self, "valid", Boolean::New(1)); |
680
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
116 } |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
117 |
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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 *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
|
123 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
|
124 } |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
125 |
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
|
126 return coord_get_matrix(coord)[idx]; |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
127 } |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
128 |
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
|
129 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
|
130 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
|
131 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
|
132 Handle<Object> js_rt; |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
133 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
|
134 |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
135 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
|
136 *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
|
137 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
|
138 } |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
139 |
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
|
140 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
|
141 |
560
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
142 js_rt = GET(self, "mbrt")->ToObject(); |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
143 rdman = xnjsmb_rt_rdman(js_rt); |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
144 rdman_coord_changed(rdman, coord); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
145 |
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
|
146 return v; |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
147 } |
560
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
148 |
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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 int r; |
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
155 |
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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 *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
|
161 } |
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
162 |
741
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
163 static void |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
164 xnjsmb_coord_remove(coord_t *coord, Handle<Object> self, const char **err) { |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
165 Handle<Object> js_rt; |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
166 redraw_man_t *rdman; |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
167 |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
168 js_rt = GET(self, "mbrt")->ToObject(); |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
169 rdman = xnjsmb_rt_rdman(js_rt); |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
170 |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
171 xnjsmb_coord_invalidate_subtree(self); |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
172 |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
173 /* Free all coords and shapes in the subtree */ |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
174 rdman_coord_free(rdman, coord); |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
175 } |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
176 |
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
|
177 #include "coord-inc.h" |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
178 |
684
b346e4699e55
Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents:
680
diff
changeset
|
179 /*! \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
|
180 */ |
666
b6fb543d69ee
Use binding generator to implement mb_rt
Thinker K.F. Li <thinker@branda.to>
parents:
661
diff
changeset
|
181 Handle<Value> export_xnjsmb_auto_coord_new(coord_t *coord) { |
695 | 182 return xnjsmb_auto_coord_new(coord); |
666
b6fb543d69ee
Use binding generator to implement mb_rt
Thinker K.F. Li <thinker@branda.to>
parents:
661
diff
changeset
|
183 } |
b6fb543d69ee
Use binding generator to implement mb_rt
Thinker K.F. Li <thinker@branda.to>
parents:
661
diff
changeset
|
184 |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
185 /*! \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
|
186 * |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
187 * \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
|
188 * |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
189 * 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
|
190 * Javascript. |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
191 */ |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
192 void |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
193 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
|
194 redraw_man_t *rdman; |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
195 coord_t *root; |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
196 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
|
197 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
|
198 |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
199 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
|
200 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
|
201 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
|
202 } |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
203 |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
204 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
|
205 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
|
206 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
|
207 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
|
208 |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
209 SET(js_rt, "root", obj); |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
210 } |
684
b346e4699e55
Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents:
680
diff
changeset
|
211 |
b346e4699e55
Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents:
680
diff
changeset
|
212 /* @} */ |