Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor GUI change to add an option that sets the deadzone for analog sticks #1271

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions core/input/gamepad_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<GamepadDevice>& gamepad);

Expand Down Expand Up @@ -109,6 +119,7 @@ class GamepadDevice
std::string _unique_id;
std::shared_ptr<InputMapping> input_mapper;
bool rumbleEnabled = false;
bool hasAnalogStick = false;
int rumblePower = 100;
u32 leftTrigger = ~0;
u32 rightTrigger = ~0;
Expand Down
1 change: 1 addition & 0 deletions core/linux-dist/evdev_gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
10 changes: 9 additions & 1 deletion core/rend/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 2 additions & 0 deletions core/sdl/sdl_gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions core/windows/xinput_gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<InputMapping> getDefaultMapping() override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ class AndroidGamepadDevice : public GamepadDevice
{
input_mapper = std::make_shared<IdentityInputMapping>();
rumbleEnabled = true;
// hasAnalogStick = true; // TODO has an analog stick but input mapping isn't persisted
}
else
{
loadMapping();
save_mapping();
hasAnalogStick = !fullAxes.empty();
}
}
~AndroidGamepadDevice() override
Expand Down
3 changes: 2 additions & 1 deletion shell/apple/emulator-ios/emulator/ios_gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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; }
Expand Down