changeset 699:0b98bdc53215

Add binding for color changing of paint_color_t in JS
author Thinker K.F. Li <thinker@branda.to>
date Wed, 11 Aug 2010 17:38:44 +0800
parents 32e1b8005403
children 8f49e0235097
files nodejs/paints.cc nodejs/paints.m4 nodejs/testcase.js
diffstat 3 files changed, 28 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/nodejs/paints.cc	Wed Aug 11 17:37:39 2010 +0800
+++ b/nodejs/paints.cc	Wed Aug 11 17:38:44 2010 +0800
@@ -50,6 +50,22 @@
 	rdman_shape_changed(rdman, sh);
 }
 
+static void
+xnjsmb_paint_color_set_color(paint_t *paint, Handle<Object> self,
+			     float r, float g, float b, float a) {
+    Handle<Value> rt_v;
+    Handle<Object> rt_o;
+    redraw_man_t *rdman;
+
+    rt_v = GET(self, "mbrt");
+    rt_o = rt_v->ToObject();
+    rdman = xnjsmb_rt_rdman(rt_o);
+
+    paint_color_set(paint, r, g, b, a);
+
+    rdman_paint_changed(rdman, paint);
+}
+
 #include "paints-inc.h"
 
 /*! \defgroup xnjsmb_paints_cons Constructor of paints
@@ -131,14 +147,8 @@
 	xnjsmb_auto_paint_color_init();
 	xnjsmb_auto_paint_image_init();
 	
-	/* xnjsmb_init_paints(); */
 	init_flag = 1;
     }
-    /*
-    rt_proto_temp = rt_temp->PrototypeTemplate();
-    SET(rt_proto_temp, "paint_color_new", xnjsmb_paint_color_new_temp);
-    SET(rt_proto_temp, "paint_image_new", xnjsmb_paint_image_new_temp);
-    */
 }
 
 /* @} */
--- a/nodejs/paints.m4	Wed Aug 11 17:37:39 2010 +0800
+++ b/nodejs/paints.m4	Wed Aug 11 17:38:44 2010 +0800
@@ -7,7 +7,9 @@
 	       (SELF, OBJ([sh], [shape], [shape_t])), 1, [])])
 
 STRUCT([paint_color], [paint_t], [],
-       [],
+       [METHOD([set_color], [xnjsmb_paint_color_set_color],
+       	       (SELF, NUMBER([r]), NUMBER([g]), NUMBER([b]), NUMBER([a])),
+	       4, [])],
        (([INHERIT], [paint])))
 
 STRUCT([paint_image], [paint_t], [],
--- a/nodejs/testcase.js	Wed Aug 11 17:37:39 2010 +0800
+++ b/nodejs/testcase.js	Wed Aug 11 17:38:44 2010 +0800
@@ -10,7 +10,6 @@
 var coord = mb_rt.coord_new(root);
 sys.puts("coord matrix: " + 
 	 [coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]]);
-sys.puts('coord='+coord);
 
 /* Testcase for image shapes */
 var img = mb_rt.image_new(10, 10, 50, 50);
@@ -55,7 +54,7 @@
 var i = 0;
 setInterval(function() {
 	var deg = (i++) * 0.1;
-	coord[2] = (i % 20) * 10;
+	coord[2] = (i % 40) * 5;
 	mb_rt.redraw_changed();
 	mb_rt.flush();
     }, 20);
@@ -65,7 +64,15 @@
 var observer;
 /* Mouse button pressed */
 observer = root.mouse_event.add_event_observer(4, function(evt) {
+	var c = 1 - (i % 40) / 40;
+	sys.puts(c);
+
 	sys.puts("mouse " + evt.x + " " + evt.y);
+	sys.puts(c);
+	sys.puts(paint.set_color);
+	paint.set_color(c, 1, 1, 1);
+	mb_rt.redraw_changed();
+	mb_rt.flush();
     });
 
 var kbobserver;