comparison render_sdl.c @ 2318:1c7329ac7f3f

Make UI respect stick deadzone
author Michael Pavone <pavone@retrodev.com>
date Sun, 02 Apr 2023 23:36:30 -0700
parents b67e4e930fa4
children 0111c8344477
comparison
equal deleted inserted replaced
2317:e836cf11783b 2318:1c7329ac7f3f
703 void render_set_event_handler(event_handler handler) 703 void render_set_event_handler(event_handler handler)
704 { 704 {
705 custom_event_handler = handler; 705 custom_event_handler = handler;
706 } 706 }
707 707
708 static int find_joystick_index(SDL_JoystickID instanceID) 708 int render_find_joystick_index(SDL_JoystickID instanceID)
709 { 709 {
710 for (int i = 0; i < MAX_JOYSTICKS; i++) { 710 for (int i = 0; i < MAX_JOYSTICKS; i++) {
711 if (joysticks[i] && SDL_JoystickInstanceID(joysticks[i]) == instanceID) { 711 if (joysticks[i] && SDL_JoystickInstanceID(joysticks[i]) == instanceID) {
712 return i; 712 return i;
713 } 713 }
836 break; 836 break;
837 case SDL_KEYUP: 837 case SDL_KEYUP:
838 handle_keyup(event->key.keysym.sym, scancode_map[event->key.keysym.scancode]); 838 handle_keyup(event->key.keysym.sym, scancode_map[event->key.keysym.scancode]);
839 break; 839 break;
840 case SDL_JOYBUTTONDOWN: 840 case SDL_JOYBUTTONDOWN:
841 handle_joydown(find_joystick_index(event->jbutton.which), event->jbutton.button); 841 handle_joydown(render_find_joystick_index(event->jbutton.which), event->jbutton.button);
842 break; 842 break;
843 case SDL_JOYBUTTONUP: 843 case SDL_JOYBUTTONUP:
844 handle_joyup(lock_joystick_index(find_joystick_index(event->jbutton.which), -1), event->jbutton.button); 844 handle_joyup(lock_joystick_index(render_find_joystick_index(event->jbutton.which), -1), event->jbutton.button);
845 break; 845 break;
846 case SDL_JOYHATMOTION: 846 case SDL_JOYHATMOTION:
847 handle_joy_dpad(lock_joystick_index(find_joystick_index(event->jhat.which), -1), event->jhat.hat, event->jhat.value); 847 handle_joy_dpad(lock_joystick_index(render_find_joystick_index(event->jhat.which), -1), event->jhat.hat, event->jhat.value);
848 break; 848 break;
849 case SDL_JOYAXISMOTION: 849 case SDL_JOYAXISMOTION:
850 handle_joy_axis(lock_joystick_index(find_joystick_index(event->jaxis.which), -1), event->jaxis.axis, event->jaxis.value); 850 handle_joy_axis(lock_joystick_index(render_find_joystick_index(event->jaxis.which), -1), event->jaxis.axis, event->jaxis.value);
851 break; 851 break;
852 case SDL_JOYDEVICEADDED: 852 case SDL_JOYDEVICEADDED:
853 if (event->jdevice.which < MAX_JOYSTICKS) { 853 if (event->jdevice.which < MAX_JOYSTICKS) {
854 int index = lowest_unused_joystick_index(); 854 int index = lowest_unused_joystick_index();
855 if (index >= 0) { 855 if (index >= 0) {
866 } 866 }
867 } 867 }
868 } 868 }
869 break; 869 break;
870 case SDL_JOYDEVICEREMOVED: { 870 case SDL_JOYDEVICEREMOVED: {
871 int index = find_joystick_index(event->jdevice.which); 871 int index = render_find_joystick_index(event->jdevice.which);
872 if (index >= 0) { 872 if (index >= 0) {
873 SDL_JoystickClose(joysticks[index]); 873 SDL_JoystickClose(joysticks[index]);
874 joysticks[index] = NULL; 874 joysticks[index] = NULL;
875 if (controllers[index]) { 875 if (controllers[index]) {
876 SDL_GameControllerClose(controllers[index]); 876 SDL_GameControllerClose(controllers[index]);