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.)
This commit is contained in:
Léo Lam 2016-07-17 14:32:06 +02:00
parent 1ad19f9371
commit 149654df5a
4 changed files with 41 additions and 8 deletions

View File

@ -167,8 +167,10 @@ ControlDialog::ControlDialog(GamepadPage* const parent, InputConfig& config,
ControlButton::ControlButton(wxWindow* const parent, ControlButton::ControlButton(wxWindow* const parent,
ControllerInterface::ControlReference* const _ref, ControllerInterface::ControlReference* const _ref,
const unsigned int width, const std::string& label) const std::string& name, const unsigned int width,
: wxButton(parent, wxID_ANY, "", wxDefaultPosition, wxSize(width, 20)), control_reference(_ref) const std::string& label)
: wxButton(parent, wxID_ANY, "", wxDefaultPosition, wxSize(width, 20)), control_reference(_ref),
m_name(name)
{ {
if (label.empty()) if (label.empty())
SetLabel(StrToWxStr(_ref->expression)); SetLabel(StrToWxStr(_ref->expression));
@ -457,8 +459,8 @@ void ControlDialog::AppendControl(wxCommandEvent& event)
UpdateGUI(); UpdateGUI();
} }
void GamepadPage::EnableSettingControl(const std::string& group_name, const std::string& name, void GamepadPage::EnablePadSetting(const std::string& group_name, const std::string& name,
const bool enabled) const bool enabled)
{ {
const auto box_iterator = const auto box_iterator =
std::find_if(control_groups.begin(), control_groups.end(), [&group_name](const auto& box) { 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); (*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) void GamepadPage::AdjustSetting(wxCommandEvent& event)
{ {
const auto* const control = static_cast<wxControl*>(event.GetEventObject()); const auto* const control = static_cast<wxControl*>(event.GetEventObject());
@ -497,7 +518,8 @@ void GamepadPage::AdjustBooleanSetting(wxCommandEvent& event)
} }
else if (control->GetLabelText() == "Relative Input") 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 = wxStaticText* const label =
new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(control->name))); 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_button->SetFont(m_SmallFont);
control_buttons.push_back(control_button); control_buttons.push_back(control_button);

View File

@ -165,9 +165,10 @@ class ControlButton : public wxButton
{ {
public: public:
ControlButton(wxWindow* const parent, ControllerInterface::ControlReference* const _ref, 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; ControllerInterface::ControlReference* const control_reference;
const std::string m_name;
}; };
class ControlGroupBox : public wxBoxSizer class ControlGroupBox : public wxBoxSizer
@ -223,7 +224,8 @@ public:
void LoadDefaults(wxCommandEvent& event); void LoadDefaults(wxCommandEvent& event);
void AdjustControlOption(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 AdjustSetting(wxCommandEvent& event);
void AdjustBooleanSetting(wxCommandEvent& event); void AdjustBooleanSetting(wxCommandEvent& event);

View File

@ -295,6 +295,7 @@ ControllerEmu::Cursor::Cursor(const std::string& _name)
controls.emplace_back(std::make_unique<Input>("Forward")); controls.emplace_back(std::make_unique<Input>("Forward"));
controls.emplace_back(std::make_unique<Input>("Backward")); controls.emplace_back(std::make_unique<Input>("Backward"));
controls.emplace_back(std::make_unique<Input>(_trans("Hide"))); controls.emplace_back(std::make_unique<Input>(_trans("Hide")));
controls.emplace_back(std::make_unique<Input>("Recenter"));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Center"), 0.5)); numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Center"), 0.5));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Width"), 0.5)); numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Width"), 0.5));

View File

@ -434,6 +434,13 @@ public:
m_x = MathUtil::Clamp(m_x + xx * SPEED_MULTIPLIER, -1.0, 1.0); m_x = MathUtil::Clamp(m_x + xx * SPEED_MULTIPLIER, -1.0, 1.0);
if (std::abs(yy) > deadzone) if (std::abs(yy) > deadzone)
m_y = MathUtil::Clamp(m_y + yy * SPEED_MULTIPLIER, -1.0, 1.0); 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 else
{ {