2013-04-18 03:43:35 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cctype>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <wx/app.h>
|
|
|
|
#include <wx/arrstr.h>
|
|
|
|
#include <wx/bitmap.h>
|
|
|
|
#include <wx/button.h>
|
|
|
|
#include <wx/chartype.h>
|
|
|
|
#include <wx/checkbox.h>
|
|
|
|
#include <wx/choice.h>
|
|
|
|
#include <wx/combobox.h>
|
|
|
|
#include <wx/control.h>
|
|
|
|
#include <wx/dcmemory.h>
|
|
|
|
#include <wx/defs.h>
|
|
|
|
#include <wx/dialog.h>
|
|
|
|
#include <wx/event.h>
|
|
|
|
#include <wx/font.h>
|
|
|
|
#include <wx/gdicmn.h>
|
|
|
|
#include <wx/listbox.h>
|
2014-07-25 01:46:46 +00:00
|
|
|
#include <wx/msgdlg.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/notebook.h>
|
|
|
|
#include <wx/panel.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/slider.h>
|
|
|
|
#include <wx/spinctrl.h>
|
|
|
|
#include <wx/statbmp.h>
|
|
|
|
#include <wx/stattext.h>
|
|
|
|
#include <wx/string.h>
|
|
|
|
#include <wx/textctrl.h>
|
|
|
|
#include <wx/timer.h>
|
|
|
|
#include <wx/toplevel.h>
|
|
|
|
#include <wx/translation.h>
|
|
|
|
#include <wx/unichar.h>
|
|
|
|
|
|
|
|
#include "Common/FileSearch.h"
|
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/IniFile.h"
|
|
|
|
#include "Common/MsgHandler.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/HW/Wiimote.h"
|
|
|
|
#include "DolphinWX/InputConfigDiag.h"
|
|
|
|
#include "DolphinWX/WxUtils.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "InputCommon/ControllerEmu.h"
|
|
|
|
#include "InputCommon/InputConfig.h"
|
|
|
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
|
|
|
#include "InputCommon/ControllerInterface/Device.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "InputCommon/ControllerInterface/ExpressionParser.h"
|
2013-07-22 06:36:26 +00:00
|
|
|
|
|
|
|
using namespace ciface::ExpressionParser;
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
void GamepadPage::ConfigExtension(wxCommandEvent& event)
|
2010-04-13 05:15:38 +00:00
|
|
|
{
|
|
|
|
ControllerEmu::Extension* const ex = ((ExtensionButton*)event.GetEventObject())->extension;
|
|
|
|
|
|
|
|
// show config diag, if "none" isn't selected
|
2011-01-14 03:05:02 +00:00
|
|
|
if (ex->switch_extension)
|
2010-04-13 05:15:38 +00:00
|
|
|
{
|
2014-12-02 03:56:18 +00:00
|
|
|
wxDialog dlg(this, wxID_ANY,
|
2014-03-06 04:02:34 +00:00
|
|
|
wxGetTranslation(StrToWxStr(ex->attachments[ex->switch_extension]->GetName())));
|
2010-04-13 05:15:38 +00:00
|
|
|
|
2011-03-18 21:30:47 +00:00
|
|
|
wxBoxSizer* const main_szr = new wxBoxSizer(wxVERTICAL);
|
2010-04-13 05:15:38 +00:00
|
|
|
const std::size_t orig_size = control_groups.size();
|
|
|
|
|
2014-02-01 22:20:35 +00:00
|
|
|
ControlGroupsSizer* const szr = new ControlGroupsSizer(ex->attachments[ex->switch_extension].get(), &dlg, this, &control_groups);
|
2011-03-18 21:30:47 +00:00
|
|
|
main_szr->Add(szr, 0, wxLEFT, 5);
|
|
|
|
main_szr->Add(dlg.CreateButtonSizer(wxOK), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);
|
|
|
|
dlg.SetSizerAndFit(main_szr);
|
|
|
|
dlg.Center();
|
2010-04-13 05:15:38 +00:00
|
|
|
|
2011-03-18 21:30:47 +00:00
|
|
|
dlg.ShowModal();
|
2010-04-13 05:15:38 +00:00
|
|
|
|
|
|
|
// remove the new groups that were just added, now that the window closed
|
2011-01-14 03:05:02 +00:00
|
|
|
control_groups.resize(orig_size);
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
PadSettingExtension::PadSettingExtension(wxWindow* const parent, ControllerEmu::Extension* const ext)
|
2014-12-02 03:56:18 +00:00
|
|
|
: PadSetting(new wxChoice(parent, wxID_ANY))
|
2010-04-13 05:15:38 +00:00
|
|
|
, extension(ext)
|
|
|
|
{
|
2014-02-01 22:20:35 +00:00
|
|
|
for (auto& attachment : extension->attachments)
|
|
|
|
{
|
|
|
|
((wxChoice*)wxcontrol)->Append(wxGetTranslation(StrToWxStr(attachment->GetName())));
|
|
|
|
}
|
2010-04-13 05:15:38 +00:00
|
|
|
|
|
|
|
UpdateGUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PadSettingExtension::UpdateGUI()
|
|
|
|
{
|
2010-07-03 08:04:10 +00:00
|
|
|
((wxChoice*)wxcontrol)->Select(extension->switch_extension);
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PadSettingExtension::UpdateValue()
|
|
|
|
{
|
2010-07-03 08:04:10 +00:00
|
|
|
extension->switch_extension = ((wxChoice*)wxcontrol)->GetSelection();
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
|
2014-07-11 14:31:06 +00:00
|
|
|
PadSettingCheckBox::PadSettingCheckBox(wxWindow* const parent, ControllerEmu::ControlGroup::Setting* const _setting)
|
2014-12-02 03:56:18 +00:00
|
|
|
: PadSetting(new wxCheckBox(parent, wxID_ANY, wxGetTranslation(StrToWxStr(_setting->name))))
|
2014-07-11 14:31:06 +00:00
|
|
|
, setting(_setting)
|
2010-04-08 03:33:16 +00:00
|
|
|
{
|
|
|
|
UpdateGUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PadSettingCheckBox::UpdateGUI()
|
|
|
|
{
|
2014-08-20 03:19:12 +00:00
|
|
|
((wxCheckBox*)wxcontrol)->SetValue(!!setting->GetValue());
|
2010-04-08 03:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PadSettingCheckBox::UpdateValue()
|
|
|
|
{
|
|
|
|
// 0.01 so its saved to the ini file as just 1. :(
|
2014-07-11 14:31:06 +00:00
|
|
|
setting->SetValue(0.01 * ((wxCheckBox*)wxcontrol)->GetValue());
|
2010-04-08 03:33:16 +00:00
|
|
|
}
|
|
|
|
|
2010-07-03 08:04:10 +00:00
|
|
|
void PadSettingSpin::UpdateGUI()
|
2010-04-08 03:33:16 +00:00
|
|
|
{
|
2014-07-11 14:31:06 +00:00
|
|
|
((wxSpinCtrl*)wxcontrol)->SetValue((int)(setting->GetValue() * 100));
|
2010-04-08 03:33:16 +00:00
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-07-03 08:04:10 +00:00
|
|
|
void PadSettingSpin::UpdateValue()
|
2010-04-08 03:33:16 +00:00
|
|
|
{
|
2014-11-09 20:02:18 +00:00
|
|
|
setting->SetValue(ControlState(((wxSpinCtrl*)wxcontrol)->GetValue()) / 100);
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2014-08-31 04:04:15 +00:00
|
|
|
ControlDialog::ControlDialog(GamepadPage* const parent, InputConfig& config, ControllerInterface::ControlReference* const ref)
|
2014-12-02 03:56:18 +00:00
|
|
|
: wxDialog(parent, wxID_ANY, _("Configure Control"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
2010-06-21 03:12:16 +00:00
|
|
|
, control_reference(ref)
|
2014-08-31 04:04:15 +00:00
|
|
|
, m_config(config)
|
2010-06-21 03:12:16 +00:00
|
|
|
, m_parent(parent)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2010-06-21 03:12:16 +00:00
|
|
|
m_devq = m_parent->controller->default_device;
|
|
|
|
|
2010-06-16 02:57:50 +00:00
|
|
|
// GetStrings() sounds slow :/
|
2014-12-02 03:56:18 +00:00
|
|
|
//device_cbox = new wxComboBox(this, wxID_ANY, StrToWxStr(ref->device_qualifier.ToString()), wxDefaultPosition, wxSize(256,-1), parent->device_cbox->GetStrings(), wxTE_PROCESS_ENTER);
|
|
|
|
device_cbox = new wxComboBox(this, wxID_ANY, StrToWxStr(m_devq.ToString()), wxDefaultPosition, wxSize(256, -1), parent->device_cbox->GetStrings(), wxTE_PROCESS_ENTER);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-05-17 16:49:00 +00:00
|
|
|
device_cbox->Bind(wxEVT_COMBOBOX, &ControlDialog::SetDevice, this);
|
|
|
|
device_cbox->Bind(wxEVT_TEXT_ENTER, &ControlDialog::SetDevice, this);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2013-01-13 08:28:12 +00:00
|
|
|
wxStaticBoxSizer* const control_chooser = CreateControlChooser(parent);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
wxStaticBoxSizer* const d_szr = new wxStaticBoxSizer(wxVERTICAL, this, _("Device"));
|
|
|
|
d_szr->Add(device_cbox, 0, wxEXPAND|wxALL, 5);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
wxBoxSizer* const szr = new wxBoxSizer(wxVERTICAL);
|
|
|
|
szr->Add(d_szr, 0, wxEXPAND|wxLEFT|wxRIGHT|wxTOP, 5);
|
|
|
|
szr->Add(control_chooser, 1, wxEXPAND|wxALL, 5);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-02-17 04:51:41 +00:00
|
|
|
SetSizerAndFit(szr); // needed
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
UpdateGUI();
|
2011-03-16 12:59:05 +00:00
|
|
|
SetFocus();
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
ControlButton::ControlButton(wxWindow* const parent, ControllerInterface::ControlReference* const _ref, const unsigned int width, const std::string& label)
|
2014-12-02 03:56:18 +00:00
|
|
|
: wxButton(parent, wxID_ANY, "", wxDefaultPosition, wxSize(width,20))
|
2011-01-14 03:05:02 +00:00
|
|
|
, control_reference(_ref)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2011-01-14 03:05:02 +00:00
|
|
|
if (label.empty())
|
2013-02-28 04:37:38 +00:00
|
|
|
SetLabel(StrToWxStr(_ref->expression));
|
2010-04-02 02:48:24 +00:00
|
|
|
else
|
2013-02-28 04:37:38 +00:00
|
|
|
SetLabel(StrToWxStr(label));
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-06-12 18:45:39 +00:00
|
|
|
void InputConfigDialog::UpdateProfileComboBox()
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2011-01-14 03:05:02 +00:00
|
|
|
std::string pname(File::GetUserPath(D_CONFIG_IDX));
|
2010-06-12 18:45:39 +00:00
|
|
|
pname += PROFILES_PATH;
|
2014-08-31 04:04:15 +00:00
|
|
|
pname += m_config.profile_name;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
CFileSearch::XStringVector exts;
|
|
|
|
exts.push_back("*.ini");
|
|
|
|
CFileSearch::XStringVector dirs;
|
2011-01-14 03:05:02 +00:00
|
|
|
dirs.push_back(pname);
|
|
|
|
CFileSearch cfs(exts, dirs);
|
2010-04-02 02:48:24 +00:00
|
|
|
const CFileSearch::XStringVector& sv = cfs.GetFileNames();
|
|
|
|
|
|
|
|
wxArrayString strs;
|
2014-02-01 23:15:18 +00:00
|
|
|
for (auto si = sv.cbegin(); si != sv.cend(); ++si)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2011-01-14 03:05:02 +00:00
|
|
|
std::string str(si->begin() + si->find_last_of('/') + 1 , si->end() - 4) ;
|
2013-02-28 04:37:38 +00:00
|
|
|
strs.push_back(StrToWxStr(str));
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2014-02-01 23:15:18 +00:00
|
|
|
for (GamepadPage* page : m_padpages)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2014-02-01 23:15:18 +00:00
|
|
|
page->profile_cbox->Clear();
|
|
|
|
page->profile_cbox->Append(strs);
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-12 18:45:39 +00:00
|
|
|
void InputConfigDialog::UpdateControlReferences()
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2014-02-01 23:15:18 +00:00
|
|
|
for (GamepadPage* page : m_padpages)
|
|
|
|
{
|
|
|
|
page->controller->UpdateReferences(g_controller_interface);
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 21:57:00 +00:00
|
|
|
void InputConfigDialog::ClickSave(wxCommandEvent& event)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2014-08-31 04:04:15 +00:00
|
|
|
m_config.SaveConfig();
|
2011-03-15 21:57:00 +00:00
|
|
|
event.Skip();
|
2010-04-14 23:50:33 +00:00
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
void ControlDialog::UpdateListContents()
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
|
|
|
control_lbox->Clear();
|
|
|
|
|
2014-09-05 00:41:42 +00:00
|
|
|
ciface::Core::Device* const dev = g_controller_interface.FindDevice(m_devq);
|
2010-06-22 08:30:33 +00:00
|
|
|
if (dev)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2010-06-21 03:12:16 +00:00
|
|
|
if (control_reference->is_input)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2014-09-05 00:41:42 +00:00
|
|
|
for (ciface::Core::Device::Input* input : dev->Inputs())
|
2014-02-01 23:15:18 +00:00
|
|
|
{
|
|
|
|
control_lbox->Append(StrToWxStr(input->GetName()));
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
2014-02-01 23:15:18 +00:00
|
|
|
else // It's an output
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2014-09-05 00:41:42 +00:00
|
|
|
for (ciface::Core::Device::Output* output : dev->Outputs())
|
2014-02-01 23:15:18 +00:00
|
|
|
{
|
|
|
|
control_lbox->Append(StrToWxStr(output->GetName()));
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-14 23:50:33 +00:00
|
|
|
}
|
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
void ControlDialog::SelectControl(const std::string& name)
|
2010-04-14 23:50:33 +00:00
|
|
|
{
|
2010-06-21 03:12:16 +00:00
|
|
|
//UpdateGUI();
|
2010-04-14 23:50:33 +00:00
|
|
|
|
2013-02-28 04:37:38 +00:00
|
|
|
const int f = control_lbox->FindString(StrToWxStr(name));
|
2010-06-21 03:12:16 +00:00
|
|
|
if (f >= 0)
|
|
|
|
control_lbox->Select(f);
|
2010-04-14 23:50:33 +00:00
|
|
|
}
|
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
void ControlDialog::UpdateGUI()
|
2010-04-14 23:50:33 +00:00
|
|
|
{
|
|
|
|
// update textbox
|
2013-02-28 04:37:38 +00:00
|
|
|
textctrl->SetValue(StrToWxStr(control_reference->expression));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-04-14 23:50:33 +00:00
|
|
|
// updates the "bound controls:" label
|
2011-01-16 17:56:26 +00:00
|
|
|
m_bound_label->SetLabel(wxString::Format(_("Bound Controls: %lu"),
|
|
|
|
(unsigned long)control_reference->BoundCount()));
|
2013-07-22 06:36:26 +00:00
|
|
|
|
|
|
|
switch (control_reference->parse_error)
|
|
|
|
{
|
|
|
|
case EXPRESSION_PARSE_SYNTAX_ERROR:
|
2014-05-17 17:17:28 +00:00
|
|
|
m_error_label->SetLabel(_("Syntax error"));
|
2013-07-22 06:36:26 +00:00
|
|
|
break;
|
|
|
|
case EXPRESSION_PARSE_NO_DEVICE:
|
2014-05-17 17:17:28 +00:00
|
|
|
m_error_label->SetLabel(_("Device not found"));
|
2013-07-22 06:36:26 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
m_error_label->SetLabel("");
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void GamepadPage::UpdateGUI()
|
|
|
|
{
|
2013-02-28 04:37:38 +00:00
|
|
|
device_cbox->SetValue(StrToWxStr(controller->default_device.ToString()));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-02-01 23:15:18 +00:00
|
|
|
for (ControlGroupBox* cgBox : control_groups)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2014-02-01 23:15:18 +00:00
|
|
|
for (ControlButton* button : cgBox->control_buttons)
|
|
|
|
{
|
|
|
|
wxString expr = StrToWxStr(button->control_reference->expression);
|
2013-06-29 22:27:11 +00:00
|
|
|
expr.Replace("&", "&&");
|
2014-02-01 23:15:18 +00:00
|
|
|
button->SetLabel(expr);
|
2013-06-17 10:52:03 +00:00
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-02-01 23:15:18 +00:00
|
|
|
for (PadSetting* padSetting : cgBox->options)
|
|
|
|
{
|
|
|
|
padSetting->UpdateGUI();
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
void GamepadPage::ClearAll(wxCommandEvent&)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
|
|
|
// just load an empty ini section to clear everything :P
|
2010-06-04 20:03:03 +00:00
|
|
|
IniFile::Section section;
|
|
|
|
controller->LoadConfig(§ion);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
// no point in using the real ControllerInterface i guess
|
2010-04-13 05:15:38 +00:00
|
|
|
ControllerInterface face;
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2014-08-31 04:04:15 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lk(m_config.controls_lock);
|
2010-06-04 20:03:03 +00:00
|
|
|
controller->UpdateReferences(face);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
UpdateGUI();
|
|
|
|
}
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
void GamepadPage::LoadDefaults(wxCommandEvent&)
|
2010-07-10 06:48:24 +00:00
|
|
|
{
|
2010-10-12 19:42:29 +00:00
|
|
|
controller->LoadDefaults(g_controller_interface);
|
2010-07-10 06:48:24 +00:00
|
|
|
|
2014-08-31 04:04:15 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lk(m_config.controls_lock);
|
2010-10-12 19:42:29 +00:00
|
|
|
controller->UpdateReferences(g_controller_interface);
|
2010-07-10 06:48:24 +00:00
|
|
|
|
|
|
|
UpdateGUI();
|
|
|
|
}
|
|
|
|
|
2013-07-22 06:48:07 +00:00
|
|
|
bool ControlDialog::Validate()
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2013-02-28 04:37:38 +00:00
|
|
|
control_reference->expression = WxStrToStr(textctrl->GetValue());
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-08-31 04:04:15 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lk(m_config.controls_lock);
|
2010-10-12 19:42:29 +00:00
|
|
|
g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
UpdateGUI();
|
2013-07-22 06:48:07 +00:00
|
|
|
|
|
|
|
return (control_reference->parse_error == EXPRESSION_PARSE_SUCCESS);
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
void GamepadPage::SetDevice(wxCommandEvent&)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2013-02-28 04:37:38 +00:00
|
|
|
controller->default_device.FromString(WxStrToStr(device_cbox->GetValue()));
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2010-04-14 23:50:33 +00:00
|
|
|
// show user what it was validated as
|
2013-02-28 04:37:38 +00:00
|
|
|
device_cbox->SetValue(StrToWxStr(controller->default_device.ToString()));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-04-14 23:50:33 +00:00
|
|
|
// this will set all the controls to this default device
|
|
|
|
controller->UpdateDefaultDevice();
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-04-14 23:50:33 +00:00
|
|
|
// update references
|
2014-08-31 04:04:15 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lk(m_config.controls_lock);
|
2011-01-14 03:05:02 +00:00
|
|
|
controller->UpdateReferences(g_controller_interface);
|
2010-04-14 23:50:33 +00:00
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
void ControlDialog::SetDevice(wxCommandEvent&)
|
2010-04-14 23:50:33 +00:00
|
|
|
{
|
2013-02-28 04:37:38 +00:00
|
|
|
m_devq.FromString(WxStrToStr(device_cbox->GetValue()));
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2010-04-14 23:50:33 +00:00
|
|
|
// show user what it was validated as
|
2013-02-28 04:37:38 +00:00
|
|
|
device_cbox->SetValue(StrToWxStr(m_devq.ToString()));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
// update gui
|
|
|
|
UpdateListContents();
|
|
|
|
}
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
void ControlDialog::ClearControl(wxCommandEvent&)
|
2010-06-21 03:12:16 +00:00
|
|
|
{
|
|
|
|
control_reference->expression.clear();
|
|
|
|
|
2014-08-31 04:04:15 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lk(m_config.controls_lock);
|
2010-10-12 19:42:29 +00:00
|
|
|
g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
|
|
|
UpdateGUI();
|
|
|
|
}
|
|
|
|
|
2013-06-17 09:55:21 +00:00
|
|
|
inline bool IsAlphabetic(wxString &str)
|
|
|
|
{
|
2014-02-01 23:15:18 +00:00
|
|
|
for (wxUniChar c : str)
|
|
|
|
if (!isalpha(c))
|
2013-06-17 09:55:21 +00:00
|
|
|
return false;
|
2014-02-01 23:15:18 +00:00
|
|
|
|
2013-06-17 09:55:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-25 18:32:25 +00:00
|
|
|
inline void GetExpressionForControl(wxString &expr,
|
|
|
|
wxString &control_name,
|
2014-09-05 00:41:42 +00:00
|
|
|
ciface::Core::DeviceQualifier *control_device = nullptr,
|
|
|
|
ciface::Core::DeviceQualifier *default_device = nullptr)
|
2010-07-03 08:04:10 +00:00
|
|
|
{
|
2013-06-17 09:55:21 +00:00
|
|
|
expr = "";
|
2010-07-03 08:04:10 +00:00
|
|
|
|
|
|
|
// non-default device
|
2013-06-25 18:32:25 +00:00
|
|
|
if (control_device && default_device && !(*control_device == *default_device))
|
|
|
|
{
|
|
|
|
expr += control_device->ToString();
|
2013-06-29 06:55:29 +00:00
|
|
|
expr += ":";
|
2013-06-25 18:32:25 +00:00
|
|
|
}
|
2010-07-03 08:04:10 +00:00
|
|
|
|
|
|
|
// append the control name
|
2013-06-25 18:32:25 +00:00
|
|
|
expr += control_name;
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2013-06-17 09:55:21 +00:00
|
|
|
if (!IsAlphabetic(expr))
|
|
|
|
expr = wxString::Format("`%s`", expr);
|
2013-06-25 18:32:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ControlDialog::GetExpressionForSelectedControl(wxString &expr)
|
|
|
|
{
|
|
|
|
const int num = control_lbox->GetSelection();
|
|
|
|
|
|
|
|
if (num < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wxString control_name = control_lbox->GetString(num);
|
|
|
|
GetExpressionForControl(expr,
|
|
|
|
control_name,
|
|
|
|
&m_devq,
|
|
|
|
&m_parent->controller->default_device);
|
2013-06-17 09:55:21 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControlDialog::SetSelectedControl(wxCommandEvent&)
|
|
|
|
{
|
|
|
|
wxString expr;
|
|
|
|
|
|
|
|
if (!GetExpressionForSelectedControl(expr))
|
|
|
|
return;
|
|
|
|
|
|
|
|
textctrl->WriteText(expr);
|
|
|
|
control_reference->expression = textctrl->GetValue();
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2014-08-31 04:04:15 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lk(m_config.controls_lock);
|
2010-10-12 19:42:29 +00:00
|
|
|
g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
UpdateGUI();
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
void ControlDialog::AppendControl(wxCommandEvent& event)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2013-06-17 09:55:21 +00:00
|
|
|
wxString device_expr, expr;
|
2010-06-21 03:12:16 +00:00
|
|
|
|
|
|
|
const wxString lbl = ((wxButton*)event.GetEventObject())->GetLabel();
|
2013-06-17 09:55:21 +00:00
|
|
|
char op = lbl[0];
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2013-06-17 09:55:21 +00:00
|
|
|
if (!GetExpressionForSelectedControl(device_expr))
|
|
|
|
return;
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2013-06-17 09:55:21 +00:00
|
|
|
// 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
|
2014-02-01 23:15:18 +00:00
|
|
|
{
|
2013-06-17 09:55:21 +00:00
|
|
|
expr = wxString::Format(" %c %s", op, device_expr);
|
2014-02-01 23:15:18 +00:00
|
|
|
}
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2013-06-17 09:55:21 +00:00
|
|
|
textctrl->WriteText(expr);
|
|
|
|
control_reference->expression = textctrl->GetValue();
|
2010-04-14 23:50:33 +00:00
|
|
|
|
2014-08-31 04:04:15 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lk(m_config.controls_lock);
|
2010-10-12 19:42:29 +00:00
|
|
|
g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
|
2010-04-14 23:50:33 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
UpdateGUI();
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
void GamepadPage::AdjustSetting(wxCommandEvent& event)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2014-08-31 04:04:15 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lk(m_config.controls_lock);
|
2010-07-03 08:04:10 +00:00
|
|
|
((PadSetting*)((wxControl*)event.GetEventObject())->GetClientData())->UpdateValue();
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2014-09-02 16:53:03 +00:00
|
|
|
void GamepadPage::AdjustSettingUI(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
m_iterate = !m_iterate;
|
|
|
|
std::lock_guard<std::recursive_mutex> lk(m_config.controls_lock);
|
|
|
|
((PadSetting*)((wxControl*)event.GetEventObject())->GetClientData())->UpdateValue();
|
|
|
|
}
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
void GamepadPage::AdjustControlOption(wxCommandEvent&)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2014-08-31 04:04:15 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lk(m_config.controls_lock);
|
2010-06-21 03:12:16 +00:00
|
|
|
m_control_dialog->control_reference->range = (ControlState)(m_control_dialog->range_slider->GetValue()) / SLIDER_TICK_COUNT;
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-13 08:28:12 +00:00
|
|
|
void GamepadPage::ConfigControl(wxEvent& event)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2014-08-31 04:04:15 +00:00
|
|
|
m_control_dialog = new ControlDialog(this, m_config, ((ControlButton*)event.GetEventObject())->control_reference);
|
2010-04-02 02:48:24 +00:00
|
|
|
m_control_dialog->ShowModal();
|
|
|
|
m_control_dialog->Destroy();
|
2010-04-14 23:50:33 +00:00
|
|
|
|
|
|
|
// update changes that were made in the dialog
|
|
|
|
UpdateGUI();
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-13 08:28:12 +00:00
|
|
|
void GamepadPage::ClearControl(wxEvent& event)
|
2010-06-05 05:30:23 +00:00
|
|
|
{
|
|
|
|
ControlButton* const btn = (ControlButton*)event.GetEventObject();
|
2010-06-21 03:12:16 +00:00
|
|
|
btn->control_reference->expression.clear();
|
2014-11-09 20:02:18 +00:00
|
|
|
btn->control_reference->range = 1.0;
|
2010-06-05 05:30:23 +00:00
|
|
|
|
2014-08-31 04:04:15 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lk(m_config.controls_lock);
|
2011-01-14 03:05:02 +00:00
|
|
|
controller->UpdateReferences(g_controller_interface);
|
2010-06-05 05:30:23 +00:00
|
|
|
|
|
|
|
// update changes
|
|
|
|
UpdateGUI();
|
|
|
|
}
|
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
void ControlDialog::DetectControl(wxCommandEvent& event)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2010-06-12 02:08:01 +00:00
|
|
|
wxButton* const btn = (wxButton*)event.GetEventObject();
|
|
|
|
const wxString lbl = btn->GetLabel();
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2014-09-05 00:41:42 +00:00
|
|
|
ciface::Core::Device* const dev = g_controller_interface.FindDevice(m_devq);
|
2010-06-22 08:30:33 +00:00
|
|
|
if (dev)
|
2010-06-12 02:08:01 +00:00
|
|
|
{
|
2011-01-05 04:35:46 +00:00
|
|
|
btn->SetLabel(_("[ waiting ]"));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-06-20 00:58:55 +00:00
|
|
|
// This makes the "waiting" text work on Linux. true (only if needed) prevents crash on Windows
|
|
|
|
wxTheApp->Yield(true);
|
2010-07-16 03:43:11 +00:00
|
|
|
|
2014-08-31 04:04:15 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lk(m_config.controls_lock);
|
2014-09-05 00:41:42 +00:00
|
|
|
ciface::Core::Device::Control* const ctrl = control_reference->Detect(DETECT_WAIT_TIME, dev);
|
2010-06-21 03:12:16 +00:00
|
|
|
|
|
|
|
// if we got input, select it in the list
|
|
|
|
if (ctrl)
|
|
|
|
SelectControl(ctrl->GetName());
|
2010-06-12 02:08:01 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
btn->SetLabel(lbl);
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
void GamepadPage::DetectControl(wxCommandEvent& event)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
|
|
|
ControlButton* btn = (ControlButton*)event.GetEventObject();
|
2014-09-02 16:53:03 +00:00
|
|
|
if (DetectButton(btn) && m_iterate == true)
|
2014-06-14 23:15:41 +00:00
|
|
|
{
|
|
|
|
auto it = std::find(control_buttons.begin(), control_buttons.end(), btn);
|
|
|
|
|
|
|
|
// std find will never return end since btn will always be found in control_buttons
|
|
|
|
++it;
|
|
|
|
for (; it != control_buttons.end(); ++it)
|
|
|
|
{
|
|
|
|
if (!DetectButton(*it))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-06-14 23:15:41 +00:00
|
|
|
bool GamepadPage::DetectButton(ControlButton* button)
|
|
|
|
{
|
|
|
|
bool success = false;
|
2010-06-21 03:12:16 +00:00
|
|
|
// find device :/
|
2014-09-05 00:41:42 +00:00
|
|
|
ciface::Core::Device* const dev = g_controller_interface.FindDevice(controller->default_device);
|
2010-06-22 08:30:33 +00:00
|
|
|
if (dev)
|
2010-06-21 03:12:16 +00:00
|
|
|
{
|
2014-06-14 23:15:41 +00:00
|
|
|
button->SetLabel(_("[ waiting ]"));
|
2010-04-14 23:50:33 +00:00
|
|
|
|
2014-06-20 00:58:55 +00:00
|
|
|
// This makes the "waiting" text work on Linux. true (only if needed) prevents crash on Windows
|
|
|
|
wxTheApp->Yield(true);
|
2010-07-16 03:43:11 +00:00
|
|
|
|
2014-08-31 04:04:15 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lk(m_config.controls_lock);
|
2014-09-05 00:41:42 +00:00
|
|
|
ciface::Core::Device::Control* const ctrl = button->control_reference->Detect(DETECT_WAIT_TIME, dev);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
// if we got input, update expression and reference
|
|
|
|
if (ctrl)
|
|
|
|
{
|
2013-06-25 18:32:25 +00:00
|
|
|
wxString control_name = ctrl->GetName();
|
|
|
|
wxString expr;
|
|
|
|
GetExpressionForControl(expr, control_name);
|
2014-06-14 23:15:41 +00:00
|
|
|
button->control_reference->expression = expr;
|
|
|
|
g_controller_interface.UpdateReference(button->control_reference, controller->default_device);
|
|
|
|
success = true;
|
2010-06-21 03:12:16 +00:00
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
2013-06-25 18:32:25 +00:00
|
|
|
|
|
|
|
UpdateGUI();
|
2014-06-14 23:15:41 +00:00
|
|
|
|
|
|
|
return success;
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-13 08:28:12 +00:00
|
|
|
wxStaticBoxSizer* ControlDialog::CreateControlChooser(GamepadPage* const parent)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2013-01-13 08:28:12 +00:00
|
|
|
wxStaticBoxSizer* const main_szr = new wxStaticBoxSizer(wxVERTICAL, this, control_reference->is_input ? _("Input") : _("Output"));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-12-02 03:56:18 +00:00
|
|
|
textctrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(-1, 48), wxTE_MULTILINE | wxTE_RICH2);
|
2013-06-17 10:45:29 +00:00
|
|
|
wxFont font = textctrl->GetFont();
|
|
|
|
font.SetFamily(wxFONTFAMILY_MODERN);
|
|
|
|
textctrl->SetFont(font);
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2014-12-02 03:56:18 +00:00
|
|
|
wxButton* const detect_button = new wxButton(this, wxID_ANY, control_reference->is_input ? _("Detect") : _("Test"));
|
2010-04-22 07:11:49 +00:00
|
|
|
|
2014-12-02 03:56:18 +00:00
|
|
|
wxButton* const clear_button = new wxButton(this, wxID_ANY, _("Clear"));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-12-02 03:56:18 +00:00
|
|
|
wxButton* const select_button = new wxButton(this, wxID_ANY, _("Select"));
|
2014-05-17 16:49:00 +00:00
|
|
|
select_button->Bind(wxEVT_BUTTON, &ControlDialog::SetSelectedControl, this);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2014-12-02 03:56:18 +00:00
|
|
|
wxButton* const or_button = new wxButton(this, wxID_ANY, _("| OR"));
|
2014-05-17 16:49:00 +00:00
|
|
|
or_button->Bind(wxEVT_BUTTON, &ControlDialog::AppendControl, this);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-12-02 03:56:18 +00:00
|
|
|
control_lbox = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 64));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
wxBoxSizer* const button_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
button_sizer->Add(detect_button, 1, 0, 5);
|
2010-07-03 08:04:10 +00:00
|
|
|
button_sizer->Add(select_button, 1, 0, 5);
|
2010-06-21 03:12:16 +00:00
|
|
|
button_sizer->Add(or_button, 1, 0, 5);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
|
|
|
if (control_reference->is_input)
|
|
|
|
{
|
|
|
|
// TODO: check if && is good on other OS
|
2014-12-02 03:56:18 +00:00
|
|
|
wxButton* const and_button = new wxButton(this, wxID_ANY, _("&& AND"));
|
|
|
|
wxButton* const not_button = new wxButton(this, wxID_ANY, _("! NOT"));
|
|
|
|
wxButton* const add_button = new wxButton(this, wxID_ANY, _("+ ADD"));
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2014-05-17 16:49:00 +00:00
|
|
|
and_button->Bind(wxEVT_BUTTON, &ControlDialog::AppendControl, this);
|
2014-08-16 01:09:35 +00:00
|
|
|
not_button->Bind(wxEVT_BUTTON, &ControlDialog::AppendControl, this);
|
2014-05-17 16:49:00 +00:00
|
|
|
add_button->Bind(wxEVT_BUTTON, &ControlDialog::AppendControl, this);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
|
|
|
button_sizer->Add(and_button, 1, 0, 5);
|
|
|
|
button_sizer->Add(not_button, 1, 0, 5);
|
|
|
|
button_sizer->Add(add_button, 1, 0, 5);
|
|
|
|
}
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2014-12-02 03:56:18 +00:00
|
|
|
range_slider = new wxSlider(this, wxID_ANY, SLIDER_TICK_COUNT, -SLIDER_TICK_COUNT * 5, SLIDER_TICK_COUNT * 5, wxDefaultPosition, wxDefaultSize, wxSL_TOP | wxSL_LABELS /*| wxSL_AUTOTICKS*/);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-30 01:58:54 +00:00
|
|
|
range_slider->SetValue((int)(control_reference->range * SLIDER_TICK_COUNT));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-05-17 16:49:00 +00:00
|
|
|
detect_button->Bind(wxEVT_BUTTON, &ControlDialog::DetectControl, this);
|
|
|
|
clear_button->Bind(wxEVT_BUTTON, &ControlDialog::ClearControl, this);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2013-01-13 08:28:12 +00:00
|
|
|
range_slider->Bind(wxEVT_SCROLL_CHANGED, &GamepadPage::AdjustControlOption, parent);
|
2014-12-02 03:56:18 +00:00
|
|
|
wxStaticText* const range_label = new wxStaticText(this, wxID_ANY, _("Range"));
|
2013-07-22 06:36:26 +00:00
|
|
|
|
2014-12-02 03:56:18 +00:00
|
|
|
m_bound_label = new wxStaticText(this, wxID_ANY, "");
|
|
|
|
m_error_label = new wxStaticText(this, wxID_ANY, "");
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
wxBoxSizer* const range_sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
range_sizer->Add(range_label, 0, wxCENTER|wxLEFT, 5);
|
|
|
|
range_sizer->Add(range_slider, 1, wxEXPAND|wxLEFT, 5);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
wxBoxSizer* const ctrls_sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
ctrls_sizer->Add(control_lbox, 1, wxEXPAND, 0);
|
|
|
|
ctrls_sizer->Add(button_sizer, 0, wxEXPAND, 0);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2013-07-22 06:48:07 +00:00
|
|
|
wxSizer* const bottom_btns_sizer = CreateButtonSizer(wxOK|wxAPPLY);
|
2011-03-16 22:22:21 +00:00
|
|
|
bottom_btns_sizer->Prepend(clear_button, 0, wxLEFT, 5);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
main_szr->Add(range_sizer, 0, wxEXPAND|wxLEFT|wxRIGHT, 5);
|
|
|
|
main_szr->Add(ctrls_sizer, 0, wxEXPAND|wxLEFT|wxRIGHT|wxBOTTOM, 5);
|
|
|
|
main_szr->Add(textctrl, 1, wxEXPAND|wxLEFT|wxRIGHT|wxBOTTOM, 5);
|
2011-03-16 22:22:21 +00:00
|
|
|
main_szr->Add(bottom_btns_sizer, 0, wxEXPAND|wxBOTTOM|wxRIGHT, 5);
|
2010-06-21 03:12:16 +00:00
|
|
|
main_szr->Add(m_bound_label, 0, wxCENTER, 0);
|
2013-07-22 06:36:26 +00:00
|
|
|
main_szr->Add(m_error_label, 0, wxCENTER, 0);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
UpdateListContents();
|
2010-04-22 07:11:49 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
return main_szr;
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
void GamepadPage::GetProfilePath(std::string& path)
|
|
|
|
{
|
|
|
|
const wxString& name = profile_cbox->GetValue();
|
2014-02-01 23:15:18 +00:00
|
|
|
if (!name.empty())
|
2010-06-21 03:12:16 +00:00
|
|
|
{
|
|
|
|
// TODO: check for dumb characters maybe
|
|
|
|
|
|
|
|
path = File::GetUserPath(D_CONFIG_IDX);
|
|
|
|
path += PROFILES_PATH;
|
2014-08-31 04:04:15 +00:00
|
|
|
path += m_config.profile_name;
|
2010-06-21 03:12:16 +00:00
|
|
|
path += '/';
|
2013-02-28 04:37:38 +00:00
|
|
|
path += WxStrToStr(profile_cbox->GetValue());
|
2010-06-21 03:12:16 +00:00
|
|
|
path += ".ini";
|
2010-04-22 07:11:49 +00:00
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
void GamepadPage::LoadProfile(wxCommandEvent&)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2010-06-21 03:12:16 +00:00
|
|
|
std::string fname;
|
|
|
|
GamepadPage::GetProfilePath(fname);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-02-01 23:15:18 +00:00
|
|
|
if (!File::Exists(fname))
|
2010-04-02 02:48:24 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
IniFile inifile;
|
2010-06-04 20:03:03 +00:00
|
|
|
inifile.Load(fname);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-08-31 04:04:15 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lk(m_config.controls_lock);
|
2010-06-21 03:12:16 +00:00
|
|
|
controller->LoadConfig(inifile.GetOrCreateSection("Profile"));
|
2010-10-12 19:42:29 +00:00
|
|
|
controller->UpdateReferences(g_controller_interface);
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
UpdateGUI();
|
|
|
|
}
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
void GamepadPage::SaveProfile(wxCommandEvent&)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2010-06-21 03:12:16 +00:00
|
|
|
std::string fname;
|
|
|
|
GamepadPage::GetProfilePath(fname);
|
2011-03-01 03:06:14 +00:00
|
|
|
File::CreateFullPath(fname);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-02-01 23:15:18 +00:00
|
|
|
if (!fname.empty())
|
2010-06-21 03:12:16 +00:00
|
|
|
{
|
|
|
|
IniFile inifile;
|
|
|
|
controller->SaveConfig(inifile.GetOrCreateSection("Profile"));
|
|
|
|
inifile.Save(fname);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2010-08-15 23:03:15 +00:00
|
|
|
m_config_dialog->UpdateProfileComboBox();
|
2010-06-21 03:12:16 +00:00
|
|
|
}
|
2010-08-15 23:03:15 +00:00
|
|
|
else
|
2013-04-08 05:16:50 +00:00
|
|
|
{
|
2014-07-25 01:46:46 +00:00
|
|
|
WxUtils::ShowErrorDialog(_("You must enter a valid profile name."));
|
2013-04-08 05:16:50 +00:00
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
void GamepadPage::DeleteProfile(wxCommandEvent&)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2010-06-21 03:12:16 +00:00
|
|
|
std::string fname;
|
|
|
|
GamepadPage::GetProfilePath(fname);
|
|
|
|
|
|
|
|
const char* const fnamecstr = fname.c_str();
|
|
|
|
|
2011-01-12 13:14:50 +00:00
|
|
|
if (File::Exists(fnamecstr) &&
|
2011-01-13 02:05:58 +00:00
|
|
|
AskYesNoT("Are you sure you want to delete \"%s\"?",
|
2013-02-28 09:11:10 +00:00
|
|
|
WxStrToStr(profile_cbox->GetValue()).c_str()))
|
2010-08-15 23:03:15 +00:00
|
|
|
{
|
2010-06-21 03:12:16 +00:00
|
|
|
File::Delete(fnamecstr);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-08-15 23:03:15 +00:00
|
|
|
m_config_dialog->UpdateProfileComboBox();
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-06-12 18:45:39 +00:00
|
|
|
void InputConfigDialog::UpdateDeviceComboBox()
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2014-09-05 00:41:42 +00:00
|
|
|
ciface::Core::DeviceQualifier dq;
|
2014-02-01 23:15:18 +00:00
|
|
|
for (GamepadPage* page : m_padpages)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2014-02-01 23:15:18 +00:00
|
|
|
page->device_cbox->Clear();
|
|
|
|
|
2014-09-05 00:41:42 +00:00
|
|
|
for (ciface::Core::Device* d : g_controller_interface.Devices())
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2014-02-01 23:15:18 +00:00
|
|
|
dq.FromDevice(d);
|
|
|
|
page->device_cbox->Append(StrToWxStr(dq.ToString()));
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
2014-02-01 23:15:18 +00:00
|
|
|
|
|
|
|
page->device_cbox->SetValue(StrToWxStr(page->controller->default_device.ToString()));
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
void GamepadPage::RefreshDevices(wxCommandEvent&)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2014-08-31 04:04:15 +00:00
|
|
|
std::lock_guard<std::recursive_mutex> lk(m_config.controls_lock);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
// refresh devices
|
2014-10-13 16:45:47 +00:00
|
|
|
g_controller_interface.Reinitialize();
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
// update all control references
|
|
|
|
m_config_dialog->UpdateControlReferences();
|
|
|
|
|
|
|
|
// update device cbox
|
|
|
|
m_config_dialog->UpdateDeviceComboBox();
|
|
|
|
}
|
|
|
|
|
2010-08-15 20:33:07 +00:00
|
|
|
ControlGroupBox::~ControlGroupBox()
|
|
|
|
{
|
2014-02-01 23:15:18 +00:00
|
|
|
for (PadSetting* padSetting : options)
|
|
|
|
delete padSetting;
|
2010-08-15 20:33:07 +00:00
|
|
|
}
|
|
|
|
|
2013-01-13 08:28:12 +00:00
|
|
|
ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWindow* const parent, GamepadPage* const eventsink)
|
2011-01-31 22:19:30 +00:00
|
|
|
: wxBoxSizer(wxVERTICAL)
|
2010-08-15 20:33:07 +00:00
|
|
|
, control_group(group)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2014-03-09 20:14:26 +00:00
|
|
|
static_bitmap = nullptr;
|
2014-06-14 23:15:41 +00:00
|
|
|
const std::vector<std::string> exclude_buttons = {"Mic", "Modifier"};
|
|
|
|
const std::vector<std::string> exclude_groups = {"IR", "Swing", "Tilt", "Shake", "UDP Wiimote", "Extension", "Rumble"};
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-04-12 20:41:38 +00:00
|
|
|
wxFont m_SmallFont(7, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
2014-02-01 22:20:35 +00:00
|
|
|
for (auto& control : group->controls)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2014-12-02 03:56:18 +00:00
|
|
|
wxStaticText* const label = new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(control->name)));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-02-01 22:20:35 +00:00
|
|
|
ControlButton* const control_button = new ControlButton(parent, control->control_ref.get(), 80);
|
2010-04-12 20:41:38 +00:00
|
|
|
control_button->SetFont(m_SmallFont);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-06 03:52:11 +00:00
|
|
|
control_buttons.push_back(control_button);
|
2014-06-14 23:15:41 +00:00
|
|
|
if (std::find(exclude_groups.begin(), exclude_groups.end(), control_group->name) == exclude_groups.end() &&
|
|
|
|
std::find(exclude_buttons.begin(), exclude_buttons.end(), control->name) == exclude_buttons.end())
|
|
|
|
eventsink->control_buttons.push_back(control_button);
|
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-02-01 22:20:35 +00:00
|
|
|
if (control->control_ref->is_input)
|
2010-06-06 03:52:11 +00:00
|
|
|
{
|
2011-01-05 04:35:46 +00:00
|
|
|
control_button->SetToolTip(_("Left-click to detect input.\nMiddle-click to clear.\nRight-click for more options."));
|
2014-05-17 16:49:00 +00:00
|
|
|
control_button->Bind(wxEVT_BUTTON, &GamepadPage::DetectControl, eventsink);
|
2010-06-06 03:52:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-05 04:35:46 +00:00
|
|
|
control_button->SetToolTip(_("Left/Right-click for more options.\nMiddle-click to clear."));
|
2014-05-17 16:49:00 +00:00
|
|
|
control_button->Bind(wxEVT_BUTTON, &GamepadPage::ConfigControl, eventsink);
|
2010-06-06 03:52:11 +00:00
|
|
|
}
|
2010-06-05 05:30:23 +00:00
|
|
|
|
2013-01-13 08:28:12 +00:00
|
|
|
control_button->Bind(wxEVT_MIDDLE_DOWN, &GamepadPage::ClearControl, eventsink);
|
|
|
|
control_button->Bind(wxEVT_RIGHT_UP, &GamepadPage::ConfigControl, eventsink);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
wxBoxSizer* const control_sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
control_sizer->AddStretchSpacer(1);
|
|
|
|
control_sizer->Add(label, 0, wxCENTER | wxRIGHT, 3);
|
|
|
|
control_sizer->Add(control_button, 0, 0, 0);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
Add(control_sizer, 0, wxEXPAND|wxLEFT|wxRIGHT, 3);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-06-05 05:30:23 +00:00
|
|
|
wxMemoryDC dc;
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
switch (group->type)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2010-07-06 13:14:51 +00:00
|
|
|
case GROUP_TYPE_STICK:
|
|
|
|
case GROUP_TYPE_TILT:
|
|
|
|
case GROUP_TYPE_CURSOR:
|
|
|
|
case GROUP_TYPE_FORCE:
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
|
|
|
wxBitmap bitmap(64, 64);
|
|
|
|
dc.SelectObject(bitmap);
|
|
|
|
dc.Clear();
|
2014-12-02 03:56:18 +00:00
|
|
|
static_bitmap = new wxStaticBitmap(parent, wxID_ANY, bitmap, wxDefaultPosition, wxDefaultSize, wxBITMAP_TYPE_BMP);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
wxBoxSizer* const szr = new wxBoxSizer(wxVERTICAL);
|
2014-02-01 22:20:35 +00:00
|
|
|
for (auto& groupSetting : group->settings)
|
2010-04-22 07:11:49 +00:00
|
|
|
{
|
2014-02-01 22:20:35 +00:00
|
|
|
PadSettingSpin* setting = new PadSettingSpin(parent, groupSetting.get());
|
2014-05-17 16:49:00 +00:00
|
|
|
setting->wxcontrol->Bind(wxEVT_SPINCTRL, &GamepadPage::AdjustSetting, eventsink);
|
2010-07-03 08:04:10 +00:00
|
|
|
options.push_back(setting);
|
2014-12-02 03:56:18 +00:00
|
|
|
szr->Add(new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(groupSetting->name))));
|
2011-01-14 03:05:02 +00:00
|
|
|
szr->Add(setting->wxcontrol, 0, wxLEFT, 0);
|
2010-04-22 07:11:49 +00:00
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
wxBoxSizer* const h_szr = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
h_szr->Add(szr, 1, 0, 5);
|
|
|
|
h_szr->Add(static_bitmap, 0, wxALL|wxCENTER, 3);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
Add(h_szr, 0, wxEXPAND|wxLEFT|wxCENTER|wxTOP, 3);
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-07-06 13:14:51 +00:00
|
|
|
case GROUP_TYPE_BUTTONS:
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2015-01-17 00:16:15 +00:00
|
|
|
// Draw buttons in rows of 8
|
|
|
|
unsigned int button_cols = group->controls.size() > 8 ? 8 : group->controls.size();
|
|
|
|
unsigned int button_rows = ceil((float)group->controls.size() / 8.0f);
|
|
|
|
wxBitmap bitmap(int(12 * button_cols + 1), (12 * button_rows) - (button_rows - 1));
|
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
dc.SelectObject(bitmap);
|
|
|
|
dc.Clear();
|
2014-12-02 03:56:18 +00:00
|
|
|
static_bitmap = new wxStaticBitmap(parent, wxID_ANY, bitmap, wxDefaultPosition, wxDefaultSize, wxBITMAP_TYPE_BMP);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-02-01 22:20:35 +00:00
|
|
|
PadSettingSpin* const threshold_cbox = new PadSettingSpin(parent, group->settings[0].get());
|
2014-05-17 16:49:00 +00:00
|
|
|
threshold_cbox->wxcontrol->Bind(wxEVT_SPINCTRL, &GamepadPage::AdjustSetting, eventsink);
|
2010-06-05 05:30:23 +00:00
|
|
|
|
2011-01-05 04:35:46 +00:00
|
|
|
threshold_cbox->wxcontrol->SetToolTip(_("Adjust the analog control pressure required to activate buttons."));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-07-03 08:04:10 +00:00
|
|
|
options.push_back(threshold_cbox);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
wxBoxSizer* const szr = new wxBoxSizer(wxHORIZONTAL);
|
2014-12-02 03:56:18 +00:00
|
|
|
szr->Add(new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(group->settings[0]->name))),
|
2011-01-14 03:05:02 +00:00
|
|
|
0, wxCENTER|wxRIGHT, 3);
|
2010-07-03 08:04:10 +00:00
|
|
|
szr->Add(threshold_cbox->wxcontrol, 0, wxRIGHT, 3);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-07-03 08:04:10 +00:00
|
|
|
Add(szr, 0, wxALL|wxCENTER, 3);
|
|
|
|
Add(static_bitmap, 0, wxALL|wxCENTER, 3);
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-07-06 13:14:51 +00:00
|
|
|
case GROUP_TYPE_MIXED_TRIGGERS:
|
|
|
|
case GROUP_TYPE_TRIGGERS:
|
2010-10-05 21:43:51 +00:00
|
|
|
case GROUP_TYPE_SLIDER:
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2010-10-05 21:43:51 +00:00
|
|
|
int height = (int)(12 * group->controls.size());
|
|
|
|
int width = 64;
|
|
|
|
|
|
|
|
if (GROUP_TYPE_MIXED_TRIGGERS == group->type)
|
|
|
|
width = 64+12+1;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2010-10-05 21:43:51 +00:00
|
|
|
if (GROUP_TYPE_TRIGGERS != group->type)
|
|
|
|
height /= 2;
|
|
|
|
|
2010-04-24 00:44:10 +00:00
|
|
|
wxBitmap bitmap(width, height+1);
|
2010-04-02 02:48:24 +00:00
|
|
|
dc.SelectObject(bitmap);
|
|
|
|
dc.Clear();
|
2014-12-02 03:56:18 +00:00
|
|
|
static_bitmap = new wxStaticBitmap(parent, wxID_ANY, bitmap, wxDefaultPosition, wxDefaultSize, wxBITMAP_TYPE_BMP);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-02-01 22:20:35 +00:00
|
|
|
for (auto& groupSetting : group->settings)
|
2010-04-24 00:44:10 +00:00
|
|
|
{
|
2014-02-01 22:20:35 +00:00
|
|
|
PadSettingSpin* setting = new PadSettingSpin(parent, groupSetting.get());
|
2014-05-17 16:49:00 +00:00
|
|
|
setting->wxcontrol->Bind(wxEVT_SPINCTRL, &GamepadPage::AdjustSetting, eventsink);
|
2010-07-03 08:04:10 +00:00
|
|
|
options.push_back(setting);
|
2011-01-14 03:05:02 +00:00
|
|
|
wxBoxSizer* const szr = new wxBoxSizer(wxHORIZONTAL);
|
2014-12-02 03:56:18 +00:00
|
|
|
szr->Add(new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(groupSetting->name))), 0, wxCENTER | wxRIGHT, 3);
|
2010-07-03 08:04:10 +00:00
|
|
|
szr->Add(setting->wxcontrol, 0, wxRIGHT, 3);
|
|
|
|
Add(szr, 0, wxALL|wxCENTER, 3);
|
2010-04-24 00:44:10 +00:00
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
Add(static_bitmap, 0, wxALL|wxCENTER, 3);
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-07-06 13:14:51 +00:00
|
|
|
case GROUP_TYPE_EXTENSION:
|
2010-04-13 05:15:38 +00:00
|
|
|
{
|
2011-01-14 03:05:02 +00:00
|
|
|
PadSettingExtension* const attachments = new PadSettingExtension(parent, (ControllerEmu::Extension*)group);
|
|
|
|
wxButton* const configure_btn = new ExtensionButton(parent, (ControllerEmu::Extension*)group);
|
2010-04-13 05:15:38 +00:00
|
|
|
|
2010-07-03 08:04:10 +00:00
|
|
|
options.push_back(attachments);
|
2010-04-13 05:15:38 +00:00
|
|
|
|
2014-05-17 16:49:00 +00:00
|
|
|
attachments->wxcontrol->Bind(wxEVT_CHOICE, &GamepadPage::AdjustSetting, eventsink);
|
|
|
|
configure_btn->Bind(wxEVT_BUTTON, &GamepadPage::ConfigExtension, eventsink);
|
2010-04-13 05:15:38 +00:00
|
|
|
|
2010-07-03 08:04:10 +00:00
|
|
|
Add(attachments->wxcontrol, 0, wxTOP|wxLEFT|wxRIGHT|wxEXPAND, 3);
|
2011-01-14 03:05:02 +00:00
|
|
|
Add(configure_btn, 0, wxALL|wxEXPAND, 3);
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-07-06 13:14:51 +00:00
|
|
|
default:
|
2010-04-08 03:33:16 +00:00
|
|
|
{
|
2010-04-13 05:15:38 +00:00
|
|
|
//options
|
2014-02-01 22:20:35 +00:00
|
|
|
for (auto& groupSetting : group->settings)
|
2010-04-08 03:33:16 +00:00
|
|
|
{
|
2014-09-07 05:59:16 +00:00
|
|
|
if (groupSetting->high == DEFAULT_HIGH_VALUE)
|
2014-09-02 16:53:03 +00:00
|
|
|
{
|
2014-09-05 15:23:54 +00:00
|
|
|
PadSettingCheckBox* setting_cbox = new PadSettingCheckBox(parent, groupSetting.get());
|
2014-09-07 05:59:16 +00:00
|
|
|
if (groupSetting->is_iterate == true)
|
2014-09-05 15:23:54 +00:00
|
|
|
{
|
|
|
|
setting_cbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustSettingUI, eventsink);
|
2014-09-07 05:59:16 +00:00
|
|
|
groupSetting->value = 0;
|
2014-09-05 15:23:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setting_cbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustSetting, eventsink);
|
|
|
|
}
|
|
|
|
options.push_back(setting_cbox);
|
|
|
|
Add(setting_cbox->wxcontrol, 0, wxALL | wxLEFT, 5);
|
2014-09-02 16:53:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-05 15:23:54 +00:00
|
|
|
PadSettingSpin* setting = new PadSettingSpin(parent, groupSetting.get());
|
|
|
|
setting->wxcontrol->Bind(wxEVT_SPINCTRL, &GamepadPage::AdjustSetting, eventsink);
|
|
|
|
options.push_back(setting);
|
|
|
|
wxBoxSizer* const szr = new wxBoxSizer(wxHORIZONTAL);
|
2014-12-02 03:56:18 +00:00
|
|
|
szr->Add(new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(groupSetting->name))), 0, wxCENTER | wxRIGHT, 3);
|
2014-09-05 15:23:54 +00:00
|
|
|
szr->Add(setting->wxcontrol, 0, wxRIGHT, 3);
|
|
|
|
Add(szr, 0, wxALL | wxCENTER, 3);
|
2014-09-02 16:53:03 +00:00
|
|
|
}
|
2010-04-08 03:33:16 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-05 05:30:23 +00:00
|
|
|
dc.SelectObject(wxNullBitmap);
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
//AddStretchSpacer(0);
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-13 08:28:12 +00:00
|
|
|
ControlGroupsSizer::ControlGroupsSizer(ControllerEmu* const controller, wxWindow* const parent, GamepadPage* const eventsink, std::vector<ControlGroupBox*>* groups)
|
2011-01-14 03:05:02 +00:00
|
|
|
: wxBoxSizer(wxHORIZONTAL)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2010-10-05 21:43:51 +00:00
|
|
|
size_t col_size = 0;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-03-09 20:14:26 +00:00
|
|
|
wxBoxSizer* stacked_groups = nullptr;
|
2014-02-01 22:20:35 +00:00
|
|
|
for (auto& group : controller->groups)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2014-02-01 22:20:35 +00:00
|
|
|
ControlGroupBox* control_group_box = new ControlGroupBox(group.get(), parent, eventsink);
|
2011-01-31 22:19:30 +00:00
|
|
|
wxStaticBoxSizer *control_group =
|
2013-10-29 05:09:01 +00:00
|
|
|
new wxStaticBoxSizer(wxVERTICAL, parent, wxGetTranslation(StrToWxStr(group->name)));
|
2011-01-31 22:19:30 +00:00
|
|
|
control_group->Add(control_group_box);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2013-10-29 05:09:01 +00:00
|
|
|
const size_t grp_size = group->controls.size() + group->settings.size();
|
2010-10-05 21:43:51 +00:00
|
|
|
col_size += grp_size;
|
2014-03-09 20:14:26 +00:00
|
|
|
if (col_size > 8 || nullptr == stacked_groups)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2011-01-14 03:05:02 +00:00
|
|
|
if (stacked_groups)
|
|
|
|
Add(stacked_groups, 0, /*wxEXPAND|*/wxBOTTOM|wxRIGHT, 5);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
stacked_groups = new wxBoxSizer(wxVERTICAL);
|
|
|
|
stacked_groups->Add(control_group, 0, wxEXPAND);
|
2010-10-05 21:43:51 +00:00
|
|
|
|
|
|
|
col_size = grp_size;
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
else
|
2013-04-08 05:16:50 +00:00
|
|
|
{
|
2011-01-14 03:05:02 +00:00
|
|
|
stacked_groups->Add(control_group, 0, wxEXPAND);
|
2013-04-08 05:16:50 +00:00
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
if (groups)
|
2011-01-31 22:19:30 +00:00
|
|
|
groups->push_back(control_group_box);
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
if (stacked_groups)
|
|
|
|
Add(stacked_groups, 0, /*wxEXPAND|*/wxBOTTOM|wxRIGHT, 5);
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
|
2014-08-31 04:04:15 +00:00
|
|
|
GamepadPage::GamepadPage(wxWindow* parent, InputConfig& config, const unsigned int pad_num, InputConfigDialog* const config_dialog)
|
2014-03-06 04:02:34 +00:00
|
|
|
: wxPanel(parent, wxID_ANY)
|
2014-08-31 04:04:15 +00:00
|
|
|
,controller(config.controllers[pad_num])
|
2010-07-03 08:04:10 +00:00
|
|
|
, m_config_dialog(config_dialog)
|
2014-08-31 04:04:15 +00:00
|
|
|
, m_config(config)
|
2010-04-13 05:15:38 +00:00
|
|
|
{
|
|
|
|
|
2014-08-31 04:04:15 +00:00
|
|
|
wxBoxSizer* control_group_sizer = new ControlGroupsSizer(m_config.controllers[pad_num], this, this, &control_groups);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
wxStaticBoxSizer* profile_sbox = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Profile"));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
// device chooser
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
wxStaticBoxSizer* const device_sbox = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Device"));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-12-02 03:56:18 +00:00
|
|
|
device_cbox = new wxComboBox(this, wxID_ANY, "", wxDefaultPosition, wxSize(64, -1));
|
2010-08-29 03:45:56 +00:00
|
|
|
device_cbox->ToggleWindowStyle(wxTE_PROCESS_ENTER);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2015-01-28 18:07:14 +00:00
|
|
|
wxButton* refresh_button = new wxButton(this, wxID_ANY, _("Refresh"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-05-17 16:49:00 +00:00
|
|
|
device_cbox->Bind(wxEVT_COMBOBOX, &GamepadPage::SetDevice, this);
|
|
|
|
device_cbox->Bind(wxEVT_TEXT_ENTER, &GamepadPage::SetDevice, this);
|
|
|
|
refresh_button->Bind(wxEVT_BUTTON, &GamepadPage::RefreshDevices, this);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
device_sbox->Add(device_cbox, 1, wxLEFT|wxRIGHT, 3);
|
|
|
|
device_sbox->Add(refresh_button, 0, wxRIGHT|wxBOTTOM, 3);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2015-01-28 18:07:14 +00:00
|
|
|
wxButton* const default_button = new wxButton(this, wxID_ANY, _("Default"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
|
|
|
wxButton* const clearall_button = new wxButton(this, wxID_ANY, _("Clear"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
2010-07-10 06:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
wxStaticBoxSizer* const clear_sbox = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Reset"));
|
2010-07-10 06:48:24 +00:00
|
|
|
clear_sbox->Add(default_button, 1, wxLEFT, 3);
|
|
|
|
clear_sbox->Add(clearall_button, 1, wxRIGHT, 3);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-05-17 16:49:00 +00:00
|
|
|
clearall_button->Bind(wxEVT_BUTTON, &GamepadPage::ClearAll, this);
|
|
|
|
default_button->Bind(wxEVT_BUTTON, &GamepadPage::LoadDefaults, this);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-12-02 03:56:18 +00:00
|
|
|
profile_cbox = new wxComboBox(this, wxID_ANY, "", wxDefaultPosition, wxSize(64, -1));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2015-01-28 18:07:14 +00:00
|
|
|
wxButton* const pload_btn = new wxButton(this, wxID_ANY, _("Load"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
|
|
|
wxButton* const psave_btn = new wxButton(this, wxID_ANY, _("Save"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
|
|
|
wxButton* const pdelete_btn = new wxButton(this, wxID_ANY, _("Delete"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-05-17 16:49:00 +00:00
|
|
|
pload_btn->Bind(wxEVT_BUTTON, &GamepadPage::LoadProfile, this);
|
|
|
|
psave_btn->Bind(wxEVT_BUTTON, &GamepadPage::SaveProfile, this);
|
|
|
|
pdelete_btn->Bind(wxEVT_BUTTON, &GamepadPage::DeleteProfile, this);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
profile_sbox->Add(profile_cbox, 1, wxLEFT, 3);
|
|
|
|
profile_sbox->Add(pload_btn, 0, wxLEFT, 3);
|
|
|
|
profile_sbox->Add(psave_btn, 0, 0, 3);
|
|
|
|
profile_sbox->Add(pdelete_btn, 0, wxRIGHT|wxBOTTOM, 3);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
wxBoxSizer* const dio = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
dio->Add(device_sbox, 1, wxEXPAND|wxRIGHT, 5);
|
|
|
|
dio->Add(clear_sbox, 0, wxEXPAND|wxRIGHT, 5);
|
|
|
|
dio->Add(profile_sbox, 1, wxEXPAND|wxRIGHT, 5);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
wxBoxSizer* const mapping = new wxBoxSizer(wxVERTICAL);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
mapping->Add(dio, 1, wxEXPAND|wxLEFT|wxTOP|wxBOTTOM, 5);
|
|
|
|
mapping->Add(control_group_sizer, 0, wxLEFT|wxEXPAND, 5);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
UpdateGUI();
|
|
|
|
|
2014-02-17 04:51:41 +00:00
|
|
|
SetSizerAndFit(mapping); // needed
|
2010-04-02 02:48:24 +00:00
|
|
|
Layout();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-12-01 20:47:38 +00:00
|
|
|
InputConfigDialog::InputConfigDialog(wxWindow* const parent, InputConfig& config, const wxString& name, const int tab_num)
|
|
|
|
: wxDialog(parent, wxID_ANY, name, wxPoint(128,-1))
|
2014-08-31 04:04:15 +00:00
|
|
|
, m_config(config)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2014-12-02 03:56:18 +00:00
|
|
|
m_pad_notebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_DEFAULT);
|
2015-01-16 22:36:05 +00:00
|
|
|
GamepadPage* gp = new GamepadPage(m_pad_notebook, m_config, tab_num, this);
|
|
|
|
m_padpages.push_back(gp);
|
|
|
|
m_pad_notebook->AddPage(gp, wxString::Format("%s [%u]", wxGetTranslation(StrToWxStr(m_config.gui_name)), 1 + tab_num));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2015-01-16 22:36:05 +00:00
|
|
|
m_pad_notebook->SetSelection(0);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
UpdateDeviceComboBox();
|
|
|
|
UpdateProfileComboBox();
|
|
|
|
|
2014-05-17 16:49:00 +00:00
|
|
|
Bind(wxEVT_BUTTON, &InputConfigDialog::ClickSave, this, wxID_OK);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
wxBoxSizer* const szr = new wxBoxSizer(wxVERTICAL);
|
|
|
|
szr->Add(m_pad_notebook, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5);
|
2011-06-03 12:26:32 +00:00
|
|
|
szr->Add(CreateButtonSizer(wxOK | wxCANCEL | wxNO_DEFAULT), 0, wxEXPAND|wxALL, 5);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-03-16 22:22:21 +00:00
|
|
|
SetSizerAndFit(szr);
|
2010-04-02 02:48:24 +00:00
|
|
|
Center();
|
|
|
|
|
|
|
|
// live preview update timer
|
2014-12-02 03:56:18 +00:00
|
|
|
m_update_timer = new wxTimer(this);
|
2013-01-13 18:07:45 +00:00
|
|
|
Bind(wxEVT_TIMER, &InputConfigDialog::UpdateBitmaps, this);
|
2011-01-14 03:05:02 +00:00
|
|
|
m_update_timer->Start(PREVIEW_UPDATE_TIME, wxTIMER_CONTINUOUS);
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
2010-06-12 18:45:39 +00:00
|
|
|
|
2010-06-13 14:49:49 +00:00
|
|
|
bool InputConfigDialog::Destroy()
|
2010-06-12 18:45:39 +00:00
|
|
|
{
|
|
|
|
m_update_timer->Stop();
|
2010-06-13 14:49:49 +00:00
|
|
|
return true;
|
2010-06-12 23:27:39 +00:00
|
|
|
}
|