diff options
author | Joel Bodenmann <joel@unormal.org> | 2013-11-10 21:07:16 +0100 |
---|---|---|
committer | Joel Bodenmann <joel@unormal.org> | 2013-11-10 21:07:16 +0100 |
commit | da2740b706d720292113445ee1db30f8a9873dc4 (patch) | |
tree | 8f8b1902d4af6a23b3daf26990f580b76ea31ea4 /src/ginput/mouse.c | |
parent | 6ca3537a696e7ace8098771a9a7105380604253d (diff) | |
parent | a8ce005e2621b0108863297948cea0fa52c8bf2a (diff) | |
download | uGFX-da2740b706d720292113445ee1db30f8a9873dc4.tar.gz uGFX-da2740b706d720292113445ee1db30f8a9873dc4.tar.bz2 uGFX-da2740b706d720292113445ee1db30f8a9873dc4.zip |
merging GDISPStreaming
Diffstat (limited to 'src/ginput/mouse.c')
-rw-r--r-- | src/ginput/mouse.c | 99 |
1 files changed, 62 insertions, 37 deletions
diff --git a/src/ginput/mouse.c b/src/ginput/mouse.c index 74b5a990..80a4ed20 100644 --- a/src/ginput/mouse.c +++ b/src/ginput/mouse.c @@ -65,35 +65,37 @@ static struct MouseConfig_t { #define FLG_CAL_OK 0x0020 #define FLG_CAL_SAVED 0x0040 #define FLG_CAL_FREE 0x0080 + #define FLG_CAL_RAW 0x0100 #if GINPUT_MOUSE_NEED_CALIBRATION GMouseCalibrationSaveRoutine fnsavecal; GMouseCalibrationLoadRoutine fnloadcal; Calibration caldata; #endif + GDisplay * display; } MouseConfig; #if GINPUT_MOUSE_NEED_CALIBRATION static inline void _tsDrawCross(const MousePoint *pp) { - gdispDrawLine(pp->x-15, pp->y, pp->x-2, pp->y, White); - gdispDrawLine(pp->x+2, pp->y, pp->x+15, pp->y, White); - gdispDrawLine(pp->x, pp->y-15, pp->x, pp->y-2, White); - gdispDrawLine(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); - gdispDrawLine(pp->x-15, pp->y+15, pp->x-7, pp->y+15, RGB2COLOR(184,158,131)); - gdispDrawLine(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)); - gdispDrawLine(pp->x-15, pp->y-15, pp->x-7, pp->y-15, RGB2COLOR(184,158,131)); - gdispDrawLine(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)); - gdispDrawLine(pp->x+7, pp->y+15, pp->x+15, pp->y+15, RGB2COLOR(184,158,131)); - gdispDrawLine(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)); - gdispDrawLine(pp->x+7, pp->y-15, pp->x+15, pp->y-15, RGB2COLOR(184,158,131)); - gdispDrawLine(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) { - gdispFillArea(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) { @@ -169,8 +171,8 @@ static void get_calibrated_reading(MouseReading *pt) { get_raw_reading(pt); #if GINPUT_MOUSE_NEED_CALIBRATION || GDISP_NEED_CONTROL - w = gdispGetWidth(); - h = gdispGetHeight(); + w = gdispGGetWidth(MouseConfig.display); + h = gdispGGetHeight(MouseConfig.display); #endif #if GINPUT_MOUSE_NEED_CALIBRATION @@ -178,14 +180,14 @@ static void get_calibrated_reading(MouseReading *pt) { #endif #if GDISP_NEED_CONTROL - switch(gdispGetOrientation()) { + switch(gdispGGetOrientation(MouseConfig.display)) { case GDISP_ROTATE_0: break; case GDISP_ROTATE_90: { - coord_t t = pt->y; - pt->y = h - 1 - pt->x; - pt->x = t; + coord_t t = pt->x; + pt->x = w - 1 - pt->y; + pt->y = t; } break; case GDISP_ROTATE_180: @@ -194,19 +196,23 @@ static void get_calibrated_reading(MouseReading *pt) { break; case GDISP_ROTATE_270: { - coord_t t = pt->x; - pt->x = w - 1 - pt->y; - pt->y = t; + coord_t t = pt->y; + pt->y = h - 1 - pt->x; + pt->x = t; } break; + default: + break; } #endif #if GINPUT_MOUSE_NEED_CALIBRATION + if (!(MouseConfig.flags & FLG_CAL_RAW)) { if (pt->x < 0) pt->x = 0; else if (pt->x >= w) pt->x = w-1; if (pt->y < 0) pt->y = 0; else if (pt->y >= h) pt->y = h-1; + } #endif } @@ -303,6 +309,7 @@ static void MousePoll(void *param) { pe->meta |= psl->srcflags; psl->srcflags = 0; } + pe->display = MouseConfig.display; geventSendEvent(psl); } } @@ -319,6 +326,10 @@ GSourceHandle ginputGetMouse(uint16_t instance) { if (instance && instance != 9999) return 0; + // Make sure we have a valid mouse display + if (!MouseConfig.display) + MouseConfig.display = GDISP; + // Do we need to initialise the mouse subsystem? if (!(MouseConfig.flags & FLG_INIT_DONE)) { ginput_lld_mouse_init(); @@ -344,7 +355,7 @@ GSourceHandle ginputGetMouse(uint16_t instance) { MouseConfig.caldata.ay = 0; MouseConfig.caldata.by = 1; MouseConfig.caldata.cy = 0; - MouseConfig.flags |= (FLG_CAL_OK|FLG_CAL_SAVED); + MouseConfig.flags |= (FLG_CAL_OK|FLG_CAL_SAVED|FLG_CAL_RAW); } else ginputCalibrateMouse(instance); #endif @@ -362,6 +373,20 @@ GSourceHandle ginputGetMouse(uint16_t instance) { return (GSourceHandle)&MouseConfig; } +void ginputSetMouseDisplay(uint16_t instance, GDisplay *g) { + if (instance) + return; + + 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) { // Win32 threads don't seem to recognise priority and/or pre-emption // so we add a sleep here to prevent 100% polled applications from locking up. @@ -393,8 +418,8 @@ bool_t ginputCalibrateMouse(uint16_t instance) { return FALSE; #else - const coord_t height = gdispGetHeight(); - const coord_t width = gdispGetWidth(); + 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))}, @@ -417,22 +442,22 @@ bool_t ginputCalibrateMouse(uint16_t instance) { MouseConfig.flags |= FLG_IN_CAL; gtimerStop(&MouseTimer); - MouseConfig.flags &= ~(FLG_CAL_OK|FLG_CAL_SAVED); + MouseConfig.flags &= ~(FLG_CAL_OK|FLG_CAL_SAVED|FLG_CAL_RAW); #if GDISP_NEED_CONTROL - gdispSetOrientation(GDISP_ROTATE_0); + gdispGSetOrientation(MouseConfig.display, GDISP_ROTATE_0); #endif #if GDISP_NEED_CLIP - gdispSetClip(0, 0, width, height); + gdispGSetClip(MouseConfig.display, 0, 0, width, height); #endif #if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0 while(1) { #endif - gdispClear(Blue); + gdispGClear(MouseConfig.display, Blue); - gdispFillStringBox(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); @@ -461,9 +486,9 @@ bool_t ginputCalibrateMouse(uint16_t instance) { _tsClearCross(pc); if (i >= 1 && pt->x == (pt-1)->x && pt->y == (pt-1)->y) { - gdispFillStringBox(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); - gdispFillArea(0, 35, width, 40, Blue); + gdispGFillArea(MouseConfig.display, 0, 35, width, 40, Blue); } } @@ -489,7 +514,7 @@ bool_t ginputCalibrateMouse(uint16_t instance) { if (err <= GINPUT_MOUSE_MAX_CALIBRATION_ERROR * GINPUT_MOUSE_MAX_CALIBRATION_ERROR) break; - gdispFillStringBox(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 @@ -512,9 +537,9 @@ bool_t ginputCalibrateMouse(uint16_t instance) { // Clear the screen using the GWIN default background color #if GFX_USE_GWIN - gdispClear(gwinGetDefaultBgColor()); + gdispGClear(MouseConfig.display, gwinGetDefaultBgColor()); #else - gdispClear(Black); + gdispGClear(MouseConfig.display, Black); #endif return TRUE; @@ -523,8 +548,8 @@ bool_t ginputCalibrateMouse(uint16_t instance) { /* Set the routines to save and fetch calibration data. * This function should be called before first calling ginputGetMouse() for a particular instance - * as the gdispGetMouse() routine may attempt to fetch calibration data and perform a startup calibration if there is no way to get it. - * If this is called after gdispGetMouse() has been called and the driver requires calibration storage, it will immediately save the data is has already obtained. + * as the ginputGetMouse() routine may attempt to fetch calibration data and perform a startup calibration if there is no way to get it. + * If this is called after ginputGetMouse() has been called and the driver requires calibration storage, it will immediately save the data is has already obtained. * The 'requireFree' parameter indicates if the fetch buffer must be free()'d to deallocate the buffer provided by the Fetch routine. */ void ginputSetMouseCalibrationRoutines(uint16_t instance, GMouseCalibrationSaveRoutine fnsave, GMouseCalibrationLoadRoutine fnload, bool_t requireFree) { |