changeset 690:86c6ebf1de25

Add JS binding for sh_rect_t
author Thinker K.F. Li <thinker@branda.to>
date Sat, 07 Aug 2010 23:00:16 +0800
parents a05a4a27ff46
children 05a453e07d01 763a4e2bbd85
files nodejs/mbfly_njs.cc nodejs/mbfly_njs.h nodejs/mbfly_njs.m4 nodejs/shapes.cc nodejs/shapes.m4 nodejs/testcase.js
diffstat 6 files changed, 64 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/nodejs/mbfly_njs.cc	Sat Aug 07 22:33:02 2010 +0800
+++ b/nodejs/mbfly_njs.cc	Sat Aug 07 23:00:16 2010 +0800
@@ -91,6 +91,7 @@
 #define xnjsmb_auto_path_new export_xnjsmb_auto_path_new
 #define xnjsmb_auto_stext_new export_xnjsmb_auto_stext_new
 #define xnjsmb_auto_image_new export_xnjsmb_auto_image_new
+#define xnjsmb_auto_rect_new export_xnjsmb_auto_rect_new
 #define xnjsmb_auto_paint_color_new export_xnjsmb_auto_paint_color_new
 #define xnjsmb_auto_paint_image_new export_xnjsmb_auto_paint_image_new
 
--- a/nodejs/mbfly_njs.h	Sat Aug 07 22:33:02 2010 +0800
+++ b/nodejs/mbfly_njs.h	Sat Aug 07 23:00:16 2010 +0800
@@ -38,9 +38,13 @@
 			  float x, float y);
 shape_t *xnjsmb_image_new(njs_runtime_t *rt, float x, float y,
 			  float w, float h);
+shape_t *xnjsmb_rect_new(njs_runtime_t *rt, float x, float y,
+			 float w, float h,
+			 float rx, float ry, const char **err);
 v8::Handle<v8::Value> export_xnjsmb_auto_path_new(shape_t *sh);
 v8::Handle<v8::Value> export_xnjsmb_auto_stext_new(shape_t *sh);
 v8::Handle<v8::Value> export_xnjsmb_auto_image_new(shape_t *sh);
+v8::Handle<v8::Value> export_xnjsmb_auto_rect_new(shape_t *sh);
 
 /* From paints.cc */
 void xnjsmb_paints_init_mb_rt_temp(v8::Handle<v8::FunctionTemplate> rt_temp);
--- a/nodejs/mbfly_njs.m4	Sat Aug 07 22:33:02 2010 +0800
+++ b/nodejs/mbfly_njs.m4	Sat Aug 07 23:00:16 2010 +0800
@@ -18,6 +18,11 @@
 	       (NUMBER(x), NUMBER(y), NUMBER(w), NUMBER(h)), 4,
 	       [OBJ([image], [shape_t])],
 	       (([MOD], [xnjsmb_mb_rt_objs_mod]))),
+	METHOD([rect_new], [xnjsmb_rect_new],
+	       (NUMBER(x), NUMBER(y), NUMBER(w), NUMBER(h),
+	        NUMBER(rx), NUMBER(ry), ERR), 6,
+	       [OBJ([rect], [shape_t])],
+	       (([MOD], [xnjsmb_mb_rt_objs_mod]))),
 	METHOD([paint_color_new], [xnjsmb_paint_color_new],
 	       (NUMBER(r), NUMBER(g), NUMBER(b), NUMBER(a), ERR), 4,
 	       [OBJ([paint_color], [paint_t])],
--- a/nodejs/shapes.cc	Sat Aug 07 22:33:02 2010 +0800
+++ b/nodejs/shapes.cc	Sat Aug 07 23:00:16 2010 +0800
@@ -89,6 +89,25 @@
 	rdman_shape_changed(rdman, sh);
 }
 
+static void
+xnjsmb_sh_rect_set(shape_t *sh, Handle<Object> self, float x, float y,
+		   float w, float h, float rx, float ry) {
+    Handle<Object> rt;
+    redraw_man_t *rdman;
+    
+    sh_rect_set(sh, x, y, w, h, rx, ry);
+    
+    /*
+     * Mark changed.
+     */
+    rt = GET(self, "mbrt")->ToObject();
+    ASSERT(rt != NULL);
+    rdman = xnjsmb_rt_rdman(rt);
+    
+    if(sh_get_coord(sh))
+	rdman_shape_changed(rdman, sh);
+}
+
 /* @} */
 
 #include "shapes-inc.h"
@@ -116,6 +135,11 @@
     return xnjsmb_auto_image_new(sh);
 }
 
+Handle<Value>
+export_xnjsmb_auto_rect_new(shape_t *sh) {
+    return xnjsmb_auto_rect_new(sh);
+}
+
 /* @} */
 
 /*! \defgroup xnjsmb_shapes_cons Constructor of shapes
@@ -156,6 +180,22 @@
     return sh;
 }
 
+shape_t *
+xnjsmb_rect_new(njs_runtime_t *rt, float x, float y, float w, float h,
+		float rx, float ry, const char **err) {
+    redraw_man_t *rdman;
+    shape_t *sh;
+
+    rdman = X_njs_MB_rdman(rt);
+    sh = rdman_shape_rect_new(rdman, x, y, w, h, rx, ry);
+    if(sh == NULL) {
+	*err = "Can not create a sh_rect_t";
+	return NULL;
+    }
+
+    return sh;
+}
+
 /* @} */
 
 /*! \brief Set properties of template of mb_rt.
@@ -174,6 +214,7 @@
 	xnjsmb_auto_path_init();
 	xnjsmb_auto_stext_init();
 	xnjsmb_auto_image_init();
+	xnjsmb_auto_rect_init();
 	temp_init_flag = 1;
     }
     return;
--- a/nodejs/shapes.m4	Sat Aug 07 22:33:02 2010 +0800
+++ b/nodejs/shapes.m4	Sat Aug 07 23:00:16 2010 +0800
@@ -16,3 +16,9 @@
        (([INHERIT], [shape])))
 
 STRUCT([image], [shape_t], [], [], (([INHERIT], [shape])))
+
+STRUCT([rect], [shape_t], [],
+       [METHOD([set], [xnjsmb_sh_rect_set],
+	       (SELF, NUMBER(x), NUMBER(y), NUMBER(w), NUMBER(h),
+	        NUMBER(rx), NUMBER(ry)), 6, [])],
+       (([INHERIT], [shape])))
--- a/nodejs/testcase.js	Sat Aug 07 22:33:02 2010 +0800
+++ b/nodejs/testcase.js	Sat Aug 07 23:00:16 2010 +0800
@@ -19,6 +19,13 @@
 paint.fill(img);
 root.add_shape(img);
 
+/* test alpha blending and rectangle */
+var rect = mb_rt.rect_new(40, 40, 100, 100, 10, 10);
+sys.puts(mb_rt.paint_color_new);
+var paint = mb_rt.paint_color_new(1, 0.5, 0.5, 0.5);
+paint.fill(rect);
+root.add_shape(rect);
+
 /* Moving a path */
 sys.puts(mb_rt.path_new);
 var path = mb_rt.path_new("m 100,50 L 120,50 L 200,150 L 180,150 z");