diff --git a/Source/Core/DolphinWX/InputConfigDiag.cpp b/Source/Core/DolphinWX/InputConfigDiag.cpp index 5971e3ac60..5f77ba7434 100644 --- a/Source/Core/DolphinWX/InputConfigDiag.cpp +++ b/Source/Core/DolphinWX/InputConfigDiag.cpp @@ -843,6 +843,13 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(groupSetting->m_name)))); szr->Add(setting->wxcontrol, 0, wxLEFT, 0); } + for (auto& groupSetting : group->boolean_settings) + { + auto* checkbox = new PadSettingCheckBox(parent, groupSetting.get()); + checkbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustSetting, eventsink); + options.push_back(checkbox); + Add(checkbox->wxcontrol, 0, wxALL | wxLEFT, 5); + } wxBoxSizer* const h_szr = new wxBoxSizer(wxHORIZONTAL); h_szr->Add(szr, 1, 0, 5); diff --git a/Source/Core/InputCommon/ControllerEmu.cpp b/Source/Core/InputCommon/ControllerEmu.cpp index 2fd85b3fac..5b0b93f021 100644 --- a/Source/Core/InputCommon/ControllerEmu.cpp +++ b/Source/Core/InputCommon/ControllerEmu.cpp @@ -299,6 +299,8 @@ ControllerEmu::Cursor::Cursor(const std::string& _name) numeric_settings.emplace_back(std::make_unique(_trans("Center"), 0.5)); numeric_settings.emplace_back(std::make_unique(_trans("Width"), 0.5)); numeric_settings.emplace_back(std::make_unique(_trans("Height"), 0.5)); + numeric_settings.emplace_back(std::make_unique(_trans("Dead Zone"), 0, 0, 20)); + boolean_settings.emplace_back(std::make_unique(_trans("Relative Input"), false)); } void ControllerEmu::LoadDefaults(const ControllerInterface& ciface) diff --git a/Source/Core/InputCommon/ControllerEmu.h b/Source/Core/InputCommon/ControllerEmu.h index 215b2557b4..d90850b137 100644 --- a/Source/Core/InputCommon/ControllerEmu.h +++ b/Source/Core/InputCommon/ControllerEmu.h @@ -12,6 +12,7 @@ #include #include "Common/IniFile.h" +#include "Common/MathUtil.h" #include "Core/ConfigManager.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/GCPadStatus.h" @@ -424,12 +425,36 @@ public: yy += (numeric_settings[0]->GetValue() - 0.5); } - *x = xx; - *y = yy; + // relative input + if (boolean_settings[0]->GetValue()) + { + const ControlState deadzone = numeric_settings[3]->GetValue(); + // deadzone to avoid the cursor slowly drifting + if (std::abs(xx) > deadzone) + m_x = MathUtil::Clamp(m_x + xx * SPEED_MULTIPLIER, -1.0, 1.0); + if (std::abs(yy) > deadzone) + m_y = MathUtil::Clamp(m_y + yy * SPEED_MULTIPLIER, -1.0, 1.0); + } + else + { + m_x = xx; + m_y = yy; + } + + *x = m_x; + *y = m_y; } } ControlState m_z; + + private: + // This is used to reduce the cursor speed for relative input + // to something that makes sense with the default range. + static constexpr double SPEED_MULTIPLIER = 0.04; + + ControlState m_x = 0.0; + ControlState m_y = 0.0; }; class Extension : public ControlGroup