# HG changeset patch # User Thinker K.F. Li # Date 1276067429 -28800 # Node ID 49e79253b6d3efd73687ac202c9b791f0374faad # Parent f87a368e847aa472c32c3c4ac828555d31c0373c Functions of setting/getting stroke width of a shape diff -r f87a368e847a -r 49e79253b6d3 include/mb_types.h --- a/include/mb_types.h Wed Jun 09 14:44:20 2010 +0800 +++ b/include/mb_types.h Wed Jun 09 15:10:29 2010 +0800 @@ -400,6 +400,7 @@ #define sh_get_fill(sh) ((sh)->fill) #define sh_get_stroke(sh) ((sh)->stroke) #define sh_set_stroke_width(sh, v) do { (sh)->stroke_width = (v); } while(0) +#define sh_get_stroke_width(sh) (sh)->stroke_width /*! \brief A sprite is a set of graphics that being an object in animation. diff -r f87a368e847a -r 49e79253b6d3 nodejs/paints.cc --- a/nodejs/paints.cc Wed Jun 09 14:44:20 2010 +0800 +++ b/nodejs/paints.cc Wed Jun 09 15:10:29 2010 +0800 @@ -41,7 +41,9 @@ rdman = xnjsmb_rt_rdman(rt); rdman_paint_fill(rdman, paint, sh); - + + rdman_shape_changed(rdman, sh); + return Null(); } @@ -74,7 +76,9 @@ rdman = xnjsmb_rt_rdman(rt); rdman_paint_stroke(rdman, paint, sh); - + + rdman_shape_changed(rdman, sh); + return Null(); } diff -r f87a368e847a -r 49e79253b6d3 nodejs/shapes.cc --- a/nodejs/shapes.cc Wed Jun 09 14:44:20 2010 +0800 +++ b/nodejs/shapes.cc Wed Jun 09 15:10:29 2010 +0800 @@ -5,6 +5,10 @@ #include } +#ifndef ASSERT +#define ASSERT(x) +#endif + using namespace v8; /*! \defgroup shape_temp Templates for shape and derivations. @@ -37,6 +41,52 @@ return Null(); } +/*! \brief Get stroke width of a shape. + */ +static Handle +xnjsmb_shape_stroke_width_getter(Local property, + const AccessorInfo &info) { + Handle self = info.This(); + shape_t *sh; + float w; + Handle w_val; + + sh = (shape_t *)UNWRAP(self); + w = sh_get_stroke_width(sh); + w_val = Number::New(w); + + return w_val; +} + +/*! \brief Set stroke width of a shape. + */ +static void +xnjsmb_shape_stroke_width_setter(Local property, + Local value, + const AccessorInfo &info) { + Handle self = info.This(); + Handle rt; + shape_t *sh; + redraw_man_t *rdman; + float w; + Handle w_num; + + sh = (shape_t *)UNWRAP(self); + w_num = value->ToNumber(); + w = w_num->Value(); + + sh_set_stroke_width(sh, w); + + /* + * Mark changed. + */ + rt = GET(self, "mbrt")->ToObject(); + ASSERT(rt != NULL); + rdman = xnjsmb_rt_rdman(rt); + + rdman_shape_changed(rdman, sh); +} + static void xnjsmb_init_shape_temp(void) { Handle temp; @@ -52,6 +102,10 @@ SET(proto_temp, "show", method_temp); method_temp = FunctionTemplate::New(xnjsmb_shape_hide); SET(proto_temp, "hide", method_temp); + + proto_temp->SetAccessor(String::New("stroke_width"), + xnjsmb_shape_stroke_width_getter, + xnjsmb_shape_stroke_width_setter); } /* @} */ diff -r f87a368e847a -r 49e79253b6d3 nodejs/testcase.js --- a/nodejs/testcase.js Wed Jun 09 14:44:20 2010 +0800 +++ b/nodejs/testcase.js Wed Jun 09 15:10:29 2010 +0800 @@ -22,4 +22,8 @@ sys.puts(paint); paint.stroke(path); +sys.puts(path.stroke_width); +path.stroke_width = 2; +sys.puts(path.stroke_width); + setTimeout(function() { sys.puts("timeout"); }, 1000);