Mercurial > MadButterfly
comparison nodejs/shapes.cc @ 748:56a5e08cd8af
Make shapes can be removed from the tree
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 25 Aug 2010 18:46:47 +0800 |
parents | dd1f3382d6a4 |
children | ed59e659a202 |
comparison
equal
deleted
inserted
replaced
747:d2f2ed27b84d | 748:56a5e08cd8af |
---|---|
9 | 9 |
10 #ifndef ASSERT | 10 #ifndef ASSERT |
11 #define ASSERT(x) | 11 #define ASSERT(x) |
12 #endif | 12 #endif |
13 | 13 |
14 #define OK 0 | |
15 | |
14 using namespace v8; | 16 using namespace v8; |
15 | 17 |
16 /*! \defgroup xnjsmb_shapes JS binding for shapes. | 18 /*! \defgroup xnjsmb_shapes JS binding for shapes. |
17 * \ingroup xnjsmb | 19 * \ingroup xnjsmb |
18 * | 20 * |
19 * @{ | 21 * @{ |
20 */ | 22 */ |
23 /*! \brief This function is called when GC collecting a shape. | |
24 * | |
25 * It was installed by Persistent<Object>::MakeWeak(). | |
26 */ | |
27 static void | |
28 xnjsmb_shape_recycled(Persistent<Value> obj, void *parameter) { | |
29 Persistent<Object> *self_hdl = (Persistent<Object> *)parameter; | |
30 Handle<Object> js_rt; | |
31 redraw_man_t *rdman; | |
32 shape_t *shape; | |
33 | |
34 shape = (shape_t *)UNWRAP(*self_hdl); | |
35 if(shape == NULL) | |
36 return; | |
37 | |
38 WRAP(*self_hdl, NULL); | |
39 | |
40 js_rt = GET(*self_hdl, "mbrt")->ToObject(); | |
41 rdman = xnjsmb_rt_rdman(js_rt); | |
42 rdman_shape_changed(rdman, shape); | |
43 rdman_shape_free(rdman, shape); | |
44 } | |
45 | |
21 static void | 46 static void |
22 xnjsmb_shape_mod(Handle<Object> self, shape_t *sh) { | 47 xnjsmb_shape_mod(Handle<Object> self, shape_t *sh) { |
23 Persistent<Object> *self_hdl; | 48 Persistent<Object> *self_hdl; |
24 | 49 |
25 /* Keep associated js object in property store for retrieving, | 50 /* Keep associated js object in property store for retrieving, |
26 * later, without create new js object. | 51 * later, without create new js object. |
27 */ | 52 */ |
28 self_hdl = new Persistent<Object>(); | 53 self_hdl = new Persistent<Object>(); |
29 *self_hdl = Persistent<Object>::New(self); | 54 *self_hdl = Persistent<Object>::New(self); |
30 mb_prop_set(&sh->obj.props, PROP_JSOBJ, self_hdl); | 55 mb_prop_set(&sh->obj.props, PROP_JSOBJ, self_hdl); |
56 | |
57 self_hdl->MakeWeak(self_hdl, xnjsmb_shape_recycled); | |
31 } | 58 } |
32 | 59 |
33 static void | 60 static void |
34 xnjsmb_sh_stext_set_style(shape_t *sh, Handle<Object> self, | 61 xnjsmb_sh_stext_set_style(shape_t *sh, Handle<Object> self, |
35 Handle<Value> blks, const char **err) { | 62 Handle<Value> blks, const char **err) { |
100 if(sh_get_coord(sh)) | 127 if(sh_get_coord(sh)) |
101 rdman_shape_changed(rdman, sh); | 128 rdman_shape_changed(rdman, sh); |
102 } | 129 } |
103 | 130 |
104 static void | 131 static void |
132 xnjsmb_shape_remove(shape_t *sh, Handle<Object> self) { | |
133 Handle<Object> js_rt; | |
134 redraw_man_t *rdman; | |
135 Persistent<Object> *self_hdl; | |
136 int r; | |
137 | |
138 self_hdl = (Persistent<Object> *)mb_prop_get(&sh->obj.props, | |
139 PROP_JSOBJ); | |
140 | |
141 SET(*self_hdl, "valid", Boolean::New(0)); | |
142 WRAP(*self_hdl, NULL); | |
143 | |
144 js_rt = GET(*self_hdl, "mbrt")->ToObject(); | |
145 ASSERT(js_rt != NULL); | |
146 rdman = xnjsmb_rt_rdman(js_rt); | |
147 | |
148 rdman_shape_changed(rdman, sh); | |
149 r = rdman_shape_free(rdman, sh); | |
150 if(r != OK) | |
151 THROW_noret("Can not free a shape for unknown reason"); | |
152 | |
153 delete self_hdl; | |
154 } | |
155 | |
156 static void | |
105 xnjsmb_sh_rect_set(shape_t *sh, Handle<Object> self, float x, float y, | 157 xnjsmb_sh_rect_set(shape_t *sh, Handle<Object> self, float x, float y, |
106 float w, float h, float rx, float ry) { | 158 float w, float h, float rx, float ry) { |
107 Handle<Object> rt; | 159 Handle<Object> rt; |
108 redraw_man_t *rdman; | 160 redraw_man_t *rdman; |
109 | 161 |