From be970bcfe469d58ad7ba3335d1a69d2c6f5c3757 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 28 Feb 2025 18:06:43 +1000 Subject: [PATCH] Qt: Handle inverted+negated axes when mapping --- src/core/fullscreen_ui.cpp | 5 +++-- src/duckstation-qt/inputbindingdialog.cpp | 5 +++-- src/duckstation-qt/inputbindingwidgets.cpp | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/fullscreen_ui.cpp b/src/core/fullscreen_ui.cpp index 63b40f713..71d8cb9bd 100644 --- a/src/core/fullscreen_ui.cpp +++ b/src/core/fullscreen_ui.cpp @@ -2270,7 +2270,8 @@ void FullscreenUI::BeginInputBinding(SettingsInterface* bsi, InputBindingInfo::T } const float abs_value = std::abs(value); - const bool reverse_threshold = (key.source_subtype == InputSubclass::ControllerAxis && initial_value > 0.5f); + const bool reverse_threshold = + (key.source_subtype == InputSubclass::ControllerAxis && std::abs(initial_value) > 0.5f); for (InputBindingKey& other_key : s_state.input_binding_new_bindings) { @@ -2305,7 +2306,7 @@ void FullscreenUI::BeginInputBinding(SettingsInterface* bsi, InputBindingInfo::T if ((reverse_threshold ? (abs_value < 0.5f) : (abs_value >= 0.5f))) { InputBindingKey key_to_add = key; - key_to_add.modifier = (value < 0.0f && !reverse_threshold) ? InputModifier::Negate : InputModifier::None; + key_to_add.modifier = (value < 0.0f) ? InputModifier::Negate : InputModifier::None; key_to_add.invert = reverse_threshold; s_state.input_binding_new_bindings.push_back(key_to_add); } diff --git a/src/duckstation-qt/inputbindingdialog.cpp b/src/duckstation-qt/inputbindingdialog.cpp index 9a3419390..a1753832c 100644 --- a/src/duckstation-qt/inputbindingdialog.cpp +++ b/src/duckstation-qt/inputbindingdialog.cpp @@ -306,7 +306,8 @@ void InputBindingDialog::inputManagerHookCallback(InputBindingKey key, float val } const float abs_value = std::abs(value); - const bool reverse_threshold = (key.source_subtype == InputSubclass::ControllerAxis && initial_value > 0.5f); + const bool reverse_threshold = + (key.source_subtype == InputSubclass::ControllerAxis && std::abs(initial_value) > 0.5f); for (InputBindingKey& other_key : m_new_bindings) { @@ -334,7 +335,7 @@ void InputBindingDialog::inputManagerHookCallback(InputBindingKey key, float val if ((reverse_threshold ? (abs_value < 0.5f) : (abs_value >= 0.5f))) { InputBindingKey key_to_add = key; - key_to_add.modifier = (value < 0.0f && !reverse_threshold) ? InputModifier::Negate : InputModifier::None; + key_to_add.modifier = (value < 0.0f) ? InputModifier::Negate : InputModifier::None; key_to_add.invert = reverse_threshold; m_new_bindings.push_back(key_to_add); } diff --git a/src/duckstation-qt/inputbindingwidgets.cpp b/src/duckstation-qt/inputbindingwidgets.cpp index bb195e75f..03325bc43 100644 --- a/src/duckstation-qt/inputbindingwidgets.cpp +++ b/src/duckstation-qt/inputbindingwidgets.cpp @@ -346,7 +346,8 @@ void InputBindingWidget::inputManagerHookCallback(InputBindingKey key, float val } const float abs_value = std::abs(value); - const bool reverse_threshold = (key.source_subtype == InputSubclass::ControllerAxis && initial_value > 0.5f); + const bool reverse_threshold = + (key.source_subtype == InputSubclass::ControllerAxis && std::abs(initial_value) > 0.5f); for (InputBindingKey& other_key : m_new_bindings) { @@ -374,7 +375,7 @@ void InputBindingWidget::inputManagerHookCallback(InputBindingKey key, float val if ((reverse_threshold ? (abs_value < 0.5f) : (abs_value >= 0.5f))) { InputBindingKey key_to_add = key; - key_to_add.modifier = (value < 0.0f && !reverse_threshold) ? InputModifier::Negate : InputModifier::None; + key_to_add.modifier = (value < 0.0f) ? InputModifier::Negate : InputModifier::None; key_to_add.invert = reverse_threshold; m_new_bindings.push_back(key_to_add); }