From 5cf07fdfbf07bbf768f3ed02bc29b45713b08106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sat, 9 Jul 2016 14:29:41 +0200 Subject: [PATCH] Add relative input for the Wiimote IR This adds an option to enable relative input for the Wiimote IR as described in issue 9014. Enabling it will result in the pointer not going back to the centre and the inputs will control the direction, not the absolute position. Also adds a Dead Zone setting which is really needed when relative input is enabled to prevent the cursor from slowly drifting on most controllers. (Note: the Deadzone setting has no effect when relative input is disabled) --- Source/Core/DolphinWX/InputConfigDiag.cpp | 7 ++++++ Source/Core/InputCommon/ControllerEmu.cpp | 2 ++ Source/Core/InputCommon/ControllerEmu.h | 29 +++++++++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) 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