From 55950365e337755e89d9d39b88a1720c16b297f0 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Tue, 25 Jun 2013 14:32:25 -0400 Subject: [PATCH] InputConfigDiag: Fix complex bindings with with left-click Detect This fixes the binding of XBox 360 controllers and similar devices with complex control names. --- Source/Core/DolphinWX/Src/InputConfigDiag.cpp | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/Source/Core/DolphinWX/Src/InputConfigDiag.cpp b/Source/Core/DolphinWX/Src/InputConfigDiag.cpp index e036d5ec71..2c6f08fde0 100644 --- a/Source/Core/DolphinWX/Src/InputConfigDiag.cpp +++ b/Source/Core/DolphinWX/Src/InputConfigDiag.cpp @@ -327,12 +327,33 @@ void ControlDialog::ClearControl(wxCommandEvent&) inline bool IsAlphabetic(wxString &str) { - for (wxString::const_iterator it = str.begin(); it != str.end(); ++it) + for (wxString::const_iterator it = str.begin(); it != str.end(); ++it) if (!isalpha(*it)) return false; return true; } +inline void GetExpressionForControl(wxString &expr, + wxString &control_name, + DeviceQualifier *control_device = NULL, + DeviceQualifier *default_device = NULL) +{ + expr = ""; + + // non-default device + if (control_device && default_device && !(*control_device == *default_device)) + { + expr += ":"; + expr += control_device->ToString(); + } + + // append the control name + expr += control_name; + + if (!IsAlphabetic(expr)) + expr = wxString::Format("`%s`", expr); +} + bool ControlDialog::GetExpressionForSelectedControl(wxString &expr) { const int num = control_lbox->GetSelection(); @@ -340,17 +361,11 @@ bool ControlDialog::GetExpressionForSelectedControl(wxString &expr) if (num < 0) return false; - expr = ""; - - // non-default device - if (!(m_devq == m_parent->controller->default_device)) - expr += m_devq.ToString(); - - // append the control name - expr += control_lbox->GetString(num); - - if (!IsAlphabetic(expr)) - expr = wxString::Format("`%s`", expr); + wxString control_name = control_lbox->GetString(num); + GetExpressionForControl(expr, + control_name, + &m_devq, + &m_parent->controller->default_device); return true; } @@ -482,12 +497,15 @@ void GamepadPage::DetectControl(wxCommandEvent& event) // if we got input, update expression and reference if (ctrl) { - btn->control_reference->expression = ctrl->GetName(); + wxString control_name = ctrl->GetName(); + wxString expr; + GetExpressionForControl(expr, control_name); + btn->control_reference->expression = expr; g_controller_interface.UpdateReference(btn->control_reference, controller->default_device); } - - btn->SetLabel(StrToWxStr(btn->control_reference->expression)); } + + UpdateGUI(); } wxStaticBoxSizer* ControlDialog::CreateControlChooser(GamepadPage* const parent)