Mercurial > MadButterfly
comparison nodejs/coord.cc @ 744:6a988e23ad2a
A dirty implementation of removing subtree
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 25 Aug 2010 14:23:06 +0800 |
parents | dd1f3382d6a4 |
children | 4ccb0553e804 |
comparison
equal
deleted
inserted
replaced
743:dd1f3382d6a4 | 744:6a988e23ad2a |
---|---|
69 */ | 69 */ |
70 static void | 70 static void |
71 xnjsmb_coord_invalidate_subtree(Handle<Object> self) { | 71 xnjsmb_coord_invalidate_subtree(Handle<Object> self) { |
72 Persistent<Object> *child_hdl; | 72 Persistent<Object> *child_hdl; |
73 Persistent<Object> *mem_hdl; | 73 Persistent<Object> *mem_hdl; |
74 redraw_man_t *rdman; | 74 coord_t *coord, *child, *last_child; |
75 coord_t *coord, *child; | 75 Handle<Object> js_rt; |
76 shape_t *mem; | 76 redraw_man_t *rdman; |
77 shape_t *mem, *last_mem; | |
77 Handle<Value> _false = Boolean::New(0); | 78 Handle<Value> _false = Boolean::New(0); |
79 int r; | |
78 | 80 |
79 if(!GET(self, "valid")->ToBoolean()->Value()) /* Invalidated object */ | 81 if(!GET(self, "valid")->ToBoolean()->Value()) /* Invalidated object */ |
80 return; | 82 return; |
81 | 83 |
84 js_rt = GET(self, "mbrt")->ToObject(); | |
85 rdman = xnjsmb_rt_rdman(js_rt); | |
86 | |
82 coord = (coord_t *)UNWRAP(self); | 87 coord = (coord_t *)UNWRAP(self); |
88 rdman_coord_changed(rdman, coord); | |
83 | 89 |
84 /* Invalidate all coords in the subtree */ | 90 /* Invalidate all coords in the subtree */ |
85 FOR_COORDS_PREORDER(coord, child) { | 91 last_child = NULL; |
92 FOR_COORDS_POSTORDER(coord, child) { | |
93 if(last_child != NULL) { | |
94 r = rdman_coord_free(rdman, coord); | |
95 if(r != OK) | |
96 THROW_noret("Unknown error"); | |
97 } | |
98 | |
86 child_hdl = (Persistent<Object> *)mb_prop_get(&child->obj.props, | 99 child_hdl = (Persistent<Object> *)mb_prop_get(&child->obj.props, |
87 PROP_JSOBJ); | 100 PROP_JSOBJ); |
88 SET(*child_hdl, "valid", _false); | 101 SET(*child_hdl, "valid", _false); |
89 WRAP(*child_hdl, NULL); | 102 WRAP(*child_hdl, NULL); |
90 | 103 |
91 /* Invalidate members of a coord */ | 104 /* Invalidate members of a coord */ |
105 last_mem = NULL; | |
92 FOR_COORD_SHAPES(child, mem) { | 106 FOR_COORD_SHAPES(child, mem) { |
107 if(last_mem != NULL) { | |
108 r = rdman_shape_free(rdman, last_mem); | |
109 if(r != OK) | |
110 THROW_noret("Unknown error"); | |
111 } | |
112 | |
93 mem_hdl = (Persistent<Object> *)mb_prop_get(&mem->obj.props, | 113 mem_hdl = (Persistent<Object> *)mb_prop_get(&mem->obj.props, |
94 PROP_JSOBJ); | 114 PROP_JSOBJ); |
95 SET(*mem_hdl, "valid", _false); | 115 SET(*mem_hdl, "valid", _false); |
96 WRAP(*mem_hdl, NULL); | 116 WRAP(*mem_hdl, NULL); |
117 | |
118 last_mem = mem; | |
97 } | 119 } |
120 if(last_mem != NULL) { | |
121 r = rdman_shape_free(rdman, last_mem); | |
122 if(r != OK) | |
123 THROW_noret("Unknown error"); | |
124 } | |
125 | |
126 last_child = child; | |
127 } | |
128 if(last_child != NULL) { | |
129 r = rdman_coord_free(rdman, coord); | |
130 if(r != OK) | |
131 THROW_noret("Unknown error"); | |
98 } | 132 } |
99 } | 133 } |
100 | 134 |
101 static void | 135 static void |
102 xnjsmb_coord_mod(Handle<Object> self, coord_t *coord) { | 136 xnjsmb_coord_mod(Handle<Object> self, coord_t *coord) { |
162 *err = "Unknown error"; | 196 *err = "Unknown error"; |
163 } | 197 } |
164 | 198 |
165 static void | 199 static void |
166 xnjsmb_coord_remove(coord_t *coord, Handle<Object> self, const char **err) { | 200 xnjsmb_coord_remove(coord_t *coord, Handle<Object> self, const char **err) { |
167 Handle<Object> js_rt; | |
168 redraw_man_t *rdman; | |
169 int r; | |
170 | |
171 js_rt = GET(self, "mbrt")->ToObject(); | |
172 rdman = xnjsmb_rt_rdman(js_rt); | |
173 | |
174 xnjsmb_coord_invalidate_subtree(self); | 201 xnjsmb_coord_invalidate_subtree(self); |
175 | |
176 /* Free all coords and shapes in the subtree */ | |
177 r = rdman_coord_free(rdman, coord); | |
178 if(r != OK) | |
179 *err = "Can not remove a coord"; | |
180 } | 202 } |
181 | 203 |
182 #include "coord-inc.h" | 204 #include "coord-inc.h" |
183 | 205 |
184 /*! \brief This function used by \ref xnjsmb_mb_rt to wrap coord object. | 206 /*! \brief This function used by \ref xnjsmb_mb_rt to wrap coord object. |