diff options
| author | 2023-05-05 17:11:53 -0600 | |
|---|---|---|
| committer | 2023-05-05 17:18:35 -0600 | |
| commit | f017335fef95d2cecc0fcda185f0e59cc1945101 (patch) | |
| tree | 3c119e1e6f51506e039a519b0baf245ae9b41747 | |
| parent | yuzu: Add motion preview to controller input (diff) | |
| download | yuzu-f017335fef95d2cecc0fcda185f0e59cc1945101.tar.gz yuzu-f017335fef95d2cecc0fcda185f0e59cc1945101.tar.xz yuzu-f017335fef95d2cecc0fcda185f0e59cc1945101.zip | |
input_common: Add property to invert an axis button
Diffstat (limited to '')
| -rw-r--r-- | src/common/input.h | 2 | ||||
| -rw-r--r-- | src/common/vector_math.h | 2 | ||||
| -rw-r--r-- | src/core/hid/input_converter.cpp | 1 | ||||
| -rw-r--r-- | src/input_common/input_engine.cpp | 2 | ||||
| -rw-r--r-- | src/input_common/input_poller.cpp | 1 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 10 |
6 files changed, 15 insertions, 3 deletions
diff --git a/src/common/input.h b/src/common/input.h index 51b277c1f..66fb15f0a 100644 --- a/src/common/input.h +++ b/src/common/input.h | |||
| @@ -111,6 +111,8 @@ struct AnalogProperties { | |||
| 111 | float offset{}; | 111 | float offset{}; |
| 112 | // Invert direction of the sensor data | 112 | // Invert direction of the sensor data |
| 113 | bool inverted{}; | 113 | bool inverted{}; |
| 114 | // Invert the state if it's converted to a button | ||
| 115 | bool inverted_button{}; | ||
| 114 | // Press once to activate, press again to release | 116 | // Press once to activate, press again to release |
| 115 | bool toggle{}; | 117 | bool toggle{}; |
| 116 | }; | 118 | }; |
diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 9a7d50abd..b4885835d 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h | |||
| @@ -265,7 +265,7 @@ public: | |||
| 265 | z = std::sin(roll) * temp + std::cos(roll) * z; | 265 | z = std::sin(roll) * temp + std::cos(roll) * z; |
| 266 | 266 | ||
| 267 | temp = x; | 267 | temp = x; |
| 268 | x = std::cosf(pitch) * x + std::sin(pitch) * z; | 268 | x = std::cos(pitch) * x + std::sin(pitch) * z; |
| 269 | z = -std::sin(pitch) * temp + std::cos(pitch) * z; | 269 | z = -std::sin(pitch) * temp + std::cos(pitch) * z; |
| 270 | 270 | ||
| 271 | temp = x; | 271 | temp = x; |
diff --git a/src/core/hid/input_converter.cpp b/src/core/hid/input_converter.cpp index 7cee39a53..a38e3bb3f 100644 --- a/src/core/hid/input_converter.cpp +++ b/src/core/hid/input_converter.cpp | |||
| @@ -54,6 +54,7 @@ Common::Input::ButtonStatus TransformToButton(const Common::Input::CallbackStatu | |||
| 54 | case Common::Input::InputType::Analog: | 54 | case Common::Input::InputType::Analog: |
| 55 | status.value = TransformToTrigger(callback).pressed.value; | 55 | status.value = TransformToTrigger(callback).pressed.value; |
| 56 | status.toggle = callback.analog_status.properties.toggle; | 56 | status.toggle = callback.analog_status.properties.toggle; |
| 57 | status.inverted = callback.analog_status.properties.inverted_button; | ||
| 57 | break; | 58 | break; |
| 58 | case Common::Input::InputType::Trigger: | 59 | case Common::Input::InputType::Trigger: |
| 59 | status.value = TransformToTrigger(callback).pressed.value; | 60 | status.value = TransformToTrigger(callback).pressed.value; |
diff --git a/src/input_common/input_engine.cpp b/src/input_common/input_engine.cpp index 91aa96aa7..49f5e7f54 100644 --- a/src/input_common/input_engine.cpp +++ b/src/input_common/input_engine.cpp | |||
| @@ -58,6 +58,8 @@ void InputEngine::SetHatButton(const PadIdentifier& identifier, int button, u8 v | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | void InputEngine::SetAxis(const PadIdentifier& identifier, int axis, f32 value) { | 60 | void InputEngine::SetAxis(const PadIdentifier& identifier, int axis, f32 value) { |
| 61 | value /= 2.0f; | ||
| 62 | value -= 0.5f; | ||
| 61 | { | 63 | { |
| 62 | std::scoped_lock lock{mutex}; | 64 | std::scoped_lock lock{mutex}; |
| 63 | ControllerData& controller = controller_list.at(identifier); | 65 | ControllerData& controller = controller_list.at(identifier); |
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index 8c6a6521a..5c2c4a463 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp | |||
| @@ -939,6 +939,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateAnalogDevice( | |||
| 939 | .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), | 939 | .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), |
| 940 | .offset = std::clamp(params.Get("offset", 0.0f), -1.0f, 1.0f), | 940 | .offset = std::clamp(params.Get("offset", 0.0f), -1.0f, 1.0f), |
| 941 | .inverted = params.Get("invert", "+") == "-", | 941 | .inverted = params.Get("invert", "+") == "-", |
| 942 | .inverted_button = params.Get("inverted", false) != 0, | ||
| 942 | .toggle = params.Get("toggle", false) != 0, | 943 | .toggle = params.Get("toggle", false) != 0, |
| 943 | }; | 944 | }; |
| 944 | input_engine->PreSetController(identifier); | 945 | input_engine->PreSetController(identifier); |
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 50b62293e..54f42e0c9 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -206,7 +206,7 @@ QString ConfigureInputPlayer::ButtonToText(const Common::ParamPackage& param) { | |||
| 206 | } | 206 | } |
| 207 | if (param.Has("axis")) { | 207 | if (param.Has("axis")) { |
| 208 | const QString axis = QString::fromStdString(param.Get("axis", "")); | 208 | const QString axis = QString::fromStdString(param.Get("axis", "")); |
| 209 | return QObject::tr("%1%2Axis %3").arg(toggle, invert, axis); | 209 | return QObject::tr("%1%2%3Axis %4").arg(toggle, inverted, invert, axis); |
| 210 | } | 210 | } |
| 211 | if (param.Has("axis_x") && param.Has("axis_y") && param.Has("axis_z")) { | 211 | if (param.Has("axis_x") && param.Has("axis_y") && param.Has("axis_z")) { |
| 212 | const QString axis_x = QString::fromStdString(param.Get("axis_x", "")); | 212 | const QString axis_x = QString::fromStdString(param.Get("axis_x", "")); |
| @@ -229,7 +229,7 @@ QString ConfigureInputPlayer::ButtonToText(const Common::ParamPackage& param) { | |||
| 229 | return QObject::tr("%1%2%3Hat %4").arg(turbo, toggle, inverted, button_name); | 229 | return QObject::tr("%1%2%3Hat %4").arg(turbo, toggle, inverted, button_name); |
| 230 | } | 230 | } |
| 231 | if (param.Has("axis")) { | 231 | if (param.Has("axis")) { |
| 232 | return QObject::tr("%1%2Axis %3").arg(toggle, inverted, button_name); | 232 | return QObject::tr("%1%2%3Axis %4").arg(toggle, inverted, invert, button_name); |
| 233 | } | 233 | } |
| 234 | if (param.Has("motion")) { | 234 | if (param.Has("motion")) { |
| 235 | return QObject::tr("%1%2Axis %3").arg(toggle, inverted, button_name); | 235 | return QObject::tr("%1%2Axis %3").arg(toggle, inverted, button_name); |
| @@ -410,6 +410,12 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 410 | button_map[button_id]->setText(ButtonToText(param)); | 410 | button_map[button_id]->setText(ButtonToText(param)); |
| 411 | emulated_controller->SetButtonParam(button_id, param); | 411 | emulated_controller->SetButtonParam(button_id, param); |
| 412 | }); | 412 | }); |
| 413 | context_menu.addAction(tr("Invert button"), [&] { | ||
| 414 | const bool invert_value = !param.Get("inverted", false); | ||
| 415 | param.Set("inverted", invert_value); | ||
| 416 | button_map[button_id]->setText(ButtonToText(param)); | ||
| 417 | emulated_controller->SetButtonParam(button_id, param); | ||
| 418 | }); | ||
| 413 | context_menu.addAction(tr("Set threshold"), [&] { | 419 | context_menu.addAction(tr("Set threshold"), [&] { |
| 414 | const int button_threshold = | 420 | const int button_threshold = |
| 415 | static_cast<int>(param.Get("threshold", 0.5f) * 100.0f); | 421 | static_cast<int>(param.Get("threshold", 0.5f) * 100.0f); |