-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
ControlGroup.h
83 lines (67 loc) · 2.07 KB
/
ControlGroup.h
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
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <algorithm>
#include <cmath>
#include <memory>
#include <string>
#include <type_traits>
#include <vector>
#include "Common/CommonTypes.h"
#include "Common/IniFile.h"
namespace ControllerEmu
{
class Control;
class NumericSettingBase;
struct NumericSettingDetails;
template <typename T>
class NumericSetting;
template <typename T>
class SettingValue;
enum class GroupType
{
Other,
Stick,
MixedTriggers,
Buttons,
Force,
Attachments,
Tilt,
Cursor,
Triggers,
Slider,
Shake,
};
class ControlGroup
{
public:
explicit ControlGroup(std::string name, GroupType type = GroupType::Other);
ControlGroup(std::string name, std::string ui_name, GroupType type = GroupType::Other);
virtual ~ControlGroup();
virtual void LoadConfig(IniFile::Section* sec, const std::string& defdev = "",
const std::string& base = "");
virtual void SaveConfig(IniFile::Section* sec, const std::string& defdev = "",
const std::string& base = "");
void SetControlExpression(int index, const std::string& expression);
template <typename T>
void AddSetting(SettingValue<T>* value, const NumericSettingDetails& details,
std::common_type_t<T> default_value, std::common_type_t<T> min_value = {},
std::common_type_t<T> max_value = T(100))
{
numeric_settings.emplace_back(
std::make_unique<NumericSetting<T>>(value, details, default_value, min_value, max_value));
}
void AddDeadzoneSetting(SettingValue<double>* value, double maximum_deadzone);
template <typename T>
static T ApplyDeadzone(T input, std::common_type_t<T> deadzone)
{
return std::copysign(std::max(T{0}, std::abs(input) - deadzone) / (T{1} - deadzone), input);
}
const std::string name;
const std::string ui_name;
const GroupType type;
std::vector<std::unique_ptr<Control>> controls;
std::vector<std::unique_ptr<NumericSettingBase>> numeric_settings;
};
} // namespace ControllerEmu