Patch adding Wii support by tueidj, part 3: SDL-level mouse changes

This part adds support for an absolute pointing device.

git-svn-id: https://svn.eduke32.com/eduke32@2623 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-05-01 12:38:14 +00:00
parent bd8559f6c3
commit bc70806d32
3 changed files with 42 additions and 9 deletions

View file

@ -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);

View file

@ -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; }

View file

@ -619,6 +619,7 @@ void grabmouse(char a)
mousegrab = a;
}
mousex = mousey = 0;
mouseabsx = mouseabsy = 0;
}
//
@ -1825,17 +1826,33 @@ 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 <VER> 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))
// <VER> is 1.3 for PK, 1.2 for tueidj
if (appactive && mousegrab)
{
#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;
case SDL_JOYAXISMOTION: