Mercurial > MadButterfly
changeset 676:f264b50c469c
Bind subject of mouse_event to JS object of coord
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 06 Aug 2010 13:33:47 +0800 |
parents | c643af2095c5 |
children | efa666d118e5 |
files | nodejs/mbfly_njs.cc nodejs/mbfly_njs.h nodejs/mbfly_njs.m4 nodejs/observer.cc nodejs/testcase.js |
diffstat | 5 files changed, 38 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/mbfly_njs.cc Fri Aug 06 00:56:26 2010 +0800 +++ b/nodejs/mbfly_njs.cc Fri Aug 06 13:33:47 2010 +0800 @@ -26,10 +26,12 @@ } static void -xnjsmb_coord_mod(Handle<Object> mbrt, Handle<Value> ret) { +xnjsmb_coord_new_mod(Handle<Object> mbrt, Handle<Value> ret) { Handle<Object> ret_obj = ret->ToObject(); Persistent<Object> *ret_obj_hdl; coord_t *coord; + subject_t *subject; + Handle<Value> subject_o; SET(ret_obj, "mbrt", mbrt); coord = (coord_t *)UNWRAP(ret_obj); @@ -38,6 +40,10 @@ */ ret_obj_hdl = new Persistent<Object>(ret_obj); mb_prop_set(&coord->obj.props, PROP_JSOBJ, ret_obj_hdl); + + subject = coord->mouse_event; + subject_o = export_xnjsmb_auto_subject_new(subject); + SET(ret_obj, "subject", subject_o); } #define xnjsmb_auto_coord_new export_xnjsmb_auto_coord_new @@ -62,6 +68,10 @@ _X_njs_MB_new(Handle<Object> self, char *display_name, int width, int height) { njs_runtime_t *obj; + coord_t *root; + subject_t *subject; + Handle<Object> root_o; + Handle<Value> subject_o; obj = X_njs_MB_new(display_name, width, height); WRAP(self, obj); /* mkroot need a wrapped object, but @@ -70,6 +80,12 @@ * here. */ X_njs_MB_init_handle_connection(obj); xnjsmb_coord_mkroot(self); + + root_o = GET(self, "root")->ToObject(); + root = (coord_t *)UNWRAP(root_o); + subject = root->mouse_event; + subject_o = export_xnjsmb_auto_subject_new(subject); + SET(root_o, "subject", subject_o); return obj; } @@ -125,6 +141,7 @@ xnjsmb_paints_init_mb_rt_temp(xnjsmb_auto_mb_rt_temp); xnjsmb_font_init_mb_rt_temp(xnjsmb_auto_mb_rt_temp); xnjsmb_img_ldr_init_mb_rt_temp(target); + xnjsmb_observer_init(); target->Set(String::New("mb_rt"), xnjsmb_auto_mb_rt_temp->GetFunction());
--- a/nodejs/mbfly_njs.h Fri Aug 06 00:56:26 2010 +0800 +++ b/nodejs/mbfly_njs.h Fri Aug 06 13:33:47 2010 +0800 @@ -42,4 +42,8 @@ void xnjsmb_img_ldr_init_mb_rt_temp(v8::Handle<v8::Object> mb_rt_temp); +/* From observer.cc */ +v8::Handle<v8::Value> export_xnjsmb_auto_subject_new(subject_t *subject); +void xnjsmb_observer_init(void); + #endif /* __MBFLY_NJS_H_ */
--- a/nodejs/mbfly_njs.m4 Fri Aug 06 00:56:26 2010 +0800 +++ b/nodejs/mbfly_njs.m4 Fri Aug 06 13:33:47 2010 +0800 @@ -4,7 +4,7 @@ STRUCT([mb_rt], [njs_runtime_t], [], [METHOD([coord_new], [xnjsmb_coord_new], (OBJ([parent], [coord], [coord_t]), ERR), 1, - [OBJ([coord], [coord_t])], (([MOD], xnjsmb_coord_mod))), + [OBJ([coord], [coord_t])], (([MOD], xnjsmb_coord_new_mod))), METHOD([redraw_changed], [xnjsmb_redraw_changed], (), 0, []), METHOD([redraw_all], [xnjsmb_redraw_all], (), 0, [])], ((CTOR, ([_X_njs_MB_new], (SELF, STR(display_name), INT(width), INT(height)), 3)))dnl
--- a/nodejs/observer.cc Fri Aug 06 00:56:26 2010 +0800 +++ b/nodejs/observer.cc Fri Aug 06 13:33:47 2010 +0800 @@ -93,6 +93,14 @@ data->func->Call(Context::GetCurrent()->Global(), 1, func_args); } +Handle<Value> +export_xnjsmb_auto_subject_new(subject_t *subject) { + Handle<Value> val; + + val = xnjsmb_auto_subject_new(subject); + return val; +} + void xnjsmb_observer_init(void) { xnjsmb_auto_observer_init();
--- a/nodejs/testcase.js Fri Aug 06 00:56:26 2010 +0800 +++ b/nodejs/testcase.js Fri Aug 06 13:33:47 2010 +0800 @@ -51,3 +51,10 @@ mb_rt.redraw_changed(); }, 20); setTimeout(function() { sys.puts("timeout"); }, 1000); + +sys.puts(root.subject); +var observer; +/* Mouse button pressed */ +observer = root.subject.add_event_observer(4, function() { + sys.puts("mouse"); + });