changeset 570:49e79253b6d3 Android_Skia

Functions of setting/getting stroke width of a shape
author Thinker K.F. Li <thinker@branda.to>
date Wed, 09 Jun 2010 15:10:29 +0800
parents f87a368e847a
children 13b15b7a463b
files include/mb_types.h nodejs/paints.cc nodejs/shapes.cc nodejs/testcase.js
diffstat 4 files changed, 65 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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.
--- 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();
 }
 
--- 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 <mb.h>
 }
 
+#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<Value>
+xnjsmb_shape_stroke_width_getter(Local<String> property,
+				 const AccessorInfo &info) {
+    Handle<Object> self = info.This();
+    shape_t *sh;
+    float w;
+    Handle<Value> 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<String> property,
+				 Local<Value> value,
+				 const AccessorInfo &info) {
+    Handle<Object> self = info.This();
+    Handle<Object> rt;
+    shape_t *sh;
+    redraw_man_t *rdman;
+    float w;
+    Handle<Number> 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<FunctionTemplate> 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);
 }
 
 /* @} */
--- 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);