Mercurial > repos > blastem
changeset 2318:1c7329ac7f3f
Make UI respect stick deadzone
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 02 Apr 2023 23:36:30 -0700 |
parents | e836cf11783b |
children | ab3d8759da08 |
files | nuklear_ui/nuklear_sdl_gles2.h render_sdl.c render_sdl.h |
diffstat | 3 files changed, 12 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/nuklear_ui/nuklear_sdl_gles2.h Sun Apr 02 23:21:39 2023 -0700 +++ b/nuklear_ui/nuklear_sdl_gles2.h Sun Apr 02 23:36:30 2023 -0700 @@ -23,7 +23,9 @@ #include <GL/glew.h> #endif #endif +#include "../render_sdl.h" #include "../render.h" +#include "../controller_info.h" NK_API struct nk_context* nk_sdl_init(SDL_Window *win); @@ -432,7 +434,9 @@ } } else if (evt->type == SDL_CONTROLLERAXISMOTION) { if (evt->caxis.axis == SDL_CONTROLLER_AXIS_LEFTY || evt->caxis.axis == SDL_CONTROLLER_AXIS_RIGHTY) { - int down = abs(evt->caxis.value) > 2000; + int joystick = render_find_joystick_index(evt->caxis.which); + controller_info info = get_controller_info(joystick); + int down = abs(evt->caxis.value) > info.stick_deadzone; if (evt->caxis.value >= 0) { if (ctx->input.keyboard.keys[NK_KEY_UP].down) { nk_input_key(ctx, NK_KEY_UP, 0);
--- a/render_sdl.c Sun Apr 02 23:21:39 2023 -0700 +++ b/render_sdl.c Sun Apr 02 23:36:30 2023 -0700 @@ -705,7 +705,7 @@ custom_event_handler = handler; } -static int find_joystick_index(SDL_JoystickID instanceID) +int render_find_joystick_index(SDL_JoystickID instanceID) { for (int i = 0; i < MAX_JOYSTICKS; i++) { if (joysticks[i] && SDL_JoystickInstanceID(joysticks[i]) == instanceID) { @@ -838,16 +838,16 @@ handle_keyup(event->key.keysym.sym, scancode_map[event->key.keysym.scancode]); break; case SDL_JOYBUTTONDOWN: - handle_joydown(find_joystick_index(event->jbutton.which), event->jbutton.button); + handle_joydown(render_find_joystick_index(event->jbutton.which), event->jbutton.button); break; case SDL_JOYBUTTONUP: - handle_joyup(lock_joystick_index(find_joystick_index(event->jbutton.which), -1), event->jbutton.button); + handle_joyup(lock_joystick_index(render_find_joystick_index(event->jbutton.which), -1), event->jbutton.button); break; case SDL_JOYHATMOTION: - handle_joy_dpad(lock_joystick_index(find_joystick_index(event->jhat.which), -1), event->jhat.hat, event->jhat.value); + handle_joy_dpad(lock_joystick_index(render_find_joystick_index(event->jhat.which), -1), event->jhat.hat, event->jhat.value); break; case SDL_JOYAXISMOTION: - handle_joy_axis(lock_joystick_index(find_joystick_index(event->jaxis.which), -1), event->jaxis.axis, event->jaxis.value); + handle_joy_axis(lock_joystick_index(render_find_joystick_index(event->jaxis.which), -1), event->jaxis.axis, event->jaxis.value); break; case SDL_JOYDEVICEADDED: if (event->jdevice.which < MAX_JOYSTICKS) { @@ -868,7 +868,7 @@ } break; case SDL_JOYDEVICEREMOVED: { - int index = find_joystick_index(event->jdevice.which); + int index = render_find_joystick_index(event->jdevice.which); if (index >= 0) { SDL_JoystickClose(joysticks[index]); joysticks[index] = NULL;
--- a/render_sdl.h Sun Apr 02 23:21:39 2023 -0700 +++ b/render_sdl.h Sun Apr 02 23:36:30 2023 -0700 @@ -8,6 +8,7 @@ void render_set_event_handler(event_handler handler); SDL_Joystick *render_get_joystick(int index); SDL_GameController *render_get_controller(int index); +int render_find_joystick_index(SDL_JoystickID instanceID); int render_lookup_button(char *name); int render_lookup_axis(char *name); void render_enable_gamepad_events(uint8_t enabled);