# HG changeset patch # User Thinker K.F. Li # Date 1276069164 -28800 # Node ID 13b15b7a463bbf70591aba2206fc14819494aafc # Parent 49e79253b6d3efd73687ac202c9b791f0374faad Redraw all and changed in Javascript diff -r 49e79253b6d3 -r 13b15b7a463b nodejs/X_supp_njs.c --- a/nodejs/X_supp_njs.c Wed Jun 09 15:10:29 2010 +0800 +++ b/nodejs/X_supp_njs.c Wed Jun 09 15:39:24 2010 +0800 @@ -115,6 +115,17 @@ free(rt); } +int +X_njs_MB_flush(njs_runtime_t *rt) { + void *xrt = rt->xrt; + int r; + extern int _X_MB_flush_x_conn_for_nodejs(void *rt); + + _X_MB_flush_x_conn_for_nodejs(xrt); + + return r; +} + njs_runtime_t * X_njs_MB_new(char *display_name, int w, int h) { njs_runtime_t *rt; diff -r 49e79253b6d3 -r 13b15b7a463b nodejs/X_supp_njs.h --- a/nodejs/X_supp_njs.h Wed Jun 09 15:10:29 2010 +0800 +++ b/nodejs/X_supp_njs.h Wed Jun 09 15:39:24 2010 +0800 @@ -14,6 +14,7 @@ extern void X_njs_MB_init_handle_connection(njs_runtime_t *rt); extern void X_njs_MB_free(njs_runtime_t *rt); extern njs_runtime_t *X_njs_MB_new(char *display_name, int w, int h); +extern int X_njs_MB_flush(njs_runtime_t *rt); extern void *_X_njs_MB_get_X_runtime(njs_runtime_t *rt); #define X_njs_MB_kbevents(rt) X_MB_kbevents((rt)->xrt) diff -r 49e79253b6d3 -r 13b15b7a463b nodejs/mbfly_njs.cc --- a/nodejs/mbfly_njs.cc Wed Jun 09 15:10:29 2010 +0800 +++ b/nodejs/mbfly_njs.cc Wed Jun 09 15:39:24 2010 +0800 @@ -61,6 +61,36 @@ xnjsmb_handle_connection(const Arguments &args) { } +static Handle +xnjsmb_rt_redraw_changed(const Arguments &args) { + Handle self = args.This(); + njs_runtime_t *rt; + redraw_man_t *rdman; + + rdman = xnjsmb_rt_rdman(self); + rdman_redraw_changed(rdman); + + rt = (njs_runtime_t *)UNWRAP(self); + X_njs_MB_flush(rt); + + return Null(); +} + +static Handle +xnjsmb_rt_redraw_all(const Arguments &args) { + Handle self = args.This(); + njs_runtime_t *rt; + redraw_man_t *rdman; + + rdman = xnjsmb_rt_rdman(self); + rdman_redraw_all(rdman); + + rt = (njs_runtime_t *)UNWRAP(self); + X_njs_MB_flush(rt); + + return Null(); +} + /* @} */ /*! \brief Get rdman associated with the runtime. @@ -106,6 +136,12 @@ func = FunctionTemplate::New(xnjsmb_coord_new); SET(rt_proto_temp, "coord_new", func); + func = FunctionTemplate::New(xnjsmb_rt_redraw_changed); + SET(rt_proto_temp, "redraw_changed", func); + + func = FunctionTemplate::New(xnjsmb_rt_redraw_all); + SET(rt_proto_temp, "redraw_all", func); + /* * Add properties to mb_rt templates for other modules. */ diff -r 49e79253b6d3 -r 13b15b7a463b nodejs/testcase.js --- a/nodejs/testcase.js Wed Jun 09 15:10:29 2010 +0800 +++ b/nodejs/testcase.js Wed Jun 09 15:39:24 2010 +0800 @@ -12,7 +12,7 @@ [coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]]); sys.puts(mb_rt.path_new); -var path = mb_rt.path_new("m 100,50 L 120,50 L 200,150 L 150,150 z"); +var path = mb_rt.path_new("m 100,50 L 120,50 L 200,150 L 180,150 z"); sys.puts(path); sys.puts(coord.add_shape); coord.add_shape(path); @@ -26,4 +26,12 @@ path.stroke_width = 2; sys.puts(path.stroke_width); +mb_rt.redraw_all(); + +var i = 0; +setInterval(function() { + var deg = (i++) * 0.1; + coord[2] = (i % 20) * 10; + mb_rt.redraw_changed(); + }, 50); setTimeout(function() { sys.puts("timeout"); }, 1000);