From 149654df5a7db04315badc95354bab3ccd02964f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 17 Jul 2016 14:32:06 +0200 Subject: [PATCH] Add a recenter control for Wiimote IR relative input This adds a recenter control binding which allows recentering the cursor when relative input is enabled. (EnableSettingControl is renamed to avoid confusions.) --- Source/Core/DolphinWX/InputConfigDiag.cpp | 35 +++++++++++++++++++---- Source/Core/DolphinWX/InputConfigDiag.h | 6 ++-- Source/Core/InputCommon/ControllerEmu.cpp | 1 + Source/Core/InputCommon/ControllerEmu.h | 7 +++++ 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/Source/Core/DolphinWX/InputConfigDiag.cpp b/Source/Core/DolphinWX/InputConfigDiag.cpp index d11c2b7db6..2748f70124 100644 --- a/Source/Core/DolphinWX/InputConfigDiag.cpp +++ b/Source/Core/DolphinWX/InputConfigDiag.cpp @@ -167,8 +167,10 @@ ControlDialog::ControlDialog(GamepadPage* const parent, InputConfig& config, ControlButton::ControlButton(wxWindow* const parent, ControllerInterface::ControlReference* const _ref, - const unsigned int width, const std::string& label) - : wxButton(parent, wxID_ANY, "", wxDefaultPosition, wxSize(width, 20)), control_reference(_ref) + const std::string& name, const unsigned int width, + const std::string& label) + : wxButton(parent, wxID_ANY, "", wxDefaultPosition, wxSize(width, 20)), control_reference(_ref), + m_name(name) { if (label.empty()) SetLabel(StrToWxStr(_ref->expression)); @@ -457,8 +459,8 @@ void ControlDialog::AppendControl(wxCommandEvent& event) UpdateGUI(); } -void GamepadPage::EnableSettingControl(const std::string& group_name, const std::string& name, - const bool enabled) +void GamepadPage::EnablePadSetting(const std::string& group_name, const std::string& name, + const bool enabled) { const auto box_iterator = std::find_if(control_groups.begin(), control_groups.end(), [&group_name](const auto& box) { @@ -477,6 +479,25 @@ void GamepadPage::EnableSettingControl(const std::string& group_name, const std: (*it)->wxcontrol->Enable(enabled); } +void GamepadPage::EnableControlButton(const std::string& group_name, const std::string& name, + const bool enabled) +{ + const auto box_iterator = + std::find_if(control_groups.begin(), control_groups.end(), [&group_name](const auto& box) { + return group_name == box->control_group->name; + }); + if (box_iterator == control_groups.end()) + return; + + const auto* box = *box_iterator; + const auto it = + std::find_if(box->control_buttons.begin(), box->control_buttons.end(), + [&name](const auto& control_button) { return control_button->m_name == name; }); + if (it == box->control_buttons.end()) + return; + (*it)->Enable(enabled); +} + void GamepadPage::AdjustSetting(wxCommandEvent& event) { const auto* const control = static_cast(event.GetEventObject()); @@ -497,7 +518,8 @@ void GamepadPage::AdjustBooleanSetting(wxCommandEvent& event) } else if (control->GetLabelText() == "Relative Input") { - EnableSettingControl("IR", "Dead Zone", pad_setting->setting->GetValue()); + EnablePadSetting("IR", "Dead Zone", pad_setting->setting->GetValue()); + EnableControlButton("IR", "Recenter", pad_setting->setting->GetValue()); } } @@ -825,7 +847,8 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin wxStaticText* const label = new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(control->name))); - ControlButton* const control_button = new ControlButton(parent, control->control_ref.get(), 80); + ControlButton* const control_button = + new ControlButton(parent, control->control_ref.get(), control->name, 80); control_button->SetFont(m_SmallFont); control_buttons.push_back(control_button); diff --git a/Source/Core/DolphinWX/InputConfigDiag.h b/Source/Core/DolphinWX/InputConfigDiag.h index 36d1d15017..7f982e5bd3 100644 --- a/Source/Core/DolphinWX/InputConfigDiag.h +++ b/Source/Core/DolphinWX/InputConfigDiag.h @@ -165,9 +165,10 @@ class ControlButton : public wxButton { public: ControlButton(wxWindow* const parent, ControllerInterface::ControlReference* const _ref, - const unsigned int width, const std::string& label = ""); + const std::string& name, const unsigned int width, const std::string& label = ""); ControllerInterface::ControlReference* const control_reference; + const std::string m_name; }; class ControlGroupBox : public wxBoxSizer @@ -223,7 +224,8 @@ public: void LoadDefaults(wxCommandEvent& event); void AdjustControlOption(wxCommandEvent& event); - void EnableSettingControl(const std::string& group_name, const std::string& name, bool enabled); + void EnablePadSetting(const std::string& group_name, const std::string& name, bool enabled); + void EnableControlButton(const std::string& group_name, const std::string& name, bool enabled); void AdjustSetting(wxCommandEvent& event); void AdjustBooleanSetting(wxCommandEvent& event); diff --git a/Source/Core/InputCommon/ControllerEmu.cpp b/Source/Core/InputCommon/ControllerEmu.cpp index 5b0b93f021..84f511f822 100644 --- a/Source/Core/InputCommon/ControllerEmu.cpp +++ b/Source/Core/InputCommon/ControllerEmu.cpp @@ -295,6 +295,7 @@ ControllerEmu::Cursor::Cursor(const std::string& _name) controls.emplace_back(std::make_unique("Forward")); controls.emplace_back(std::make_unique("Backward")); controls.emplace_back(std::make_unique(_trans("Hide"))); + controls.emplace_back(std::make_unique("Recenter")); numeric_settings.emplace_back(std::make_unique(_trans("Center"), 0.5)); numeric_settings.emplace_back(std::make_unique(_trans("Width"), 0.5)); diff --git a/Source/Core/InputCommon/ControllerEmu.h b/Source/Core/InputCommon/ControllerEmu.h index d90850b137..90247d699e 100644 --- a/Source/Core/InputCommon/ControllerEmu.h +++ b/Source/Core/InputCommon/ControllerEmu.h @@ -434,6 +434,13 @@ public: 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); + + // recenter + if (controls[7]->control_ref->State() > 0.5) + { + m_x = 0.0; + m_y = 0.0; + } } else {