From e642edb4e182cad5aa2b109b3baf23cacc903084 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 24 Oct 2013 18:33:40 +1000 Subject: [PATCH] Store the display locally within the mouse structure. Add ginputGetMouseDisplay() --- include/ginput/mouse.h | 10 ++++++ src/ginput/mouse.c | 71 +++++++++++++++++++++++------------------- 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/include/ginput/mouse.h b/include/ginput/mouse.h index f13379c3..aa9864a9 100644 --- a/include/ginput/mouse.h +++ b/include/ginput/mouse.h @@ -56,6 +56,7 @@ typedef struct GEventMouse_t { GMETA_MOUSE_CXTCLICK = 8 // For mice - The right button has just been depressed // For touch - a long press has just occurred } meta; + GDisplay * display; // The display this mouse is currently associated with. } GEventMouse; // Mouse/Touch Listen Flags - passed to geventAddSourceToListener() @@ -106,6 +107,15 @@ extern "C" { */ void ginputSetMouseDisplay(uint16_t instance, GDisplay *g); + /** + * @brief Get the display currently associated with the mouse + * @return A pointer to the display + * + * @param[in] instance The ID of the mouse input instance + * @param[in] g The GDisplay to which this mouse belongs + */ + GDisplay *ginputGetMouseDisplay(uint16_t instance); + /** * @brief Get the current mouse position and button status * @note Unlinke a listener event, this status cannot record meta events such as diff --git a/src/ginput/mouse.c b/src/ginput/mouse.c index b662008e..99ef04f6 100644 --- a/src/ginput/mouse.c +++ b/src/ginput/mouse.c @@ -19,8 +19,6 @@ #include "ginput/lld/mouse.h" -static GDisplay *mouseDisplay = 0; - #if GINPUT_MOUSE_NEED_CALIBRATION #if !defined(GFX_USE_GDISP) || !GFX_USE_GDISP #error "GINPUT: GFX_USE_GDISP must be defined when mouse or touch calibration is required" @@ -72,30 +70,31 @@ static struct MouseConfig_t { GMouseCalibrationLoadRoutine fnloadcal; Calibration caldata; #endif + GDisplay * display; } MouseConfig; #if GINPUT_MOUSE_NEED_CALIBRATION static inline void _tsDrawCross(const MousePoint *pp) { - gdispGDrawLine(mouseDisplay, pp->x-15, pp->y, pp->x-2, pp->y, White); - gdispGDrawLine(mouseDisplay, pp->x+2, pp->y, pp->x+15, pp->y, White); - gdispGDrawLine(mouseDisplay, pp->x, pp->y-15, pp->x, pp->y-2, White); - gdispGDrawLine(mouseDisplay, pp->x, pp->y+2, pp->x, pp->y+15, White); + gdispGDrawLine(MouseConfig.display, pp->x-15, pp->y, pp->x-2, pp->y, White); + gdispGDrawLine(MouseConfig.display, pp->x+2, pp->y, pp->x+15, pp->y, White); + gdispGDrawLine(MouseConfig.display, pp->x, pp->y-15, pp->x, pp->y-2, White); + gdispGDrawLine(MouseConfig.display, pp->x, pp->y+2, pp->x, pp->y+15, White); - gdispGDrawLine(mouseDisplay, pp->x-15, pp->y+15, pp->x-7, pp->y+15, RGB2COLOR(184,158,131)); - gdispGDrawLine(mouseDisplay, pp->x-15, pp->y+7, pp->x-15, pp->y+15, RGB2COLOR(184,158,131)); + gdispGDrawLine(MouseConfig.display, pp->x-15, pp->y+15, pp->x-7, pp->y+15, RGB2COLOR(184,158,131)); + gdispGDrawLine(MouseConfig.display, pp->x-15, pp->y+7, pp->x-15, pp->y+15, RGB2COLOR(184,158,131)); - gdispGDrawLine(mouseDisplay, pp->x-15, pp->y-15, pp->x-7, pp->y-15, RGB2COLOR(184,158,131)); - gdispGDrawLine(mouseDisplay, pp->x-15, pp->y-7, pp->x-15, pp->y-15, RGB2COLOR(184,158,131)); + gdispGDrawLine(MouseConfig.display, pp->x-15, pp->y-15, pp->x-7, pp->y-15, RGB2COLOR(184,158,131)); + gdispGDrawLine(MouseConfig.display, pp->x-15, pp->y-7, pp->x-15, pp->y-15, RGB2COLOR(184,158,131)); - gdispGDrawLine(mouseDisplay, pp->x+7, pp->y+15, pp->x+15, pp->y+15, RGB2COLOR(184,158,131)); - gdispGDrawLine(mouseDisplay, pp->x+15, pp->y+7, pp->x+15, pp->y+15, RGB2COLOR(184,158,131)); + gdispGDrawLine(MouseConfig.display, pp->x+7, pp->y+15, pp->x+15, pp->y+15, RGB2COLOR(184,158,131)); + gdispGDrawLine(MouseConfig.display, pp->x+15, pp->y+7, pp->x+15, pp->y+15, RGB2COLOR(184,158,131)); - gdispGDrawLine(mouseDisplay, pp->x+7, pp->y-15, pp->x+15, pp->y-15, RGB2COLOR(184,158,131)); - gdispGDrawLine(mouseDisplay, pp->x+15, pp->y-15, pp->x+15, pp->y-7, RGB2COLOR(184,158,131)); + gdispGDrawLine(MouseConfig.display, pp->x+7, pp->y-15, pp->x+15, pp->y-15, RGB2COLOR(184,158,131)); + gdispGDrawLine(MouseConfig.display, pp->x+15, pp->y-15, pp->x+15, pp->y-7, RGB2COLOR(184,158,131)); } static inline void _tsClearCross(const MousePoint *pp) { - gdispGFillArea(mouseDisplay, pp->x - 15, pp->y - 15, 42, 42, Blue); + gdispGFillArea(MouseConfig.display, pp->x - 15, pp->y - 15, 42, 42, Blue); } static inline void _tsTransform(MouseReading *pt, const Calibration *c) { @@ -171,8 +170,8 @@ static void get_calibrated_reading(MouseReading *pt) { get_raw_reading(pt); #if GINPUT_MOUSE_NEED_CALIBRATION || GDISP_NEED_CONTROL - w = gdispGGetWidth(mouseDisplay); - h = gdispGGetHeight(mouseDisplay); + w = gdispGGetWidth(MouseConfig.display); + h = gdispGGetHeight(MouseConfig.display); #endif #if GINPUT_MOUSE_NEED_CALIBRATION @@ -180,7 +179,7 @@ static void get_calibrated_reading(MouseReading *pt) { #endif #if GDISP_NEED_CONTROL - switch(gdispGGetOrientation(mouseDisplay)) { + switch(gdispGGetOrientation(MouseConfig.display)) { case GDISP_ROTATE_0: break; case GDISP_ROTATE_90: @@ -305,6 +304,7 @@ static void MousePoll(void *param) { pe->meta |= psl->srcflags; psl->srcflags = 0; } + pe->display = MouseConfig.display; geventSendEvent(psl); } } @@ -322,8 +322,8 @@ GSourceHandle ginputGetMouse(uint16_t instance) { return 0; // Make sure we have a valid mouse display - if (!mouseDisplay) - mouseDisplay = GDISP; + if (!MouseConfig.display) + MouseConfig.display = GDISP; // Do we need to initialise the mouse subsystem? if (!(MouseConfig.flags & FLG_INIT_DONE)) { @@ -372,7 +372,14 @@ void ginputSetMouseDisplay(uint16_t instance, GDisplay *g) { if (instance) return; - mouseDisplay = g ? g : GDISP; + MouseConfig.display = g ? g : GDISP; +} + +GDisplay *ginputGetMouseDisplay(uint16_t instance) { + if (instance) + return 0; + + return MouseConfig.display; } bool_t ginputGetMouseStatus(uint16_t instance, GEventMouse *pe) { @@ -406,8 +413,8 @@ bool_t ginputCalibrateMouse(uint16_t instance) { return FALSE; #else - const coord_t height = gdispGGetHeight(mouseDisplay); - const coord_t width = gdispGGetWidth(mouseDisplay); + const coord_t height = gdispGGetHeight(MouseConfig.display); + const coord_t width = gdispGGetWidth(MouseConfig.display); const MousePoint cross[] = {{(width / 4), (height / 4)}, {(width - (width / 4)) , (height / 4)}, {(width - (width / 4)) , (height - (height / 4))}, @@ -433,19 +440,19 @@ bool_t ginputCalibrateMouse(uint16_t instance) { MouseConfig.flags &= ~(FLG_CAL_OK|FLG_CAL_SAVED); #if GDISP_NEED_CONTROL - gdispGSetOrientation(mouseDisplay, GDISP_ROTATE_0); + gdispGSetOrientation(MouseConfig.display, GDISP_ROTATE_0); #endif #if GDISP_NEED_CLIP - gdispGSetClip(mouseDisplay, 0, 0, width, height); + gdispGSetClip(MouseConfig.display, 0, 0, width, height); #endif #if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0 while(1) { #endif - gdispGClear(mouseDisplay, Blue); + gdispGClear(MouseConfig.display, Blue); - gdispGFillStringBox(mouseDisplay, 0, 5, width, 30, GINPUT_MOUSE_CALIBRATION_TEXT, font1, White, Blue, justifyCenter); + gdispGFillStringBox(MouseConfig.display, 0, 5, width, 30, GINPUT_MOUSE_CALIBRATION_TEXT, font1, White, Blue, justifyCenter); for(i = 0, pt = points, pc = cross; i < GINPUT_MOUSE_CALIBRATION_POINTS; i++, pt++, pc++) { _tsDrawCross(pc); @@ -474,9 +481,9 @@ bool_t ginputCalibrateMouse(uint16_t instance) { _tsClearCross(pc); if (i >= 1 && pt->x == (pt-1)->x && pt->y == (pt-1)->y) { - gdispGFillStringBox(mouseDisplay, 0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_SAME_TEXT, font2, Red, Yellow, justifyCenter); + gdispGFillStringBox(MouseConfig.display, 0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_SAME_TEXT, font2, Red, Yellow, justifyCenter); gfxSleepMilliseconds(5000); - gdispGFillArea(mouseDisplay, 0, 35, width, 40, Blue); + gdispGFillArea(MouseConfig.display, 0, 35, width, 40, Blue); } } @@ -502,7 +509,7 @@ bool_t ginputCalibrateMouse(uint16_t instance) { if (err <= GINPUT_MOUSE_MAX_CALIBRATION_ERROR * GINPUT_MOUSE_MAX_CALIBRATION_ERROR) break; - gdispGFillStringBox(mouseDisplay, 0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_ERROR_TEXT, font2, Red, Yellow, justifyCenter); + gdispGFillStringBox(MouseConfig.display, 0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_ERROR_TEXT, font2, Red, Yellow, justifyCenter); gfxSleepMilliseconds(5000); } #endif @@ -525,9 +532,9 @@ bool_t ginputCalibrateMouse(uint16_t instance) { // Clear the screen using the GWIN default background color #if GFX_USE_GWIN - gdispGClear(mouseDisplay, gwinGetDefaultBgColor()); + gdispGClear(MouseConfig.display, gwinGetDefaultBgColor()); #else - gdispGClear(mouseDisplay, Black); + gdispGClear(MouseConfig.display, Black); #endif return TRUE;