Add handling of the joystick hats. This allows the classic controller Dpad

to be used (maybe the wiimote as well)
This commit is contained in:
simon.kagstrom 2009-05-11 19:20:59 +00:00
parent 0fa258f107
commit 735aa67171

View File

@ -29,7 +29,7 @@ static struct joyinfo joys[MAX_INPUT_DEVICES];
static void read_joy (unsigned int nr) static void read_joy (unsigned int nr)
{ {
unsigned int num, i, axes, axis; unsigned int num, i, axes, axis, hats;
SDL_Joystick *joy; SDL_Joystick *joy;
if (currprefs.input_selected_setting == 0) { if (currprefs.input_selected_setting == 0) {
@ -43,6 +43,25 @@ static void read_joy (unsigned int nr)
setjoystickstate (nr, i, axis, 32767); setjoystickstate (nr, i, axis, 32767);
} }
/* Handle hat - used e.g., for the Wii */
hats = SDL_JoystickNumHats (joy);
for (i = 0; i < hats; i++) {
Uint8 v = SDL_JoystickGetHat (joy, i);
int x = 0, y = 0;
if (v & SDL_HAT_UP)
y = -1;
if (v & SDL_HAT_DOWN)
y = 1;
if (v & SDL_HAT_LEFT)
x = -1;
if (v & SDL_HAT_RIGHT)
x = 1;
setjoystickstate (nr, 0, x, 1);
setjoystickstate (nr, 1, y, 1);
}
num = SDL_JoystickNumButtons (joy); num = SDL_JoystickNumButtons (joy);
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
int bs = SDL_JoystickGetButton (joy, i) ? 1 : 0; int bs = SDL_JoystickGetButton (joy, i) ? 1 : 0;