comparison nodejs/paints.cc @ 636:cc39cf3f623c

paint_image_t for nodejs. It is still can not be used. Waiting for binding of image loader and shape_image.
author Thinker K.F. Li <thinker@branda.to>
date Mon, 26 Jul 2010 09:19:03 +0800
parents 5a68e2bcea17
children 714cd6470bd9
comparison
equal deleted inserted replaced
635:058945dff7bd 636:cc39cf3f623c
152 return paint_color_obj; 152 return paint_color_obj;
153 } 153 }
154 154
155 static Persistent<FunctionTemplate> xnjsmb_paint_color_new_temp; 155 static Persistent<FunctionTemplate> xnjsmb_paint_color_new_temp;
156 156
157 /*! \brief Constructor of paint_image_t objects for Javascript.
158 */
159 static Handle<Value>
160 xnjsmb_paint_image(const Arguments &args) {
161 int argc = args.Length();
162 Handle<Object> rt;
163 Handle<Object> self = args.This();
164 Handle<Object> img_obj;
165 redraw_man_t *rdman;
166 mb_img_data_t *img;
167 paint_t *paint;
168
169 if(argc != 2)
170 THROW("Invalid number of arguments (!= 2)");
171 if(!args[0]->IsObject() || !args[1]->IsObject())
172 THROW("Invalid argument type");
173
174 rt = args[0]->ToObject();
175 img_obj = args[1]->ToObject();
176
177 rdman = xnjsmb_rt_rdman(rt);
178 img = (mb_img_data_t *)UNWRAP(img_obj);
179
180 paint = rdman_paint_image_new(rdman, img);
181 ASSERT(paint != NULL);
182
183 WRAP(self, paint);
184 SET(self, "mbrt", rt);
185
186 return Null();
187 }
188
189 static Persistent<FunctionTemplate> xnjsmb_paint_image_temp;
190
191 /*! \brief Create and return a paint_image object.
192 */
193 static Handle<Value>
194 xnjsmb_paint_image_new(const Arguments &args) {
195 int argc = args.Length();
196 HandleScope scope;
197 Handle<Object> rt = args.This();
198 Handle<Object> paint_image_obj;
199 Handle<Value> pi_args[2];
200 Handle<Function> paint_image_func;
201
202 if(argc != 1)
203 THROW("Invalid number of arguments (!= 2)");
204 if(!args[0]->IsObject())
205 THROW("Invalid argument type");
206
207 pi_args[0] = rt;
208 pi_args[1] = args[0]; // image
209 paint_image_func = xnjsmb_paint_image_temp->GetFunction();
210 paint_image_obj = paint_image_func->NewInstance(2, pi_args);
211
212 scope.Close(paint_image_obj);
213 return paint_image_obj;
214 }
215
216 static Persistent<FunctionTemplate> xnjsmb_paint_image_new_temp;
217
157 /*! \brief Create templates for paint types. 218 /*! \brief Create templates for paint types.
158 * 219 *
159 * This function is only called one time for every execution. 220 * This function is only called one time for every execution.
160 */ 221 */
161 static void 222 static void
184 */ 245 */
185 temp = FunctionTemplate::New(xnjsmb_paint_color); 246 temp = FunctionTemplate::New(xnjsmb_paint_color);
186 xnjsmb_paint_color_temp = Persistent<FunctionTemplate>::New(temp); 247 xnjsmb_paint_color_temp = Persistent<FunctionTemplate>::New(temp);
187 xnjsmb_paint_color_temp->SetClassName(String::New("paint_color")); 248 xnjsmb_paint_color_temp->SetClassName(String::New("paint_color"));
188 xnjsmb_paint_color_temp->Inherit(xnjsmb_paint_temp); 249 xnjsmb_paint_color_temp->Inherit(xnjsmb_paint_temp);
189 250
190 inst_temp = xnjsmb_paint_color_temp->InstanceTemplate(); 251 inst_temp = xnjsmb_paint_color_temp->InstanceTemplate();
191 inst_temp->SetInternalFieldCount(1); 252 inst_temp->SetInternalFieldCount(1);
192 253
193 temp = FunctionTemplate::New(xnjsmb_paint_color_new); 254 temp = FunctionTemplate::New(xnjsmb_paint_color_new);
194 xnjsmb_paint_color_new_temp = Persistent<FunctionTemplate>::New(temp); 255 xnjsmb_paint_color_new_temp = Persistent<FunctionTemplate>::New(temp);
256
257 /*
258 * Paint image
259 */
260 temp = FunctionTemplate::New(xnjsmb_paint_image);
261 xnjsmb_paint_image_temp = Persistent<FunctionTemplate>::New(temp);
262 xnjsmb_paint_image_temp->SetClassName(String::New("paint_image"));
263 xnjsmb_paint_image_temp->Inherit(xnjsmb_paint_temp);
264
265 inst_temp = xnjsmb_paint_image_temp->InstanceTemplate();
266 inst_temp->SetInternalFieldCount(1);
267
268 temp = FunctionTemplate::New(xnjsmb_paint_image_new);
269 xnjsmb_paint_image_new_temp = Persistent<FunctionTemplate>::New(temp);
195 } 270 }
196 271
197 void xnjsmb_paints_init_mb_rt_temp(Handle<FunctionTemplate> rt_temp) { 272 void xnjsmb_paints_init_mb_rt_temp(Handle<FunctionTemplate> rt_temp) {
198 static int init_flag = 0; 273 static int init_flag = 0;
199 Handle<ObjectTemplate> rt_proto_temp; 274 Handle<ObjectTemplate> rt_proto_temp;
203 init_flag = 1; 278 init_flag = 1;
204 } 279 }
205 280
206 rt_proto_temp = rt_temp->PrototypeTemplate(); 281 rt_proto_temp = rt_temp->PrototypeTemplate();
207 SET(rt_proto_temp, "paint_color_new", xnjsmb_paint_color_new_temp); 282 SET(rt_proto_temp, "paint_color_new", xnjsmb_paint_color_new_temp);
208 } 283 SET(rt_proto_temp, "paint_image_new", xnjsmb_paint_image_new_temp);
284 }