diff --git a/core/input/gamepad_device.h b/core/input/gamepad_device.h index 9819414cd..f2ede73de 100644 --- a/core/input/gamepad_device.h +++ b/core/input/gamepad_device.h @@ -70,6 +70,16 @@ class GamepadDevice } } } + bool has_analog_stick() const { return hasAnalogStick; } + float get_dead_zone() const { return input_mapper->dead_zone; } + void set_dead_zone(float deadzone) { + if (deadzone != input_mapper->dead_zone) + { + input_mapper->dead_zone = deadzone; + input_mapper->set_dirty(); + save_mapping(); + } + } static void Register(const std::shared_ptr& gamepad); @@ -109,6 +119,7 @@ class GamepadDevice std::string _unique_id; std::shared_ptr input_mapper; bool rumbleEnabled = false; + bool hasAnalogStick = false; int rumblePower = 100; u32 leftTrigger = ~0; u32 rightTrigger = ~0; diff --git a/core/linux-dist/evdev_gamepad.h b/core/linux-dist/evdev_gamepad.h index ae40832e8..cfbe27355 100644 --- a/core/linux-dist/evdev_gamepad.h +++ b/core/linux-dist/evdev_gamepad.h @@ -65,6 +65,7 @@ class EvdevGamepadDevice : public GamepadDevice } else INFO_LOG(INPUT, "using custom mapping '%s'", input_mapper->name.c_str()); + hasAnalogStick = true; } ~EvdevGamepadDevice() override { diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index 0a48ea75f..fa2353ab7 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -1682,9 +1682,17 @@ static void gui_display_settings() ImGui::SameLine(0, 16 * settings.display.uiScale); int power = gamepad->get_rumble_power(); ImGui::SetNextItemWidth(150 * settings.display.uiScale); - if (ImGui::SliderInt("Rumble", &power, 0, 100)) + if (ImGui::SliderInt("Rumble", &power, 0, 100, "%d%%")) gamepad->set_rumble_power(power); } + if (gamepad->has_analog_stick()) + { + ImGui::SameLine(0, 16 * settings.display.uiScale); + int deadzone = std::round(gamepad->get_dead_zone() * 100.f); + ImGui::SetNextItemWidth(150 * settings.display.uiScale); + if (ImGui::SliderInt("Dead zone", &deadzone, 0, 100, "%d%%")) + gamepad->set_dead_zone(deadzone / 100.f); + } ImGui::NextColumn(); ImGui::PopID(); } diff --git a/core/sdl/sdl_gamepad.h b/core/sdl/sdl_gamepad.h index a5fb64386..05e0a450c 100644 --- a/core/sdl/sdl_gamepad.h +++ b/core/sdl/sdl_gamepad.h @@ -205,6 +205,8 @@ class SDLGamepad : public GamepadDevice #else rumbleEnabled = (SDL_JoystickRumble(sdl_joystick, 1, 1, 1) != -1); #endif + + hasAnalogStick = SDL_JoystickNumAxes(sdl_joystick) > 0; } bool gamepad_axis_input(u32 code, int value) override diff --git a/core/windows/xinput_gamepad.h b/core/windows/xinput_gamepad.h index 873fc17d7..a6243e8fe 100644 --- a/core/windows/xinput_gamepad.h +++ b/core/windows/xinput_gamepad.h @@ -45,6 +45,7 @@ class XInputGamepadDevice : public GamepadDevice char buf[32]; sprintf(buf, "xinput-%d", xinput_port + 1); _unique_id = buf; + hasAnalogStick = true; } std::shared_ptr getDefaultMapping() override { diff --git a/shell/android-studio/flycast/src/main/jni/src/android_gamepad.h b/shell/android-studio/flycast/src/main/jni/src/android_gamepad.h index 159bf0b6b..c95b62057 100644 --- a/shell/android-studio/flycast/src/main/jni/src/android_gamepad.h +++ b/shell/android-studio/flycast/src/main/jni/src/android_gamepad.h @@ -107,11 +107,13 @@ class AndroidGamepadDevice : public GamepadDevice { input_mapper = std::make_shared(); rumbleEnabled = true; + // hasAnalogStick = true; // TODO has an analog stick but input mapping isn't persisted } else { loadMapping(); save_mapping(); + hasAnalogStick = !fullAxes.empty(); } } ~AndroidGamepadDevice() override diff --git a/shell/apple/emulator-ios/emulator/ios_gamepad.h b/shell/apple/emulator-ios/emulator/ios_gamepad.h index 5e4a4abd1..5b4b33317 100644 --- a/shell/apple/emulator-ios/emulator/ios_gamepad.h +++ b/shell/apple/emulator-ios/emulator/ios_gamepad.h @@ -229,7 +229,7 @@ class IOSGamepad : public GamepadDevice [gcController.extendedGamepad.rightThumbstick.yAxis setValueChangedHandler:^(GCControllerAxisInput *axis, float value) { gamepad_axis_input(IOS_AXIS_RY, (int)std::roundf(-32767.f * value)); }]; - + hasAnalogStick = true; } else { @@ -491,6 +491,7 @@ class IOSVirtualGamepad : public GamepadDevice _name = "Virtual Gamepad"; _unique_id = "ios-virtual-gamepad"; input_mapper = getDefaultMapping(); + //hasAnalogStick = true; // TODO has an analog stick but input mapping isn't persisted } bool is_virtual_gamepad() override { return true; }