From c736bc25729fc72b7c766bd95ba0b5443e44a937 Mon Sep 17 00:00:00 2001 From: Daniel Stuart Baxter Date: Fri, 29 May 2015 09:44:41 -0500 Subject: [PATCH] Added support for hat input aka 'dpads' --- src/input_common/sdl_input/sdl_input.cpp | 66 ++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/src/input_common/sdl_input/sdl_input.cpp b/src/input_common/sdl_input/sdl_input.cpp index 6958aa473..c47f6f859 100644 --- a/src/input_common/sdl_input/sdl_input.cpp +++ b/src/input_common/sdl_input/sdl_input.cpp @@ -111,10 +111,68 @@ void SDLController::ProcessInput() { pad_id += input_event.jhat.hat * 4; switch(input_event.jhat.value) { - case SDL_HAT_LEFT: break; - case SDL_HAT_RIGHT: pad_id += 1; break; - case SDL_HAT_UP: pad_id += 2; break; - case SDL_HAT_DOWN: pad_id += 3; break; + case SDL_HAT_CENTERED: + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+1, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+2, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+3, joypad_id}).hex; + break; + + case SDL_HAT_LEFT: + controller.pad_state.hex |= KeyMap::GetPadKey({pad_id, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+1, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+2, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+3, joypad_id}).hex; + break; + + case SDL_HAT_LEFTUP: + controller.pad_state.hex |= KeyMap::GetPadKey({pad_id, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+1, joypad_id}).hex; + controller.pad_state.hex |= KeyMap::GetPadKey({pad_id+2, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+3, joypad_id}).hex; + break; + + case SDL_HAT_LEFTDOWN: + controller.pad_state.hex |= KeyMap::GetPadKey({pad_id, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+1, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+2, joypad_id}).hex; + controller.pad_state.hex |= KeyMap::GetPadKey({pad_id+3, joypad_id}).hex; + break; + + case SDL_HAT_RIGHT: + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex; + controller.pad_state.hex |= KeyMap::GetPadKey({pad_id+1, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+2, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+3, joypad_id}).hex; + break; + + case SDL_HAT_RIGHTUP: + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex; + controller.pad_state.hex |= KeyMap::GetPadKey({pad_id+1, joypad_id}).hex; + controller.pad_state.hex |= KeyMap::GetPadKey({pad_id+2, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+3, joypad_id}).hex; + break; + + case SDL_HAT_RIGHTDOWN: + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex; + controller.pad_state.hex |= KeyMap::GetPadKey({pad_id+1, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+2, joypad_id}).hex; + controller.pad_state.hex |= KeyMap::GetPadKey({pad_id+3, joypad_id}).hex; + break; + + case SDL_HAT_UP: + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+1, joypad_id}).hex; + controller.pad_state.hex |= KeyMap::GetPadKey({pad_id+2, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+3, joypad_id}).hex; + break; + + case SDL_HAT_DOWN: + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+1, joypad_id}).hex; + controller.pad_state.hex &= ~KeyMap::GetPadKey({pad_id+2, joypad_id}).hex; + controller.pad_state.hex |= KeyMap::GetPadKey({pad_id+3, joypad_id}).hex; + break; } break;