Mercurial > MadButterfly
changeset 231:2637519e2bd7
Move mouse event handler and interpreter to src/mouse.c.
- Also change makefiles of examples with a better configuration.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 18 Dec 2008 22:37:15 +0800 |
parents | 3e6da6f6a226 |
children | 527894c2ad39 |
files | examples/calculator/Makefile.am examples/dynamic/Makefile.am examples/tank/Makefile.am include/mb_redraw_man.h src/Makefile.am src/mouse.c src/redraw_man.c |
diffstat | 7 files changed, 111 insertions(+), 94 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/calculator/Makefile.am Wed Dec 17 21:37:39 2008 +0800 +++ b/examples/calculator/Makefile.am Thu Dec 18 22:37:15 2008 +0800 @@ -5,7 +5,7 @@ calc_SOURCES = main.c nodist_calc_SOURCES = calculator_scr.c calculator_scr.h -calc_CPPFLAGS = @cairo_CFLAGS@ -I$(top_srcdir) +calc_CPPFLAGS = @cairo_CFLAGS@ $(INCLUDES) calc_LDFLAGS = @cairo_LIBS@ calc_LDADD = $(top_builddir)/src/libmbfly.la BUILT_SOURCES = calculator_scr.c calculator_scr.h calculator_scr.mb
--- a/examples/dynamic/Makefile.am Wed Dec 17 21:37:39 2008 +0800 +++ b/examples/dynamic/Makefile.am Thu Dec 18 22:37:15 2008 +0800 @@ -5,12 +5,11 @@ dynamic_SOURCES = main.c nodist_dynamic_SOURCES = menu.c menu.h menu.mb button.c button.h button.mb -dynamic_CPPFLAGS = @cairo_CFLAGS@ -I$(top_srcdir) +CPPFLAGS = @cairo_CFLAGS@ $(INCLUDES) dynamic_LDFLAGS = @cairo_LIBS@ dynamic_LDADD = $(top_builddir)/src/libmbfly.la BUILT_SOURCES = menu.c menu.h menu.mb button.c button.h button.mb CLEANFILES = menu.c menu.h menu.mb button.c button.h button.mb -INCLUDES= @cairo_CFLAGS@ -I$(top_srcdir) menu.mb: $(srcdir)/menu.svg $(top_srcdir)/tools/svg2code.py $? $@
--- a/examples/tank/Makefile.am Wed Dec 17 21:37:39 2008 +0800 +++ b/examples/tank/Makefile.am Thu Dec 18 22:37:15 2008 +0800 @@ -7,7 +7,7 @@ tank_SOURCES = tank_main.c nodist_tank_SOURCES = svgs.h \ $(svg_sources) $(svg_sources:.c=.h) $(svg_sources:.c=.mb) -tank_CPPFLAGS = @cairo_CFLAGS@ -I$(top_srcdir) +tank_CPPFLAGS = @cairo_CFLAGS@ tank_LDFLAGS = @cairo_LIBS@ tank_LDADD = $(top_builddir)/src/libmbfly.la BUILT_SOURCES = svgs.h \
--- a/include/mb_redraw_man.h Wed Dec 17 21:37:39 2008 +0800 +++ b/include/mb_redraw_man.h Thu Dec 18 22:37:15 2008 +0800 @@ -71,6 +71,7 @@ subject_t *redraw; /*!< \brief Notified after redrawing. */ subject_t *addrm_monitor; /*!< \brief Monitor adding/removing observers * to/from mouse event subjects. + * \see addrm_monitor_hdlr() */ mb_obj_t *last_mouse_over; };
--- a/src/Makefile.am Wed Dec 17 21:37:39 2008 +0800 +++ b/src/Makefile.am Thu Dec 18 22:37:15 2008 +0800 @@ -7,7 +7,8 @@ libmbfly_la_SOURCES = animate.c chgcolor.c coord.c event.c geo.c \ observer.c paint.c redraw_man.c rotate.c shape_path.c \ shape_rect.c shape_text.c shift.c subtree_free.c timer.c \ - timertool.c tools.c visibility.c X_supp.c prop.c sprite.c + timertool.c tools.c visibility.c X_supp.c prop.c sprite.c \ + mouse.c libmbfly_la_CPPFLAGS = @cairo_CFLAGS@ libmbfly_la_LDFLAGS = @cairo_LIBS@
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/mouse.c Thu Dec 18 22:37:15 2008 +0800 @@ -0,0 +1,104 @@ +#include "mb_types.h" +#include "mb_redraw_man.h" + +#define ASSERT(x) + +static void mouse_event_interpreter(event_t *evt, void *arg) { + mouse_event_t *mevt = (mouse_event_t *)evt; + redraw_man_t *rdman = (redraw_man_t *)arg; + mb_obj_t *obj; + mouse_event_t new_evt; + coord_t *coord; + shape_t *shape; + + ASSERT(evt->type == EVT_MOUSE_MOVE_RAW); + + obj = (mb_obj_t *)subject_get_object(evt->cur_tgt); + if(rdman->last_mouse_over == obj) { + evt->type = EVT_MOUSE_MOVE; + return; + } + + new_evt.x = mevt->x; + new_evt.y = mevt->y; + new_evt.but_state = mevt->but_state; + new_evt.button = mevt->button; + + if(rdman->last_mouse_over != NULL) { + new_evt.event.type = EVT_MOUSE_OUT; + if(IS_MBO_COORD(rdman->last_mouse_over)) { + coord = (coord_t *)rdman->last_mouse_over; + subject_notify(coord->mouse_event, (event_t *)&new_evt); + } else if(IS_MBO_SHAPES(rdman->last_mouse_over)) { + shape = (shape_t *)rdman->last_mouse_over; + ASSERT(shape->geo != NULL); + subject_notify(shape->geo->mouse_event, (event_t *)&new_evt); + } + } + + new_evt.event.type = EVT_MOUSE_OVER; + subject_notify(evt->cur_tgt, (event_t *)&new_evt); + rdman->last_mouse_over = obj; + + evt->flags |= EVTF_STOP_NOTIFY; +} + +/*! \brief This is event handler that observes addrm_monitor subject. + * + * addrm_monitor subject is a member of redraw manager objects. + * Monitor of mouse event subjects of mb_obj_t objects are set to this + * subject by redraw manager. + * + * addrm_monitor_hdlr() monitor adding and removing observers of mouse + * event subjects, and install special observers to these subjects to handle + * and interpret mouse events (EVT_MOUSE_MOVE_RAW). + */ +void addrm_monitor_hdlr(event_t *evt, void *arg) { + monitor_event_t *mevt; + redraw_man_t *rdman; + mb_obj_t *obj; + mb_prop_store_t *props; + observer_t *observer; + int cnt = 0; + + mevt = (monitor_event_t *)evt; + rdman = (redraw_man_t *)evt->tgt; + obj = (mb_obj_t *)subject_get_object(mevt->subject); + props = mb_obj_prop_store(obj); + + switch(evt->type) { + case EVT_MONITOR_ADD: + if(!mb_prop_has(props, PROP_MEVT_OB_CNT)) + cnt = 0; + else + cnt = (int)mb_prop_get(props, PROP_MEVT_OB_CNT); + + cnt++; + mb_prop_set(props, PROP_MEVT_OB_CNT, (void *)cnt); + if(cnt == 1) { + observer = + subject_add_event_observer_head(mevt->subject, + EVT_MOUSE_MOVE_RAW, + mouse_event_interpreter, + rdman); + ASSERT(observer != NULL); + mb_prop_set(props, PROP_MEVT_OBSERVER, observer); + } + break; + + case EVT_MONITOR_REMOVE: + cnt = (int)mb_prop_get(props, PROP_MEVT_OB_CNT); + cnt--; + mb_prop_set(props, PROP_MEVT_OB_CNT, (void *)cnt); + if(cnt == 1) { + observer = (observer_t *)mb_prop_get(props, PROP_MEVT_OBSERVER); + subject_remove_observer(mevt->subject, observer); + mb_prop_del(props, PROP_MEVT_OBSERVER); + } + break; + + case EVT_MONITOR_FREE: + break; + } +} +
--- a/src/redraw_man.c Wed Dec 17 21:37:39 2008 +0800 +++ b/src/redraw_man.c Thu Dec 18 22:37:15 2008 +0800 @@ -242,99 +242,11 @@ static void mouse_event_root_dummy(event_t *evt, void *arg) { } -static void mouse_event_interpreter(event_t *evt, void *arg) { - mouse_event_t *mevt = (mouse_event_t *)evt; - redraw_man_t *rdman = (redraw_man_t *)arg; - mb_obj_t *obj; - mouse_event_t new_evt; - coord_t *coord; - shape_t *shape; - - ASSERT(evt->type == EVT_MOUSE_MOVE_RAW); - - obj = (mb_obj_t *)subject_get_object(evt->cur_tgt); - if(rdman->last_mouse_over == obj) { - evt->type = EVT_MOUSE_MOVE; - return; - } - - new_evt.x = mevt->x; - new_evt.y = mevt->y; - new_evt.but_state = mevt->but_state; - new_evt.button = mevt->button; - - if(rdman->last_mouse_over != NULL) { - new_evt.event.type = EVT_MOUSE_OUT; - if(IS_MBO_COORD(rdman->last_mouse_over)) { - coord = (coord_t *)rdman->last_mouse_over; - subject_notify(coord->mouse_event, (event_t *)&new_evt); - } else if(IS_MBO_SHAPES(rdman->last_mouse_over)) { - shape = (shape_t *)rdman->last_mouse_over; - ASSERT(shape->geo != NULL); - subject_notify(shape->geo->mouse_event, (event_t *)&new_evt); - } - } - - new_evt.event.type = EVT_MOUSE_OVER; - subject_notify(evt->cur_tgt, (event_t *)&new_evt); - rdman->last_mouse_over = obj; - - evt->flags |= EVTF_STOP_NOTIFY; -} - -static void addrm_monitor_hdlr(event_t *evt, void *arg) { - monitor_event_t *mevt; - redraw_man_t *rdman; - mb_obj_t *obj; - mb_prop_store_t *props; - observer_t *observer; - int cnt = 0; - - mevt = (monitor_event_t *)evt; - rdman = (redraw_man_t *)evt->tgt; - obj = (mb_obj_t *)subject_get_object(mevt->subject); - props = mb_obj_prop_store(obj); - - switch(evt->type) { - case EVT_MONITOR_ADD: - if(!mb_prop_has(props, PROP_MEVT_OB_CNT)) - cnt = 0; - else - cnt = (int)mb_prop_get(props, PROP_MEVT_OB_CNT); - - cnt++; - mb_prop_set(props, PROP_MEVT_OB_CNT, (void *)cnt); - if(cnt == 1) { - observer = - subject_add_event_observer_head(mevt->subject, - EVT_MOUSE_MOVE_RAW, - mouse_event_interpreter, - rdman); - ASSERT(observer != NULL); - mb_prop_set(props, PROP_MEVT_OBSERVER, observer); - } - break; - - case EVT_MONITOR_REMOVE: - cnt = (int)mb_prop_get(props, PROP_MEVT_OB_CNT); - cnt--; - mb_prop_set(props, PROP_MEVT_OB_CNT, (void *)cnt); - if(cnt == 1) { - observer = (observer_t *)mb_prop_get(props, PROP_MEVT_OBSERVER); - subject_remove_observer(mevt->subject, observer); - mb_prop_del(props, PROP_MEVT_OBSERVER); - } - break; - - case EVT_MONITOR_FREE: - break; - } -} - int redraw_man_init(redraw_man_t *rdman, cairo_t *cr, cairo_t *backend) { extern void redraw_man_destroy(redraw_man_t *rdman); extern int _paint_color_size; observer_t *addrm_ob; + extern void addrm_monitor_hdlr(event_t *evt, void *arg); memset(rdman, 0, sizeof(redraw_man_t));