Mercurial > MadButterfly
changeset 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 | 6639d386db78 |
children | d796e6b8b97e |
files | nodejs/Makefile.am nodejs/mbfly_njs.cc nodejs/mbfly_njs.h nodejs/paints.cc nodejs/testcase.js nodejs/wscript |
diffstat | 6 files changed, 102 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/Makefile.am Tue Jun 08 09:08:23 2010 +0800 +++ b/nodejs/Makefile.am Wed Jun 09 12:28:03 2010 +0800 @@ -1,5 +1,5 @@ -mbfly_node_SRCS = mbfly_njs.cc X_supp_njs.c coord.cc shapes.cc +mbfly_node_SRCS = mbfly_njs.cc X_supp_njs.c coord.cc shapes.cc paints.cc mbfly_node_CFLAGS= -I$(abs_top_builddir)/include \ -I$(abs_top_srcdir)/include \ -I$(prefix)/include \
--- a/nodejs/mbfly_njs.cc Tue Jun 08 09:08:23 2010 +0800 +++ b/nodejs/mbfly_njs.cc Wed Jun 09 12:28:03 2010 +0800 @@ -106,7 +106,11 @@ func = FunctionTemplate::New(xnjsmb_coord_new); SET(rt_proto_temp, "coord_new", func); + /* + * Add properties to mb_rt templates for other modules. + */ xnjsmb_shapes_init_mb_rt_temp(mb_rt_func); + xnjsmb_paints_init_mb_rt_temp(mb_rt_func); target->Set(String::New("mb_rt"), mb_rt_func->GetFunction()); }
--- a/nodejs/mbfly_njs.h Tue Jun 08 09:08:23 2010 +0800 +++ b/nodejs/mbfly_njs.h Wed Jun 09 12:28:03 2010 +0800 @@ -26,5 +26,7 @@ /* From shapes.cc */ void xnjsmb_shapes_init_mb_rt_temp(v8::Handle<v8::FunctionTemplate> rt_temp); +/* From paints.cc */ +void xnjsmb_paints_init_mb_rt_temp(v8::Handle<v8::FunctionTemplate> rt_temp); #endif /* __MBFLY_NJS_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nodejs/paints.cc Wed Jun 09 12:28:03 2010 +0800 @@ -0,0 +1,92 @@ +#include <v8.h> + +extern "C" { +#include "mb.h" +} + +#include "mbfly_njs.h" + +using namespace v8; + + +/*! \brief Base type of all types of paints. + */ +static Handle<Value> +xnjsmb_paint(const Arguments &args) { +} + +/*! \brief Constructor of color paint_color_t object for Javascript. + */ +static Handle<Value> +xnjsmb_paint_color(const Arguments &args) { +} + +static Persistent<FunctionTemplate> paint_temp; +static Persistent<FunctionTemplate> paint_color_temp; + +/*! \brief Create and return a paint_color object. + */ +static Handle<Value> +xnjsmb_paint_color_new(const Arguments &args) { + HandleScope scope; + Handle<Object> rt = args.This(); + Handle<Object> paint_color_obj; + Handle<Function> paint_color_func; + Handle<Value> pc_args[4]; + int argc; + int i; + + argc = args.Length(); + if(argc != 4) + THROW("Invalid number of arguments (r, g, b, a)"); + for(i = 0; i < 4; i++) + if(!args[i]->IsNumber()) + THROW("Invalid argument type"); + + pc_args[0] = rt; + pc_args[1] = args[0]; // r + pc_args[2] = args[1]; // g + pc_args[3] = args[2]; // b + pc_args[4] = args[3]; // a + paint_color_func = paint_color_temp->GetFunction(); + paint_color_obj = paint_color_func->NewInstance(1, pc_args); + + scope.Close(paint_color_obj); + return paint_color_obj; +} + +static Persistent<FunctionTemplate> paint_color_new_temp; + +/*! \brief Create templates for paint types. + * + * This function is only called one time for every execution. + */ +static void +xnjsmb_init_paints(void) { + Handle<FunctionTemplate> temp; + + temp = FunctionTemplate::New(xnjsmb_paint); + paint_temp = Persistent<FunctionTemplate>::New(temp); + paint_temp->SetClassName(String::New("paint")); + + temp = FunctionTemplate::New(xnjsmb_paint_color); + paint_color_temp = Persistent<FunctionTemplate>::New(temp); + paint_color_temp->SetClassName(String::New("paint_color")); + paint_color_temp->Inherit(paint_temp); + + temp = FunctionTemplate::New(xnjsmb_paint_color_new); + paint_color_new_temp = Persistent<FunctionTemplate>::New(temp); +} + +void xnjsmb_paints_init_mb_rt_temp(Handle<FunctionTemplate> rt_temp) { + static int init_flag = 0; + Handle<ObjectTemplate> rt_proto_temp; + + if(!init_flag) { + xnjsmb_init_paints(); + init_flag = 1; + } + + rt_proto_temp = rt_temp->PrototypeTemplate(); + SET(rt_proto_temp, "paint_color_new", paint_color_new_temp); +}
--- a/nodejs/testcase.js Tue Jun 08 09:08:23 2010 +0800 +++ b/nodejs/testcase.js Wed Jun 09 12:28:03 2010 +0800 @@ -17,4 +17,6 @@ sys.puts(coord.add_shape); coord.add_shape(path); +sys.puts(mb_rt.paint_color_new); + setTimeout(function() { sys.puts("timeout"); }, 1000);
--- a/nodejs/wscript Tue Jun 08 09:08:23 2010 +0800 +++ b/nodejs/wscript Wed Jun 09 12:28:03 2010 +0800 @@ -23,7 +23,7 @@ obj = conf.new_task_gen('cxx', 'shlib', 'node_addon') obj.target = 'mbfly' - obj.source = 'mbfly_njs.cc coord.cc shapes.cc' + obj.source = 'mbfly_njs.cc coord.cc shapes.cc paints.cc' obj.add_objects = 'X_supp_njs.o' obj.staticlib = 'mbfly'