Mercurial > MadButterfly
changeset 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 | 1eb9ee5ae4f2 |
children | f7057177abbb |
files | examples/dynamic/button.svg examples/dynamic/main.c examples/dynamic/menu.svg |
diffstat | 3 files changed, 147 insertions(+), 127 deletions(-) [+] |
line wrap: on
line diff
--- 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"> <sodipodi:namedview id="base" pagecolor="#ffffff" @@ -26,10 +27,10 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="0.7" - inkscape:cx="239.91999" - inkscape:cy="667.92389" + inkscape:cx="257.06285" + inkscape:cy="365.06674" inkscape:document-units="px" - inkscape:current-layer="g2430" + inkscape:current-layer="layer1" showgrid="false" inkscape:window-width="1400" inkscape:window-height="978" @@ -40,43 +41,43 @@ <linearGradient id="linearGradient4066"> <stop - style="stop-color:#000000;stop-opacity:0;" + id="stop4068" offset="0" - id="stop4068" /> + style="stop-color:#000000;stop-opacity:0;" /> <stop - style="stop-color:#000000;stop-opacity:1" + id="stop4070" offset="1" - id="stop4070" /> + style="stop-color:#000000;stop-opacity:1" /> </linearGradient> <linearGradient id="linearGradient4026"> <stop - style="stop-color:#000000;stop-opacity:1;" + id="stop4028" offset="0" - id="stop4028" /> + style="stop-color:#000000;stop-opacity:1;" /> <stop - style="stop-color:#ffffff;stop-opacity:0;" + id="stop4030" offset="1" - id="stop4030" /> + style="stop-color:#ffffff;stop-opacity:0;" /> </linearGradient> <linearGradient id="linearGradient4018"> <stop - style="stop-color:#000000;stop-opacity:1;" + id="stop4020" offset="0" - id="stop4020" /> + style="stop-color:#000000;stop-opacity:1;" /> <stop - style="stop-color:#0000ff;stop-opacity:0;" + id="stop4022" offset="1" - id="stop4022" /> + style="stop-color:#0000ff;stop-opacity:0;" /> </linearGradient> <inkscape:perspective - id="perspective10" - inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 526.18109 : 1" + inkscape:vp_y="0 : 1000 : 0" inkscape:vp_z="744.09448 : 526.18109 : 1" - inkscape:vp_y="0 : 1000 : 0" - inkscape:vp_x="0 : 526.18109 : 1" - sodipodi:type="inkscape:persp3d" /> + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + id="perspective10" /> </defs> <metadata id="metadata7"> @@ -90,110 +91,107 @@ </rdf:RDF> </metadata> <g - id="layer1" - inkscape:groupmode="layer" + style="display:inline" inkscape:label="bg" - style="display:inline"> + inkscape:groupmode="layer" + id="layer1"> <text - xml:space="preserve" - style="font-size:30px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" - x="235.71429" + id="text4380" y="282.36218" - id="text4380"><tspan - sodipodi:role="line" - id="tspan4382" + x="235.71429" + style="font-size:30px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" + xml:space="preserve"><tspan + y="282.36218" x="235.71429" - y="282.36218" /></text> + id="tspan4382" + sodipodi:role="line" /></text> <g - transform="translate(20.000001,42.857139)" - id="btn" - frame="click" - mbname="btn"> + mbname="btn" + transform="translate(148.57143,98.571429)" + id="btn"> + <g + style="display:none" + mbname="btn_normal" + transform="translate(148.57143,98.571429)" + id="btn_normal" + frame="normal"> + <rect + style="fill:#0000ff" + id="rect2651" + width="122.85714" + height="47.142857" + x="-1.4285715" + y="1.4285747" + rx="6.0995407" + ry="5.0559778" /> + <text + xml:space="preserve" + style="font-size:24px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" + x="10.000002" + y="32.85714" + id="text2653"><tspan + sodipodi:role="line" + id="tspan2655" + x="10.000002" + y="32.85714">Click Me</tspan></text> + </g> <g - id="g2430" - mbname="btn" - transform="translate(-78.571429,44.285714)"> - <g - frame="normal" - id="btn_normal" - mbname="btn_normal" - transform="translate(1.4285713e-7,-60)"> - <rect - style="fill:#0000ff" - id="rect2493" - width="82.85714" - height="42.857143" - x="220" - y="69.505035" - rx="5.4543843" - ry="7.1427469" /> - <text - xml:space="preserve" - style="font-size:24px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" - x="232.85715" - y="99.505043" - id="text2495"><tspan - sodipodi:role="line" - id="tspan2497" - x="232.85715" - y="99.505043">Rect</tspan></text> - </g> - <g - frame="active" - id="btn_active" - mbname="btn_active" - transform="translate(-1.4285757,30.000005)"> - <rect - style="fill:#00ffff" - id="rect2481" - width="82.85714" - height="42.857143" - x="220" - y="69.505035" - rx="5.4543843" - ry="7.1427469" /> - <text - xml:space="preserve" - style="font-size:24px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" - x="232.85715" - y="99.505043" - id="text2483"><tspan - sodipodi:role="line" - id="tspan2485" - x="232.85715" - y="99.505043">Rect</tspan></text> - </g> - <g - frame="click" - id="btn_click" - mbname="btn_click" - transform="translate(-1.4285715,117.14286)"> - <rect - style="fill:#0000ff" - id="rect2488" - width="82.85714" - height="42.857143" - x="220" - y="69.505035" - rx="5.4543843" - ry="7.1427469" /> - <text - xml:space="preserve" - style="font-size:24px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" - x="232.85715" - y="99.505043" - id="text2490"><tspan - sodipodi:role="line" - id="tspan2492" - x="232.85715" - y="99.505043">Rect</tspan></text> - </g> + style="" + mbname="btn_active" + transform="translate(148.57143,98.571429)" + id="btn_active" + frame="active"> + <rect + style="fill:#00ffff" + id="rect2727" + width="122.85714" + height="47.142857" + x="-1.4285715" + y="1.4285747" + rx="6.0995407" + ry="5.0559778" /> + <text + xml:space="preserve" + style="font-size:24px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" + x="10.000002" + y="32.85714" + id="text2729"><tspan + sodipodi:role="line" + id="tspan2731" + x="10.000002" + y="32.85714">Click Me</tspan></text> + </g> + <g + style="display:none" + mbname="btn_click" + transform="translate(148.57143,98.571429)" + id="btn_click" + frame="click"> + <rect + style="fill:#0000ff" + id="rect2734" + width="122.85714" + height="47.142857" + x="-1.4285715" + y="1.4285747" + rx="6.0995407" + ry="5.0559778" /> + <text + xml:space="preserve" + style="font-size:24px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" + x="10.000002" + y="32.85714" + id="text2736"><tspan + sodipodi:role="line" + id="tspan2738" + x="10.000002" + y="32.85714">Click Me</tspan></text> </g> </g> </g> <g - inkscape:groupmode="layer" - id="layer2" + style="display:inline" inkscape:label="text" - style="display:inline" /> + id="layer2" + inkscape:groupmode="layer" /> </svg>
--- 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; }
--- 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" /> <g id="rect" - inkscape:label="#g2389"> + inkscape:label="#g2389" + transform="translate(442.85714,7.1428571)"> <rect ry="7.1427469" rx="5.4543843"