summaryrefslogtreecommitdiff
path: root/src/input_common/input_poller.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/input_poller.h')
-rw-r--r--src/input_common/input_poller.h217
1 files changed, 217 insertions, 0 deletions
diff --git a/src/input_common/input_poller.h b/src/input_common/input_poller.h
new file mode 100644
index 000000000..8a0977d58
--- /dev/null
+++ b/src/input_common/input_poller.h
@@ -0,0 +1,217 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included
4
5#pragma once
6
7namespace Input {
8class InputDevice;
9
10template <typename InputDevice>
11class Factory;
12}; // namespace Input
13
14namespace InputCommon {
15class InputEngine;
16
17class OutputFactory final : public Common::Input::Factory<Common::Input::OutputDevice> {
18public:
19 explicit OutputFactory(std::shared_ptr<InputEngine> input_engine_);
20
21 /**
22 * Creates an output device from the parameters given.
23 * @param params contains parameters for creating the device:
24 * - "guid" text string for identifying controllers
25 * - "port": port of the connected device
26 * - "pad": slot of the connected controller
27 * @returns a unique output device with the parameters specified
28 */
29 std::unique_ptr<Common::Input::OutputDevice> Create(
30 const Common::ParamPackage& params) override;
31
32private:
33 std::shared_ptr<InputEngine> input_engine;
34};
35
36/**
37 * An Input factory. It receives input events and forward them to all input devices it created.
38 */
39class InputFactory final : public Common::Input::Factory<Common::Input::InputDevice> {
40public:
41 explicit InputFactory(std::shared_ptr<InputEngine> input_engine_);
42
43 /**
44 * Creates an input device from the parameters given. Identifies the type of input to be
45 * returned if it contains the following parameters:
46 * - button: Contains "button" or "code"
47 * - hat_button: Contains "hat"
48 * - analog: Contains "axis"
49 * - trigger: Contains "button" and "axis"
50 * - stick: Contains "axis_x" and "axis_y"
51 * - motion: Contains "axis_x", "axis_y" and "axis_z"
52 * - motion: Contains "motion"
53 * - touch: Contains "button", "axis_x" and "axis_y"
54 * - battery: Contains "battery"
55 * - output: Contains "output"
56 * @param params contains parameters for creating the device:
57 * - "code": the code of the keyboard key to bind with the input
58 * - "button": same as "code" but for controller buttons
59 * - "hat": similar as "button" but it's a group of hat buttons from SDL
60 * - "axis": the axis number of the axis to bind with the input
61 * - "motion": the motion number of the motion to bind with the input
62 * - "axis_x": same as axis but specifying horizontal direction
63 * - "axis_y": same as axis but specifying vertical direction
64 * - "axis_z": same as axis but specifying forward direction
65 * - "battery": Only used as a placeholder to set the input type
66 * @returns a unique input device with the parameters specified
67 */
68 std::unique_ptr<Common::Input::InputDevice> Create(const Common::ParamPackage& params) override;
69
70private:
71 /**
72 * Creates a button device from the parameters given.
73 * @param params contains parameters for creating the device:
74 * - "code": the code of the keyboard key to bind with the input
75 * - "button": same as "code" but for controller buttons
76 * - "toggle": press once to enable, press again to disable
77 * - "inverted": inverts the output of the button
78 * - "guid": text string for identifying controllers
79 * - "port": port of the connected device
80 * - "pad": slot of the connected controller
81 * @returns a unique input device with the parameters specified
82 */
83 std::unique_ptr<Common::Input::InputDevice> CreateButtonDevice(
84 const Common::ParamPackage& params);
85
86 /**
87 * Creates a hat button device from the parameters given.
88 * @param params contains parameters for creating the device:
89 * - "button": the controller hat id to bind with the input
90 * - "direction": the direction id to be detected
91 * - "toggle": press once to enable, press again to disable
92 * - "inverted": inverts the output of the button
93 * - "guid": text string for identifying controllers
94 * - "port": port of the connected device
95 * - "pad": slot of the connected controller
96 * @returns a unique input device with the parameters specified
97 */
98 std::unique_ptr<Common::Input::InputDevice> CreateHatButtonDevice(
99 const Common::ParamPackage& params);
100
101 /**
102 * Creates a stick device from the parameters given.
103 * @param params contains parameters for creating the device:
104 * - "axis_x": the controller horizontal axis id to bind with the input
105 * - "axis_y": the controller vertical axis id to bind with the input
106 * - "deadzone": the minimum required value to be detected
107 * - "range": the maximum value required to reach 100%
108 * - "threshold": the minimum required value to considered pressed
109 * - "offset_x": the amount of offset in the x axis
110 * - "offset_y": the amount of offset in the y axis
111 * - "invert_x": inverts the sign of the horizontal axis
112 * - "invert_y": inverts the sign of the vertical axis
113 * - "guid": text string for identifying controllers
114 * - "port": port of the connected device
115 * - "pad": slot of the connected controller
116 * @returns a unique input device with the parameters specified
117 */
118 std::unique_ptr<Common::Input::InputDevice> CreateStickDevice(
119 const Common::ParamPackage& params);
120
121 /**
122 * Creates an analog device from the parameters given.
123 * @param params contains parameters for creating the device:
124 * - "axis": the controller axis id to bind with the input
125 * - "deadzone": the minimum required value to be detected
126 * - "range": the maximum value required to reach 100%
127 * - "threshold": the minimum required value to considered pressed
128 * - "offset": the amount of offset in the axis
129 * - "invert": inverts the sign of the axis
130 * - "guid": text string for identifying controllers
131 * - "port": port of the connected device
132 * - "pad": slot of the connected controller
133 * @returns a unique input device with the parameters specified
134 */
135 std::unique_ptr<Common::Input::InputDevice> CreateAnalogDevice(
136 const Common::ParamPackage& params);
137
138 /**
139 * Creates a trigger device from the parameters given.
140 * @param params contains parameters for creating the device:
141 * - "button": the controller hat id to bind with the input
142 * - "direction": the direction id to be detected
143 * - "toggle": press once to enable, press again to disable
144 * - "inverted": inverts the output of the button
145 * - "axis": the controller axis id to bind with the input
146 * - "deadzone": the minimum required value to be detected
147 * - "range": the maximum value required to reach 100%
148 * - "threshold": the minimum required value to considered pressed
149 * - "offset": the amount of offset in the axis
150 * - "invert": inverts the sign of the axis
151 * - "guid": text string for identifying controllers
152 * - "port": port of the connected device
153 * - "pad": slot of the connected controller
154 * @returns a unique input device with the parameters specified
155 */
156 std::unique_ptr<Common::Input::InputDevice> CreateTriggerDevice(
157 const Common::ParamPackage& params);
158
159 /**
160 * Creates a touch device from the parameters given.
161 * @param params contains parameters for creating the device:
162 * - "button": the controller hat id to bind with the input
163 * - "direction": the direction id to be detected
164 * - "toggle": press once to enable, press again to disable
165 * - "inverted": inverts the output of the button
166 * - "axis_x": the controller horizontal axis id to bind with the input
167 * - "axis_y": the controller vertical axis id to bind with the input
168 * - "deadzone": the minimum required value to be detected
169 * - "range": the maximum value required to reach 100%
170 * - "threshold": the minimum required value to considered pressed
171 * - "offset_x": the amount of offset in the x axis
172 * - "offset_y": the amount of offset in the y axis
173 * - "invert_x": inverts the sign of the horizontal axis
174 * - "invert_y": inverts the sign of the vertical axis
175 * - "guid": text string for identifying controllers
176 * - "port": port of the connected device
177 * - "pad": slot of the connected controller
178 * @returns a unique input device with the parameters specified
179 */
180 std::unique_ptr<Common::Input::InputDevice> CreateTouchDevice(
181 const Common::ParamPackage& params);
182
183 /**
184 * Creates a battery device from the parameters given.
185 * @param params contains parameters for creating the device:
186 * - "guid": text string for identifying controllers
187 * - "port": port of the connected device
188 * - "pad": slot of the connected controller
189 * @returns a unique input device with the parameters specified
190 */
191 std::unique_ptr<Common::Input::InputDevice> CreateBatteryDevice(
192 const Common::ParamPackage& params);
193
194 /**
195 * Creates a motion device from the parameters given.
196 * @param params contains parameters for creating the device:
197 * - "axis_x": the controller horizontal axis id to bind with the input
198 * - "axis_y": the controller vertical axis id to bind with the input
199 * - "axis_z": the controller forward axis id to bind with the input
200 * - "deadzone": the minimum required value to be detected
201 * - "range": the maximum value required to reach 100%
202 * - "offset_x": the amount of offset in the x axis
203 * - "offset_y": the amount of offset in the y axis
204 * - "offset_z": the amount of offset in the z axis
205 * - "invert_x": inverts the sign of the horizontal axis
206 * - "invert_y": inverts the sign of the vertical axis
207 * - "invert_z": inverts the sign of the forward axis
208 * - "guid": text string for identifying controllers
209 * - "port": port of the connected device
210 * - "pad": slot of the connected controller
211 * @returns a unique input device with the parameters specified
212 */
213 std::unique_ptr<Common::Input::InputDevice> CreateMotionDevice(Common::ParamPackage params);
214
215 std::shared_ptr<InputEngine> input_engine;
216};
217} // namespace InputCommon