2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:43:35 +00:00
|
|
|
// 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/bitmap.h>
|
|
|
|
#include <wx/button.h>
|
|
|
|
#include <wx/checkbox.h>
|
|
|
|
#include <wx/choice.h>
|
|
|
|
#include <wx/combobox.h>
|
|
|
|
#include <wx/control.h>
|
|
|
|
#include <wx/dcmemory.h>
|
|
|
|
#include <wx/dialog.h>
|
2016-07-13 10:49:28 +00:00
|
|
|
#include <wx/event.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/font.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/textctrl.h>
|
|
|
|
#include <wx/timer.h>
|
|
|
|
|
|
|
|
#include "Common/FileSearch.h"
|
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/IniFile.h"
|
|
|
|
#include "Common/MsgHandler.h"
|
2015-03-05 08:49:10 +00:00
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/HW/GCKeyboard.h"
|
|
|
|
#include "Core/HW/GCPad.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/HW/Wiimote.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "Core/HotkeyManager.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/InputConfigDiag.h"
|
|
|
|
#include "DolphinWX/WxUtils.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "InputCommon/ControllerEmu.h"
|
|
|
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
|
|
|
#include "InputCommon/ControllerInterface/Device.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "InputCommon/ControllerInterface/ExpressionParser.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "InputCommon/InputConfig.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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
ControllerEmu::Extension* const ex = ((ExtensionButton*)event.GetEventObject())->extension;
|
2010-04-13 05:15:38 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// show config diag, if "none" isn't selected
|
|
|
|
if (ex->switch_extension)
|
|
|
|
{
|
|
|
|
wxDialog dlg(this, wxID_ANY,
|
|
|
|
wxGetTranslation(StrToWxStr(ex->attachments[ex->switch_extension]->GetName())));
|
2010-04-13 05:15:38 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxBoxSizer* const main_szr = new wxBoxSizer(wxVERTICAL);
|
|
|
|
const std::size_t orig_size = control_groups.size();
|
2010-04-13 05:15:38 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
ControlGroupsSizer* const szr = new ControlGroupsSizer(
|
|
|
|
ex->attachments[ex->switch_extension].get(), &dlg, this, &control_groups);
|
|
|
|
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
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
dlg.ShowModal();
|
2010-04-13 05:15:38 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// remove the new groups that were just added, now that the window closed
|
|
|
|
control_groups.resize(orig_size);
|
|
|
|
}
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
PadSettingExtension::PadSettingExtension(wxWindow* const parent,
|
|
|
|
ControllerEmu::Extension* const ext)
|
|
|
|
: PadSetting(new wxChoice(parent, wxID_ANY)), extension(ext)
|
2010-04-13 05:15:38 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
for (auto& attachment : extension->attachments)
|
|
|
|
{
|
|
|
|
((wxChoice*)wxcontrol)->Append(wxGetTranslation(StrToWxStr(attachment->GetName())));
|
|
|
|
}
|
2010-04-13 05:15:38 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
UpdateGUI();
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PadSettingExtension::UpdateGUI()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
((wxChoice*)wxcontrol)->Select(extension->switch_extension);
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PadSettingExtension::UpdateValue()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
extension->switch_extension = ((wxChoice*)wxcontrol)->GetSelection();
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
PadSettingCheckBox::PadSettingCheckBox(wxWindow* const parent,
|
2016-07-11 17:35:32 +00:00
|
|
|
ControllerEmu::ControlGroup::BooleanSetting* const _setting)
|
|
|
|
: PadSetting(new wxCheckBox(parent, wxID_ANY, wxGetTranslation(StrToWxStr(_setting->m_name)))),
|
2016-06-24 08:43:46 +00:00
|
|
|
setting(_setting)
|
2010-04-08 03:33:16 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
UpdateGUI();
|
2010-04-08 03:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PadSettingCheckBox::UpdateGUI()
|
|
|
|
{
|
2016-07-11 17:35:32 +00:00
|
|
|
((wxCheckBox*)wxcontrol)->SetValue(setting->GetValue());
|
2016-07-13 10:49:28 +00:00
|
|
|
// Force WX to trigger an event after updating the value
|
|
|
|
wxCommandEvent event(wxEVT_CHECKBOX);
|
|
|
|
event.SetEventObject(wxcontrol);
|
|
|
|
wxPostEvent(wxcontrol, event);
|
2010-04-08 03:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PadSettingCheckBox::UpdateValue()
|
|
|
|
{
|
2016-07-11 17:35:32 +00:00
|
|
|
setting->SetValue(((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
|
|
|
{
|
2016-06-24 08:43:46 +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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
setting->SetValue(ControlState(((wxSpinCtrl*)wxcontrol)->GetValue()) / 100);
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
ControlDialog::ControlDialog(GamepadPage* const parent, InputConfig& config,
|
|
|
|
ControllerInterface::ControlReference* const ref)
|
|
|
|
: wxDialog(parent, wxID_ANY, _("Configure Control"), wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
|
|
|
|
control_reference(ref), m_config(config), m_parent(parent)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_devq = m_parent->controller->default_device;
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// GetStrings() sounds slow :/
|
|
|
|
// 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
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxStaticBoxSizer* const control_chooser = CreateControlChooser(parent);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
SetSizerAndFit(szr); // needed
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
UpdateGUI();
|
|
|
|
SetFocus();
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
ControlButton::ControlButton(wxWindow* const parent,
|
|
|
|
ControllerInterface::ControlReference* const _ref,
|
2016-07-17 12:32:06 +00:00
|
|
|
const std::string& name, const unsigned int width,
|
|
|
|
const std::string& label)
|
|
|
|
: wxButton(parent, wxID_ANY, "", wxDefaultPosition, wxSize(width, 20)), control_reference(_ref),
|
|
|
|
m_name(name)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (label.empty())
|
|
|
|
SetLabel(StrToWxStr(_ref->expression));
|
|
|
|
else
|
|
|
|
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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string pname(File::GetUserPath(D_CONFIG_IDX));
|
|
|
|
pname += PROFILES_PATH;
|
|
|
|
pname += m_config.GetProfileName();
|
|
|
|
|
|
|
|
std::vector<std::string> sv = DoFileSearch({".ini"}, {pname});
|
|
|
|
|
|
|
|
wxArrayString strs;
|
|
|
|
for (const std::string& filename : sv)
|
|
|
|
{
|
|
|
|
std::string base;
|
|
|
|
SplitPath(filename, nullptr, &base, nullptr);
|
|
|
|
strs.push_back(StrToWxStr(base));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (GamepadPage* page : m_padpages)
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
for (GamepadPage* page : m_padpages)
|
|
|
|
{
|
|
|
|
page->controller->UpdateReferences(g_controller_interface);
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 00:29:44 +00:00
|
|
|
void InputConfigDialog::OnClose(wxCloseEvent& event)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_config.SaveConfig();
|
2016-08-16 00:29:44 +00:00
|
|
|
EndModal(wxID_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputConfigDialog::OnCloseButton(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
Close();
|
2010-04-14 23:50:33 +00:00
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2015-04-28 00:48:04 +00:00
|
|
|
int ControlDialog::GetRangeSliderValue() const
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return range_slider->GetValue();
|
2015-04-28 00:48:04 +00:00
|
|
|
}
|
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
void ControlDialog::UpdateListContents()
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
control_lbox->Clear();
|
|
|
|
|
2016-06-25 19:46:39 +00:00
|
|
|
const auto dev = g_controller_interface.FindDevice(m_devq);
|
|
|
|
if (dev != nullptr)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
if (control_reference->is_input)
|
|
|
|
{
|
|
|
|
for (ciface::Core::Device::Input* input : dev->Inputs())
|
|
|
|
{
|
|
|
|
control_lbox->Append(StrToWxStr(input->GetName()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // It's an output
|
|
|
|
{
|
|
|
|
for (ciface::Core::Device::Output* output : dev->Outputs())
|
|
|
|
{
|
|
|
|
control_lbox->Append(StrToWxStr(output->GetName()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// UpdateGUI();
|
2010-04-14 23:50:33 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
const int f = control_lbox->FindString(StrToWxStr(name));
|
|
|
|
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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// update textbox
|
|
|
|
textctrl->SetValue(StrToWxStr(control_reference->expression));
|
|
|
|
|
|
|
|
// updates the "bound controls:" label
|
|
|
|
m_bound_label->SetLabel(
|
|
|
|
wxString::Format(_("Bound Controls: %lu"), (unsigned long)control_reference->BoundCount()));
|
|
|
|
|
|
|
|
switch (control_reference->parse_error)
|
|
|
|
{
|
|
|
|
case EXPRESSION_PARSE_SYNTAX_ERROR:
|
|
|
|
m_error_label->SetLabel(_("Syntax error"));
|
|
|
|
break;
|
|
|
|
case EXPRESSION_PARSE_NO_DEVICE:
|
|
|
|
m_error_label->SetLabel(_("Device not found"));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
m_error_label->SetLabel("");
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void GamepadPage::UpdateGUI()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
device_cbox->SetValue(StrToWxStr(controller->default_device.ToString()));
|
|
|
|
|
|
|
|
for (ControlGroupBox* cgBox : control_groups)
|
|
|
|
{
|
|
|
|
for (ControlButton* button : cgBox->control_buttons)
|
|
|
|
{
|
|
|
|
wxString expr = StrToWxStr(button->control_reference->expression);
|
|
|
|
expr.Replace("&", "&&");
|
|
|
|
button->SetLabel(expr);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// just load an empty ini section to clear everything :P
|
|
|
|
IniFile::Section section;
|
|
|
|
controller->LoadConfig(§ion);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// no point in using the real ControllerInterface i guess
|
|
|
|
ControllerInterface face;
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
controller->UpdateReferences(face);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
UpdateGUI();
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
void GamepadPage::LoadDefaults(wxCommandEvent&)
|
2010-07-10 06:48:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
controller->LoadDefaults(g_controller_interface);
|
2010-07-10 06:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
controller->UpdateReferences(g_controller_interface);
|
2010-07-10 06:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
UpdateGUI();
|
2010-07-10 06:48:24 +00:00
|
|
|
}
|
|
|
|
|
2013-07-22 06:48:07 +00:00
|
|
|
bool ControlDialog::Validate()
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
control_reference->expression = WxStrToStr(textctrl->GetValue());
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-07-14 15:45:59 +00:00
|
|
|
auto lock = ControllerEmu::GetStateLock();
|
2016-06-24 08:43:46 +00:00
|
|
|
g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
UpdateGUI();
|
2013-07-22 06:48:07 +00:00
|
|
|
|
2016-07-13 14:51:19 +00:00
|
|
|
return (control_reference->parse_error == EXPRESSION_PARSE_SUCCESS ||
|
|
|
|
control_reference->parse_error == EXPRESSION_PARSE_NO_DEVICE);
|
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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
controller->default_device.FromString(WxStrToStr(device_cbox->GetValue()));
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// show user what it was validated as
|
|
|
|
device_cbox->SetValue(StrToWxStr(controller->default_device.ToString()));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// this will set all the controls to this default device
|
|
|
|
controller->UpdateDefaultDevice();
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// update references
|
|
|
|
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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_devq.FromString(WxStrToStr(device_cbox->GetValue()));
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// show user what it was validated as
|
|
|
|
device_cbox->SetValue(StrToWxStr(m_devq.ToString()));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// update gui
|
|
|
|
UpdateListContents();
|
2010-06-21 03:12:16 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
void ControlDialog::ClearControl(wxCommandEvent&)
|
2010-06-21 03:12:16 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
control_reference->expression.clear();
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2016-07-14 15:45:59 +00:00
|
|
|
auto lock = ControllerEmu::GetStateLock();
|
2016-06-24 08:43:46 +00:00
|
|
|
g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
UpdateGUI();
|
2010-07-03 08:04:10 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
inline bool IsAlphabetic(wxString& str)
|
2013-06-17 09:55:21 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
for (wxUniChar c : str)
|
|
|
|
if (!isalpha(c))
|
|
|
|
return false;
|
2014-02-01 23:15:18 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return true;
|
2013-06-17 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
inline void GetExpressionForControl(wxString& expr, wxString& control_name,
|
|
|
|
ciface::Core::DeviceQualifier* control_device = nullptr,
|
|
|
|
ciface::Core::DeviceQualifier* default_device = nullptr)
|
2010-07-03 08:04:10 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
expr = "";
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// non-default device
|
|
|
|
if (control_device && default_device && !(*control_device == *default_device))
|
|
|
|
{
|
|
|
|
expr += control_device->ToString();
|
|
|
|
expr += ":";
|
|
|
|
}
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// append the control name
|
|
|
|
expr += control_name;
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (!IsAlphabetic(expr))
|
|
|
|
expr = wxString::Format("`%s`", expr);
|
2013-06-25 18:32:25 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
bool ControlDialog::GetExpressionForSelectedControl(wxString& expr)
|
2013-06-25 18:32:25 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
const int num = control_lbox->GetSelection();
|
2013-06-25 18:32:25 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (num < 0)
|
|
|
|
return false;
|
2013-06-25 18:32:25 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
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
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return true;
|
2013-06-17 09:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControlDialog::SetSelectedControl(wxCommandEvent&)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
wxString expr;
|
2013-06-17 09:55:21 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (!GetExpressionForSelectedControl(expr))
|
|
|
|
return;
|
2013-06-17 09:55:21 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
textctrl->WriteText(expr);
|
|
|
|
control_reference->expression = textctrl->GetValue();
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2016-07-14 15:45:59 +00:00
|
|
|
auto lock = ControllerEmu::GetStateLock();
|
2016-06-24 08:43:46 +00:00
|
|
|
g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
wxString device_expr, expr;
|
|
|
|
|
|
|
|
const wxString lbl = ((wxButton*)event.GetEventObject())->GetLabel();
|
|
|
|
char op = lbl[0];
|
|
|
|
|
|
|
|
if (!GetExpressionForSelectedControl(device_expr))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
textctrl->WriteText(expr);
|
|
|
|
control_reference->expression = textctrl->GetValue();
|
|
|
|
|
2016-07-14 15:45:59 +00:00
|
|
|
auto lock = ControllerEmu::GetStateLock();
|
2016-06-24 08:43:46 +00:00
|
|
|
g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
|
|
|
|
|
|
|
|
UpdateGUI();
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2016-07-17 12:32:06 +00:00
|
|
|
void GamepadPage::EnablePadSetting(const std::string& group_name, const std::string& name,
|
|
|
|
const bool enabled)
|
2016-07-13 10:49:28 +00:00
|
|
|
{
|
|
|
|
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->options.begin(), box->options.end(), [&name](const auto& pad_setting) {
|
|
|
|
return pad_setting->wxcontrol->GetLabelText() == name;
|
|
|
|
});
|
|
|
|
if (it == box->options.end())
|
|
|
|
return;
|
|
|
|
(*it)->wxcontrol->Enable(enabled);
|
|
|
|
}
|
|
|
|
|
2016-07-17 12:32:06 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-01-14 03:05:02 +00:00
|
|
|
void GamepadPage::AdjustSetting(wxCommandEvent& event)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-07-13 10:49:28 +00:00
|
|
|
const auto* const control = static_cast<wxControl*>(event.GetEventObject());
|
|
|
|
auto* const pad_setting = static_cast<PadSetting*>(control->GetClientData());
|
|
|
|
pad_setting->UpdateValue();
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 10:49:28 +00:00
|
|
|
void GamepadPage::AdjustBooleanSetting(wxCommandEvent& event)
|
2014-09-02 16:53:03 +00:00
|
|
|
{
|
2016-07-13 10:49:28 +00:00
|
|
|
const auto* const control = static_cast<wxControl*>(event.GetEventObject());
|
|
|
|
auto* const pad_setting = static_cast<PadSettingCheckBox*>(control->GetClientData());
|
|
|
|
pad_setting->UpdateValue();
|
|
|
|
|
|
|
|
// TODO: find a cleaner way to have actions depending on the setting
|
|
|
|
if (control->GetLabelText() == "Iterative Input")
|
|
|
|
{
|
|
|
|
m_iterate = pad_setting->setting->GetValue();
|
|
|
|
}
|
|
|
|
else if (control->GetLabelText() == "Relative Input")
|
|
|
|
{
|
2016-07-17 12:32:06 +00:00
|
|
|
EnablePadSetting("IR", "Dead Zone", pad_setting->setting->GetValue());
|
|
|
|
EnableControlButton("IR", "Recenter", pad_setting->setting->GetValue());
|
2016-07-13 10:49:28 +00:00
|
|
|
}
|
2014-09-02 16:53:03 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
void GamepadPage::AdjustControlOption(wxCommandEvent&)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_control_dialog->control_reference->range =
|
|
|
|
(ControlState)(m_control_dialog->GetRangeSliderValue()) / 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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_control_dialog = new ControlDialog(this, m_config,
|
|
|
|
((ControlButton*)event.GetEventObject())->control_reference);
|
|
|
|
m_control_dialog->ShowModal();
|
|
|
|
m_control_dialog->Destroy();
|
2010-04-14 23:50:33 +00:00
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
ControlButton* const btn = (ControlButton*)event.GetEventObject();
|
|
|
|
btn->control_reference->expression.clear();
|
|
|
|
btn->control_reference->range = 1.0;
|
2010-06-05 05:30:23 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
controller->UpdateReferences(g_controller_interface);
|
2010-06-05 05:30:23 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// update changes
|
|
|
|
UpdateGUI();
|
2010-06-05 05:30:23 +00:00
|
|
|
}
|
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
void ControlDialog::DetectControl(wxCommandEvent& event)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
wxButton* const btn = (wxButton*)event.GetEventObject();
|
|
|
|
const wxString lbl = btn->GetLabel();
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2016-06-25 19:46:39 +00:00
|
|
|
const auto dev = g_controller_interface.FindDevice(m_devq);
|
|
|
|
if (dev != nullptr)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
m_event_filter.BlockEvents(true);
|
|
|
|
btn->SetLabel(_("[ waiting ]"));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-25 19:46:39 +00:00
|
|
|
ciface::Core::Device::Control* const ctrl =
|
|
|
|
control_reference->Detect(DETECT_WAIT_TIME, dev.get());
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// if we got input, select it in the list
|
|
|
|
if (ctrl)
|
|
|
|
SelectControl(ctrl->GetName());
|
2010-06-12 02:08:01 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
btn->SetLabel(lbl);
|
2015-09-20 01:36:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// This lets the input events be sent to the filter and discarded before unblocking
|
|
|
|
wxTheApp->Yield(true);
|
|
|
|
m_event_filter.BlockEvents(false);
|
|
|
|
}
|
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
|
|
|
{
|
2016-08-15 09:31:14 +00:00
|
|
|
auto* btn = static_cast<ControlButton*>(event.GetEventObject());
|
|
|
|
if (DetectButton(btn) && m_iterate)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
auto it = std::find(control_buttons.begin(), control_buttons.end(), btn);
|
2016-08-15 09:31:14 +00:00
|
|
|
// it can and will be control_buttons.end() for any control that is in the exclude list.
|
|
|
|
if (it == control_buttons.end())
|
|
|
|
return;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
++it;
|
|
|
|
for (; it != control_buttons.end(); ++it)
|
|
|
|
{
|
|
|
|
if (!DetectButton(*it))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-14 23:15:41 +00:00
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-06-14 23:15:41 +00:00
|
|
|
bool GamepadPage::DetectButton(ControlButton* button)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
bool success = false;
|
|
|
|
// find device :/
|
2016-06-25 19:46:39 +00:00
|
|
|
const auto dev = g_controller_interface.FindDevice(controller->default_device);
|
|
|
|
if (dev != nullptr)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
m_event_filter.BlockEvents(true);
|
|
|
|
button->SetLabel(_("[ waiting ]"));
|
|
|
|
|
|
|
|
// This makes the "waiting" text work on Linux. true (only if needed) prevents crash on Windows
|
|
|
|
wxTheApp->Yield(true);
|
|
|
|
|
|
|
|
ciface::Core::Device::Control* const ctrl =
|
2016-06-25 19:46:39 +00:00
|
|
|
button->control_reference->Detect(DETECT_WAIT_TIME, dev.get());
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
// if we got input, update expression and reference
|
|
|
|
if (ctrl)
|
|
|
|
{
|
|
|
|
wxString control_name = ctrl->GetName();
|
|
|
|
wxString expr;
|
|
|
|
GetExpressionForControl(expr, control_name);
|
|
|
|
button->control_reference->expression = expr;
|
2016-07-14 15:45:59 +00:00
|
|
|
auto lock = ControllerEmu::GetStateLock();
|
2016-06-24 08:43:46 +00:00
|
|
|
g_controller_interface.UpdateReference(button->control_reference, controller->default_device);
|
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This lets the input events be sent to the filter and discarded before unblocking
|
|
|
|
wxTheApp->Yield(true);
|
|
|
|
m_event_filter.BlockEvents(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateGUI();
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
wxStaticBoxSizer* const main_szr = new wxStaticBoxSizer(
|
|
|
|
wxVERTICAL, this, control_reference->is_input ? _("Input") : _("Output"));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
textctrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(-1, 48),
|
|
|
|
wxTE_MULTILINE | wxTE_RICH2);
|
|
|
|
wxFont font = textctrl->GetFont();
|
|
|
|
font.SetFamily(wxFONTFAMILY_MODERN);
|
|
|
|
textctrl->SetFont(font);
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxButton* const clear_button = new wxButton(this, wxID_ANY, _("Clear"));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxButton* const select_button = new wxButton(this, wxID_ANY, _("Select"));
|
|
|
|
select_button->Bind(wxEVT_BUTTON, &ControlDialog::SetSelectedControl, this);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxButton* const or_button = new wxButton(this, wxID_ANY, _("| OR"));
|
|
|
|
or_button->Bind(wxEVT_BUTTON, &ControlDialog::AppendControl, this);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
control_lbox = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 64));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxBoxSizer* const button_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
button_sizer->Add(detect_button, 1, 0, 5);
|
|
|
|
button_sizer->Add(select_button, 1, 0, 5);
|
|
|
|
button_sizer->Add(or_button, 1, 0, 5);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (control_reference->is_input)
|
|
|
|
{
|
|
|
|
// TODO: check if && is good on other OS
|
|
|
|
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
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
and_button->Bind(wxEVT_BUTTON, &ControlDialog::AppendControl, this);
|
|
|
|
not_button->Bind(wxEVT_BUTTON, &ControlDialog::AppendControl, this);
|
|
|
|
add_button->Bind(wxEVT_BUTTON, &ControlDialog::AppendControl, this);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
range_slider->SetValue((int)(control_reference->range * SLIDER_TICK_COUNT));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
range_slider->Bind(wxEVT_SCROLL_CHANGED, &GamepadPage::AdjustControlOption, parent);
|
|
|
|
wxStaticText* const range_label = new wxStaticText(this, wxID_ANY, _("Range"));
|
2013-07-22 06:36:26 +00:00
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxSizer* const bottom_btns_sizer = CreateButtonSizer(wxOK | wxAPPLY);
|
|
|
|
bottom_btns_sizer->Prepend(clear_button, 0, wxLEFT, 5);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +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);
|
|
|
|
main_szr->Add(bottom_btns_sizer, 0, wxEXPAND | wxBOTTOM | wxRIGHT, 5);
|
|
|
|
main_szr->Add(m_bound_label, 0, wxCENTER, 0);
|
|
|
|
main_szr->Add(m_error_label, 0, wxCENTER, 0);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
UpdateListContents();
|
2010-04-22 07:11:49 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return main_szr;
|
2010-06-21 03:12:16 +00:00
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
void GamepadPage::GetProfilePath(std::string& path)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
const wxString& name = profile_cbox->GetValue();
|
|
|
|
if (!name.empty())
|
|
|
|
{
|
|
|
|
// TODO: check for dumb characters maybe
|
|
|
|
|
|
|
|
path = File::GetUserPath(D_CONFIG_IDX);
|
|
|
|
path += PROFILES_PATH;
|
|
|
|
path += m_config.GetProfileName();
|
|
|
|
path += '/';
|
|
|
|
path += WxStrToStr(profile_cbox->GetValue());
|
|
|
|
path += ".ini";
|
|
|
|
}
|
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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string fname;
|
|
|
|
GamepadPage::GetProfilePath(fname);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (!File::Exists(fname))
|
|
|
|
return;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
IniFile inifile;
|
|
|
|
inifile.Load(fname);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
controller->LoadConfig(inifile.GetOrCreateSection("Profile"));
|
|
|
|
controller->UpdateReferences(g_controller_interface);
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
UpdateGUI();
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
void GamepadPage::SaveProfile(wxCommandEvent&)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string fname;
|
|
|
|
GamepadPage::GetProfilePath(fname);
|
|
|
|
File::CreateFullPath(fname);
|
|
|
|
|
|
|
|
if (!fname.empty())
|
|
|
|
{
|
|
|
|
IniFile inifile;
|
|
|
|
controller->SaveConfig(inifile.GetOrCreateSection("Profile"));
|
|
|
|
inifile.Save(fname);
|
|
|
|
|
|
|
|
m_config_dialog->UpdateProfileComboBox();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WxUtils::ShowErrorDialog(_("You must enter a valid profile name."));
|
|
|
|
}
|
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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string fname;
|
|
|
|
GamepadPage::GetProfilePath(fname);
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
const char* const fnamecstr = fname.c_str();
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (File::Exists(fnamecstr) && AskYesNoT("Are you sure you want to delete \"%s\"?",
|
|
|
|
WxStrToStr(profile_cbox->GetValue()).c_str()))
|
|
|
|
{
|
|
|
|
File::Delete(fnamecstr);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
for (GamepadPage* page : m_padpages)
|
|
|
|
{
|
|
|
|
page->device_cbox->Clear();
|
|
|
|
|
2016-06-25 19:46:39 +00:00
|
|
|
for (const std::string& device_string : g_controller_interface.GetAllDeviceStrings())
|
|
|
|
page->device_cbox->Append(StrToWxStr(device_string));
|
2016-06-24 08:43:46 +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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
bool was_unpaused = Core::PauseAndLock(true);
|
2015-03-05 08:49:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// refresh devices
|
|
|
|
g_controller_interface.Reinitialize();
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// update all control references
|
|
|
|
m_config_dialog->UpdateControlReferences();
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// update device cbox
|
|
|
|
m_config_dialog->UpdateDeviceComboBox();
|
2015-03-05 08:49:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
Wiimote::LoadConfig();
|
|
|
|
Keyboard::LoadConfig();
|
|
|
|
Pad::LoadConfig();
|
|
|
|
HotkeyManagerEmu::LoadConfig();
|
2015-03-05 08:49:10 +00:00
|
|
|
|
2016-07-14 19:41:05 +00:00
|
|
|
UpdateGUI();
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
Core::PauseAndLock(false, was_unpaused);
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-08-15 20:33:07 +00:00
|
|
|
ControlGroupBox::~ControlGroupBox()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
for (PadSetting* padSetting : options)
|
|
|
|
delete padSetting;
|
2010-08-15 20:33:07 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWindow* const parent,
|
|
|
|
GamepadPage* const eventsink)
|
|
|
|
: wxBoxSizer(wxVERTICAL), control_group(group)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
static_bitmap = nullptr;
|
|
|
|
const std::vector<std::string> exclude_buttons = {"Mic", "Modifier"};
|
|
|
|
const std::vector<std::string> exclude_groups = {"IR", "Swing", "Tilt", "Shake",
|
|
|
|
"UDP Wiimote", "Extension", "Rumble"};
|
|
|
|
|
|
|
|
wxFont m_SmallFont(7, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
|
|
|
for (auto& control : group->controls)
|
|
|
|
{
|
|
|
|
wxStaticText* const label =
|
|
|
|
new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(control->name)));
|
|
|
|
|
2016-07-17 12:32:06 +00:00
|
|
|
ControlButton* const control_button =
|
|
|
|
new ControlButton(parent, control->control_ref.get(), control->name, 80);
|
2016-06-24 08:43:46 +00:00
|
|
|
control_button->SetFont(m_SmallFont);
|
|
|
|
|
|
|
|
control_buttons.push_back(control_button);
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (control->control_ref->is_input)
|
|
|
|
{
|
|
|
|
control_button->SetToolTip(
|
|
|
|
_("Left-click to detect input.\nMiddle-click to clear.\nRight-click for more options."));
|
|
|
|
control_button->Bind(wxEVT_BUTTON, &GamepadPage::DetectControl, eventsink);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
control_button->SetToolTip(_("Left/Right-click for more options.\nMiddle-click to clear."));
|
|
|
|
control_button->Bind(wxEVT_BUTTON, &GamepadPage::ConfigControl, eventsink);
|
|
|
|
}
|
|
|
|
|
|
|
|
control_button->Bind(wxEVT_MIDDLE_DOWN, &GamepadPage::ClearControl, eventsink);
|
|
|
|
control_button->Bind(wxEVT_RIGHT_UP, &GamepadPage::ConfigControl, eventsink);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
Add(control_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxMemoryDC dc;
|
|
|
|
|
|
|
|
switch (group->type)
|
|
|
|
{
|
|
|
|
case GROUP_TYPE_STICK:
|
|
|
|
case GROUP_TYPE_TILT:
|
|
|
|
case GROUP_TYPE_CURSOR:
|
|
|
|
case GROUP_TYPE_FORCE:
|
|
|
|
{
|
|
|
|
wxBitmap bitmap(64, 64);
|
|
|
|
dc.SelectObject(bitmap);
|
|
|
|
dc.Clear();
|
|
|
|
static_bitmap = new wxStaticBitmap(parent, wxID_ANY, bitmap, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxBITMAP_TYPE_BMP);
|
|
|
|
|
|
|
|
wxBoxSizer* const szr = new wxBoxSizer(wxVERTICAL);
|
2016-07-11 17:35:32 +00:00
|
|
|
for (auto& groupSetting : group->numeric_settings)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
PadSettingSpin* setting = new PadSettingSpin(parent, groupSetting.get());
|
|
|
|
setting->wxcontrol->Bind(wxEVT_SPINCTRL, &GamepadPage::AdjustSetting, eventsink);
|
|
|
|
options.push_back(setting);
|
|
|
|
szr->Add(
|
2016-07-11 17:35:32 +00:00
|
|
|
new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(groupSetting->m_name))));
|
2016-06-24 08:43:46 +00:00
|
|
|
szr->Add(setting->wxcontrol, 0, wxLEFT, 0);
|
|
|
|
}
|
2016-07-09 12:29:41 +00:00
|
|
|
for (auto& groupSetting : group->boolean_settings)
|
|
|
|
{
|
|
|
|
auto* checkbox = new PadSettingCheckBox(parent, groupSetting.get());
|
2016-07-13 10:49:28 +00:00
|
|
|
checkbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustBooleanSetting, eventsink);
|
2016-07-09 12:29:41 +00:00
|
|
|
options.push_back(checkbox);
|
|
|
|
Add(checkbox->wxcontrol, 0, wxALL | wxLEFT, 5);
|
|
|
|
}
|
2016-06-24 08:43:46 +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);
|
|
|
|
|
|
|
|
Add(h_szr, 0, wxEXPAND | wxLEFT | wxCENTER | wxTOP, 3);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GROUP_TYPE_BUTTONS:
|
|
|
|
{
|
|
|
|
// 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), (11 * button_rows) + 1);
|
|
|
|
|
|
|
|
dc.SelectObject(bitmap);
|
|
|
|
dc.Clear();
|
|
|
|
static_bitmap = new wxStaticBitmap(parent, wxID_ANY, bitmap, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxBITMAP_TYPE_BMP);
|
|
|
|
|
2016-07-11 17:35:32 +00:00
|
|
|
auto* const threshold_cbox = new PadSettingSpin(parent, group->numeric_settings[0].get());
|
2016-06-24 08:43:46 +00:00
|
|
|
threshold_cbox->wxcontrol->Bind(wxEVT_SPINCTRL, &GamepadPage::AdjustSetting, eventsink);
|
|
|
|
|
|
|
|
threshold_cbox->wxcontrol->SetToolTip(
|
|
|
|
_("Adjust the analog control pressure required to activate buttons."));
|
|
|
|
|
|
|
|
options.push_back(threshold_cbox);
|
|
|
|
|
|
|
|
wxBoxSizer* const szr = new wxBoxSizer(wxHORIZONTAL);
|
2016-07-11 17:35:32 +00:00
|
|
|
szr->Add(new wxStaticText(parent, wxID_ANY,
|
|
|
|
wxGetTranslation(StrToWxStr(group->numeric_settings[0]->m_name))),
|
|
|
|
0, wxCENTER | wxRIGHT, 3);
|
2016-06-24 08:43:46 +00:00
|
|
|
szr->Add(threshold_cbox->wxcontrol, 0, wxRIGHT, 3);
|
|
|
|
|
|
|
|
Add(szr, 0, wxALL | wxCENTER, 3);
|
|
|
|
Add(static_bitmap, 0, wxALL | wxCENTER, 3);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GROUP_TYPE_MIXED_TRIGGERS:
|
|
|
|
case GROUP_TYPE_TRIGGERS:
|
|
|
|
case GROUP_TYPE_SLIDER:
|
|
|
|
{
|
|
|
|
int height = (int)(12 * group->controls.size());
|
|
|
|
int width = 64;
|
|
|
|
|
|
|
|
if (GROUP_TYPE_MIXED_TRIGGERS == group->type)
|
|
|
|
width = 64 + 12 + 1;
|
|
|
|
|
|
|
|
if (GROUP_TYPE_TRIGGERS != group->type)
|
|
|
|
height /= 2;
|
|
|
|
|
|
|
|
wxBitmap bitmap(width, height + 1);
|
|
|
|
dc.SelectObject(bitmap);
|
|
|
|
dc.Clear();
|
|
|
|
static_bitmap = new wxStaticBitmap(parent, wxID_ANY, bitmap, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxBITMAP_TYPE_BMP);
|
|
|
|
|
2016-07-11 17:35:32 +00:00
|
|
|
for (auto& groupSetting : group->numeric_settings)
|
2016-06-24 08:43:46 +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);
|
2016-07-11 17:35:32 +00:00
|
|
|
szr->Add(
|
|
|
|
new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(groupSetting->m_name))), 0,
|
|
|
|
wxCENTER | wxRIGHT, 3);
|
2016-06-24 08:43:46 +00:00
|
|
|
szr->Add(setting->wxcontrol, 0, wxRIGHT, 3);
|
|
|
|
Add(szr, 0, wxALL | wxCENTER, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
Add(static_bitmap, 0, wxALL | wxCENTER, 3);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GROUP_TYPE_EXTENSION:
|
|
|
|
{
|
|
|
|
PadSettingExtension* const attachments =
|
|
|
|
new PadSettingExtension(parent, (ControllerEmu::Extension*)group);
|
|
|
|
wxButton* const configure_btn = new ExtensionButton(parent, (ControllerEmu::Extension*)group);
|
|
|
|
|
|
|
|
options.push_back(attachments);
|
|
|
|
|
|
|
|
attachments->wxcontrol->Bind(wxEVT_CHOICE, &GamepadPage::AdjustSetting, eventsink);
|
|
|
|
configure_btn->Bind(wxEVT_BUTTON, &GamepadPage::ConfigExtension, eventsink);
|
|
|
|
|
|
|
|
Add(attachments->wxcontrol, 0, wxTOP | wxLEFT | wxRIGHT | wxEXPAND, 3);
|
|
|
|
Add(configure_btn, 0, wxALL | wxEXPAND, 3);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
// options
|
2016-07-11 17:35:32 +00:00
|
|
|
for (auto& groupSetting : group->boolean_settings)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-07-11 17:35:32 +00:00
|
|
|
PadSettingCheckBox* setting_cbox = new PadSettingCheckBox(parent, groupSetting.get());
|
2016-07-13 10:49:28 +00:00
|
|
|
setting_cbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustBooleanSetting, eventsink);
|
2016-07-11 17:35:32 +00:00
|
|
|
if (groupSetting->m_name == "Iterative Input")
|
|
|
|
groupSetting->SetValue(false);
|
|
|
|
options.push_back(setting_cbox);
|
|
|
|
Add(setting_cbox->wxcontrol, 0, wxALL | wxLEFT, 5);
|
|
|
|
}
|
|
|
|
for (auto& groupSetting : group->numeric_settings)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
szr->Add(
|
|
|
|
new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(groupSetting->m_name))), 0,
|
|
|
|
wxCENTER | wxRIGHT, 3);
|
|
|
|
szr->Add(setting->wxcontrol, 0, wxRIGHT, 3);
|
|
|
|
Add(szr, 0, wxALL | wxCENTER, 3);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dc.SelectObject(wxNullBitmap);
|
|
|
|
|
|
|
|
// AddStretchSpacer(0);
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
ControlGroupsSizer::ControlGroupsSizer(ControllerEmu* const controller, wxWindow* const parent,
|
|
|
|
GamepadPage* const eventsink,
|
|
|
|
std::vector<ControlGroupBox*>* groups)
|
|
|
|
: wxBoxSizer(wxHORIZONTAL)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
size_t col_size = 0;
|
|
|
|
|
|
|
|
wxBoxSizer* stacked_groups = nullptr;
|
|
|
|
for (auto& group : controller->groups)
|
|
|
|
{
|
|
|
|
ControlGroupBox* control_group_box = new ControlGroupBox(group.get(), parent, eventsink);
|
|
|
|
wxStaticBoxSizer* control_group =
|
|
|
|
new wxStaticBoxSizer(wxVERTICAL, parent, wxGetTranslation(StrToWxStr(group->ui_name)));
|
|
|
|
control_group->Add(control_group_box);
|
|
|
|
|
2016-07-11 17:35:32 +00:00
|
|
|
const size_t grp_size =
|
|
|
|
group->controls.size() + group->numeric_settings.size() + group->boolean_settings.size();
|
2016-06-24 08:43:46 +00:00
|
|
|
col_size += grp_size;
|
|
|
|
if (col_size > 8 || nullptr == stacked_groups)
|
|
|
|
{
|
|
|
|
if (stacked_groups)
|
|
|
|
Add(stacked_groups, 0, /*wxEXPAND|*/ wxBOTTOM | wxRIGHT, 5);
|
|
|
|
|
|
|
|
stacked_groups = new wxBoxSizer(wxVERTICAL);
|
|
|
|
stacked_groups->Add(control_group, 0, wxEXPAND);
|
|
|
|
|
|
|
|
col_size = grp_size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stacked_groups->Add(control_group, 0, wxEXPAND);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (groups)
|
|
|
|
groups->push_back(control_group_box);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stacked_groups)
|
|
|
|
Add(stacked_groups, 0, /*wxEXPAND|*/ wxBOTTOM | wxRIGHT, 5);
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
GamepadPage::GamepadPage(wxWindow* parent, InputConfig& config, const int pad_num,
|
|
|
|
InputConfigDialog* const config_dialog)
|
|
|
|
: wxPanel(parent, wxID_ANY), controller(config.GetController(pad_num)),
|
|
|
|
m_config_dialog(config_dialog), m_config(config)
|
2010-04-13 05:15:38 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
wxBoxSizer* control_group_sizer = new ControlGroupsSizer(controller, this, this, &control_groups);
|
2010-04-13 05:15:38 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxStaticBoxSizer* profile_sbox = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Profile"));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// device chooser
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxStaticBoxSizer* const device_sbox = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Device"));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
device_cbox = new wxComboBox(this, wxID_ANY, "", wxDefaultPosition, wxSize(64, -1));
|
|
|
|
device_cbox->ToggleWindowStyle(wxTE_PROCESS_ENTER);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxButton* refresh_button =
|
|
|
|
new wxButton(this, wxID_ANY, _("Refresh"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxStaticBoxSizer* const clear_sbox = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Reset"));
|
|
|
|
clear_sbox->Add(default_button, 1, wxLEFT, 3);
|
|
|
|
clear_sbox->Add(clearall_button, 1, wxRIGHT, 3);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
profile_cbox = new wxComboBox(this, wxID_ANY, "", wxDefaultPosition, wxSize(64, -1));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxBoxSizer* const mapping = new wxBoxSizer(wxVERTICAL);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +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
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
UpdateGUI();
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
SetSizerAndFit(mapping); // needed
|
|
|
|
Layout();
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
InputConfigDialog::InputConfigDialog(wxWindow* const parent, InputConfig& config,
|
|
|
|
const wxString& name, const int tab_num)
|
|
|
|
: wxDialog(parent, wxID_ANY, name, wxPoint(128, -1)), m_config(config)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_pad_notebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_DEFAULT);
|
|
|
|
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.GetGUIName())),
|
|
|
|
1 + tab_num));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
m_pad_notebook->SetSelection(0);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
UpdateDeviceComboBox();
|
|
|
|
UpdateProfileComboBox();
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-08-16 00:29:44 +00:00
|
|
|
Bind(wxEVT_CLOSE_WINDOW, &InputConfigDialog::OnClose, this);
|
|
|
|
Bind(wxEVT_BUTTON, &InputConfigDialog::OnCloseButton, this, wxID_CLOSE);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxBoxSizer* const szr = new wxBoxSizer(wxVERTICAL);
|
|
|
|
szr->Add(m_pad_notebook, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 5);
|
2016-08-16 00:29:44 +00:00
|
|
|
szr->Add(CreateButtonSizer(wxCLOSE), 0, wxEXPAND | wxALL, 5);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
SetLayoutAdaptationMode(wxDIALOG_ADAPTATION_MODE_ENABLED);
|
|
|
|
SetSizerAndFit(szr);
|
|
|
|
Center();
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// live preview update timer
|
|
|
|
m_update_timer.SetOwner(this);
|
|
|
|
Bind(wxEVT_TIMER, &InputConfigDialog::UpdateBitmaps, this);
|
|
|
|
m_update_timer.Start(PREVIEW_UPDATE_TIME, wxTIMER_CONTINUOUS);
|
2010-06-12 23:27:39 +00:00
|
|
|
}
|
2015-09-20 01:36:24 +00:00
|
|
|
|
|
|
|
int InputEventFilter::FilterEvent(wxEvent& event)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (m_block && ShouldCatchEventType(event.GetEventType()))
|
|
|
|
{
|
|
|
|
event.StopPropagation();
|
|
|
|
return Event_Processed;
|
|
|
|
}
|
2015-09-20 01:36:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return Event_Skip;
|
2015-09-20 01:36:24 +00:00
|
|
|
}
|