Mercurial > MadButterfly
comparison nodejs/coord.cc @ 822:586e50f82c1f
Unify coding style tag for emacs and vim.
author | Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com> |
---|---|
date | Tue, 14 Sep 2010 01:08:39 +0800 |
parents | 84853c8559cf |
children | 379fd510ba38 |
comparison
equal
deleted
inserted
replaced
821:bfdc82bbd6e4 | 822:586e50f82c1f |
---|---|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- | |
2 // vim: sw=4:ts=8:sts=4 | |
1 #include <stdio.h> | 3 #include <stdio.h> |
2 #include <v8.h> | 4 #include <v8.h> |
3 | 5 |
4 extern "C" { | 6 extern "C" { |
5 #include "mb.h" | 7 #include "mb.h" |
81 PROP_JSOBJ); | 83 PROP_JSOBJ); |
82 SET(*child_hdl, "valid", _false); | 84 SET(*child_hdl, "valid", _false); |
83 WRAP(*child_hdl, NULL); | 85 WRAP(*child_hdl, NULL); |
84 child_hdl->Dispose(); | 86 child_hdl->Dispose(); |
85 delete child_hdl; | 87 delete child_hdl; |
86 | 88 |
87 /* Invalidate members of a coord */ | 89 /* Invalidate members of a coord */ |
88 FOR_COORD_SHAPES(child, mem) { | 90 FOR_COORD_SHAPES(child, mem) { |
89 mem_hdl = (Persistent<Object> *)mb_prop_get(&mem->obj.props, | 91 mem_hdl = (Persistent<Object> *)mb_prop_get(&mem->obj.props, |
90 PROP_JSOBJ); | 92 PROP_JSOBJ); |
91 SET(*mem_hdl, "valid", _false); | 93 SET(*mem_hdl, "valid", _false); |
105 static void | 107 static void |
106 xnjsmb_coord_free_subtree(redraw_man_t *rdman, coord_t *coord) { | 108 xnjsmb_coord_free_subtree(redraw_man_t *rdman, coord_t *coord) { |
107 coord_t *child, *last_child; | 109 coord_t *child, *last_child; |
108 shape_t *mem, *last_mem; | 110 shape_t *mem, *last_mem; |
109 int r; | 111 int r; |
110 | 112 |
111 rdman_coord_changed(rdman, coord); | 113 rdman_coord_changed(rdman, coord); |
112 | 114 |
113 last_child = NULL; | 115 last_child = NULL; |
114 FOR_COORDS_POSTORDER(coord, child) { | 116 FOR_COORDS_POSTORDER(coord, child) { |
115 if(last_child != NULL) { | 117 if(last_child != NULL) { |
116 r = rdman_coord_free(rdman, last_child); | 118 r = rdman_coord_free(rdman, last_child); |
117 if(r != OK) | 119 if(r != OK) |
118 THROW_noret("Unknown error"); | 120 THROW_noret("Unknown error"); |
119 } | 121 } |
120 | 122 |
121 /* Free members of a coord */ | 123 /* Free members of a coord */ |
122 last_mem = NULL; | 124 last_mem = NULL; |
123 FOR_COORD_SHAPES(child, mem) { | 125 FOR_COORD_SHAPES(child, mem) { |
124 if(last_mem != NULL) { | 126 if(last_mem != NULL) { |
125 r = rdman_shape_free(rdman, last_mem); | 127 r = rdman_shape_free(rdman, last_mem); |
147 static void | 149 static void |
148 xnjsmb_coord_mod(Handle<Object> self, coord_t *coord) { | 150 xnjsmb_coord_mod(Handle<Object> self, coord_t *coord) { |
149 Persistent<Object> *self_hdl; | 151 Persistent<Object> *self_hdl; |
150 subject_t *subject; | 152 subject_t *subject; |
151 Handle<Value> subject_o; | 153 Handle<Value> subject_o; |
152 | 154 |
153 /* Keep associated js object in property store for retrieving, | 155 /* Keep associated js object in property store for retrieving, |
154 * later, without create new js object. | 156 * later, without create new js object. |
155 */ | 157 */ |
156 self_hdl = new Persistent<Object>(); | 158 self_hdl = new Persistent<Object>(); |
157 *self_hdl = Persistent<Object>::New(self); | 159 *self_hdl = Persistent<Object>::New(self); |
177 static float | 179 static float |
178 coord_set_index(coord_t *coord, Handle<Object> self, | 180 coord_set_index(coord_t *coord, Handle<Object> self, |
179 int idx, float v, const char **err) { | 181 int idx, float v, const char **err) { |
180 Handle<Object> js_rt; | 182 Handle<Object> js_rt; |
181 redraw_man_t *rdman; | 183 redraw_man_t *rdman; |
182 | 184 |
183 if(idx < 0 || idx >= 6) { | 185 if(idx < 0 || idx >= 6) { |
184 *err = "Invalid index: out of range"; | 186 *err = "Invalid index: out of range"; |
185 return 0; | 187 return 0; |
186 } | 188 } |
187 | 189 |
188 coord_get_matrix(coord)[idx] = v; | 190 coord_get_matrix(coord)[idx] = v; |
189 | 191 |
190 js_rt = GET(self, "mbrt")->ToObject(); | 192 js_rt = GET(self, "mbrt")->ToObject(); |
191 rdman = xnjsmb_rt_rdman(js_rt); | 193 rdman = xnjsmb_rt_rdman(js_rt); |
192 rdman_coord_changed(rdman, coord); | 194 rdman_coord_changed(rdman, coord); |
193 | 195 |
194 return v; | 196 return v; |
199 shape_t *shape, const char **err) { | 201 shape_t *shape, const char **err) { |
200 Handle<Object> js_rt; | 202 Handle<Object> js_rt; |
201 Persistent<Object> *shape_hdl; | 203 Persistent<Object> *shape_hdl; |
202 redraw_man_t *rdman; | 204 redraw_man_t *rdman; |
203 int r; | 205 int r; |
204 | 206 |
205 js_rt = GET(self, "mbrt")->ToObject(); | 207 js_rt = GET(self, "mbrt")->ToObject(); |
206 rdman = xnjsmb_rt_rdman(js_rt); | 208 rdman = xnjsmb_rt_rdman(js_rt); |
207 r = rdman_add_shape(rdman, shape, coord); | 209 r = rdman_add_shape(rdman, shape, coord); |
208 if(r != 0) | 210 if(r != 0) |
209 *err = "Unknown error"; | 211 *err = "Unknown error"; |
217 | 219 |
218 static void | 220 static void |
219 xnjsmb_coord_remove(coord_t *coord, Handle<Object> self) { | 221 xnjsmb_coord_remove(coord_t *coord, Handle<Object> self) { |
220 Handle<Object> js_rt; | 222 Handle<Object> js_rt; |
221 redraw_man_t *rdman; | 223 redraw_man_t *rdman; |
222 | 224 |
223 if(!GET(self, "valid")->ToBoolean()->Value()) /* Invalidated object */ | 225 if(!GET(self, "valid")->ToBoolean()->Value()) /* Invalidated object */ |
224 THROW_noret("Invalid object"); | 226 THROW_noret("Invalid object"); |
225 | 227 |
226 js_rt = GET(self, "mbrt")->ToObject(); | 228 js_rt = GET(self, "mbrt")->ToObject(); |
227 rdman = xnjsmb_rt_rdman(js_rt); | 229 rdman = xnjsmb_rt_rdman(js_rt); |
228 | 230 |
229 xnjsmb_coord_invalidate_subtree(coord); | 231 xnjsmb_coord_invalidate_subtree(coord); |
230 xnjsmb_coord_free_subtree(rdman, coord); | 232 xnjsmb_coord_free_subtree(rdman, coord); |
232 | 234 |
233 static void | 235 static void |
234 xnjsmb_coord_show(coord_t *coord, Handle<Object> self) { | 236 xnjsmb_coord_show(coord_t *coord, Handle<Object> self) { |
235 Handle<Object> js_rt; | 237 Handle<Object> js_rt; |
236 redraw_man_t *rdman; | 238 redraw_man_t *rdman; |
237 | 239 |
238 js_rt = GET(self, "mbrt")->ToObject(); | 240 js_rt = GET(self, "mbrt")->ToObject(); |
239 ASSERT(js_rt != NULL); | 241 ASSERT(js_rt != NULL); |
240 rdman = xnjsmb_rt_rdman(js_rt); | 242 rdman = xnjsmb_rt_rdman(js_rt); |
241 | 243 |
242 coord_show(coord); | 244 coord_show(coord); |
243 rdman_coord_changed(rdman, coord); | 245 rdman_coord_changed(rdman, coord); |
244 } | 246 } |
245 | 247 |
246 static void | 248 static void |
247 xnjsmb_coord_hide(coord_t *coord, Handle<Object> self) { | 249 xnjsmb_coord_hide(coord_t *coord, Handle<Object> self) { |
248 Handle<Object> js_rt; | 250 Handle<Object> js_rt; |
249 redraw_man_t *rdman; | 251 redraw_man_t *rdman; |
250 | 252 |
251 js_rt = GET(self, "mbrt")->ToObject(); | 253 js_rt = GET(self, "mbrt")->ToObject(); |
252 ASSERT(js_rt != NULL); | 254 ASSERT(js_rt != NULL); |
253 rdman = xnjsmb_rt_rdman(js_rt); | 255 rdman = xnjsmb_rt_rdman(js_rt); |
254 | 256 |
255 coord_hide(coord); | 257 coord_hide(coord); |
256 rdman_coord_changed(rdman, coord); | 258 rdman_coord_changed(rdman, coord); |
257 } | 259 } |
258 | 260 |
259 static void | 261 static void |
260 xnjsmb_coord_set_opacity(coord_t *coord, Handle<Object> self, | 262 xnjsmb_coord_set_opacity(coord_t *coord, Handle<Object> self, |
261 float opacity) { | 263 float opacity) { |
262 Handle<Object> js_rt; | 264 Handle<Object> js_rt; |
263 redraw_man_t *rdman; | 265 redraw_man_t *rdman; |
264 | 266 |
265 js_rt = GET(self, "mbrt")->ToObject(); | 267 js_rt = GET(self, "mbrt")->ToObject(); |
266 ASSERT(js_rt != NULL); | 268 ASSERT(js_rt != NULL); |
267 rdman = xnjsmb_rt_rdman(js_rt); | 269 rdman = xnjsmb_rt_rdman(js_rt); |
268 | 270 |
269 coord_set_opacity(coord, opacity); | 271 coord_set_opacity(coord, opacity); |
270 rdman_coord_changed(rdman, coord); | 272 rdman_coord_changed(rdman, coord); |
271 } | 273 } |
272 | 274 |
273 #include "coord-inc.h" | 275 #include "coord-inc.h" |
294 | 296 |
295 if(!init_flag) { | 297 if(!init_flag) { |
296 xnjsmb_auto_coord_init(); | 298 xnjsmb_auto_coord_init(); |
297 init_flag = 1; | 299 init_flag = 1; |
298 } | 300 } |
299 | 301 |
300 rdman = xnjsmb_rt_rdman(js_rt); | 302 rdman = xnjsmb_rt_rdman(js_rt); |
301 root = rdman_get_root(rdman); | 303 root = rdman_get_root(rdman); |
302 obj = xnjsmb_auto_coord_new(root).As<Object>(); | 304 obj = xnjsmb_auto_coord_new(root).As<Object>(); |
303 SET(obj, "mbrt", js_rt); | 305 SET(obj, "mbrt", js_rt); |
304 | 306 |