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