comparison nodejs/shapes.cc @ 641:f60d8fa1c55b

Javascript binding for shape_image_t
author Thinker K.F. Li <thinker@branda.to>
date Mon, 26 Jul 2010 22:29:33 +0800
parents 5a68e2bcea17
children a65720721c60
comparison
equal deleted inserted replaced
640:9016e7e70f7d 641:f60d8fa1c55b
262 262
263 func = xnjsmb_shape_stext_temp->GetFunction(); 263 func = xnjsmb_shape_stext_temp->GetFunction();
264 stext_obj = func->NewInstance(4, stext_args); 264 stext_obj = func->NewInstance(4, stext_args);
265 ASSERT(stext_obj != NULL); 265 ASSERT(stext_obj != NULL);
266 266
267 scope.Close(stext_obj);
267 return stext_obj; 268 return stext_obj;
268 } 269 }
269 270
270 /*! \brief Setup style blocks for a stext. 271 /*! \brief Setup style blocks for a stext.
271 * 272 *
311 return Null(); 312 return Null();
312 } 313 }
313 314
314 /*! \brief Initialize function template for stext objects. 315 /*! \brief Initialize function template for stext objects.
315 */ 316 */
316 void 317 static void
317 xnjsmb_init_stext_temp(void) { 318 xnjsmb_init_stext_temp(void) {
318 Handle<FunctionTemplate> func_temp; 319 Handle<FunctionTemplate> func_temp;
319 Handle<FunctionTemplate> meth_temp; 320 Handle<FunctionTemplate> meth_temp;
320 Handle<ObjectTemplate> inst_temp; 321 Handle<ObjectTemplate> inst_temp;
321 Handle<ObjectTemplate> proto_temp; 322 Handle<ObjectTemplate> proto_temp;
334 xnjsmb_shape_stext_temp = Persistent<FunctionTemplate>::New(func_temp); 335 xnjsmb_shape_stext_temp = Persistent<FunctionTemplate>::New(func_temp);
335 } 336 }
336 337
337 /* @} */ 338 /* @} */
338 339
340 /*! \defgroup image_temp Templates for image objects.
341 *
342 * @{
343 */
344
345 static Handle<Value>
346 xnjsmb_shape_image(const Arguments &args) {
347 int argc = args.Length();
348 Handle<Object> self = args.This();
349 Handle<Object> rt;
350 float x, y;
351 float w, h;
352 redraw_man_t *rdman;
353 shape_t *img;
354
355 if(argc != 5)
356 THROW("Invalid number of arguments (!= 5)");
357 if(!args[0]->IsObject() ||
358 !args[1]->IsNumber() || !args[2]->IsNumber() ||
359 !args[3]->IsNumber() || !args[4]->IsNumber())
360 THROW("Invalid argument type");
361
362 rt = args[0]->ToObject();
363 x = args[1]->ToNumber()->Value();
364 y = args[2]->ToNumber()->Value();
365 w = args[3]->ToNumber()->Value();
366 h = args[4]->ToNumber()->Value();
367
368 rdman = xnjsmb_rt_rdman(rt);
369 img = rdman_shape_image_new(rdman, x, y, w, h);
370
371 WRAP(self, img);
372 SET(self, "mbrt", rt);
373
374 return Null();
375 }
376
377 static Persistent<FunctionTemplate> xnjsmb_shape_image_temp;
378
379 static Handle<Value>
380 xnjsmb_shape_image_new(const Arguments &args) {
381 HandleScope scope;
382 int argc = args.Length();
383 Handle<Object> self = args.This();
384 Handle<Value> img_args[5];
385 Handle<Object> img_obj;
386 Handle<Function> func;
387
388 if(argc != 4)
389 THROW("Invalid number of arguments (!= 3)");
390
391 img_args[0] = self;
392 img_args[1] = args[0];
393 img_args[2] = args[1];
394 img_args[3] = args[2];
395 img_args[4] = args[3];
396
397 func = xnjsmb_shape_image_temp->GetFunction();
398 img_obj = func->NewInstance(5, img_args);
399 ASSERT(img_obj != NULL);
400
401 scope.Close(img_obj);
402 return img_obj;
403 }
404
405 static void
406 xnjsmb_init_image_temp() {
407 Handle<FunctionTemplate> func_temp;
408 Handle<FunctionTemplate> meth_temp;
409 Handle<ObjectTemplate> inst_temp;
410 Handle<ObjectTemplate> proto_temp;
411
412 func_temp = FunctionTemplate::New(xnjsmb_shape_image);
413 func_temp->Inherit(xnjsmb_shape_temp);
414 func_temp->SetClassName(String::New("image"));
415
416 inst_temp = func_temp->InstanceTemplate();
417 inst_temp->SetInternalFieldCount(1);
418
419 xnjsmb_shape_image_temp = Persistent<FunctionTemplate>::New(func_temp);
420 }
421
422 /* @} */
423
339 /*! \brief Set properties of template of mb_rt. 424 /*! \brief Set properties of template of mb_rt.
340 */ 425 */
341 void 426 void
342 xnjsmb_shapes_init_mb_rt_temp(Handle<FunctionTemplate> rt_temp) { 427 xnjsmb_shapes_init_mb_rt_temp(Handle<FunctionTemplate> rt_temp) {
343 HandleScope scope; 428 HandleScope scope;
344 Handle<FunctionTemplate> path_new_temp, stext_new_temp; 429 Handle<FunctionTemplate> path_new_temp, stext_new_temp;
430 Handle<FunctionTemplate> image_new_temp;
345 Handle<ObjectTemplate> rt_proto_temp; 431 Handle<ObjectTemplate> rt_proto_temp;
346 static int temp_init_flag = 0; 432 static int temp_init_flag = 0;
347 433
348 if(temp_init_flag == 0) { 434 if(temp_init_flag == 0) {
349 xnjsmb_init_shape_temp(); 435 xnjsmb_init_shape_temp();
357 path_new_temp = FunctionTemplate::New(xnjsmb_shape_path_new); 443 path_new_temp = FunctionTemplate::New(xnjsmb_shape_path_new);
358 SET(rt_proto_temp, "path_new", path_new_temp); 444 SET(rt_proto_temp, "path_new", path_new_temp);
359 445
360 stext_new_temp = FunctionTemplate::New(xnjsmb_shape_stext_new); 446 stext_new_temp = FunctionTemplate::New(xnjsmb_shape_stext_new);
361 SET(rt_proto_temp, "stext_new", stext_new_temp); 447 SET(rt_proto_temp, "stext_new", stext_new_temp);
362 } 448
449 image_new_temp = FunctionTemplate::New(xnjsmb_shape_image_new);
450 SET(rt_proto_temp, "image_new", image_new_temp);
451 }