InputConfigDiag: Fix complex bindings with with left-click Detect

This fixes the binding of XBox 360 controllers and similar devices
with complex control names.
This commit is contained in:
Jasper St. Pierre 2013-06-25 14:32:25 -04:00
parent 21ca344a21
commit 55950365e3

View File

@ -333,6 +333,27 @@ inline bool IsAlphabetic(wxString &str)
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)