0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-26 15:53:01 +00:00

uxnemu: Add dpad support

More info about joyhats in SDL2:
	https://wiki.libsdl.org/SDL2/SDL_JoyHatEvent
This commit is contained in:
Lior Stern 2023-04-12 13:48:52 +03:00 committed by Devine Lu Linvega
parent 344c5c9904
commit 847b3f2b56

View file

@ -436,6 +436,42 @@ handle_events(Uxn *u)
controller_down(u, &u->dev[0x80], get_button_joystick(&event));
else if(event.type == SDL_JOYBUTTONUP)
controller_up(u, &u->dev[0x80], get_button_joystick(&event));
else if(event.type == SDL_JOYHATMOTION) {
/* NOTE: Assuming there is only one joyhat in the controller */
switch(event.jhat.value) {
case SDL_HAT_UP:
controller_down(u, &u->dev[0x80], 0x10);
break;
case SDL_HAT_DOWN:
controller_down(u, &u->dev[0x80], 0x20);
break;
case SDL_HAT_LEFT:
controller_down(u, &u->dev[0x80], 0x40);
break;
case SDL_HAT_RIGHT:
controller_down(u, &u->dev[0x80], 0x80);
break;
case SDL_HAT_LEFTDOWN:
controller_down(u, &u->dev[0x80], 0x40 | 0x20);
break;
case SDL_HAT_LEFTUP:
controller_down(u, &u->dev[0x80], 0x40 | 0x10);
break;
case SDL_HAT_RIGHTDOWN:
controller_down(u, &u->dev[0x80], 0x80 | 0x20);
break;
case SDL_HAT_RIGHTUP:
controller_down(u, &u->dev[0x80], 0x80 | 0x10);
break;
case SDL_HAT_CENTERED:
/* Set all directions to down */
controller_up(u, &u->dev[0x80], 0x10 | 0x20 | 0x40 | 0x80);
break;
default:
/* Ignore */
break;
}
}
/* Console */
else if(event.type == stdin_event)
console_input(u, event.cbutton.button);