From 90760a30a3681c99db8b5964e671e4d1ac6d581b Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Mon, 3 Feb 2014 22:27:58 -0800 Subject: [PATCH] Move key mapping into its own function --- src/platform/sdl/sdl-events.c | 43 ++++++++++++++++++----------------- src/platform/sdl/sdl-events.h | 2 ++ 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/platform/sdl/sdl-events.c b/src/platform/sdl/sdl-events.c index 2133d37bb..1efea8360 100644 --- a/src/platform/sdl/sdl-events.c +++ b/src/platform/sdl/sdl-events.c @@ -28,6 +28,26 @@ void GBASDLDeinitEvents(struct GBASDLEvents* context) { SDL_QuitSubSystem(SDL_INIT_JOYSTICK); } +enum GBAKey GBASDLMapButtonToKey(int button) { + // Sorry, hardcoded to my gamepad for now + switch (button) { + case 2: + return GBA_KEY_A; + case 1: + return GBA_KEY_B; + case 6: + return GBA_KEY_L; + case 7: + return GBA_KEY_R; + case 8: + return GBA_KEY_START; + case 9: + return GBA_KEY_SELECT; + default: + return GBA_KEY_NONE; + } +} + static void _pauseAfterFrame(struct GBAThread* context) { context->frameCallback = 0; GBAThreadPause(context); @@ -165,27 +185,8 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLEvents static void _GBASDLHandleJoyButton(struct GBAThread* context, const struct SDL_JoyButtonEvent* event) { enum GBAKey key = 0; - // Sorry, hardcoded to my gamepad for now - switch (event->button) { - case 2: - key = GBA_KEY_A; - break; - case 1: - key = GBA_KEY_B; - break; - case 6: - key = GBA_KEY_L; - break; - case 7: - key = GBA_KEY_R; - break; - case 8: - key = GBA_KEY_START; - break; - case 9: - key = GBA_KEY_SELECT; - break; - default: + key = GBASDLMapButtonToKey(event->button); + if (key == GBA_KEY_NONE) { return; } diff --git a/src/platform/sdl/sdl-events.h b/src/platform/sdl/sdl-events.h index bbf2c832a..6d8b4a0ac 100644 --- a/src/platform/sdl/sdl-events.h +++ b/src/platform/sdl/sdl-events.h @@ -18,4 +18,6 @@ void GBASDLDeinitEvents(struct GBASDLEvents*); void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLEvents* sdlContext, const union SDL_Event* event); +enum GBAKey GBASDLMapButtonToKey(int button); + #endif