diff --git a/polymer/eduke32/build/include/baselayer.h b/polymer/eduke32/build/include/baselayer.h index 7922b9127..f7f60a660 100644 --- a/polymer/eduke32/build/include/baselayer.h +++ b/polymer/eduke32/build/include/baselayer.h @@ -87,7 +87,7 @@ extern int32_t defaultres[][2]; extern void SetKey(int32_t key, int32_t state); // mouse -extern volatile int32_t mousex, mousey, mouseb; +extern volatile int32_t mousex, mousey, mouseb, mouseabsx, mouseabsy; extern volatile uint8_t mousegrab, moustat; // joystick @@ -131,6 +131,7 @@ int32_t initmouse(void); void uninitmouse(void); void grabmouse(char a); void readmousexy(int32_t *x, int32_t *y); +void readmouseabsxy(int32_t *x, int32_t *y); void readmousebstatus(int32_t *b); void setjoydeadzone(int32_t axis, uint16_t dead, uint16_t satur); void getjoydeadzone(int32_t axis, uint16_t *dead, uint16_t *satur); diff --git a/polymer/eduke32/build/src/baselayer.c b/polymer/eduke32/build/src/baselayer.c index bab97e02b..fe0b15d7b 100644 --- a/polymer/eduke32/build/src/baselayer.c +++ b/polymer/eduke32/build/src/baselayer.c @@ -16,7 +16,7 @@ char keyasciififo[KEYFIFOSIZ], keyasciififoplc, keyasciififoend; char remap[256]; int32_t remapinit=0; char key_names[256][24]; -volatile int32_t mousex=0,mousey=0,mouseb=0; +volatile int32_t mousex=0,mousey=0,mouseb=0,mouseabsx=0,mouseabsy=0; volatile uint8_t moustat = 0, mousegrab = 0; int32_t *joyaxis = NULL, joyb=0, *joyhat = NULL; char joyisgamepad=0, joynumaxes=0, joynumbuttons=0, joynumhats=0; @@ -101,6 +101,21 @@ void readmousexy(int32_t *x, int32_t *y) mousex = mousey = 0; } +void readmouseabsxy(int32_t *x, int32_t *y) +{ + if (!moustat || !mousegrab || !appactive) + { + // no mouse, centre it + *x = xdim >> 1; + *y = ydim >> 1; + } + else + { + *x = mouseabsx; + *y = mouseabsy; + } +} + void readmousebstatus(int32_t *b) { if (!moustat || !mousegrab || !appactive) { *b = 0; return; } diff --git a/polymer/eduke32/build/src/sdlayer.c b/polymer/eduke32/build/src/sdlayer.c index e7c9d37bf..2f04643cc 100644 --- a/polymer/eduke32/build/src/sdlayer.c +++ b/polymer/eduke32/build/src/sdlayer.c @@ -619,6 +619,7 @@ void grabmouse(char a) mousegrab = a; } mousex = mousey = 0; + mouseabsx = mouseabsy = 0; } // @@ -1825,16 +1826,32 @@ int32_t handleevents(void) break; case SDL_MOUSEMOTION: - // SDL 1.3 doesn't handle relative mouse movement correctly yet as the cursor still clips to the screen edges + // SDL doesn't handle relative mouse movement correctly yet as the cursor still clips to the screen edges // so, we call SDL_WarpMouse() to center the cursor and ignore the resulting motion event that occurs - if (appactive && mousegrab && (ev.motion.x != xdim>>1 || ev.motion.y != ydim>>1)) + // is 1.3 for PK, 1.2 for tueidj + if (appactive && mousegrab) { - mousex += ev.motion.xrel; - mousey += ev.motion.yrel; - -#ifndef DEBUGGINGAIDS - SDL_WarpMouse(xdim>>1, ydim>>1); +#ifdef GEKKO + // check if it's a wiimote pointer pretending to be a mouse + if (ev.motion.state & SDL_BUTTON_X2MASK) + { + // the absolute values are used to draw the crosshair + mouseabsx = ev.motion.x; + mouseabsy = ev.motion.y; + // hack: reduce the scale of the "relative" motions + // to make it act more like a real mouse + ev.motion.xrel /= 16; + ev.motion.yrel /= 12; + } #endif + if (ev.motion.x != xdim>>1 || ev.motion.y != ydim>>1) + { + mousex += ev.motion.xrel; + mousey += ev.motion.yrel; +#ifndef DEBUGGINGAIDS + SDL_WarpMouse(xdim>>1, ydim>>1); +#endif + } } break;