Added support for hat input aka 'dpads'

This commit is contained in:
Daniel Stuart Baxter 2015-05-29 09:44:41 -05:00
parent d1d04df937
commit c736bc2572

View File

@ -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;