From 74e94d39b9b66adeaf8bcbb8789d79110102bb15 Mon Sep 17 00:00:00 2001 From: Andrew Hannam Date: Sun, 2 Dec 2012 17:10:27 +1000 Subject: Split Attaching Sources to a GWIN button Split Attaching Sources to a GWIN button to allow for new input types that require a parameter in future eg. Keyboard will require a parameter. --- demos/modules/ginput_touch_driver_test/main.c | 8 +++--- include/gwin/gwin_button.h | 11 +++++++-- src/gwin/button.c | 35 +++++++++++---------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/demos/modules/ginput_touch_driver_test/main.c b/demos/modules/ginput_touch_driver_test/main.c index 8a31ec74..dc8bb0f9 100644 --- a/demos/modules/ginput_touch_driver_test/main.c +++ b/demos/modules/ginput_touch_driver_test/main.c @@ -201,13 +201,13 @@ StepCalibrate: gwinSetButtonText(ghNext, "Next", FALSE); gsNext = gwinGetButtonSource(ghNext); geventAttachSource(&gl, gsNext, 0); - gwinAttachButtonSource(ghNext, gs, GEVENT_MOUSE); + gwinAttachButtonMouseSource(ghNext, gs); ghPrev = gwinCreateButton(&gPrev, swidth-100, 0, 50, 20, &fontUI2, GBTN_NORMAL); gwinSetButtonText(ghPrev, "Back", FALSE); gsPrev = gwinGetButtonSource(ghPrev); geventAttachSource(&gl, gsPrev, 0); - gwinAttachButtonSource(ghPrev, gs, GEVENT_MOUSE); + gwinAttachButtonMouseSource(ghPrev, gs); #if 0 { @@ -221,8 +221,8 @@ StepCalibrate: // below are correct for the Win32 toggle driver. gsButton1 = ginputGetToggle(GINPUT_TOGGLE_MOMENTARY1); gsButton2 = ginputGetToggle(GINPUT_TOGGLE_MOMENTARY2); - gwinAttachButtonSource(ghNext, gsButton2, GEVENT_TOGGLE); - gwinAttachButtonSource(ghPrev, gsButton1, GEVENT_TOGGLE); + gwinAttachButtonToggleSource(ghNext, gsButton2); + gwinAttachButtonToggleSource(ghPrev, gsButton1); } #endif } diff --git a/include/gwin/gwin_button.h b/include/gwin/gwin_button.h index 69a2474c..e95628e4 100644 --- a/include/gwin/gwin_button.h +++ b/include/gwin/gwin_button.h @@ -129,8 +129,15 @@ extern "C" { // Get the source handle so the application can listen for events #define gwinGetButtonSource(gh) ((GSourceHandle)(gh)) - // Attach a source to this button. Sources recognised: Mouse, Touch and Toggle - others are ignored (returns false). - bool_t gwinAttachButtonSource(GHandle gh, GSourceHandle gsh, GEventType type); + #if defined(GINPUT_NEED_MOUSE) && GINPUT_NEED_MOUSE + // Attach a mouse source to this button. + bool_t gwinAttachButtonMouseSource(GHandle gh, GSourceHandle gsh); + #endif + + #if defined(GINPUT_NEED_TOGGLE) && GINPUT_NEED_TOGGLE + // Attach a toggle source to this button. + bool_t gwinAttachButtonToggleSource(GHandle gh, GSourceHandle gsh); + #endif #ifdef __cplusplus } diff --git a/src/gwin/button.c b/src/gwin/button.c index 43c6d5d4..4e1e45f5 100644 --- a/src/gwin/button.c +++ b/src/gwin/button.c @@ -297,30 +297,23 @@ void gwinButtonDraw(GHandle gh) { #undef gbw } -// Attach a source to this button. Sources recognised: Mouse, Touch and Toggle - others are ignored (returns false). -bool_t gwinAttachButtonSource(GHandle gh, GSourceHandle gsh, GEventType type) { - #define gbw ((GButtonObject *)gh) - unsigned flags; +#if defined(GINPUT_NEED_MOUSE) && GINPUT_NEED_MOUSE + bool_t gwinAttachButtonMouseSource(GHandle gh, GSourceHandle gsh) { + if (gh->type != GW_BUTTON) + return FALSE; - switch (type) { - #if defined(GINPUT_NEED_MOUSE) && GINPUT_NEED_MOUSE - case GEVENT_MOUSE: - case GEVENT_TOUCH: - flags = GLISTEN_MOUSEMETA; - break; - #endif - #if defined(GINPUT_NEED_TOGGLE) && GINPUT_NEED_TOGGLE - case GEVENT_TOGGLE: - flags = GLISTEN_TOGGLE_OFF|GLISTEN_TOGGLE_ON; - break; - #endif - default: - return FALSE; + return geventAttachSource(&((GButtonObject *)gh)->listener, gsh, GLISTEN_MOUSEMETA); } - return geventAttachSource(&gbw->listener, gsh, flags); +#endif - #undef gbw -} +#if defined(GINPUT_NEED_TOGGLE) && GINPUT_NEED_TOGGLE + bool_t gwinAttachButtonToggleSource(GHandle gh, GSourceHandle gsh) { + if (gh->type != GW_BUTTON) + return FALSE; + + return geventAttachSource(&((GButtonObject *)gh)->listener, gsh, GLISTEN_TOGGLE_OFF|GLISTEN_TOGGLE_ON); + } +#endif #endif /* GFX_USE_GWIN && GWIN_NEED_BUTTON */ /** @} */ -- cgit v1.2.3