Mercurial > MadButterfly
diff examples/dynamic/main.c @ 221:ad4f8a956505
Implement a workaround for the button class. However, this won't solve all issues. We can use this as example to fix the mouse out event issue. When we move the curosr over the text inside the button. The upper layer group will receive MOUSE_OUT events. This is absolute incorrect.
author | wycc |
---|---|
date | Sun, 14 Dec 2008 12:35:13 +0800 |
parents | 8d9d717c9300 |
children | 29e1b2bffe4c |
line wrap: on
line diff
--- a/examples/dynamic/main.c Sat Dec 13 17:33:14 2008 +0800 +++ b/examples/dynamic/main.c Sun Dec 14 12:35:13 2008 +0800 @@ -34,6 +34,7 @@ coord_t *click; void (*press)(); void *arg; + observer_t *obs_move,*obs_out,*obs_press; } mb_button_t; @@ -43,6 +44,8 @@ #define CMOUSE(e) (coord_get_mouse_event(e)) +static void mb_button_pressed(event_t *evt, void *arg); +static void mb_button_out(event_t *evt, void *arg); static void mb_button_move(event_t *evt, void *arg) { @@ -52,8 +55,12 @@ printf("Mouse move\n"); COORD_SHOW(btn->active); + COORD_HIDE(btn->normal); rdman_coord_changed(btn->en->rdman,btn->root); rdman_redraw_changed(btn->en->rdman); + subject_remove_observer(CMOUSE(btn->normal), btn->obs_move); + btn->obs_press = subject_add_event_observer(CMOUSE(btn->active), EVT_MOUSE_BUT_PRESS, mb_button_pressed,btn); + btn->obs_out = subject_add_event_observer(CMOUSE(btn->active), EVT_MOUSE_OUT, mb_button_out,btn); } static void mb_button_out(event_t *evt, void *arg) { @@ -62,18 +69,26 @@ printf("mouse out\n"); COORD_HIDE(btn->active); + COORD_SHOW(btn->normal); rdman_coord_changed(btn->en->rdman,btn->root); rdman_redraw_changed(btn->en->rdman); + subject_remove_observer(CMOUSE(btn->active), btn->obs_press); + subject_remove_observer(CMOUSE(btn->active), btn->obs_out); + btn->obs_move = subject_add_event_observer(CMOUSE(btn->normal), EVT_MOUSE_MOVE, mb_button_move,btn); } -void mb_button_show_active(const mb_timeval_t *tmo, const mb_timeval_t *now, void *arg) +void mb_button_show_active(event_t *evt, void *arg) { mb_button_t *btn = (mb_button_t *) arg; engine_t *en = btn->en; COORD_HIDE(btn->click); + COORD_SHOW(btn->active); rdman_coord_changed(btn->en->rdman,btn->root); rdman_redraw_changed(btn->en->rdman); + subject_remove_observer(CMOUSE(btn->click), btn->obs_press); + btn->obs_press = subject_add_event_observer(CMOUSE(btn->active), EVT_MOUSE_BUT_PRESS, mb_button_pressed,btn); + btn->obs_out = subject_add_event_observer(CMOUSE(btn->active), EVT_MOUSE_OUT, mb_button_out,btn); } void mb_button_pressed(event_t *evt, void *arg) @@ -84,13 +99,16 @@ printf("Pressed\n"); COORD_SHOW(btn->click); + COORD_HIDE(btn->active); rdman_coord_changed(en->rdman,en->button->root_coord); rdman_redraw_changed(en->rdman); get_now(&now); MB_TIMEVAL_SET(&to, 0, 500); MB_TIMEVAL_ADD(&to,&now); - - mb_tman_timeout(X_MB_tman(btn->en->rt), &to, mb_button_show_active, arg); + subject_remove_observer(CMOUSE(btn->active), btn->obs_press); + subject_remove_observer(CMOUSE(btn->active), btn->obs_out); + btn->obs_press = subject_add_event_observer(CMOUSE(btn->click), EVT_MOUSE_BUT_RELEASE, mb_button_show_active,btn); + btn->obs_out = NULL; } mb_button_t *mb_button_new(engine_t *en,mb_sprite_t *sp, char *name) { @@ -117,6 +135,7 @@ // Show only the normal button COORD_HIDE(btn->active); COORD_HIDE(btn->click); + COORD_SHOW(btn->normal); // Move to the same position btn->active->matrix[2] = 200; btn->active->matrix[5] = 200; @@ -125,9 +144,11 @@ btn->click->matrix[2] = 200; btn->click->matrix[5] = 200; btn->en = en; - subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_MOVE, mb_button_move,btn); - subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_OUT, mb_button_out,btn); - subject_add_event_observer(CMOUSE(btn->root), EVT_MOUSE_BUT_RELEASE, mb_button_pressed,btn); + btn->obs_move = subject_add_event_observer(CMOUSE(btn->normal), EVT_MOUSE_MOVE, mb_button_move,btn); + btn->obs_out = NULL; + btn->obs_press = NULL; + rdman_coord_changed(en->rdman,en->button->root_coord); + rdman_redraw_changed(en->rdman); return btn; } @@ -150,7 +171,7 @@ return en; } -void engine_close(engine_t *en) +void engine_mainloop(engine_t *en) { /* * Start handle connections, includes one to X server. @@ -269,7 +290,7 @@ subject_add_event_observer(subject, EVT_MOUSE_BUT_RELEASE, add_rect, en); - engine_close(en); + engine_mainloop(en); return 0; }