comparison nodejs/paints.cc @ 569:f87a368e847a Android_Skia

Functions of stroke and fill a shape
author Thinker K.F. Li <thinker@branda.to>
date Wed, 09 Jun 2010 14:44:20 +0800
parents d796e6b8b97e
children 49e79253b6d3
comparison
equal deleted inserted replaced
568:d796e6b8b97e 569:f87a368e847a
10 10
11 #ifndef ASSERT 11 #ifndef ASSERT
12 #define ASSERT(x) 12 #define ASSERT(x)
13 #endif 13 #endif
14 14
15
16 /*! \brief Fill a shape with the paint.
17 */
18 static Handle<Value>
19 xnjsmb_paint_fill(const Arguments &args) {
20 int argc = args.Length();
21 Handle<Object> self = args.This();
22 Handle<Object> sh_obj;
23 Handle<Object> rt;
24 Handle<Value> rt_val;
25 paint_t *paint;
26 shape_t *sh;
27 redraw_man_t *rdman;
28
29 if(argc != 1)
30 THROW("Invalid number of arguments (!= 1)");
31 if(!args[0]->IsObject())
32 THROW("Invalid argument type (shape)");
33
34 paint = (paint_t *)UNWRAP(self);
35
36 sh_obj = args[0]->ToObject();
37 sh = (shape_t *)UNWRAP(sh_obj);
38
39 rt_val = GET(self, "mbrt");
40 rt = rt_val->ToObject();
41 rdman = xnjsmb_rt_rdman(rt);
42
43 rdman_paint_fill(rdman, paint, sh);
44
45 return Null();
46 }
47
48 /*! \brief Stroke a shape with the paint.
49 */
50 static Handle<Value>
51 xnjsmb_paint_stroke(const Arguments &args) {
52 int argc = args.Length();
53 Handle<Object> self = args.This();
54 Handle<Object> sh_obj;
55 Handle<Object> rt;
56 Handle<Value> rt_val, sh_val;
57 paint_t *paint;
58 shape_t *sh;
59 redraw_man_t *rdman;
60
61 if(argc != 1)
62 THROW("Invalid number of arguments (!= 1)");
63 if(!args[0]->IsObject())
64 THROW("Invalid argument type (shape)");
65
66 paint = (paint_t *)UNWRAP(self);
67
68 sh_val = args[0];
69 sh_obj = sh_val->ToObject();
70 sh = (shape_t *)UNWRAP(sh_obj);
71
72 rt_val = GET(self, "mbrt");
73 rt = rt_val->ToObject();
74 rdman = xnjsmb_rt_rdman(rt);
75
76 rdman_paint_stroke(rdman, paint, sh);
77
78 return Null();
79 }
15 80
16 /*! \brief Constructor of color paint_color_t object for Javascript. 81 /*! \brief Constructor of color paint_color_t object for Javascript.
17 */ 82 */
18 static Handle<Value> 83 static Handle<Value>
19 xnjsmb_paint_color(const Arguments &args) { 84 xnjsmb_paint_color(const Arguments &args) {
40 rdman = xnjsmb_rt_rdman(rt); 105 rdman = xnjsmb_rt_rdman(rt);
41 paint = rdman_paint_color_new(rdman, r, g, b, a); 106 paint = rdman_paint_color_new(rdman, r, g, b, a);
42 ASSERT(sh != NULL); 107 ASSERT(sh != NULL);
43 108
44 WRAP(self, paint); 109 WRAP(self, paint);
110 SET(self, "mbrt", rt);
45 111
46 return Null(); 112 return Null();
47 } 113 }
48 114
49 static Persistent<FunctionTemplate> xnjsmb_paint_temp; 115 static Persistent<FunctionTemplate> xnjsmb_paint_temp;
86 * 152 *
87 * This function is only called one time for every execution. 153 * This function is only called one time for every execution.
88 */ 154 */
89 static void 155 static void
90 xnjsmb_init_paints(void) { 156 xnjsmb_init_paints(void) {
91 Handle<FunctionTemplate> temp; 157 Handle<FunctionTemplate> temp, meth;
92 Handle<ObjectTemplate> inst_temp; 158 Handle<ObjectTemplate> inst_temp;
159 Handle<ObjectTemplate> proto_temp;
93 160
94 /* 161 /*
95 * Base type of paint types. 162 * Base type of paint types.
96 */ 163 */
97 temp = FunctionTemplate::New(); 164 temp = FunctionTemplate::New();
98 xnjsmb_paint_temp = Persistent<FunctionTemplate>::New(temp); 165 xnjsmb_paint_temp = Persistent<FunctionTemplate>::New(temp);
99 xnjsmb_paint_temp->SetClassName(String::New("paint")); 166 xnjsmb_paint_temp->SetClassName(String::New("paint"));
167
168 meth = FunctionTemplate::New(xnjsmb_paint_fill);
169 proto_temp = xnjsmb_paint_temp->PrototypeTemplate();
170 SET(proto_temp, "fill", meth);
171
172 meth = FunctionTemplate::New(xnjsmb_paint_stroke);
173 proto_temp = xnjsmb_paint_temp->PrototypeTemplate();
174 SET(proto_temp, "stroke", meth);
100 175
101 /* 176 /*
102 * Paint color 177 * Paint color
103 */ 178 */
104 temp = FunctionTemplate::New(xnjsmb_paint_color); 179 temp = FunctionTemplate::New(xnjsmb_paint_color);