This commit is contained in:
Lior Halphon 2018-06-04 01:52:34 +03:00
commit 8f892ab798
2 changed files with 32 additions and 0 deletions

View File

@ -730,6 +730,23 @@ void run_gui(bool is_running)
else if (event.jbutton.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) event.key.keysym.scancode = SDL_SCANCODE_RIGHT; else if (event.jbutton.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT) event.key.keysym.scancode = SDL_SCANCODE_RIGHT;
break; break;
case SDL_JOYHATMOTION: {
uint8_t value = event.jhat.value;
if (value != 0) {
uint32_t scancode =
value == SDL_HAT_UP ? SDL_SCANCODE_UP
: value == SDL_HAT_DOWN ? SDL_SCANCODE_DOWN
: value == SDL_HAT_LEFT ? SDL_SCANCODE_LEFT
: value == SDL_HAT_RIGHT ? SDL_SCANCODE_RIGHT
: 0;
if (scancode != 0) {
event.type = SDL_KEYDOWN;
event.key.keysym.scancode = scancode;
}
}
}
case SDL_JOYAXISMOTION: { case SDL_JOYAXISMOTION: {
static bool axis_active[2] = {false, false}; static bool axis_active[2] = {false, false};
event.jaxis.axis = fix_joypad_axis(event.jaxis.axis); event.jaxis.axis = fix_joypad_axis(event.jaxis.axis);

View File

@ -166,6 +166,21 @@ static void handle_events(GB_gameboy_t *gb)
} }
break; break;
case SDL_JOYHATMOTION:
{
uint8_t value = event.jhat.value;
int8_t updown =
value == SDL_HAT_LEFTUP || value == SDL_HAT_UP || value == SDL_HAT_RIGHTUP ? -1 : (value == SDL_HAT_LEFTDOWN || value == SDL_HAT_DOWN || value == SDL_HAT_RIGHTDOWN ? 1 : 0);
int8_t leftright =
value == SDL_HAT_LEFTUP || value == SDL_HAT_LEFT || value == SDL_HAT_LEFTDOWN ? -1 : (value == SDL_HAT_RIGHTUP || value == SDL_HAT_RIGHT || value == SDL_HAT_RIGHTDOWN ? 1 : 0);
GB_set_key_state(gb, GB_KEY_LEFT, leftright == -1);
GB_set_key_state(gb, GB_KEY_RIGHT, leftright == 1);
GB_set_key_state(gb, GB_KEY_UP, updown == -1);
GB_set_key_state(gb, GB_KEY_DOWN, updown == 1);
break;
};
case SDL_KEYDOWN: case SDL_KEYDOWN:
switch (event.key.keysym.scancode) { switch (event.key.keysym.scancode) {
case SDL_SCANCODE_ESCAPE: { case SDL_SCANCODE_ESCAPE: {