Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
InputConfigDiag: Update for the new expression language
Modify the buttons and editor interface for the new expression
language, like the new op name for add, the new device name syntax,
and add new editing features, like simple selection behavior on
unary ops.
  • Loading branch information
magcius committed Jun 25, 2013
1 parent a42388d commit 03a835e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 30 deletions.
82 changes: 52 additions & 30 deletions Source/Core/DolphinWX/Src/InputConfigDiag.cpp
Expand Up @@ -239,10 +239,7 @@ void GamepadPage::UpdateGUI()
std::vector<ControlButton*>::const_iterator i = (*g)->control_buttons.begin()
, e = (*g)->control_buttons.end();
for (; i!=e; ++i)
//if (std::string::npos == (*i)->control_reference->expression.find_first_of("`|&!#"))
(*i)->SetLabel(StrToWxStr((*i)->control_reference->expression));
//else
//(*i)->SetLabel(wxT("..."));
(*i)->SetLabel(StrToWxStr((*i)->control_reference->expression));

// cboxes
std::vector<PadSetting*>::const_iterator si = (*g)->options.begin()
Expand Down Expand Up @@ -323,23 +320,45 @@ void ControlDialog::ClearControl(wxCommandEvent&)
UpdateGUI();
}

void ControlDialog::SetSelectedControl(wxCommandEvent&)
inline bool IsAlphabetic(wxString &str)
{
for (wxString::const_iterator it = str.begin(); it != str.end(); ++it)
if (!isalpha(*it))
return false;
return true;
}

bool ControlDialog::GetExpressionForSelectedControl(wxString &expr)
{
const int num = control_lbox->GetSelection();

if (num < 0)
return;
return false;

wxString expr;
expr = "";

// non-default device
if (false == (m_devq == m_parent->controller->default_device))
expr.append(wxT('`')).append(StrToWxStr(m_devq.ToString())).append(wxT('`'));
if (!(m_devq == m_parent->controller->default_device))
expr += m_devq.ToString();

// append the control name
expr += control_lbox->GetString(num);

control_reference->expression = WxStrToStr(expr);
if (!IsAlphabetic(expr))
expr = wxString::Format("`%s`", expr);

return true;
}

void ControlDialog::SetSelectedControl(wxCommandEvent&)
{
wxString expr;

if (!GetExpressionForSelectedControl(expr))
return;

textctrl->WriteText(expr);
control_reference->expression = textctrl->GetValue();

std::lock_guard<std::recursive_mutex> lk(m_plugin.controls_lock);
g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
Expand All @@ -349,28 +368,30 @@ void ControlDialog::SetSelectedControl(wxCommandEvent&)

void ControlDialog::AppendControl(wxCommandEvent& event)
{
const int num = control_lbox->GetSelection();

if (num < 0)
return;
wxString device_expr, expr;

// o boy!, hax
const wxString lbl = ((wxButton*)event.GetEventObject())->GetLabel();
char op = lbl[0];

wxString expr = textctrl->GetValue();

// append the operator to the expression
if (wxT('!') == lbl[0] || false == expr.empty())
expr += lbl[0];

// non-default device
if (false == (m_devq == m_parent->controller->default_device))
expr.append(wxT('`')).append(StrToWxStr(m_devq.ToString())).append(wxT('`'));
if (!GetExpressionForSelectedControl(device_expr))
return;

// append the control name
expr += control_lbox->GetString(num);
// Unary ops (that is, '!') are a special case. When there's a selection,
// put parens around it and prepend it with a '!', but when there's nothing,
// just add a '!device'.
if (op == '!')
{
wxString selection = textctrl->GetStringSelection();
if (selection == "")
expr = wxString::Format("%c%s", op, device_expr);
else
expr = wxString::Format("%c(%s)", op, selection);
}
else
expr = wxString::Format(" %c %s", op, device_expr);

control_reference->expression = WxStrToStr(expr);
textctrl->WriteText(expr);
control_reference->expression = textctrl->GetValue();

std::lock_guard<std::recursive_mutex> lk(m_plugin.controls_lock);
g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
Expand Down Expand Up @@ -478,6 +499,9 @@ wxStaticBoxSizer* ControlDialog::CreateControlChooser(GamepadPage* const parent)
wxButton* const select_button = new wxButton(this, -1, _("Select"));
select_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ControlDialog::SetSelectedControl, this);

wxButton* const not_button = new wxButton(this, -1, _("! NOT"), wxDefaultPosition);
not_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ControlDialog::AppendControl, this);

wxButton* const or_button = new wxButton(this, -1, _("| OR"), wxDefaultPosition);
or_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ControlDialog::AppendControl, this);

Expand All @@ -492,11 +516,9 @@ wxStaticBoxSizer* ControlDialog::CreateControlChooser(GamepadPage* const parent)
{
// TODO: check if && is good on other OS
wxButton* const and_button = new wxButton(this, -1, _("&& AND"), wxDefaultPosition);
wxButton* const not_button = new wxButton(this, -1, _("! NOT"), wxDefaultPosition);
wxButton* const add_button = new wxButton(this, -1, _("^ ADD"), wxDefaultPosition);
wxButton* const add_button = new wxButton(this, -1, _("+ ADD"), wxDefaultPosition);

and_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ControlDialog::AppendControl, this);
not_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ControlDialog::AppendControl, this);
add_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ControlDialog::AppendControl, this);

button_sizer->Add(and_button, 1, 0, 5);
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinWX/Src/InputConfigDiag.h
Expand Up @@ -113,6 +113,7 @@ class ControlDialog : public wxDialog
GamepadPage* const m_parent;
wxStaticText* m_bound_label;
DeviceQualifier m_devq;
bool GetExpressionForSelectedControl(wxString &expr);
};

class ExtensionButton : public wxButton
Expand Down

0 comments on commit 03a835e

Please sign in to comment.