changeset 738:4f9773574234

Merge
author wycc
date Sat, 21 Aug 2010 19:14:49 +0800
parents 99186cce8cdd (current diff) d0ee92a96c47 (diff)
children 4916c3a3fe3c
files
diffstat 6 files changed, 165 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/nodejs/mbfly_njs.cc	Sat Aug 21 19:13:38 2010 +0800
+++ b/nodejs/mbfly_njs.cc	Sat Aug 21 19:14:49 2010 +0800
@@ -94,6 +94,8 @@
 #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
+#define xnjsmb_auto_paint_linear_new export_xnjsmb_auto_paint_linear_new
+#define xnjsmb_auto_paint_radial_new export_xnjsmb_auto_paint_radial_new
 
 #include "mbfly_njs-inc.h"
 
--- a/nodejs/mbfly_njs.h	Sat Aug 21 19:13:38 2010 +0800
+++ b/nodejs/mbfly_njs.h	Sat Aug 21 19:14:49 2010 +0800
@@ -53,8 +53,16 @@
 				const char **err);
 paint_t *xnjsmb_paint_image_new(njs_runtime_t *rt, mb_img_data_t *img,
 				const char **err);
+paint_t *xnjsmb_paint_linear_new(njs_runtime_t *rt,
+				 float x1, float y1, float x2, float y2,
+				 const char **err);
+paint_t *xnjsmb_paint_radial_new(njs_runtime_t *rt,
+				 float cx, float cy, float r,
+				 const char **err);
 v8::Handle<v8::Value> export_xnjsmb_auto_paint_color_new(paint_t *paint);
 v8::Handle<v8::Value> export_xnjsmb_auto_paint_image_new(paint_t *paint);
+v8::Handle<v8::Value> export_xnjsmb_auto_paint_linear_new(paint_t *sh);
+v8::Handle<v8::Value> export_xnjsmb_auto_paint_radial_new(paint_t *sh);
 
 /* From font.cc */
 void xnjsmb_font_init_mb_rt_temp(v8::Handle<v8::FunctionTemplate> mb_rt_temp);
--- a/nodejs/mbfly_njs.m4	Sat Aug 21 19:13:38 2010 +0800
+++ b/nodejs/mbfly_njs.m4	Sat Aug 21 19:14:49 2010 +0800
@@ -31,6 +31,14 @@
 	METHOD([paint_image_new], [xnjsmb_paint_image_new],
 	       (OBJ([img], [img_data], [mb_img_data_t]), ERR), 1,
 	       [OBJ([paint_image], [paint_t])],
+	       (([MOD], [xnjsmb_mb_rt_objs_mod]))),
+	METHOD([paint_linear_new], [xnjsmb_paint_linear_new],
+	       (NUMBER(x1), NUMBER(y1), NUMBER(x2), NUMBER(y2), ERR), 4,
+	       [OBJ([paint_linear], [paint_t])],
+	       (([MOD], [xnjsmb_mb_rt_objs_mod]))),
+	METHOD([paint_radial_new], [xnjsmb_paint_radial_new],
+	       (NUMBER(cx), NUMBER(cy), NUMBER(r), ERR), 3,
+	       [OBJ([paint_radial], [paint_t])],
 	       (([MOD], [xnjsmb_mb_rt_objs_mod])))],
 	((CTOR, ([_X_njs_MB_new], (SELF, STR(display_name), INT(width), INT(height)), 3)))dnl
 )
--- a/nodejs/paints.cc	Sat Aug 21 19:13:38 2010 +0800
+++ b/nodejs/paints.cc	Sat Aug 21 19:14:49 2010 +0800
@@ -66,6 +66,72 @@
     rdman_paint_changed(rdman, paint);
 }
 
+/*! \brief Set stops for linear paint for Javascript code.
+ */
+static void
+xnjsmb_paint_linear_set_stops(paint_t *paint, Handle<Value> stops) {
+    Array *stops_o;
+    Array *stop_o;
+    int nstops;
+    grad_stop_t *grad_stops, *old_grad_stops;
+    int i;
+
+    stops_o = Array::Cast(*stops);
+    nstops = stops_o->Length();
+    grad_stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * nstops);
+    ASSERT(grad_stops != NULL);
+
+    for(i = 0; i < nstops; i++) {
+	stop_o = Array::Cast(*stops_o->Get(i));
+	ASSERT(stop_o->Length() == 5);
+	grad_stop_init(grad_stops + i,
+		       stop_o->Get(0)->ToNumber()->Value(),  /* off */
+		       stop_o->Get(1)->ToNumber()->Value(),  /* r */
+		       stop_o->Get(2)->ToNumber()->Value(),  /* g */
+		       stop_o->Get(3)->ToNumber()->Value(),  /* b */
+		       stop_o->Get(4)->ToNumber()->Value()); /* a */
+    }
+    
+    old_grad_stops = paint_linear_stops(paint, nstops, grad_stops);
+    if(old_grad_stops)
+	free(old_grad_stops);	/* The stops, here, were allocated for
+				 * previous calling of this
+				 * function. */
+}
+
+/*! \brief Set stops for radial paint for Javascript code.
+ */
+static void
+xnjsmb_paint_radial_set_stops(paint_t *paint, Handle<Value> stops) {
+    Array *stops_o;
+    Array *stop_o;
+    int nstops;
+    grad_stop_t *grad_stops, *old_grad_stops;
+    int i;
+
+    stops_o = Array::Cast(*stops);
+    nstops = stops_o->Length();
+    grad_stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * nstops);
+    ASSERT(grad_stops != NULL);
+
+    for(i = 0; i < nstops; i++) {
+	stop_o = Array::Cast(*stops_o->Get(i));
+	ASSERT(stop_o->Length() == 5);
+	grad_stop_init(grad_stops + i,
+		       stop_o->Get(0)->ToNumber()->Value(),  /* off */
+		       stop_o->Get(1)->ToNumber()->Value(),  /* r */
+		       stop_o->Get(2)->ToNumber()->Value(),  /* g */
+		       stop_o->Get(3)->ToNumber()->Value(),  /* b */
+		       stop_o->Get(4)->ToNumber()->Value()); /* a */
+    }
+    
+    old_grad_stops = paint_radial_stops(paint, nstops, grad_stops);
+    if(old_grad_stops)
+	free(old_grad_stops);	/* The stops, here, were allocated for
+				 * previous calling of this
+				 * function. */
+}
+
 #include "paints-inc.h"
 
 /*! \defgroup xnjsmb_paints_cons Constructor of paints
@@ -105,6 +171,40 @@
     return paint;
 }
 
+paint_t *
+xnjsmb_paint_linear_new(njs_runtime_t *rt,
+			float x1, float y1, float x2, float y2,
+			const char **err) {
+    paint_t *paint;
+    redraw_man_t *rdman;
+
+    rdman = X_njs_MB_rdman(rt);
+    paint = rdman_paint_linear_new(rdman, x1, y1, x2, y2);
+    if(paint == NULL) {
+	*err = "can not allocate a paint_linear_t";
+	return NULL;
+    }
+
+    return paint;
+}
+
+paint_t *
+xnjsmb_paint_radial_new(njs_runtime_t *rt,
+			float cx, float cy, float r,
+			const char **err) {
+    paint_t *paint;
+    redraw_man_t *rdman;
+
+    rdman = X_njs_MB_rdman(rt);
+    paint = rdman_paint_radial_new(rdman, cx, cy, r);
+    if(paint == NULL) {
+	*err = "can not allocate a paint_radial_t";
+	return NULL;
+    }
+
+    return paint;
+}
+
 /* @} */
 
 /*! \defgroup xnjsmb_paints_export Exported wrapper maker for paints
@@ -131,6 +231,24 @@
     
     return ret;
 }
+
+Handle<Value>
+export_xnjsmb_auto_paint_linear_new(paint_t *paint) {
+    Handle<Value> ret;
+    
+    ret = xnjsmb_auto_paint_linear_new(paint);
+    
+    return ret;
+}
+
+Handle<Value>
+export_xnjsmb_auto_paint_radial_new(paint_t *paint) {
+    Handle<Value> ret;
+    
+    ret = xnjsmb_auto_paint_radial_new(paint);
+    
+    return ret;
+}
 /* @} */
 
 /*! \brief Initialize paints for mbfly.
@@ -146,6 +264,8 @@
 	xnjsmb_auto_paint_init();
 	xnjsmb_auto_paint_color_init();
 	xnjsmb_auto_paint_image_init();
+	xnjsmb_auto_paint_linear_init();
+	xnjsmb_auto_paint_radial_init();
 	
 	init_flag = 1;
     }
--- a/nodejs/paints.m4	Sat Aug 21 19:13:38 2010 +0800
+++ b/nodejs/paints.m4	Sat Aug 21 19:14:49 2010 +0800
@@ -15,3 +15,13 @@
 STRUCT([paint_image], [paint_t], [],
        [],
        (([INHERIT], [paint])))
+
+STRUCT([paint_linear], [paint_t], [],
+       [METHOD([set_stops], [xnjsmb_paint_linear_set_stops],
+       (ARRAY([stops])), 1, [])],
+       (([INHERIT], [paint])))
+
+STRUCT([paint_radial], [paint_t], [],
+       [METHOD([set_stops], [xnjsmb_paint_radial_set_stops],
+       (ARRAY([stops])), 1, [])],
+       (([INHERIT], [paint])))
--- a/nodejs/testcase.js	Sat Aug 21 19:13:38 2010 +0800
+++ b/nodejs/testcase.js	Sat Aug 21 19:14:49 2010 +0800
@@ -19,6 +19,22 @@
 paint.fill(img);
 root.add_shape(img);
 
+/* test linear paint and rectangle */
+var rect = mb_rt.rect_new(100, 100, 50, 50, 10, 10);
+sys.puts(mb_rt.paint_linear_new);
+var paint = mb_rt.paint_linear_new(100, 100, 150, 150);
+paint.set_stops([[0, 0, 1, 0, 1], [1, 0, 0, 1, 1]]);
+paint.fill(rect);
+root.add_shape(rect);
+
+/* test radial paint and rectangle */
+var rect = mb_rt.rect_new(150, 100, 50, 50, 10, 10);
+sys.puts(mb_rt.paint_radial_new);
+var paint = mb_rt.paint_radial_new(175, 125, 25);
+paint.set_stops([[0, 0, 1, 0, 1], [1, 0, 0, 1, 1]]);
+paint.fill(rect);
+root.add_shape(rect);
+
 /* test alpha blending and rectangle */
 var rect = mb_rt.rect_new(40, 40, 100, 100, 10, 10);
 sys.puts(mb_rt.paint_color_new);
@@ -57,7 +73,7 @@
 	var deg = (i++) * 0.1;
 	coord[2] = (i % 40) * 5;
 	mb_rt.redraw_changed();
-	//mb_rt.flush();
+	mb_rt.flush();
     }, 20);
 setTimeout(function() { sys.puts("timeout"); }, 1000);