comparison nodejs/paints.cc @ 567:a12c3448afb6 Android_Skia

Add dummy paint_color templates
author Thinker K.F. Li <thinker@branda.to>
date Wed, 09 Jun 2010 12:28:03 +0800
parents
children d796e6b8b97e
comparison
equal deleted inserted replaced
566:6639d386db78 567:a12c3448afb6
1 #include <v8.h>
2
3 extern "C" {
4 #include "mb.h"
5 }
6
7 #include "mbfly_njs.h"
8
9 using namespace v8;
10
11
12 /*! \brief Base type of all types of paints.
13 */
14 static Handle<Value>
15 xnjsmb_paint(const Arguments &args) {
16 }
17
18 /*! \brief Constructor of color paint_color_t object for Javascript.
19 */
20 static Handle<Value>
21 xnjsmb_paint_color(const Arguments &args) {
22 }
23
24 static Persistent<FunctionTemplate> paint_temp;
25 static Persistent<FunctionTemplate> paint_color_temp;
26
27 /*! \brief Create and return a paint_color object.
28 */
29 static Handle<Value>
30 xnjsmb_paint_color_new(const Arguments &args) {
31 HandleScope scope;
32 Handle<Object> rt = args.This();
33 Handle<Object> paint_color_obj;
34 Handle<Function> paint_color_func;
35 Handle<Value> pc_args[4];
36 int argc;
37 int i;
38
39 argc = args.Length();
40 if(argc != 4)
41 THROW("Invalid number of arguments (r, g, b, a)");
42 for(i = 0; i < 4; i++)
43 if(!args[i]->IsNumber())
44 THROW("Invalid argument type");
45
46 pc_args[0] = rt;
47 pc_args[1] = args[0]; // r
48 pc_args[2] = args[1]; // g
49 pc_args[3] = args[2]; // b
50 pc_args[4] = args[3]; // a
51 paint_color_func = paint_color_temp->GetFunction();
52 paint_color_obj = paint_color_func->NewInstance(1, pc_args);
53
54 scope.Close(paint_color_obj);
55 return paint_color_obj;
56 }
57
58 static Persistent<FunctionTemplate> paint_color_new_temp;
59
60 /*! \brief Create templates for paint types.
61 *
62 * This function is only called one time for every execution.
63 */
64 static void
65 xnjsmb_init_paints(void) {
66 Handle<FunctionTemplate> temp;
67
68 temp = FunctionTemplate::New(xnjsmb_paint);
69 paint_temp = Persistent<FunctionTemplate>::New(temp);
70 paint_temp->SetClassName(String::New("paint"));
71
72 temp = FunctionTemplate::New(xnjsmb_paint_color);
73 paint_color_temp = Persistent<FunctionTemplate>::New(temp);
74 paint_color_temp->SetClassName(String::New("paint_color"));
75 paint_color_temp->Inherit(paint_temp);
76
77 temp = FunctionTemplate::New(xnjsmb_paint_color_new);
78 paint_color_new_temp = Persistent<FunctionTemplate>::New(temp);
79 }
80
81 void xnjsmb_paints_init_mb_rt_temp(Handle<FunctionTemplate> rt_temp) {
82 static int init_flag = 0;
83 Handle<ObjectTemplate> rt_proto_temp;
84
85 if(!init_flag) {
86 xnjsmb_init_paints();
87 init_flag = 1;
88 }
89
90 rt_proto_temp = rt_temp->PrototypeTemplate();
91 SET(rt_proto_temp, "paint_color_new", paint_color_new_temp);
92 }