# HG changeset patch # User wycc # Date 1229229313 -28800 # Node ID ad4f8a9565058c907346bf7caf217103b7e36257 # Parent 1eb9ee5ae4f2193ad698944123543e38246df48c 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. diff -r 1eb9ee5ae4f2 -r ad4f8a956505 examples/dynamic/button.svg --- a/examples/dynamic/button.svg Sat Dec 13 17:33:14 2008 +0800 +++ b/examples/dynamic/button.svg Sun Dec 14 12:35:13 2008 +0800 @@ -8,13 +8,14 @@ xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="744.09448819" - height="1052.3622047" + width="720" + height="480" id="svg2" sodipodi:version="0.32" inkscape:version="0.46" sodipodi:docname="button.svg" - inkscape:output_extension="org.inkscape.output.svg.inkscape"> + inkscape:output_extension="org.inkscape.output.svg.inkscape" + version="1.0"> + style="stop-color:#000000;stop-opacity:0;" /> + style="stop-color:#000000;stop-opacity:1" /> + style="stop-color:#000000;stop-opacity:1;" /> + style="stop-color:#ffffff;stop-opacity:0;" /> + style="stop-color:#000000;stop-opacity:1;" /> + style="stop-color:#0000ff;stop-opacity:0;" /> + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + id="perspective10" /> @@ -90,110 +91,107 @@ + inkscape:groupmode="layer" + id="layer1"> + id="tspan4382" + sodipodi:role="line" /> + mbname="btn" + transform="translate(148.57143,98.571429)" + id="btn"> + - - - Rect - - - - Rect - - - - Rect - + style="" + mbname="btn_active" + transform="translate(148.57143,98.571429)" + id="btn_active" + frame="active"> + + Click Me + + + id="layer2" + inkscape:groupmode="layer" /> diff -r 1eb9ee5ae4f2 -r ad4f8a956505 examples/dynamic/main.c --- 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; } diff -r 1eb9ee5ae4f2 -r ad4f8a956505 examples/dynamic/menu.svg --- a/examples/dynamic/menu.svg Sat Dec 13 17:33:14 2008 +0800 +++ b/examples/dynamic/menu.svg Sun Dec 14 12:35:13 2008 +0800 @@ -72,7 +72,8 @@ ry="7.1427469" /> + inkscape:label="#g2389" + transform="translate(442.85714,7.1428571)">