# HG changeset patch # User Thinker K.F. Li # Date 1281519524 -28800 # Node ID 0b98bdc53215e482a73bee35a418eba6bf971688 # Parent 32e1b8005403ef22a491e71e522d12de69a01f4a Add binding for color changing of paint_color_t in JS diff -r 32e1b8005403 -r 0b98bdc53215 nodejs/paints.cc --- 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 self, + float r, float g, float b, float a) { + Handle rt_v; + Handle 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); - */ } /* @} */ diff -r 32e1b8005403 -r 0b98bdc53215 nodejs/paints.m4 --- 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], [], diff -r 32e1b8005403 -r 0b98bdc53215 nodejs/testcase.js --- 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;