comparison nodejs/paints.cc @ 568:d796e6b8b97e Android_Skia

Real initialize a paint_color_t object for paint_color JS obj
author Thinker K.F. Li <thinker@branda.to>
date Wed, 09 Jun 2010 14:10:58 +0800
parents a12c3448afb6
children f87a368e847a
comparison
equal deleted inserted replaced
567:a12c3448afb6 568:d796e6b8b97e
6 6
7 #include "mbfly_njs.h" 7 #include "mbfly_njs.h"
8 8
9 using namespace v8; 9 using namespace v8;
10 10
11 #ifndef ASSERT
12 #define ASSERT(x)
13 #endif
11 14
12 /*! \brief Base type of all types of paints.
13 */
14 static Handle<Value>
15 xnjsmb_paint(const Arguments &args) {
16 }
17 15
18 /*! \brief Constructor of color paint_color_t object for Javascript. 16 /*! \brief Constructor of color paint_color_t object for Javascript.
19 */ 17 */
20 static Handle<Value> 18 static Handle<Value>
21 xnjsmb_paint_color(const Arguments &args) { 19 xnjsmb_paint_color(const Arguments &args) {
20 int argc = args.Length();
21 Handle<Object> self = args.This();
22 Handle<Object> rt;
23 redraw_man_t *rdman;
24 paint_t *paint;
25 float r, g, b, a;
26
27 if(argc != 5)
28 THROW("Invalid number of arguments (!= 5)");
29 if(!args[0]->IsObject() || !args[1]->IsNumber() ||
30 !args[2]->IsNumber() || !args[3]->IsNumber() ||
31 !args[4]->IsNumber())
32 THROW("Invalid argument type");
33
34 rt = args[0]->ToObject();
35 r = args[1]->ToNumber()->Value();
36 g = args[2]->ToNumber()->Value();
37 b = args[3]->ToNumber()->Value();
38 a = args[4]->ToNumber()->Value();
39
40 rdman = xnjsmb_rt_rdman(rt);
41 paint = rdman_paint_color_new(rdman, r, g, b, a);
42 ASSERT(sh != NULL);
43
44 WRAP(self, paint);
45
46 return Null();
22 } 47 }
23 48
24 static Persistent<FunctionTemplate> paint_temp; 49 static Persistent<FunctionTemplate> xnjsmb_paint_temp;
25 static Persistent<FunctionTemplate> paint_color_temp; 50 static Persistent<FunctionTemplate> xnjsmb_paint_color_temp;
26 51
27 /*! \brief Create and return a paint_color object. 52 /*! \brief Create and return a paint_color object.
28 */ 53 */
29 static Handle<Value> 54 static Handle<Value>
30 xnjsmb_paint_color_new(const Arguments &args) { 55 xnjsmb_paint_color_new(const Arguments &args) {
31 HandleScope scope; 56 HandleScope scope;
32 Handle<Object> rt = args.This(); 57 Handle<Object> rt = args.This();
33 Handle<Object> paint_color_obj; 58 Handle<Object> paint_color_obj;
34 Handle<Function> paint_color_func; 59 Handle<Function> paint_color_func;
35 Handle<Value> pc_args[4]; 60 Handle<Value> pc_args[5];
36 int argc; 61 int argc;
37 int i; 62 int i;
38 63
39 argc = args.Length(); 64 argc = args.Length();
40 if(argc != 4) 65 if(argc != 4)
46 pc_args[0] = rt; 71 pc_args[0] = rt;
47 pc_args[1] = args[0]; // r 72 pc_args[1] = args[0]; // r
48 pc_args[2] = args[1]; // g 73 pc_args[2] = args[1]; // g
49 pc_args[3] = args[2]; // b 74 pc_args[3] = args[2]; // b
50 pc_args[4] = args[3]; // a 75 pc_args[4] = args[3]; // a
51 paint_color_func = paint_color_temp->GetFunction(); 76 paint_color_func = xnjsmb_paint_color_temp->GetFunction();
52 paint_color_obj = paint_color_func->NewInstance(1, pc_args); 77 paint_color_obj = paint_color_func->NewInstance(5, pc_args);
53 78
54 scope.Close(paint_color_obj); 79 scope.Close(paint_color_obj);
55 return paint_color_obj; 80 return paint_color_obj;
56 } 81 }
57 82
58 static Persistent<FunctionTemplate> paint_color_new_temp; 83 static Persistent<FunctionTemplate> xnjsmb_paint_color_new_temp;
59 84
60 /*! \brief Create templates for paint types. 85 /*! \brief Create templates for paint types.
61 * 86 *
62 * This function is only called one time for every execution. 87 * This function is only called one time for every execution.
63 */ 88 */
64 static void 89 static void
65 xnjsmb_init_paints(void) { 90 xnjsmb_init_paints(void) {
66 Handle<FunctionTemplate> temp; 91 Handle<FunctionTemplate> temp;
92 Handle<ObjectTemplate> inst_temp;
67 93
68 temp = FunctionTemplate::New(xnjsmb_paint); 94 /*
69 paint_temp = Persistent<FunctionTemplate>::New(temp); 95 * Base type of paint types.
70 paint_temp->SetClassName(String::New("paint")); 96 */
97 temp = FunctionTemplate::New();
98 xnjsmb_paint_temp = Persistent<FunctionTemplate>::New(temp);
99 xnjsmb_paint_temp->SetClassName(String::New("paint"));
71 100
101 /*
102 * Paint color
103 */
72 temp = FunctionTemplate::New(xnjsmb_paint_color); 104 temp = FunctionTemplate::New(xnjsmb_paint_color);
73 paint_color_temp = Persistent<FunctionTemplate>::New(temp); 105 xnjsmb_paint_color_temp = Persistent<FunctionTemplate>::New(temp);
74 paint_color_temp->SetClassName(String::New("paint_color")); 106 xnjsmb_paint_color_temp->SetClassName(String::New("paint_color"));
75 paint_color_temp->Inherit(paint_temp); 107 xnjsmb_paint_color_temp->Inherit(xnjsmb_paint_temp);
108
109 inst_temp = xnjsmb_paint_color_temp->InstanceTemplate();
110 inst_temp->SetInternalFieldCount(1);
76 111
77 temp = FunctionTemplate::New(xnjsmb_paint_color_new); 112 temp = FunctionTemplate::New(xnjsmb_paint_color_new);
78 paint_color_new_temp = Persistent<FunctionTemplate>::New(temp); 113 xnjsmb_paint_color_new_temp = Persistent<FunctionTemplate>::New(temp);
79 } 114 }
80 115
81 void xnjsmb_paints_init_mb_rt_temp(Handle<FunctionTemplate> rt_temp) { 116 void xnjsmb_paints_init_mb_rt_temp(Handle<FunctionTemplate> rt_temp) {
82 static int init_flag = 0; 117 static int init_flag = 0;
83 Handle<ObjectTemplate> rt_proto_temp; 118 Handle<ObjectTemplate> rt_proto_temp;
86 xnjsmb_init_paints(); 121 xnjsmb_init_paints();
87 init_flag = 1; 122 init_flag = 1;
88 } 123 }
89 124
90 rt_proto_temp = rt_temp->PrototypeTemplate(); 125 rt_proto_temp = rt_temp->PrototypeTemplate();
91 SET(rt_proto_temp, "paint_color_new", paint_color_new_temp); 126 SET(rt_proto_temp, "paint_color_new", xnjsmb_paint_color_new_temp);
92 } 127 }