# HG changeset patch # User Thinker K.F. Li # Date 1276092410 -28800 # Node ID a2faee809514a3f750acfd81e6a67a35457bdc32 # Parent dcd7adb2c0fc0b35c3c7e6fb9f8195f48c71d078 Implement stext type for Javascript diff -r dcd7adb2c0fc -r a2faee809514 nodejs/shapes.cc --- a/nodejs/shapes.cc Wed Jun 09 17:30:09 2010 +0800 +++ b/nodejs/shapes.cc Wed Jun 09 22:06:50 2010 +0800 @@ -192,17 +192,112 @@ /* @} */ +/*! \defgroup stext_path Template for stext objects. + * + * @{ + */ + +/*! \brief Constructor for stext objects. + * + * 4 arguments + * \param rt is a runtime object. + * \param data is a text to be showed. + * \param x is postion in x-axis. + * \param y is position in y-axis. + */ +static Handle +xnjsmb_shape_stext(const Arguments &args) { + int argc = args.Length(); + Handle self = args.This(); + Handle rt; + float x, y; + char *data; + redraw_man_t *rdman; + shape_t *stext; + + if(argc != 4) + THROW("Invalid number of arguments (!= 4)"); + if(!args[0]->IsObject() || !args[1]->IsString() || + !args[2]->IsNumber() || !args[3]->IsNumber()) + THROW("Invalid argument type"); + + rt = args[0]->ToObject(); + String::Utf8Value data_utf8(args[1]); + data = *data_utf8; + x = args[2]->ToNumber()->Value(); + y = args[3]->ToNumber()->Value(); + + rdman = xnjsmb_rt_rdman(rt); + ASSERT(rdman != NULL); + + stext = rdman_shape_stext_new(rdman, data, x, y); + + WRAP(self, stext); + SET(self, "mbrt", rt); + + return Null(); +} + +static Persistent xnjsmb_shape_stext_temp; + +/*! \brief Create a stext and return it. + */ +static Handle +xnjsmb_shape_stext_new(const Arguments &args) { + HandleScope scope; + int argc = args.Length(); + Handle self = args.This(); + Handle stext_args[4]; + Handle stext_obj; + Handle func; + + if(argc != 3) + THROW("Invalid number of arguments (!= 3)"); + + stext_args[0] = self; + stext_args[1] = args[0]; + stext_args[2] = args[1]; + stext_args[3] = args[2]; + + func = xnjsmb_shape_stext_temp->GetFunction(); + stext_obj = func->NewInstance(4, stext_args); + ASSERT(stext_obj != NULL); + + return stext_obj; +} + +/*! \brief Initialize function template for stext objects. + */ +void +xnjsmb_init_stext_temp(void) { + Handle func_temp; + Handle inst_temp; + + func_temp = FunctionTemplate::New(xnjsmb_shape_stext); + func_temp->Inherit(xnjsmb_shape_temp); + func_temp->SetClassName(String::New("stext")); + + inst_temp = func_temp->InstanceTemplate(); + inst_temp->SetInternalFieldCount(1); + + xnjsmb_shape_stext_temp = Persistent::New(func_temp); +} + +/* @} */ + /*! \brief Set properties of template of mb_rt. */ void xnjsmb_shapes_init_mb_rt_temp(Handle rt_temp) { - Handle path_new_temp; + HandleScope scope; + Handle path_new_temp, stext_new_temp; Handle rt_proto_temp; static int temp_init_flag = 0; if(temp_init_flag == 0) { xnjsmb_init_shape_temp(); xnjsmb_init_path_temp(); + xnjsmb_init_stext_temp(); temp_init_flag = 1; } @@ -210,4 +305,7 @@ path_new_temp = FunctionTemplate::New(xnjsmb_shape_path_new); SET(rt_proto_temp, "path_new", path_new_temp); + + stext_new_temp = FunctionTemplate::New(xnjsmb_shape_stext_new); + SET(rt_proto_temp, "stext_new", stext_new_temp); } diff -r dcd7adb2c0fc -r a2faee809514 nodejs/testcase.js --- a/nodejs/testcase.js Wed Jun 09 17:30:09 2010 +0800 +++ b/nodejs/testcase.js Wed Jun 09 22:06:50 2010 +0800 @@ -18,7 +18,7 @@ coord.add_shape(path); sys.puts(mb_rt.paint_color_new); -var paint = mb_rt.paint_color_new(1.0, 1.0, 1.0, 1.0); +var paint = mb_rt.paint_color_new(1, 1, 1, 1); sys.puts(paint); paint.stroke(path);