Mercurial > MadButterfly
changeset 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 |
files | nodejs/paints.cc nodejs/shapes.cc nodejs/testcase.js |
diffstat | 3 files changed, 80 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/paints.cc Wed Jun 09 14:10:58 2010 +0800 +++ b/nodejs/paints.cc Wed Jun 09 14:44:20 2010 +0800 @@ -13,6 +13,71 @@ #endif +/*! \brief Fill a shape with the paint. + */ +static Handle<Value> +xnjsmb_paint_fill(const Arguments &args) { + int argc = args.Length(); + Handle<Object> self = args.This(); + Handle<Object> sh_obj; + Handle<Object> rt; + Handle<Value> rt_val; + paint_t *paint; + shape_t *sh; + redraw_man_t *rdman; + + if(argc != 1) + THROW("Invalid number of arguments (!= 1)"); + if(!args[0]->IsObject()) + THROW("Invalid argument type (shape)"); + + paint = (paint_t *)UNWRAP(self); + + sh_obj = args[0]->ToObject(); + sh = (shape_t *)UNWRAP(sh_obj); + + rt_val = GET(self, "mbrt"); + rt = rt_val->ToObject(); + rdman = xnjsmb_rt_rdman(rt); + + rdman_paint_fill(rdman, paint, sh); + + return Null(); +} + +/*! \brief Stroke a shape with the paint. + */ +static Handle<Value> +xnjsmb_paint_stroke(const Arguments &args) { + int argc = args.Length(); + Handle<Object> self = args.This(); + Handle<Object> sh_obj; + Handle<Object> rt; + Handle<Value> rt_val, sh_val; + paint_t *paint; + shape_t *sh; + redraw_man_t *rdman; + + if(argc != 1) + THROW("Invalid number of arguments (!= 1)"); + if(!args[0]->IsObject()) + THROW("Invalid argument type (shape)"); + + paint = (paint_t *)UNWRAP(self); + + sh_val = args[0]; + sh_obj = sh_val->ToObject(); + sh = (shape_t *)UNWRAP(sh_obj); + + rt_val = GET(self, "mbrt"); + rt = rt_val->ToObject(); + rdman = xnjsmb_rt_rdman(rt); + + rdman_paint_stroke(rdman, paint, sh); + + return Null(); +} + /*! \brief Constructor of color paint_color_t object for Javascript. */ static Handle<Value> @@ -42,6 +107,7 @@ ASSERT(sh != NULL); WRAP(self, paint); + SET(self, "mbrt", rt); return Null(); } @@ -88,8 +154,9 @@ */ static void xnjsmb_init_paints(void) { - Handle<FunctionTemplate> temp; + Handle<FunctionTemplate> temp, meth; Handle<ObjectTemplate> inst_temp; + Handle<ObjectTemplate> proto_temp; /* * Base type of paint types. @@ -97,6 +164,14 @@ temp = FunctionTemplate::New(); xnjsmb_paint_temp = Persistent<FunctionTemplate>::New(temp); xnjsmb_paint_temp->SetClassName(String::New("paint")); + + meth = FunctionTemplate::New(xnjsmb_paint_fill); + proto_temp = xnjsmb_paint_temp->PrototypeTemplate(); + SET(proto_temp, "fill", meth); + + meth = FunctionTemplate::New(xnjsmb_paint_stroke); + proto_temp = xnjsmb_paint_temp->PrototypeTemplate(); + SET(proto_temp, "stroke", meth); /* * Paint color
--- a/nodejs/shapes.cc Wed Jun 09 14:10:58 2010 +0800 +++ b/nodejs/shapes.cc Wed Jun 09 14:44:20 2010 +0800 @@ -89,6 +89,7 @@ sh = rdman_shape_path_new(rdman, dstr); WRAP(self, sh); + SET(self, "mbrt", rt); return Null(); }
--- a/nodejs/testcase.js Wed Jun 09 14:10:58 2010 +0800 +++ b/nodejs/testcase.js Wed Jun 09 14:44:20 2010 +0800 @@ -12,13 +12,14 @@ [coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]]); sys.puts(mb_rt.path_new); -var path = mb_rt.path_new("m 100,100 L 200,200"); +var path = mb_rt.path_new("m 100,50 L 120,50 L 200,150 L 150,150 z"); sys.puts(path); sys.puts(coord.add_shape); coord.add_shape(path); sys.puts(mb_rt.paint_color_new); -var paint = mb_rt.paint_color_new(1, 1, 1, 1); +var paint = mb_rt.paint_color_new(1.0, 1.0, 1.0, 1.0); sys.puts(paint); +paint.stroke(path); setTimeout(function() { sys.puts("timeout"); }, 1000);