summaryrefslogtreecommitdiffstats
path: root/src/input_common/input_poller.h
blob: 3c1e5b541f95b8a3cf20f4db7bc12f1a887d8373 (plain) (blame)
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
// Copyright 2021 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included

#pragma once

namespace Input {
class InputDevice;

template <typename InputDevice>
class Factory;
}; // namespace Input

namespace InputCommon {
class InputEngine;
/**
 * An Input factory. It receives input events and forward them to all input devices it created.
 */
class InputFactory final : public Input::Factory<Input::InputDevice> {
public:
    explicit InputFactory(std::shared_ptr<InputEngine> input_engine_);

    /**
     * Creates a input device from the parameters given. Identifies the type of input to be returned
     * if it contains the following parameters:
     * - button: Contains "button" or "code"
     * - hat_button: Contains "hat"
     * - analog: Contains "axis"
     * - trigger: Contains "button" and  "axis"
     * - stick: Contains "axis_x" and "axis_y"
     * - motion: Contains "axis_x", "axis_y" and "axis_z"
     * - motion: Contains "motion"
     * - touch: Contains "button", "axis_x" and "axis_y"
     * - battery: Contains "battery"
     * @param params contains parameters for creating the device:
     * @param    - "code": the code of the keyboard key to bind with the input
     * @param    - "button": same as "code" but for controller buttons
     * @param    - "hat": similar as "button" but it's a group of hat buttons from SDL
     * @param    - "axis": the axis number of the axis to bind with the input
     * @param    - "motion": the motion number of the motion to bind with the input
     * @param    - "axis_x": same as axis but specifing horizontal direction
     * @param    - "axis_y": same as axis but specifing vertical direction
     * @param    - "axis_z": same as axis but specifing forward direction
     * @param   - "battery": Only used as a placeholder to set the input type
     * @return an unique input device with the parameters specified
     */
    std::unique_ptr<Input::InputDevice> Create(const Common::ParamPackage& params) override;

private:
    /**
     * Creates a button device from the parameters given.
     * @param params contains parameters for creating the device:
     * @param    - "code": the code of the keyboard key to bind with the input
     * @param    - "button": same as "code" but for controller buttons
     * @param    - "toggle": press once to enable, press again to disable
     * @param    - "inverted": inverts the output of the button
     * @param    - "guid": text string for identifing controllers
     * @param    - "port": port of the connected device
     * @param    - "pad": slot of the connected controller
     * @return an unique input device with the parameters specified
     */
    std::unique_ptr<Input::InputDevice> CreateButtonDevice(const Common::ParamPackage& params);

    /**
     * Creates a hat button device from the parameters given.
     * @param params contains parameters for creating the device:
     * @param    - "button": the controller hat id to bind with the input
     * @param    - "direction": the direction id to be detected
     * @param    - "toggle": press once to enable, press again to disable
     * @param    - "inverted": inverts the output of the button
     * @param    - "guid": text string for identifing controllers
     * @param    - "port": port of the connected device
     * @param    - "pad": slot of the connected controller
     * @return an unique input device with the parameters specified
     */
    std::unique_ptr<Input::InputDevice> CreateHatButtonDevice(const Common::ParamPackage& params);

    /**
     * Creates a stick device from the parameters given.
     * @param params contains parameters for creating the device:
     * @param    - "axis_x": the controller horizontal axis id to bind with the input
     * @param    - "axis_y": the controller vertical axis id to bind with the input
     * @param    - "deadzone": the mimimum required value to be detected
     * @param    - "range": the maximum value required to reach 100%
     * @param    - "threshold": the mimimum required value to considered pressed
     * @param    - "offset_x": the amount of offset in the x axis
     * @param    - "offset_y": the amount of offset in the y axis
     * @param    - "invert_x": inverts the sign of the horizontal axis
     * @param    - "invert_y": inverts the sign of the vertical axis
     * @param    - "guid": text string for identifing controllers
     * @param    - "port": port of the connected device
     * @param    - "pad": slot of the connected controller
     * @return an unique input device with the parameters specified
     */
    std::unique_ptr<Input::InputDevice> CreateStickDevice(const Common::ParamPackage& params);

    /**
     * Creates an analog device from the parameters given.
     * @param params contains parameters for creating the device:
     * @param    - "axis": the controller axis id to bind with the input
     * @param    - "deadzone": the mimimum required value to be detected
     * @param    - "range": the maximum value required to reach 100%
     * @param    - "threshold": the mimimum required value to considered pressed
     * @param    - "offset": the amount of offset in the axis
     * @param    - "invert": inverts the sign of the axis
     * @param    - "guid": text string for identifing controllers
     * @param    - "port": port of the connected device
     * @param    - "pad": slot of the connected controller
     * @return an unique input device with the parameters specified
     */
    std::unique_ptr<Input::InputDevice> CreateAnalogDevice(const Common::ParamPackage& params);

    /**
     * Creates a trigger device from the parameters given.
     * @param params contains parameters for creating the device:
     * @param    - "button": the controller hat id to bind with the input
     * @param    - "direction": the direction id to be detected
     * @param    - "toggle": press once to enable, press again to disable
     * @param    - "inverted": inverts the output of the button
     * @param    - "axis": the controller axis id to bind with the input
     * @param    - "deadzone": the mimimum required value to be detected
     * @param    - "range": the maximum value required to reach 100%
     * @param    - "threshold": the mimimum required value to considered pressed
     * @param    - "offset": the amount of offset in the axis
     * @param    - "invert": inverts the sign of the axis
     * @param    - "guid": text string for identifing controllers
     * @param    - "port": port of the connected device
     * @param    - "pad": slot of the connected controller
     * @return an unique input device with the parameters specified
     */
    std::unique_ptr<Input::InputDevice> CreateTriggerDevice(const Common::ParamPackage& params);

    /**
     * Creates a touch device from the parameters given.
     * @param params contains parameters for creating the device:
     * @param    - "button": the controller hat id to bind with the input
     * @param    - "direction": the direction id to be detected
     * @param    - "toggle": press once to enable, press again to disable
     * @param    - "inverted": inverts the output of the button
     * @param    - "axis_x": the controller horizontal axis id to bind with the input
     * @param    - "axis_y": the controller vertical axis id to bind with the input
     * @param    - "deadzone": the mimimum required value to be detected
     * @param    - "range": the maximum value required to reach 100%
     * @param    - "threshold": the mimimum required value to considered pressed
     * @param    - "offset_x": the amount of offset in the x axis
     * @param    - "offset_y": the amount of offset in the y axis
     * @param    - "invert_x": inverts the sign of the horizontal axis
     * @param    - "invert_y": inverts the sign of the vertical axis
     * @param    - "guid": text string for identifing controllers
     * @param    - "port": port of the connected device
     * @param    - "pad": slot of the connected controller
     * @return an unique input device with the parameters specified
     */
    std::unique_ptr<Input::InputDevice> CreateTouchDevice(const Common::ParamPackage& params);

    /**
     * Creates a battery device from the parameters given.
     * @param params contains parameters for creating the device:
     * @param    - "guid": text string for identifing controllers
     * @param    - "port": port of the connected device
     * @param    - "pad": slot of the connected controller
     * @return an unique input device with the parameters specified
     */
    std::unique_ptr<Input::InputDevice> CreateBatteryDevice(const Common::ParamPackage& params);

    /**
     * Creates a motion device from the parameters given.
     * @param params contains parameters for creating the device:
     * @param    - "axis_x": the controller horizontal axis id to bind with the input
     * @param    - "axis_y": the controller vertical axis id to bind with the input
     * @param    - "axis_z": the controller fordward axis id to bind with the input
     * @param    - "deadzone": the mimimum required value to be detected
     * @param    - "range": the maximum value required to reach 100%
     * @param    - "offset_x": the amount of offset in the x axis
     * @param    - "offset_y": the amount of offset in the y axis
     * @param    - "offset_z": the amount of offset in the z axis
     * @param    - "invert_x": inverts the sign of the horizontal axis
     * @param    - "invert_y": inverts the sign of the vertical axis
     * @param    - "invert_z": inverts the sign of the fordward axis
     * @param    - "guid": text string for identifing controllers
     * @param    - "port": port of the connected device
     * @param    - "pad": slot of the connected controller
     * @return an unique input device with the parameters specified
     */
    std::unique_ptr<Input::InputDevice> CreateMotionDevice(Common::ParamPackage params);

    std::shared_ptr<InputEngine> input_engine;
};
} // namespace InputCommon