I'm using a standard SDL input polling routine to parse all events until the buffer is empty. Problem is that if a diagonal is pressed SDL does not appear to poll two events, one for each direction, but instead polls one event according to the diagram below.
1 0 7
2 + 6
3 4 5
I'm sure all other versions of SDL I've used, including the GP2X could read diagonals by generating two events (eg up/left would generate both an up and a left event rather than a single diagonal event).
I am trying to read the dpad using the following code but it doesn't handle transition between the four main directions and the diagonals very well. Anyone have any suggestions on the best way to do this on the Wiz?
1 0 7
2 + 6
3 4 5
I'm sure all other versions of SDL I've used, including the GP2X could read diagonals by generating two events (eg up/left would generate both an up and a left event rather than a single diagonal event).
I am trying to read the dpad using the following code but it doesn't handle transition between the four main directions and the diagonals very well. Anyone have any suggestions on the best way to do this on the Wiz?
Code:
#define MY_LEFT (1)
#define MY_RIGHT (2)
#define MY_UP (4)
#define MY_DOWN (8)
int get_key()
{
int keydata=0;
SDL_Event event;
while( SDL_PollEvent( &event ) )
{
if (event.type==SDL_JOYBUTTONUP)
{
switch(event.jbutton.button)
{
case GP2X_BUTTON_DOWNLEFT:
DOWNDOWN=0;
LEFTDOWN=0;
break;
case GP2X_BUTTON_DOWNRIGHT:
DOWNDOWN=0;
RIGHTDOWN=0;
break;
case GP2X_BUTTON_UPLEFT:
UPDOWN=0;
LEFTDOWN=0;
break;
case GP2X_BUTTON_UPRIGHT:
UPDOWN=0;
RIGHTDOWN=0;
break;
case GP2X_BUTTON_UP:
UPDOWN=0;
break;
case GP2X_BUTTON_LEFT:
LEFTDOWN=0;
break;
case GP2X_BUTTON_RIGHT:
RIGHTDOWN=0;
break;
case GP2X_BUTTON_DOWN:
DOWNDOWN=0;
break;
default:
break;
}
}
if (event.type== SDL_JOYBUTTONDOWN)
{ // GP2X buttons
switch( event.jbutton.button )
{
case GP2X_BUTTON_UP:
UPDOWN=1;
break;
case GP2X_BUTTON_LEFT:
LEFTDOWN=1;
break;
case GP2X_BUTTON_RIGHT:
RIGHTDOWN=1;
break;
case GP2X_BUTTON_DOWN:
DOWNDOWN=1;
break;
case GP2X_BUTTON_DOWNLEFT:
DOWNDOWN=1;
LEFTDOWN=1;
break;
case GP2X_BUTTON_DOWNRIGHT:
DOWNDOWN=1;
RIGHTDOWN=1;
break;
case GP2X_BUTTON_UPLEFT:
UPDOWN=1;
LEFTDOWN=1;
break;
case GP2X_BUTTON_UPRIGHT:
UPDOWN=1;
RIGHTDOWN=1;
break;
default:
break;
}
}
}
if (UPDOWN) keydata|=MY_UP;
if (LEFTDOWN) keydata|=MY_LEFT;
if (RIGHTDOWN) keydata|=MY_RIGHT;
if (DOWNDOWN) keydata|=MY_DOWN;
return keydata;
}