1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
|
// Copyright 2010 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#define SLIDER_TICK_COUNT 100
#define DETECT_WAIT_TIME 2500
#define PREVIEW_UPDATE_TIME 25
#define DEFAULT_HIGH_VALUE 100
// might have to change this setup for Wiimote
#define PROFILES_PATH "Profiles/"
#include <cstddef>
#include <string>
#include <vector>
#include <wx/button.h>
#include <wx/dialog.h>
#include <wx/eventfilter.h>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/spinctrl.h>
#include <wx/timer.h>
#include "InputCommon/ControllerEmu.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/ControllerInterface/Device.h"
class InputConfig;
class wxComboBox;
class wxListBox;
class wxNotebook;
class wxSlider;
class wxStaticBitmap;
class wxStaticText;
class wxTextCtrl;
class PadSetting
{
protected:
PadSetting(wxControl* const _control) : wxcontrol(_control) { wxcontrol->SetClientData(this); }
public:
virtual void UpdateGUI() = 0;
virtual void UpdateValue() = 0;
virtual ~PadSetting() {}
wxControl* const wxcontrol;
};
class PadSettingExtension : public PadSetting
{
public:
PadSettingExtension(wxWindow* const parent, ControllerEmu::Extension* const ext);
void UpdateGUI() override;
void UpdateValue() override;
ControllerEmu::Extension* const extension;
};
class PadSettingSpin : public PadSetting
{
public:
PadSettingSpin(wxWindow* const parent, ControllerEmu::ControlGroup::Setting* const _setting)
: PadSetting(new wxSpinCtrl(parent, wxID_ANY, wxEmptyString, wxDefaultPosition,
wxSize(54, -1), 0, _setting->low, _setting->high, (int)(_setting->value * 100)))
, setting(_setting) {}
void UpdateGUI() override;
void UpdateValue() override;
ControllerEmu::ControlGroup::Setting* const setting;
};
class PadSettingCheckBox : public PadSetting
{
public:
PadSettingCheckBox(wxWindow* const parent, ControllerEmu::ControlGroup::Setting* const setting);
void UpdateGUI() override;
void UpdateValue() override;
ControllerEmu::ControlGroup::Setting* const setting;
};
class InputEventFilter : public wxEventFilter
{
public:
InputEventFilter()
{
wxEvtHandler::AddFilter(this);
}
~InputEventFilter()
{
wxEvtHandler::RemoveFilter(this);
}
int FilterEvent(wxEvent& event) override;
void BlockEvents(bool block) { m_block = block; }
private:
static bool 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;
}
bool m_block = false;
};
class GamepadPage;
class ControlDialog : public wxDialog
{
public:
ControlDialog(GamepadPage* const parent, InputConfig& config, ControllerInterface::ControlReference* const ref);
bool Validate() override;
int GetRangeSliderValue() const;
ControllerInterface::ControlReference* const control_reference;
InputConfig& m_config;
private:
wxStaticBoxSizer* CreateControlChooser(GamepadPage* const parent);
void UpdateGUI();
void UpdateListContents();
void SelectControl(const std::string& name);
void DetectControl(wxCommandEvent& event);
void ClearControl(wxCommandEvent& event);
void SetDevice(wxCommandEvent& event);
void SetSelectedControl(wxCommandEvent& event);
void AppendControl(wxCommandEvent& event);
bool GetExpressionForSelectedControl(wxString &expr);
GamepadPage* const m_parent;
wxComboBox* device_cbox;
wxTextCtrl* textctrl;
wxListBox* control_lbox;
wxSlider* range_slider;
wxStaticText* m_bound_label;
wxStaticText* m_error_label;
InputEventFilter m_event_filter;
ciface::Core::DeviceQualifier m_devq;
};
class ExtensionButton : public wxButton
{
public:
ExtensionButton(wxWindow* const parent, ControllerEmu::Extension* const ext)
: wxButton(parent, wxID_ANY, _("Configure"), wxDefaultPosition)
, extension(ext) {}
ControllerEmu::Extension* const extension;
};
class ControlButton : public wxButton
{
public:
ControlButton(wxWindow* const parent, ControllerInterface::ControlReference* const _ref, const unsigned int width, const std::string& label = "");
ControllerInterface::ControlReference* const control_reference;
};
class ControlGroupBox : public wxBoxSizer
{
public:
ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWindow* const parent, GamepadPage* const eventsink);
~ControlGroupBox();
std::vector<PadSetting*> options;
ControllerEmu::ControlGroup* const control_group;
wxStaticBitmap* static_bitmap;
std::vector<ControlButton*> control_buttons;
};
class ControlGroupsSizer : public wxBoxSizer
{
public:
ControlGroupsSizer(ControllerEmu* const controller, wxWindow* const parent, GamepadPage* const eventsink, std::vector<ControlGroupBox*>* const groups = nullptr);
};
class InputConfigDialog;
class GamepadPage : public wxPanel
{
friend class InputConfigDialog;
friend class ControlDialog;
public:
GamepadPage(wxWindow* parent, InputConfig& config, const int pad_num, InputConfigDialog* const config_dialog);
void UpdateGUI();
void RefreshDevices(wxCommandEvent& event);
void LoadProfile(wxCommandEvent& event);
void SaveProfile(wxCommandEvent& event);
void DeleteProfile(wxCommandEvent& event);
void ConfigControl(wxEvent& event);
void ClearControl(wxEvent& event);
void DetectControl(wxCommandEvent& event);
void ConfigExtension(wxCommandEvent& event);
void SetDevice(wxCommandEvent& event);
void ClearAll(wxCommandEvent& event);
void LoadDefaults(wxCommandEvent& event);
void AdjustControlOption(wxCommandEvent& event);
void AdjustSetting(wxCommandEvent& event);
void AdjustSettingUI(wxCommandEvent& event);
void GetProfilePath(std::string& path);
wxComboBox* profile_cbox;
wxComboBox* device_cbox;
std::vector<ControlGroupBox*> control_groups;
std::vector<ControlButton*> control_buttons;
protected:
ControllerEmu* const controller;
private:
ControlDialog* m_control_dialog;
InputConfigDialog* const m_config_dialog;
InputConfig& m_config;
InputEventFilter m_event_filter;
bool DetectButton(ControlButton* button);
bool m_iterate = false;
};
class InputConfigDialog : public wxDialog
{
public:
InputConfigDialog(wxWindow* const parent, InputConfig& config, const wxString& name, const int tab_num = 0);
void ClickSave(wxCommandEvent& event);
void UpdateDeviceComboBox();
void UpdateProfileComboBox();
void UpdateControlReferences();
void UpdateBitmaps(wxTimerEvent&);
private:
wxNotebook* m_pad_notebook;
std::vector<GamepadPage*> m_padpages;
InputConfig& m_config;
wxTimer m_update_timer;
};
|