Move key mapping into its own function

This commit is contained in:
Jeffrey Pfau 2014-02-03 22:27:58 -08:00
parent 5a17030c65
commit 90760a30a3
2 changed files with 24 additions and 21 deletions

View File

@ -28,6 +28,26 @@ void GBASDLDeinitEvents(struct GBASDLEvents* context) {
SDL_QuitSubSystem(SDL_INIT_JOYSTICK); 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) { static void _pauseAfterFrame(struct GBAThread* context) {
context->frameCallback = 0; context->frameCallback = 0;
GBAThreadPause(context); 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) { static void _GBASDLHandleJoyButton(struct GBAThread* context, const struct SDL_JoyButtonEvent* event) {
enum GBAKey key = 0; enum GBAKey key = 0;
// Sorry, hardcoded to my gamepad for now key = GBASDLMapButtonToKey(event->button);
switch (event->button) { if (key == GBA_KEY_NONE) {
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:
return; return;
} }

View File

@ -18,4 +18,6 @@ void GBASDLDeinitEvents(struct GBASDLEvents*);
void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLEvents* sdlContext, const union SDL_Event* event); void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLEvents* sdlContext, const union SDL_Event* event);
enum GBAKey GBASDLMapButtonToKey(int button);
#endif #endif