From 8da314ea63f3d5379eabb515b56cf06e5910e152 Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 8 Feb 2018 21:54:30 +0000 Subject: [PATCH] Fixes for joypad buttons. --- src/system/input.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/system/input.c b/src/system/input.c index 8c8536b..92125c4 100644 --- a/src/system/input.c +++ b/src/system/input.c @@ -102,6 +102,22 @@ static void doMouseMotion(SDL_MouseMotionEvent *event) } } +static void doButtonDown(SDL_JoyButtonEvent *event) +{ + if (event->state == SDL_PRESSED) + { + app.joypadButton[event->button] = 1; + } +} + +static void doButtonUp(SDL_JoyButtonEvent *event) +{ + if (event->state == SDL_RELEASED) + { + app.joypadButton[event->button] = 0; + } +} + void clearInput(void) { SDL_Event event; @@ -150,6 +166,14 @@ void handleInput(void) case SDL_KEYUP: doKeyUp(&event.key); break; + + case SDL_JOYBUTTONDOWN: + doButtonDown(&event.jbutton); + break; + + case SDL_JOYBUTTONUP: + doButtonUp(&event.jbutton); + break; case SDL_QUIT: exit(0); @@ -158,11 +182,6 @@ void handleInput(void) } SDL_GetMouseState(&app.mouse.x, &app.mouse.y); - - for (i = 0 ; i < SDL_CONTROLLER_BUTTON_MAX ; i++) - { - app.joypadButton[i] = SDL_JoystickGetButton(app.joypad, i); - } for (i = 0 ; i < JOYPAD_AXIS_MAX ; i++) {