diff options
author | german77 <juangerman-13@hotmail.com> | 2022-02-06 18:46:54 -0600 |
---|---|---|
committer | german77 <juangerman-13@hotmail.com> | 2022-02-06 19:56:03 -0600 |
commit | 6a4ab3e0d25dcc5b37cc146f99cf167dc4e8a6b6 (patch) | |
tree | 22aba4c6a3a031eb66cae703ac8b640f1afef148 /src/yuzu/configuration/configure_input_player.cpp | |
parent | b720009dc0641a0899d9be347c892472a6916ef5 (diff) |
yuzu: Add auto center on right click
Diffstat (limited to 'src/yuzu/configuration/configure_input_player.cpp')
-rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index cc0534907a..9db564663e 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp @@ -488,6 +488,32 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i emulated_controller->SetStickParam(analog_id, {}); analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]")); }); + context_menu.addAction(tr("Center axis"), [&] { + const auto stick_value = + emulated_controller->GetSticksValues()[analog_id]; + const float offset_x = stick_value.x.properties.offset; + const float offset_y = stick_value.y.properties.offset; + float raw_value_x = stick_value.x.raw_value; + float raw_value_y = stick_value.y.raw_value; + // See Core::HID::SanitizeStick() to obtain the original raw axis value + if (std::abs(offset_x) < 0.5f) { + if (raw_value_x > 0) { + raw_value_x *= 1 + offset_x; + } else { + raw_value_x *= 1 - offset_x; + } + } + if (std::abs(offset_x) < 0.5f) { + if (raw_value_y > 0) { + raw_value_y *= 1 + offset_y; + } else { + raw_value_y *= 1 - offset_y; + } + } + param.Set("offset_x", -raw_value_x + offset_x); + param.Set("offset_y", -raw_value_y + offset_y); + emulated_controller->SetStickParam(analog_id, param); + }); context_menu.addAction(tr("Invert axis"), [&] { if (sub_button_id == 2 || sub_button_id == 3) { const bool invert_value = param.Get("invert_x", "+") == "-"; |