Mercurial > MadButterfly
comparison nodejs/shapes.cc @ 574:a2faee809514
Implement stext type for Javascript
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 09 Jun 2010 22:06:50 +0800 |
parents | 49e79253b6d3 |
children | 5a68e2bcea17 |
comparison
equal
deleted
inserted
replaced
572:dcd7adb2c0fc | 574:a2faee809514 |
---|---|
190 return path_obj; | 190 return path_obj; |
191 } | 191 } |
192 | 192 |
193 /* @} */ | 193 /* @} */ |
194 | 194 |
195 /*! \defgroup stext_path Template for stext objects. | |
196 * | |
197 * @{ | |
198 */ | |
199 | |
200 /*! \brief Constructor for stext objects. | |
201 * | |
202 * 4 arguments | |
203 * \param rt is a runtime object. | |
204 * \param data is a text to be showed. | |
205 * \param x is postion in x-axis. | |
206 * \param y is position in y-axis. | |
207 */ | |
208 static Handle<Value> | |
209 xnjsmb_shape_stext(const Arguments &args) { | |
210 int argc = args.Length(); | |
211 Handle<Object> self = args.This(); | |
212 Handle<Object> rt; | |
213 float x, y; | |
214 char *data; | |
215 redraw_man_t *rdman; | |
216 shape_t *stext; | |
217 | |
218 if(argc != 4) | |
219 THROW("Invalid number of arguments (!= 4)"); | |
220 if(!args[0]->IsObject() || !args[1]->IsString() || | |
221 !args[2]->IsNumber() || !args[3]->IsNumber()) | |
222 THROW("Invalid argument type"); | |
223 | |
224 rt = args[0]->ToObject(); | |
225 String::Utf8Value data_utf8(args[1]); | |
226 data = *data_utf8; | |
227 x = args[2]->ToNumber()->Value(); | |
228 y = args[3]->ToNumber()->Value(); | |
229 | |
230 rdman = xnjsmb_rt_rdman(rt); | |
231 ASSERT(rdman != NULL); | |
232 | |
233 stext = rdman_shape_stext_new(rdman, data, x, y); | |
234 | |
235 WRAP(self, stext); | |
236 SET(self, "mbrt", rt); | |
237 | |
238 return Null(); | |
239 } | |
240 | |
241 static Persistent<FunctionTemplate> xnjsmb_shape_stext_temp; | |
242 | |
243 /*! \brief Create a stext and return it. | |
244 */ | |
245 static Handle<Value> | |
246 xnjsmb_shape_stext_new(const Arguments &args) { | |
247 HandleScope scope; | |
248 int argc = args.Length(); | |
249 Handle<Object> self = args.This(); | |
250 Handle<Value> stext_args[4]; | |
251 Handle<Object> stext_obj; | |
252 Handle<Function> func; | |
253 | |
254 if(argc != 3) | |
255 THROW("Invalid number of arguments (!= 3)"); | |
256 | |
257 stext_args[0] = self; | |
258 stext_args[1] = args[0]; | |
259 stext_args[2] = args[1]; | |
260 stext_args[3] = args[2]; | |
261 | |
262 func = xnjsmb_shape_stext_temp->GetFunction(); | |
263 stext_obj = func->NewInstance(4, stext_args); | |
264 ASSERT(stext_obj != NULL); | |
265 | |
266 return stext_obj; | |
267 } | |
268 | |
269 /*! \brief Initialize function template for stext objects. | |
270 */ | |
271 void | |
272 xnjsmb_init_stext_temp(void) { | |
273 Handle<FunctionTemplate> func_temp; | |
274 Handle<ObjectTemplate> inst_temp; | |
275 | |
276 func_temp = FunctionTemplate::New(xnjsmb_shape_stext); | |
277 func_temp->Inherit(xnjsmb_shape_temp); | |
278 func_temp->SetClassName(String::New("stext")); | |
279 | |
280 inst_temp = func_temp->InstanceTemplate(); | |
281 inst_temp->SetInternalFieldCount(1); | |
282 | |
283 xnjsmb_shape_stext_temp = Persistent<FunctionTemplate>::New(func_temp); | |
284 } | |
285 | |
286 /* @} */ | |
287 | |
195 /*! \brief Set properties of template of mb_rt. | 288 /*! \brief Set properties of template of mb_rt. |
196 */ | 289 */ |
197 void | 290 void |
198 xnjsmb_shapes_init_mb_rt_temp(Handle<FunctionTemplate> rt_temp) { | 291 xnjsmb_shapes_init_mb_rt_temp(Handle<FunctionTemplate> rt_temp) { |
199 Handle<FunctionTemplate> path_new_temp; | 292 HandleScope scope; |
293 Handle<FunctionTemplate> path_new_temp, stext_new_temp; | |
200 Handle<ObjectTemplate> rt_proto_temp; | 294 Handle<ObjectTemplate> rt_proto_temp; |
201 static int temp_init_flag = 0; | 295 static int temp_init_flag = 0; |
202 | 296 |
203 if(temp_init_flag == 0) { | 297 if(temp_init_flag == 0) { |
204 xnjsmb_init_shape_temp(); | 298 xnjsmb_init_shape_temp(); |
205 xnjsmb_init_path_temp(); | 299 xnjsmb_init_path_temp(); |
300 xnjsmb_init_stext_temp(); | |
206 temp_init_flag = 1; | 301 temp_init_flag = 1; |
207 } | 302 } |
208 | 303 |
209 rt_proto_temp = rt_temp->PrototypeTemplate(); | 304 rt_proto_temp = rt_temp->PrototypeTemplate(); |
210 | 305 |
211 path_new_temp = FunctionTemplate::New(xnjsmb_shape_path_new); | 306 path_new_temp = FunctionTemplate::New(xnjsmb_shape_path_new); |
212 SET(rt_proto_temp, "path_new", path_new_temp); | 307 SET(rt_proto_temp, "path_new", path_new_temp); |
213 } | 308 |
309 stext_new_temp = FunctionTemplate::New(xnjsmb_shape_stext_new); | |
310 SET(rt_proto_temp, "stext_new", stext_new_temp); | |
311 } |