diff options
| author | 2021-09-20 16:41:15 -0500 | |
|---|---|---|
| committer | 2021-11-24 20:30:22 -0600 | |
| commit | 854c933716f0f5e1dbf62157c5a76e65213b30b2 (patch) | |
| tree | 229ada777d889243bdfcb6c240ad615c246cd8c6 /src/input_common/input_poller.h | |
| parent | input_common: Create input_engine (diff) | |
| download | yuzu-854c933716f0f5e1dbf62157c5a76e65213b30b2.tar.gz yuzu-854c933716f0f5e1dbf62157c5a76e65213b30b2.tar.xz yuzu-854c933716f0f5e1dbf62157c5a76e65213b30b2.zip | |
input_common: Create input poller and mapping
Diffstat (limited to 'src/input_common/input_poller.h')
| -rw-r--r-- | src/input_common/input_poller.h | 189 |
1 files changed, 189 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..3c1e5b541 --- /dev/null +++ b/src/input_common/input_poller.h | |||
| @@ -0,0 +1,189 @@ | |||
| 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 | |||
| 7 | namespace Input { | ||
| 8 | class InputDevice; | ||
| 9 | |||
| 10 | template <typename InputDevice> | ||
| 11 | class Factory; | ||
| 12 | }; // namespace Input | ||
| 13 | |||
| 14 | namespace InputCommon { | ||
| 15 | class InputEngine; | ||
| 16 | /** | ||
| 17 | * An Input factory. It receives input events and forward them to all input devices it created. | ||
| 18 | */ | ||
| 19 | class InputFactory final : public Input::Factory<Input::InputDevice> { | ||
| 20 | public: | ||
| 21 | explicit InputFactory(std::shared_ptr<InputEngine> input_engine_); | ||
| 22 | |||
| 23 | /** | ||
| 24 | * Creates a input device from the parameters given. Identifies the type of input to be returned | ||
| 25 | * if it contains the following parameters: | ||
| 26 | * - button: Contains "button" or "code" | ||
| 27 | * - hat_button: Contains "hat" | ||
| 28 | * - analog: Contains "axis" | ||
| 29 | * - trigger: Contains "button" and "axis" | ||
| 30 | * - stick: Contains "axis_x" and "axis_y" | ||
| 31 | * - motion: Contains "axis_x", "axis_y" and "axis_z" | ||
| 32 | * - motion: Contains "motion" | ||
| 33 | * - touch: Contains "button", "axis_x" and "axis_y" | ||
| 34 | * - battery: Contains "battery" | ||
| 35 | * @param params contains parameters for creating the device: | ||
| 36 | * @param - "code": the code of the keyboard key to bind with the input | ||
| 37 | * @param - "button": same as "code" but for controller buttons | ||
| 38 | * @param - "hat": similar as "button" but it's a group of hat buttons from SDL | ||
| 39 | * @param - "axis": the axis number of the axis to bind with the input | ||
| 40 | * @param - "motion": the motion number of the motion to bind with the input | ||
| 41 | * @param - "axis_x": same as axis but specifing horizontal direction | ||
| 42 | * @param - "axis_y": same as axis but specifing vertical direction | ||
| 43 | * @param - "axis_z": same as axis but specifing forward direction | ||
| 44 | * @param - "battery": Only used as a placeholder to set the input type | ||
| 45 | * @return an unique input device with the parameters specified | ||
| 46 | */ | ||
| 47 | std::unique_ptr<Input::InputDevice> Create(const Common::ParamPackage& params) override; | ||
| 48 | |||
| 49 | private: | ||
| 50 | /** | ||
| 51 | * Creates a button device from the parameters given. | ||
| 52 | * @param params contains parameters for creating the device: | ||
| 53 | * @param - "code": the code of the keyboard key to bind with the input | ||
| 54 | * @param - "button": same as "code" but for controller buttons | ||
| 55 | * @param - "toggle": press once to enable, press again to disable | ||
| 56 | * @param - "inverted": inverts the output of the button | ||
| 57 | * @param - "guid": text string for identifing controllers | ||
| 58 | * @param - "port": port of the connected device | ||
| 59 | * @param - "pad": slot of the connected controller | ||
| 60 | * @return an unique input device with the parameters specified | ||
| 61 | */ | ||
| 62 | std::unique_ptr<Input::InputDevice> CreateButtonDevice(const Common::ParamPackage& params); | ||
| 63 | |||
| 64 | /** | ||
| 65 | * Creates a hat button device from the parameters given. | ||
| 66 | * @param params contains parameters for creating the device: | ||
| 67 | * @param - "button": the controller hat id to bind with the input | ||
| 68 | * @param - "direction": the direction id to be detected | ||
| 69 | * @param - "toggle": press once to enable, press again to disable | ||
| 70 | * @param - "inverted": inverts the output of the button | ||
| 71 | * @param - "guid": text string for identifing controllers | ||
| 72 | * @param - "port": port of the connected device | ||
| 73 | * @param - "pad": slot of the connected controller | ||
| 74 | * @return an unique input device with the parameters specified | ||
| 75 | */ | ||
| 76 | std::unique_ptr<Input::InputDevice> CreateHatButtonDevice(const Common::ParamPackage& params); | ||
| 77 | |||
| 78 | /** | ||
| 79 | * Creates a stick device from the parameters given. | ||
| 80 | * @param params contains parameters for creating the device: | ||
| 81 | * @param - "axis_x": the controller horizontal axis id to bind with the input | ||
| 82 | * @param - "axis_y": the controller vertical axis id to bind with the input | ||
| 83 | * @param - "deadzone": the mimimum required value to be detected | ||
| 84 | * @param - "range": the maximum value required to reach 100% | ||
| 85 | * @param - "threshold": the mimimum required value to considered pressed | ||
| 86 | * @param - "offset_x": the amount of offset in the x axis | ||
| 87 | * @param - "offset_y": the amount of offset in the y axis | ||
| 88 | * @param - "invert_x": inverts the sign of the horizontal axis | ||
| 89 | * @param - "invert_y": inverts the sign of the vertical axis | ||
| 90 | * @param - "guid": text string for identifing controllers | ||
| 91 | * @param - "port": port of the connected device | ||
| 92 | * @param - "pad": slot of the connected controller | ||
| 93 | * @return an unique input device with the parameters specified | ||
| 94 | */ | ||
| 95 | std::unique_ptr<Input::InputDevice> CreateStickDevice(const Common::ParamPackage& params); | ||
| 96 | |||
| 97 | /** | ||
| 98 | * Creates an analog device from the parameters given. | ||
| 99 | * @param params contains parameters for creating the device: | ||
| 100 | * @param - "axis": the controller axis id to bind with the input | ||
| 101 | * @param - "deadzone": the mimimum required value to be detected | ||
| 102 | * @param - "range": the maximum value required to reach 100% | ||
| 103 | * @param - "threshold": the mimimum required value to considered pressed | ||
| 104 | * @param - "offset": the amount of offset in the axis | ||
| 105 | * @param - "invert": inverts the sign of the axis | ||
| 106 | * @param - "guid": text string for identifing controllers | ||
| 107 | * @param - "port": port of the connected device | ||
| 108 | * @param - "pad": slot of the connected controller | ||
| 109 | * @return an unique input device with the parameters specified | ||
| 110 | */ | ||
| 111 | std::unique_ptr<Input::InputDevice> CreateAnalogDevice(const Common::ParamPackage& params); | ||
| 112 | |||
| 113 | /** | ||
| 114 | * Creates a trigger device from the parameters given. | ||
| 115 | * @param params contains parameters for creating the device: | ||
| 116 | * @param - "button": the controller hat id to bind with the input | ||
| 117 | * @param - "direction": the direction id to be detected | ||
| 118 | * @param - "toggle": press once to enable, press again to disable | ||
| 119 | * @param - "inverted": inverts the output of the button | ||
| 120 | * @param - "axis": the controller axis id to bind with the input | ||
| 121 | * @param - "deadzone": the mimimum required value to be detected | ||
| 122 | * @param - "range": the maximum value required to reach 100% | ||
| 123 | * @param - "threshold": the mimimum required value to considered pressed | ||
| 124 | * @param - "offset": the amount of offset in the axis | ||
| 125 | * @param - "invert": inverts the sign of the axis | ||
| 126 | * @param - "guid": text string for identifing controllers | ||
| 127 | * @param - "port": port of the connected device | ||
| 128 | * @param - "pad": slot of the connected controller | ||
| 129 | * @return an unique input device with the parameters specified | ||
| 130 | */ | ||
| 131 | std::unique_ptr<Input::InputDevice> CreateTriggerDevice(const Common::ParamPackage& params); | ||
| 132 | |||
| 133 | /** | ||
| 134 | * Creates a touch device from the parameters given. | ||
| 135 | * @param params contains parameters for creating the device: | ||
| 136 | * @param - "button": the controller hat id to bind with the input | ||
| 137 | * @param - "direction": the direction id to be detected | ||
| 138 | * @param - "toggle": press once to enable, press again to disable | ||
| 139 | * @param - "inverted": inverts the output of the button | ||
| 140 | * @param - "axis_x": the controller horizontal axis id to bind with the input | ||
| 141 | * @param - "axis_y": the controller vertical axis id to bind with the input | ||
| 142 | * @param - "deadzone": the mimimum required value to be detected | ||
| 143 | * @param - "range": the maximum value required to reach 100% | ||
| 144 | * @param - "threshold": the mimimum required value to considered pressed | ||
| 145 | * @param - "offset_x": the amount of offset in the x axis | ||
| 146 | * @param - "offset_y": the amount of offset in the y axis | ||
| 147 | * @param - "invert_x": inverts the sign of the horizontal axis | ||
| 148 | * @param - "invert_y": inverts the sign of the vertical axis | ||
| 149 | * @param - "guid": text string for identifing controllers | ||
| 150 | * @param - "port": port of the connected device | ||
| 151 | * @param - "pad": slot of the connected controller | ||
| 152 | * @return an unique input device with the parameters specified | ||
| 153 | */ | ||
| 154 | std::unique_ptr<Input::InputDevice> CreateTouchDevice(const Common::ParamPackage& params); | ||
| 155 | |||
| 156 | /** | ||
| 157 | * Creates a battery device from the parameters given. | ||
| 158 | * @param params contains parameters for creating the device: | ||
| 159 | * @param - "guid": text string for identifing controllers | ||
| 160 | * @param - "port": port of the connected device | ||
| 161 | * @param - "pad": slot of the connected controller | ||
| 162 | * @return an unique input device with the parameters specified | ||
| 163 | */ | ||
| 164 | std::unique_ptr<Input::InputDevice> CreateBatteryDevice(const Common::ParamPackage& params); | ||
| 165 | |||
| 166 | /** | ||
| 167 | * Creates a motion device from the parameters given. | ||
| 168 | * @param params contains parameters for creating the device: | ||
| 169 | * @param - "axis_x": the controller horizontal axis id to bind with the input | ||
| 170 | * @param - "axis_y": the controller vertical axis id to bind with the input | ||
| 171 | * @param - "axis_z": the controller fordward axis id to bind with the input | ||
| 172 | * @param - "deadzone": the mimimum required value to be detected | ||
| 173 | * @param - "range": the maximum value required to reach 100% | ||
| 174 | * @param - "offset_x": the amount of offset in the x axis | ||
| 175 | * @param - "offset_y": the amount of offset in the y axis | ||
| 176 | * @param - "offset_z": the amount of offset in the z axis | ||
| 177 | * @param - "invert_x": inverts the sign of the horizontal axis | ||
| 178 | * @param - "invert_y": inverts the sign of the vertical axis | ||
| 179 | * @param - "invert_z": inverts the sign of the fordward axis | ||
| 180 | * @param - "guid": text string for identifing controllers | ||
| 181 | * @param - "port": port of the connected device | ||
| 182 | * @param - "pad": slot of the connected controller | ||
| 183 | * @return an unique input device with the parameters specified | ||
| 184 | */ | ||
| 185 | std::unique_ptr<Input::InputDevice> CreateMotionDevice(Common::ParamPackage params); | ||
| 186 | |||
| 187 | std::shared_ptr<InputEngine> input_engine; | ||
| 188 | }; | ||
| 189 | } // namespace InputCommon | ||