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
|
|
|
|
2017-02-09 03:15:43 +00:00
|
|
|
#include "DolphinWX/Input/InputConfigDiag.h"
|
|
|
|
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <algorithm>
|
2016-08-02 06:22:48 +00:00
|
|
|
#include <array>
|
2014-02-22 22:36:30 +00:00
|
|
|
#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>
|
2016-08-02 06:22:48 +00:00
|
|
|
#include <wx/dcclient.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#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/spinctrl.h>
|
|
|
|
#include <wx/statbmp.h>
|
2016-08-02 06:22:48 +00:00
|
|
|
#include <wx/statbox.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#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"
|
2017-02-25 03:56:33 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2017-02-09 03:15:43 +00:00
|
|
|
|
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-11-20 05:49:31 +00:00
|
|
|
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "Core/HotkeyManager.h"
|
2017-02-09 03:15:43 +00:00
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
#include "DolphinWX/DolphinSlider.h"
|
2016-11-19 00:54:06 +00:00
|
|
|
#include "DolphinWX/Input/ClassicInputConfigDiag.h"
|
|
|
|
#include "DolphinWX/Input/DrumsInputConfigDiag.h"
|
|
|
|
#include "DolphinWX/Input/GuitarInputConfigDiag.h"
|
|
|
|
#include "DolphinWX/Input/NunchukInputConfigDiag.h"
|
|
|
|
#include "DolphinWX/Input/TurntableInputConfigDiag.h"
|
2017-07-12 07:11:29 +00:00
|
|
|
#include "DolphinWX/UINeedsControllerState.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/WxUtils.h"
|
2017-02-09 03:15:43 +00:00
|
|
|
|
|
|
|
#include "InputCommon/ControlReference/ControlReference.h"
|
2016-10-12 00:48:38 +00:00
|
|
|
#include "InputCommon/ControlReference/ExpressionParser.h"
|
2017-02-09 03:15:43 +00:00
|
|
|
#include "InputCommon/ControllerEmu/Control/Control.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/Extension.h"
|
2017-01-30 03:32:04 +00:00
|
|
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
2017-02-26 20:00:24 +00:00
|
|
|
#include "InputCommon/ControllerEmu/Setting/BooleanSetting.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
|
|
|
#include "InputCommon/ControllerInterface/Device.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "InputCommon/InputConfig.h"
|
2013-07-22 06:36:26 +00:00
|
|
|
|
2017-06-07 22:24:29 +00:00
|
|
|
using ciface::ExpressionParser::ParseStatus;
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
void InputConfigDialog::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-11-20 05:49:31 +00:00
|
|
|
int extension_type = ex->switch_extension;
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// show config diag, if "none" isn't selected
|
2016-11-20 05:49:31 +00:00
|
|
|
switch (extension_type)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-11-20 05:49:31 +00:00
|
|
|
case WiimoteEmu::EXT_NUNCHUK:
|
|
|
|
{
|
2017-01-27 05:05:09 +00:00
|
|
|
NunchukInputConfigDialog dlg(this, m_config, _("Nunchuk Configuration"), device_cbox,
|
|
|
|
m_port_num);
|
2016-11-19 00:54:06 +00:00
|
|
|
dlg.ShowModal();
|
2016-11-20 05:49:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WiimoteEmu::EXT_CLASSIC:
|
|
|
|
{
|
2017-01-27 05:05:09 +00:00
|
|
|
ClassicInputConfigDialog dlg(this, m_config, _("Classic Controller Configuration"), device_cbox,
|
|
|
|
m_port_num);
|
2016-11-19 00:54:06 +00:00
|
|
|
dlg.ShowModal();
|
2016-11-20 05:49:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WiimoteEmu::EXT_GUITAR:
|
|
|
|
{
|
2017-01-27 05:05:09 +00:00
|
|
|
GuitarInputConfigDialog dlg(this, m_config, _("Guitar Configuration"), device_cbox, m_port_num);
|
2016-11-19 00:54:06 +00:00
|
|
|
dlg.ShowModal();
|
2016-11-20 05:49:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WiimoteEmu::EXT_DRUMS:
|
|
|
|
{
|
2017-01-27 05:05:09 +00:00
|
|
|
DrumsInputConfigDialog dlg(this, m_config, _("Drums Configuration"), device_cbox, m_port_num);
|
2016-11-19 00:54:06 +00:00
|
|
|
dlg.ShowModal();
|
2016-11-20 05:49:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WiimoteEmu::EXT_TURNTABLE:
|
|
|
|
{
|
2017-01-27 05:05:09 +00:00
|
|
|
TurntableInputConfigDialog dlg(this, m_config, _("Turntable Configuration"), device_cbox,
|
|
|
|
m_port_num);
|
2016-11-19 00:54:06 +00:00
|
|
|
dlg.ShowModal();
|
2016-11-20 05:49:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
|
2016-12-31 23:46:56 +00:00
|
|
|
PadSetting::PadSetting(wxControl* const _control) : wxcontrol(_control)
|
|
|
|
{
|
|
|
|
wxcontrol->SetClientData(this);
|
|
|
|
}
|
|
|
|
|
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,
|
2017-02-26 20:00:24 +00:00
|
|
|
ControllerEmu::BooleanSetting* const _setting)
|
2017-02-18 11:48:28 +00:00
|
|
|
: PadSetting(
|
|
|
|
new wxCheckBox(parent, wxID_ANY, wxGetTranslation(StrToWxStr(_setting->m_ui_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
|
|
|
}
|
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
PadSettingSpin::PadSettingSpin(wxWindow* const parent,
|
2017-02-26 20:00:24 +00:00
|
|
|
ControllerEmu::NumericSetting* const settings)
|
2016-08-02 06:22:48 +00:00
|
|
|
: PadSetting(new wxSpinCtrl(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxSP_ARROW_KEYS, settings->m_low, settings->m_high,
|
|
|
|
(int)(settings->m_value * 100))),
|
|
|
|
setting(settings)
|
|
|
|
{
|
|
|
|
// Compute how wide the control needs to be to fit the maximum value in it.
|
|
|
|
// This accounts for borders, margins and the spinner buttons.
|
|
|
|
wxcontrol->SetMinSize(WxUtils::GetTextWidgetMinSize(static_cast<wxSpinCtrl*>(wxcontrol)));
|
|
|
|
wxcontrol->SetLabelText(setting->m_name);
|
|
|
|
}
|
|
|
|
|
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-11-18 07:03:06 +00:00
|
|
|
ControlDialog::ControlDialog(InputConfigDialog* const parent, InputConfig& config,
|
2016-10-12 00:48:38 +00:00
|
|
|
ControlReference* const ref)
|
2016-06-24 08:43:46 +00:00
|
|
|
: 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
|
|
|
{
|
2017-11-04 21:08:26 +00:00
|
|
|
m_devq = m_parent->GetController()->GetDefaultDevice();
|
2016-08-02 06:22:48 +00:00
|
|
|
const int space5 = FromDIP(5);
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// GetStrings() sounds slow :/
|
2016-08-02 06:22:48 +00:00
|
|
|
device_cbox = new wxComboBox(this, wxID_ANY, StrToWxStr(m_devq.ToString()), wxDefaultPosition,
|
|
|
|
wxDLG_UNIT(this, wxSize(180, -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"));
|
2016-08-02 06:22:48 +00:00
|
|
|
d_szr->AddSpacer(space5);
|
|
|
|
d_szr->Add(device_cbox, 0, wxEXPAND | wxLEFT | wxRIGHT, space5);
|
|
|
|
d_szr->AddSpacer(space5);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxBoxSizer* const szr = new wxBoxSizer(wxVERTICAL);
|
2016-08-02 06:22:48 +00:00
|
|
|
szr->AddSpacer(space5);
|
|
|
|
szr->Add(d_szr, 0, wxEXPAND | wxLEFT | wxRIGHT, space5);
|
|
|
|
szr->AddSpacer(space5);
|
|
|
|
szr->Add(control_chooser, 1, wxEXPAND | wxLEFT | wxRIGHT, space5);
|
|
|
|
szr->AddSpacer(space5);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
SetLayoutAdaptationMode(wxDIALOG_ADAPTATION_MODE_ENABLED);
|
|
|
|
SetLayoutAdaptationLevel(wxDIALOG_ADAPTATION_STANDARD_SIZER);
|
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-12-31 23:46:56 +00:00
|
|
|
ExtensionButton::ExtensionButton(wxWindow* const parent, ControllerEmu::Extension* const ext)
|
|
|
|
: wxButton(parent, wxID_ANY, _("Configure"), wxDefaultPosition), extension(ext)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-12 00:48:38 +00:00
|
|
|
ControlButton::ControlButton(wxWindow* const parent, ControlReference* const _ref,
|
2016-07-17 12:32:06 +00:00
|
|
|
const std::string& name, const unsigned int width,
|
|
|
|
const std::string& label)
|
2016-08-02 06:22:48 +00:00
|
|
|
: wxButton(parent, wxID_ANY), control_reference(_ref), m_name(name),
|
|
|
|
m_configured_width(FromDIP(width))
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (label.empty())
|
2017-06-08 02:02:16 +00:00
|
|
|
SetLabelText(StrToWxStr(_ref->GetExpression()));
|
2016-06-24 08:43:46 +00:00
|
|
|
else
|
|
|
|
SetLabel(StrToWxStr(label));
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
wxSize ControlButton::DoGetBestSize() const
|
|
|
|
{
|
|
|
|
if (m_configured_width == wxDefaultCoord)
|
|
|
|
return wxButton::DoGetBestSize();
|
|
|
|
|
|
|
|
static constexpr int PADDING_HEIGHT = 4;
|
|
|
|
wxClientDC dc(const_cast<ControlButton*>(this));
|
|
|
|
wxFontMetrics metrics = dc.GetFontMetrics();
|
|
|
|
return {m_configured_width, metrics.height + FromDIP(PADDING_HEIGHT * 2)};
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2017-06-21 04:24:26 +00:00
|
|
|
std::vector<std::string> sv = Common::DoFileSearch({pname}, {".ini"});
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
wxArrayString strs;
|
|
|
|
for (const std::string& filename : sv)
|
|
|
|
{
|
|
|
|
std::string base;
|
|
|
|
SplitPath(filename, nullptr, &base, nullptr);
|
|
|
|
strs.push_back(StrToWxStr(base));
|
|
|
|
}
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
profile_cbox->Clear();
|
|
|
|
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-11-18 07:03:06 +00:00
|
|
|
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-08-02 06:22:48 +00:00
|
|
|
return m_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
|
|
|
{
|
2016-12-09 21:13:11 +00:00
|
|
|
if (control_reference->IsInput())
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
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
|
2017-06-08 02:02:16 +00:00
|
|
|
textctrl->SetValue(StrToWxStr(control_reference->GetExpression()));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
// updates the "bound controls:" label
|
|
|
|
m_bound_label->SetLabel(
|
|
|
|
wxString::Format(_("Bound Controls: %lu"), (unsigned long)control_reference->BoundCount()));
|
|
|
|
|
2016-12-09 21:19:23 +00:00
|
|
|
switch (control_reference->GetParseStatus())
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-02-28 09:58:03 +00:00
|
|
|
case ParseStatus::SyntaxError:
|
2016-06-24 08:43:46 +00:00
|
|
|
m_error_label->SetLabel(_("Syntax error"));
|
|
|
|
break;
|
2017-06-07 23:03:36 +00:00
|
|
|
case ParseStatus::Successful:
|
2017-09-17 06:37:30 +00:00
|
|
|
m_error_label->SetLabel(control_reference->BoundCount() > 0 ? wxString{} :
|
|
|
|
_("Device not found"));
|
2016-06-24 08:43:46 +00:00
|
|
|
break;
|
2017-06-07 23:03:36 +00:00
|
|
|
case ParseStatus::EmptyExpression:
|
2016-06-24 08:43:46 +00:00
|
|
|
m_error_label->SetLabel("");
|
2017-06-07 23:03:36 +00:00
|
|
|
break;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2017-09-17 06:37:30 +00:00
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
void InputConfigDialog::UpdateGUI()
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-11-18 07:03:06 +00:00
|
|
|
if (device_cbox != nullptr)
|
2017-11-04 21:08:26 +00:00
|
|
|
device_cbox->SetValue(StrToWxStr(controller->GetDefaultDevice().ToString()));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
for (ControlGroupBox* cgBox : control_groups)
|
|
|
|
{
|
|
|
|
for (ControlButton* button : cgBox->control_buttons)
|
|
|
|
{
|
2017-06-08 02:02:16 +00:00
|
|
|
button->SetLabelText(StrToWxStr(button->control_reference->GetExpression()));
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (PadSetting* padSetting : cgBox->options)
|
|
|
|
{
|
|
|
|
padSetting->UpdateGUI();
|
|
|
|
}
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
void InputConfigDialog::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
|
|
|
}
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
void InputConfigDialog::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
|
|
|
{
|
2017-06-08 02:02:16 +00:00
|
|
|
control_reference->SetExpression(WxStrToStr(textctrl->GetValue()));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2017-02-09 03:15:43 +00:00
|
|
|
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
2016-10-12 00:48:38 +00:00
|
|
|
control_reference->UpdateReference(g_controller_interface,
|
2017-11-04 21:08:26 +00:00
|
|
|
m_parent->GetController()->GetDefaultDevice());
|
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
|
|
|
|
2017-02-28 09:58:03 +00:00
|
|
|
const auto parse_status = control_reference->GetParseStatus();
|
2017-06-07 23:03:36 +00:00
|
|
|
return parse_status == ParseStatus::Successful || parse_status == ParseStatus::EmptyExpression;
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
void InputConfigDialog::SetDevice(wxCommandEvent&)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2017-11-04 21:08:26 +00:00
|
|
|
controller->SetDefaultDevice(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
|
2017-11-04 21:08:26 +00:00
|
|
|
device_cbox->SetValue(StrToWxStr(controller->GetDefaultDevice().ToString()));
|
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
|
|
|
{
|
2017-06-08 02:02:16 +00:00
|
|
|
control_reference->SetExpression("");
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2017-02-09 03:15:43 +00:00
|
|
|
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
2016-10-12 00:48:38 +00:00
|
|
|
control_reference->UpdateReference(g_controller_interface,
|
2017-11-04 21:08:26 +00:00
|
|
|
m_parent->GetController()->GetDefaultDevice());
|
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,
|
2017-11-04 21:08:26 +00:00
|
|
|
const ciface::Core::DeviceQualifier* control_device = nullptr,
|
|
|
|
const 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);
|
2017-11-04 21:08:26 +00:00
|
|
|
GetExpressionForControl(expr, control_name, &m_devq,
|
|
|
|
&m_parent->GetController()->GetDefaultDevice());
|
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);
|
2017-06-08 02:02:16 +00:00
|
|
|
control_reference->SetExpression(WxStrToStr(textctrl->GetValue()));
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2017-02-09 03:15:43 +00:00
|
|
|
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
2016-10-12 00:48:38 +00:00
|
|
|
control_reference->UpdateReference(g_controller_interface,
|
2017-11-04 21:08:26 +00:00
|
|
|
m_parent->GetController()->GetDefaultDevice());
|
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);
|
2017-06-08 02:02:16 +00:00
|
|
|
control_reference->SetExpression(WxStrToStr(textctrl->GetValue()));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-02-09 03:15:43 +00:00
|
|
|
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
2016-10-12 00:48:38 +00:00
|
|
|
control_reference->UpdateReference(g_controller_interface,
|
2017-11-04 21:08:26 +00:00
|
|
|
m_parent->GetController()->GetDefaultDevice());
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
UpdateGUI();
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
void InputConfigDialog::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-11-18 07:03:06 +00:00
|
|
|
void InputConfigDialog::EnableControlButton(const std::string& group_name, const std::string& name,
|
|
|
|
const bool enabled)
|
2016-07-17 12:32:06 +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->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);
|
|
|
|
}
|
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
void ControlDialog::OnRangeSlide(wxScrollEvent& event)
|
|
|
|
{
|
|
|
|
m_range_spinner->SetValue(event.GetPosition());
|
|
|
|
control_reference->range = static_cast<ControlState>(event.GetPosition()) / SLIDER_TICK_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControlDialog::OnRangeSpin(wxSpinEvent& event)
|
|
|
|
{
|
|
|
|
m_range_slider->SetValue(event.GetValue());
|
|
|
|
control_reference->range = static_cast<ControlState>(event.GetValue()) / SLIDER_TICK_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControlDialog::OnRangeThumbtrack(wxScrollEvent& event)
|
|
|
|
{
|
|
|
|
m_range_spinner->SetValue(event.GetPosition());
|
|
|
|
}
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
void InputConfigDialog::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-11-18 07:03:06 +00:00
|
|
|
void InputConfigDialog::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
|
|
|
}
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
void InputConfigDialog::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
|
|
|
}
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
void InputConfigDialog::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();
|
2017-06-08 02:02:16 +00:00
|
|
|
btn->control_reference->SetExpression("");
|
2016-06-24 08:43:46 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
void InputConfigDialog::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
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
bool InputConfigDialog::DetectButton(ControlButton* button)
|
2014-06-14 23:15:41 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
bool success = false;
|
|
|
|
// find device :/
|
2017-11-04 21:08:26 +00:00
|
|
|
const auto dev = g_controller_interface.FindDevice(controller->GetDefaultDevice());
|
2016-06-25 19:46:39 +00:00
|
|
|
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);
|
2017-06-08 02:02:16 +00:00
|
|
|
button->control_reference->SetExpression(WxStrToStr(expr));
|
2017-02-09 03:15:43 +00:00
|
|
|
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
|
2016-10-12 00:48:38 +00:00
|
|
|
button->control_reference->UpdateReference(g_controller_interface,
|
2017-11-04 21:08:26 +00:00
|
|
|
controller->GetDefaultDevice());
|
2016-06-24 08:43:46 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
wxStaticBoxSizer* ControlDialog::CreateControlChooser(InputConfigDialog* const parent)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
wxStaticBoxSizer* const main_szr = new wxStaticBoxSizer(
|
2016-12-09 21:13:11 +00:00
|
|
|
wxVERTICAL, this, control_reference->IsInput() ? _("Input") : _("Output"));
|
2016-08-02 06:22:48 +00:00
|
|
|
const int space5 = FromDIP(5);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
textctrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
|
|
|
|
wxDLG_UNIT(this, wxSize(-1, 32)), wxTE_MULTILINE | wxTE_RICH2);
|
2016-06-24 08:43:46 +00:00
|
|
|
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 =
|
2016-12-09 21:13:11 +00:00
|
|
|
new wxButton(this, wxID_ANY, control_reference->IsInput() ? _("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-08-02 06:22:48 +00:00
|
|
|
control_lbox = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, 48)));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxBoxSizer* const button_sizer = new wxBoxSizer(wxVERTICAL);
|
2016-08-02 06:22:48 +00:00
|
|
|
button_sizer->Add(detect_button, 1);
|
|
|
|
button_sizer->Add(select_button, 1);
|
|
|
|
button_sizer->Add(or_button, 1);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2016-12-09 21:13:11 +00:00
|
|
|
if (control_reference->IsInput())
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
// 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-08-02 06:22:48 +00:00
|
|
|
button_sizer->Add(and_button, 1);
|
|
|
|
button_sizer->Add(not_button, 1);
|
|
|
|
button_sizer->Add(add_button, 1);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2010-06-21 03:12:16 +00:00
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
m_range_slider = new DolphinSlider(
|
|
|
|
this, wxID_ANY, static_cast<int>(control_reference->range * SLIDER_TICK_COUNT),
|
|
|
|
-SLIDER_TICK_COUNT * 5, SLIDER_TICK_COUNT * 5, wxDefaultPosition, wxDefaultSize, wxSL_TOP);
|
|
|
|
m_range_spinner = new wxSpinCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
|
|
|
|
wxDLG_UNIT(this, wxSize(32, -1)),
|
|
|
|
wxSP_ARROW_KEYS | wxALIGN_RIGHT, m_range_slider->GetMin(),
|
|
|
|
m_range_slider->GetMax(), m_range_slider->GetValue());
|
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-08-02 06:22:48 +00:00
|
|
|
m_range_slider->Bind(wxEVT_SCROLL_CHANGED, &ControlDialog::OnRangeSlide, this);
|
|
|
|
m_range_slider->Bind(wxEVT_SCROLL_THUMBTRACK, &ControlDialog::OnRangeThumbtrack, this);
|
|
|
|
m_range_spinner->Bind(wxEVT_SPINCTRL, &ControlDialog::OnRangeSpin, this);
|
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);
|
2016-08-02 06:22:48 +00:00
|
|
|
range_sizer->Add(new wxStaticText(this, wxID_ANY, _("Range")), 0, wxALIGN_CENTER_VERTICAL);
|
|
|
|
range_sizer->Add(
|
|
|
|
new wxStaticText(this, wxID_ANY, wxString::Format("%d", m_range_slider->GetMin())), 0,
|
|
|
|
wxALIGN_CENTER_VERTICAL | wxLEFT, space5);
|
|
|
|
range_sizer->Add(m_range_slider, 1, wxEXPAND);
|
|
|
|
range_sizer->Add(
|
|
|
|
new wxStaticText(this, wxID_ANY, wxString::Format("%d", m_range_slider->GetMax())), 0,
|
|
|
|
wxALIGN_CENTER_VERTICAL);
|
|
|
|
range_sizer->Add(m_range_spinner, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, space5);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxBoxSizer* const ctrls_sizer = new wxBoxSizer(wxHORIZONTAL);
|
2016-08-02 06:22:48 +00:00
|
|
|
ctrls_sizer->Add(control_lbox, 1, wxEXPAND);
|
|
|
|
ctrls_sizer->Add(button_sizer, 0, wxEXPAND);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
wxSizer* const bottom_btns_sizer = CreateButtonSizer(wxOK | wxAPPLY);
|
2016-08-02 06:22:48 +00:00
|
|
|
bottom_btns_sizer->Prepend(clear_button, 0, wxLEFT, space5);
|
|
|
|
|
|
|
|
main_szr->Add(range_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, space5);
|
|
|
|
main_szr->AddSpacer(space5);
|
|
|
|
main_szr->Add(ctrls_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, space5);
|
|
|
|
main_szr->AddSpacer(space5);
|
|
|
|
main_szr->Add(textctrl, 1, wxEXPAND | wxLEFT | wxRIGHT, space5);
|
|
|
|
main_szr->AddSpacer(space5);
|
|
|
|
main_szr->Add(bottom_btns_sizer, 0, wxEXPAND | wxRIGHT, space5);
|
|
|
|
main_szr->AddSpacer(space5);
|
|
|
|
main_szr->Add(m_bound_label, 0, wxALIGN_CENTER_HORIZONTAL);
|
|
|
|
main_szr->Add(m_error_label, 0, wxALIGN_CENTER_HORIZONTAL);
|
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
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
void InputConfigDialog::GetProfilePath(std::string& path)
|
2010-06-21 03:12:16 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2017-02-09 03:15:43 +00:00
|
|
|
ControllerEmu::EmulatedController* InputConfigDialog::GetController() const
|
2016-11-18 07:03:06 +00:00
|
|
|
{
|
|
|
|
return controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputConfigDialog::LoadProfile(wxCommandEvent&)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string fname;
|
2016-11-18 07:03:06 +00:00
|
|
|
InputConfigDialog::GetProfilePath(fname);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
IniFile inifile;
|
2017-06-29 09:20:38 +00:00
|
|
|
if (!inifile.Load(fname))
|
|
|
|
return;
|
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
|
|
|
}
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
void InputConfigDialog::SaveProfile(wxCommandEvent&)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string fname;
|
2016-11-18 07:03:06 +00:00
|
|
|
InputConfigDialog::GetProfilePath(fname);
|
2016-06-24 08:43:46 +00:00
|
|
|
File::CreateFullPath(fname);
|
|
|
|
|
|
|
|
if (!fname.empty())
|
|
|
|
{
|
|
|
|
IniFile inifile;
|
|
|
|
controller->SaveConfig(inifile.GetOrCreateSection("Profile"));
|
|
|
|
inifile.Save(fname);
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
UpdateProfileComboBox();
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WxUtils::ShowErrorDialog(_("You must enter a valid profile name."));
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
void InputConfigDialog::DeleteProfile(wxCommandEvent&)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string fname;
|
2016-11-18 07:03:06 +00:00
|
|
|
InputConfigDialog::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-11-18 07:03:06 +00:00
|
|
|
UpdateProfileComboBox();
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
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-11-18 07:03:06 +00:00
|
|
|
device_cbox->Clear();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
for (const std::string& device_string : g_controller_interface.GetAllDeviceStrings())
|
|
|
|
device_cbox->Append(StrToWxStr(device_string));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-11-04 21:08:26 +00:00
|
|
|
device_cbox->SetValue(StrToWxStr(controller->GetDefaultDevice().ToString()));
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
void InputConfigDialog::RefreshDevices(wxCommandEvent&)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2017-07-21 06:06:02 +00:00
|
|
|
Core::RunAsCPUThread([&] {
|
|
|
|
// refresh devices
|
|
|
|
g_controller_interface.RefreshDevices();
|
2015-03-05 08:49:10 +00:00
|
|
|
|
2017-07-21 06:06:02 +00:00
|
|
|
// update all control references
|
|
|
|
UpdateControlReferences();
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2017-07-21 06:06:02 +00:00
|
|
|
// update device cbox
|
|
|
|
UpdateDeviceComboBox();
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2017-07-21 06:06:02 +00:00
|
|
|
Wiimote::LoadConfig();
|
|
|
|
Keyboard::LoadConfig();
|
|
|
|
Pad::LoadConfig();
|
|
|
|
HotkeyManagerEmu::LoadConfig();
|
2015-03-05 08:49:10 +00:00
|
|
|
|
2017-07-21 06:06:02 +00:00
|
|
|
UpdateGUI();
|
|
|
|
});
|
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-12-31 23:46:56 +00:00
|
|
|
bool ControlGroupBox::HasBitmapHeading() const
|
|
|
|
{
|
2017-02-25 05:35:02 +00:00
|
|
|
return control_group->type == ControllerEmu::GroupType::Stick ||
|
|
|
|
control_group->type == ControllerEmu::GroupType::Tilt ||
|
|
|
|
control_group->type == ControllerEmu::GroupType::Cursor ||
|
|
|
|
control_group->type == ControllerEmu::GroupType::Force;
|
2016-12-31 23:46:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWindow* const parent,
|
2016-11-18 07:03:06 +00:00
|
|
|
InputConfigDialog* eventsink)
|
|
|
|
: wxStaticBoxSizer(wxVERTICAL, parent, wxGetTranslation(StrToWxStr(group->ui_name))),
|
|
|
|
control_group(group), static_bitmap(nullptr), m_scale(1)
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2016-08-02 06:22:48 +00:00
|
|
|
static constexpr std::array<const char* const, 2> exclude_buttons{{"Mic", "Modifier"}};
|
|
|
|
static constexpr std::array<const char* const, 7> exclude_groups{
|
|
|
|
{"IR", "Swing", "Tilt", "Shake", "UDP Wiimote", "Extension", "Rumble"}};
|
|
|
|
|
|
|
|
wxFont small_font(7, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
|
|
|
const int space3 = parent->FromDIP(3);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
wxFlexGridSizer* control_grid = new wxFlexGridSizer(2, 0, space3);
|
|
|
|
control_grid->AddGrowableCol(0);
|
|
|
|
for (const auto& control : group->controls)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2018-03-30 19:42:26 +00:00
|
|
|
const wxString control_ui_name = StrToWxStr(control->ui_name);
|
|
|
|
|
2018-04-10 15:22:30 +00:00
|
|
|
const bool translate = control->translate == ControllerEmu::Translate;
|
2018-03-30 19:42:26 +00:00
|
|
|
wxStaticText* const label = new wxStaticText(
|
2018-04-10 15:22:30 +00:00
|
|
|
parent, wxID_ANY, translate ? wxGetTranslation(control_ui_name) : control_ui_name);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-07-17 12:32:06 +00:00
|
|
|
ControlButton* const control_button =
|
2017-04-30 12:53:33 +00:00
|
|
|
new ControlButton(parent, control->control_ref.get(), control->ui_name, 80);
|
2016-08-02 06:22:48 +00:00
|
|
|
control_button->SetFont(small_font);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
control_buttons.push_back(control_button);
|
|
|
|
if (std::find(exclude_groups.begin(), exclude_groups.end(), control_group->name) ==
|
|
|
|
exclude_groups.end() &&
|
2017-04-30 12:53:33 +00:00
|
|
|
std::find(exclude_buttons.begin(), exclude_buttons.end(), control->ui_name) ==
|
2016-06-24 08:43:46 +00:00
|
|
|
exclude_buttons.end())
|
|
|
|
eventsink->control_buttons.push_back(control_button);
|
|
|
|
|
2016-12-09 21:13:11 +00:00
|
|
|
if (control->control_ref->IsInput())
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
control_button->SetToolTip(
|
|
|
|
_("Left-click to detect input.\nMiddle-click to clear.\nRight-click for more options."));
|
2016-11-18 07:03:06 +00:00
|
|
|
control_button->Bind(wxEVT_BUTTON, &InputConfigDialog::DetectControl, eventsink);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
control_button->SetToolTip(_("Left/Right-click for more options.\nMiddle-click to clear."));
|
2016-11-18 07:03:06 +00:00
|
|
|
control_button->Bind(wxEVT_BUTTON, &InputConfigDialog::ConfigControl, eventsink);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
control_button->Bind(wxEVT_MIDDLE_DOWN, &InputConfigDialog::ClearControl, eventsink);
|
|
|
|
control_button->Bind(wxEVT_RIGHT_UP, &InputConfigDialog::ConfigControl, eventsink);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
control_grid->Add(label, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT);
|
|
|
|
control_grid->Add(control_button, 0, wxALIGN_CENTER_VERTICAL);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2016-08-02 06:22:48 +00:00
|
|
|
Add(control_grid, 0, wxEXPAND | wxLEFT | wxRIGHT, space3);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
switch (group->type)
|
|
|
|
{
|
2017-02-25 05:35:02 +00:00
|
|
|
case ControllerEmu::GroupType::Stick:
|
|
|
|
case ControllerEmu::GroupType::Tilt:
|
|
|
|
case ControllerEmu::GroupType::Cursor:
|
|
|
|
case ControllerEmu::GroupType::Force:
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-08-02 06:22:48 +00:00
|
|
|
wxSize bitmap_size = parent->FromDIP(wxSize(64, 64));
|
|
|
|
m_scale = bitmap_size.GetWidth() / 64.0;
|
|
|
|
|
|
|
|
wxBitmap bitmap;
|
|
|
|
bitmap.CreateScaled(bitmap_size.GetWidth(), bitmap_size.GetHeight(), wxBITMAP_SCREEN_DEPTH,
|
|
|
|
parent->GetContentScaleFactor());
|
|
|
|
wxMemoryDC dc(bitmap);
|
2016-06-24 08:43:46 +00:00
|
|
|
dc.Clear();
|
2016-08-02 06:22:48 +00:00
|
|
|
dc.SelectObject(wxNullBitmap);
|
2016-06-24 08:43:46 +00:00
|
|
|
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());
|
2016-11-18 07:03:06 +00:00
|
|
|
setting->wxcontrol->Bind(wxEVT_SPINCTRL, &InputConfigDialog::AdjustSetting, eventsink);
|
2016-06-24 08:43:46 +00:00
|
|
|
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-08-02 06:22:48 +00:00
|
|
|
szr->Add(setting->wxcontrol);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2016-07-09 12:29:41 +00:00
|
|
|
for (auto& groupSetting : group->boolean_settings)
|
|
|
|
{
|
|
|
|
auto* checkbox = new PadSettingCheckBox(parent, groupSetting.get());
|
2016-11-18 07:03:06 +00:00
|
|
|
checkbox->wxcontrol->Bind(wxEVT_CHECKBOX, &InputConfigDialog::AdjustBooleanSetting,
|
|
|
|
eventsink);
|
2016-07-09 12:29:41 +00:00
|
|
|
options.push_back(checkbox);
|
2016-08-02 06:22:48 +00:00
|
|
|
Add(checkbox->wxcontrol, 0, wxALL | wxLEFT, space3);
|
2016-07-09 12:29:41 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
wxBoxSizer* const h_szr = new wxBoxSizer(wxHORIZONTAL);
|
2016-08-02 06:22:48 +00:00
|
|
|
h_szr->Add(szr, 1, wxEXPAND | wxTOP | wxBOTTOM, space3);
|
|
|
|
h_szr->AddSpacer(space3);
|
|
|
|
h_szr->Add(static_bitmap, 0, wxALIGN_CENTER_VERTICAL | wxTOP | wxBOTTOM, space3);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
AddSpacer(space3);
|
|
|
|
Add(h_szr, 0, wxEXPAND | wxLEFT | wxRIGHT, space3);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-02-25 05:35:02 +00:00
|
|
|
case ControllerEmu::GroupType::Buttons:
|
2016-06-24 08:43:46 +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);
|
2016-08-02 06:22:48 +00:00
|
|
|
wxSize bitmap_size(12 * button_cols + 1, 11 * button_rows + 1);
|
|
|
|
wxSize bitmap_scaled_size = parent->FromDIP(bitmap_size);
|
|
|
|
m_scale = static_cast<double>(bitmap_scaled_size.GetWidth()) / bitmap_size.GetWidth();
|
|
|
|
|
|
|
|
wxBitmap bitmap;
|
|
|
|
bitmap.CreateScaled(bitmap_scaled_size.GetWidth(), bitmap_scaled_size.GetHeight(),
|
|
|
|
wxBITMAP_SCREEN_DEPTH, parent->GetContentScaleFactor());
|
|
|
|
wxMemoryDC dc(bitmap);
|
2016-06-24 08:43:46 +00:00
|
|
|
dc.Clear();
|
2016-08-02 06:22:48 +00:00
|
|
|
dc.SelectObject(wxNullBitmap);
|
2016-06-24 08:43:46 +00:00
|
|
|
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-11-18 07:03:06 +00:00
|
|
|
threshold_cbox->wxcontrol->Bind(wxEVT_SPINCTRL, &InputConfigDialog::AdjustSetting, eventsink);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
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))),
|
2016-08-02 06:22:48 +00:00
|
|
|
0, wxALIGN_CENTER_VERTICAL | wxRIGHT, space3);
|
|
|
|
szr->Add(threshold_cbox->wxcontrol, 0, wxRIGHT, space3);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
AddSpacer(space3);
|
|
|
|
Add(szr, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT, space3);
|
|
|
|
AddSpacer(space3);
|
|
|
|
Add(static_bitmap, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT, space3);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-02-25 05:35:02 +00:00
|
|
|
case ControllerEmu::GroupType::MixedTriggers:
|
|
|
|
case ControllerEmu::GroupType::Triggers:
|
|
|
|
case ControllerEmu::GroupType::Slider:
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
int height = (int)(12 * group->controls.size());
|
|
|
|
int width = 64;
|
|
|
|
|
2017-02-25 05:35:02 +00:00
|
|
|
if (group->type == ControllerEmu::GroupType::MixedTriggers)
|
2016-06-24 08:43:46 +00:00
|
|
|
width = 64 + 12 + 1;
|
|
|
|
|
2017-02-25 05:35:02 +00:00
|
|
|
if (group->type != ControllerEmu::GroupType::Triggers)
|
2016-06-24 08:43:46 +00:00
|
|
|
height /= 2;
|
2016-08-02 06:22:48 +00:00
|
|
|
height += 1;
|
|
|
|
|
|
|
|
wxSize bitmap_size = parent->FromDIP(wxSize(width, height));
|
|
|
|
m_scale = static_cast<double>(bitmap_size.GetWidth()) / width;
|
|
|
|
wxBitmap bitmap;
|
|
|
|
bitmap.CreateScaled(bitmap_size.GetWidth(), bitmap_size.GetHeight(), wxBITMAP_SCREEN_DEPTH,
|
|
|
|
parent->GetContentScaleFactor());
|
|
|
|
wxMemoryDC dc(bitmap);
|
2016-06-24 08:43:46 +00:00
|
|
|
dc.Clear();
|
2016-08-02 06:22:48 +00:00
|
|
|
dc.SelectObject(wxNullBitmap);
|
2016-06-24 08:43:46 +00:00
|
|
|
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());
|
2016-11-18 07:03:06 +00:00
|
|
|
setting->wxcontrol->Bind(wxEVT_SPINCTRL, &InputConfigDialog::AdjustSetting, eventsink);
|
2016-06-24 08:43:46 +00:00
|
|
|
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,
|
2016-08-02 06:22:48 +00:00
|
|
|
wxALIGN_CENTER_VERTICAL);
|
|
|
|
szr->Add(setting->wxcontrol, 0, wxLEFT, space3);
|
|
|
|
|
|
|
|
AddSpacer(space3);
|
|
|
|
Add(szr, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT, space3);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
AddSpacer(space3);
|
|
|
|
Add(static_bitmap, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT, space3);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-02-25 05:35:02 +00:00
|
|
|
case ControllerEmu::GroupType::Extension:
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
PadSettingExtension* const attachments =
|
|
|
|
new PadSettingExtension(parent, (ControllerEmu::Extension*)group);
|
|
|
|
wxButton* const configure_btn = new ExtensionButton(parent, (ControllerEmu::Extension*)group);
|
|
|
|
|
|
|
|
options.push_back(attachments);
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
attachments->wxcontrol->Bind(wxEVT_CHOICE, &InputConfigDialog::AdjustSetting, eventsink);
|
|
|
|
configure_btn->Bind(wxEVT_BUTTON, &InputConfigDialog::ConfigExtension, eventsink);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
AddSpacer(space3);
|
|
|
|
Add(attachments->wxcontrol, 0, wxEXPAND | wxLEFT | wxRIGHT, space3);
|
|
|
|
AddSpacer(space3);
|
|
|
|
Add(configure_btn, 0, wxEXPAND | wxLEFT | wxRIGHT, space3);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
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-11-18 07:03:06 +00:00
|
|
|
setting_cbox->wxcontrol->Bind(wxEVT_CHECKBOX, &InputConfigDialog::AdjustBooleanSetting,
|
|
|
|
eventsink);
|
2016-07-11 17:35:32 +00:00
|
|
|
if (groupSetting->m_name == "Iterative Input")
|
|
|
|
groupSetting->SetValue(false);
|
|
|
|
options.push_back(setting_cbox);
|
2016-08-02 06:22:48 +00:00
|
|
|
AddSpacer(space3);
|
|
|
|
Add(setting_cbox->wxcontrol, 0, wxLEFT | wxRIGHT, space3);
|
2016-07-11 17:35:32 +00:00
|
|
|
}
|
|
|
|
for (auto& groupSetting : group->numeric_settings)
|
|
|
|
{
|
|
|
|
PadSettingSpin* setting = new PadSettingSpin(parent, groupSetting.get());
|
2016-11-18 07:03:06 +00:00
|
|
|
setting->wxcontrol->Bind(wxEVT_SPINCTRL, &InputConfigDialog::AdjustSetting, eventsink);
|
2016-07-11 17:35:32 +00:00
|
|
|
options.push_back(setting);
|
|
|
|
wxBoxSizer* const szr = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
szr->Add(
|
|
|
|
new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(groupSetting->m_name))), 0,
|
2016-08-02 06:22:48 +00:00
|
|
|
wxALIGN_CENTER_VERTICAL, space3);
|
|
|
|
szr->Add(setting->wxcontrol, 0, wxLEFT, space3);
|
|
|
|
AddSpacer(space3);
|
2016-11-18 07:03:06 +00:00
|
|
|
Add(szr, 0, wxLEFT | wxRIGHT | wxALIGN_RIGHT, space3);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2016-08-02 06:22:48 +00:00
|
|
|
break;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-02 06:22:48 +00:00
|
|
|
AddSpacer(space3);
|
2016-11-18 07:03:06 +00:00
|
|
|
eventsink->control_groups.push_back(this);
|
2010-04-02 02:48:24 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
wxBoxSizer* InputConfigDialog::CreateDeviceChooserGroupBox()
|
2010-04-13 05:15:38 +00:00
|
|
|
{
|
2016-08-02 06:22:48 +00:00
|
|
|
const int space3 = FromDIP(3);
|
|
|
|
wxStaticBoxSizer* const device_sbox = new wxStaticBoxSizer(wxVERTICAL, this, _("Device"));
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
device_cbox = new wxComboBox(device_sbox->GetStaticBox(), wxID_ANY, "");
|
2016-06-24 08:43:46 +00:00
|
|
|
device_cbox->ToggleWindowStyle(wxTE_PROCESS_ENTER);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
wxButton* refresh_button = new wxButton(device_sbox->GetStaticBox(), wxID_ANY, _("Refresh"),
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
device_cbox->Bind(wxEVT_COMBOBOX, &InputConfigDialog::SetDevice, this);
|
|
|
|
device_cbox->Bind(wxEVT_TEXT_ENTER, &InputConfigDialog::SetDevice, this);
|
|
|
|
refresh_button->Bind(wxEVT_BUTTON, &InputConfigDialog::RefreshDevices, this);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
wxBoxSizer* const device_sbox_in = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
device_sbox_in->Add(WxUtils::GiveMinSizeDIP(device_cbox, wxSize(64, -1)), 1,
|
|
|
|
wxALIGN_CENTER_VERTICAL);
|
|
|
|
device_sbox_in->Add(refresh_button, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, space3);
|
|
|
|
device_sbox->Add(device_sbox_in, 1, wxEXPAND | wxLEFT | wxRIGHT, space3);
|
|
|
|
device_sbox->AddSpacer(space3);
|
2016-11-18 07:03:06 +00:00
|
|
|
return device_sbox;
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
wxBoxSizer* InputConfigDialog::CreaterResetGroupBox(wxOrientation orientation)
|
|
|
|
{
|
|
|
|
const int space3 = FromDIP(3);
|
|
|
|
wxStaticBoxSizer* const clear_sbox = new wxStaticBoxSizer(orientation, this, _("Reset"));
|
2010-07-10 06:48:24 +00:00
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
wxButton* const default_button = new wxButton(clear_sbox->GetStaticBox(), wxID_ANY, _("Default"),
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
|
|
|
wxButton* const clearall_button = new wxButton(clear_sbox->GetStaticBox(), wxID_ANY, _("Clear"),
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
wxBoxSizer* clear_sbox_in = new wxBoxSizer(orientation);
|
|
|
|
clear_sbox_in->Add(default_button, 1, wxEXPAND);
|
|
|
|
clear_sbox_in->Add(clearall_button, 1, wxEXPAND);
|
|
|
|
clear_sbox->Add(clear_sbox_in, 1, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, space3);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
clearall_button->Bind(wxEVT_BUTTON, &InputConfigDialog::ClearAll, this);
|
|
|
|
default_button->Bind(wxEVT_BUTTON, &InputConfigDialog::LoadDefaults, this);
|
|
|
|
return clear_sbox;
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
wxBoxSizer* InputConfigDialog::CreateProfileChooserGroupBox()
|
|
|
|
{
|
|
|
|
const int space3 = FromDIP(3);
|
2016-08-02 06:22:48 +00:00
|
|
|
wxStaticBoxSizer* profile_sbox = new wxStaticBoxSizer(wxVERTICAL, this, _("Profile"));
|
|
|
|
profile_cbox = new wxComboBox(profile_sbox->GetStaticBox(), wxID_ANY, "");
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
wxButton* const pload_btn = new wxButton(profile_sbox->GetStaticBox(), wxID_ANY, _("Load"),
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
|
|
|
wxButton* const psave_btn = new wxButton(profile_sbox->GetStaticBox(), wxID_ANY, _("Save"),
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
|
|
|
wxButton* const pdelete_btn = new wxButton(profile_sbox->GetStaticBox(), wxID_ANY, _("Delete"),
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-11-18 07:03:06 +00:00
|
|
|
pload_btn->Bind(wxEVT_BUTTON, &InputConfigDialog::LoadProfile, this);
|
|
|
|
psave_btn->Bind(wxEVT_BUTTON, &InputConfigDialog::SaveProfile, this);
|
|
|
|
pdelete_btn->Bind(wxEVT_BUTTON, &InputConfigDialog::DeleteProfile, this);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-08-02 06:22:48 +00:00
|
|
|
wxBoxSizer* profile_sbox_in = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
profile_sbox_in->Add(WxUtils::GiveMinSizeDIP(profile_cbox, wxSize(64, -1)), 1,
|
|
|
|
wxALIGN_CENTER_VERTICAL);
|
|
|
|
profile_sbox_in->AddSpacer(space3);
|
|
|
|
profile_sbox_in->Add(pload_btn, 0, wxALIGN_CENTER_VERTICAL);
|
|
|
|
profile_sbox_in->Add(psave_btn, 0, wxALIGN_CENTER_VERTICAL);
|
|
|
|
profile_sbox_in->Add(pdelete_btn, 0, wxALIGN_CENTER_VERTICAL);
|
|
|
|
profile_sbox->Add(profile_sbox_in, 1, wxEXPAND | wxLEFT | wxRIGHT, space3);
|
|
|
|
profile_sbox->AddSpacer(space3);
|
2016-11-18 07:03:06 +00:00
|
|
|
return profile_sbox;
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
InputConfigDialog::InputConfigDialog(wxWindow* const parent, InputConfig& config,
|
2016-11-18 07:03:06 +00:00
|
|
|
const wxString& name, const int port_num)
|
|
|
|
: wxDialog(parent, wxID_ANY, name), controller(config.GetController(port_num)),
|
|
|
|
m_config(config), m_port_num(port_num)
|
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);
|
2017-07-12 07:11:29 +00:00
|
|
|
Bind(wxEVT_ACTIVATE, &InputConfigDialog::OnActivate, this);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
SetLayoutAdaptationMode(wxDIALOG_ADAPTATION_MODE_ENABLED);
|
2016-08-02 06:22:48 +00:00
|
|
|
SetLayoutAdaptationLevel(wxDIALOG_ADAPTATION_STANDARD_SIZER);
|
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
|
|
|
|
2017-07-12 07:11:29 +00:00
|
|
|
void InputConfigDialog::OnActivate(wxActivateEvent& event)
|
|
|
|
{
|
|
|
|
// Needed for input bitmaps
|
|
|
|
SetUINeedsControllerState(event.GetActive());
|
|
|
|
}
|
|
|
|
|
2016-12-31 23:46:56 +00:00
|
|
|
InputEventFilter::InputEventFilter()
|
|
|
|
{
|
|
|
|
wxEvtHandler::AddFilter(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
InputEventFilter::~InputEventFilter()
|
|
|
|
{
|
|
|
|
wxEvtHandler::RemoveFilter(this);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2016-12-31 23:46:56 +00:00
|
|
|
|
|
|
|
void InputEventFilter::BlockEvents(bool block)
|
|
|
|
{
|
|
|
|
m_block = block;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::ShouldCatchEventType(wxEventType type)
|
|
|
|
{
|
|
|
|
return type == wxEVT_KEY_DOWN || type == wxEVT_KEY_UP || type == wxEVT_CHAR ||
|
|
|
|
type == wxEVT_CHAR_HOOK || type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_UP ||
|
|
|
|
type == wxEVT_MIDDLE_DOWN || type == wxEVT_MIDDLE_UP || type == wxEVT_RIGHT_DOWN ||
|
|
|
|
type == wxEVT_RIGHT_UP;
|
|
|
|
}
|