diff options
Diffstat (limited to 'src/input_common/main.h')
| -rw-r--r-- | src/input_common/main.h | 152 |
1 files changed, 42 insertions, 110 deletions
diff --git a/src/input_common/main.h b/src/input_common/main.h index 6390d3f09..c6f97f691 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h | |||
| @@ -13,6 +13,10 @@ namespace Common { | |||
| 13 | class ParamPackage; | 13 | class ParamPackage; |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | namespace Common::Input { | ||
| 17 | enum class ButtonNames; | ||
| 18 | } | ||
| 19 | |||
| 16 | namespace Settings::NativeAnalog { | 20 | namespace Settings::NativeAnalog { |
| 17 | enum Values : int; | 21 | enum Values : int; |
| 18 | } | 22 | } |
| @@ -25,56 +29,26 @@ namespace Settings::NativeMotion { | |||
| 25 | enum Values : int; | 29 | enum Values : int; |
| 26 | } | 30 | } |
| 27 | 31 | ||
| 28 | namespace MouseInput { | 32 | namespace InputCommon { |
| 33 | class Keyboard; | ||
| 29 | class Mouse; | 34 | class Mouse; |
| 30 | } | 35 | class TouchScreen; |
| 36 | struct MappingData; | ||
| 37 | } // namespace InputCommon | ||
| 31 | 38 | ||
| 32 | namespace TasInput { | 39 | namespace InputCommon::TasInput { |
| 33 | class Tas; | 40 | class Tas; |
| 34 | } | 41 | } // namespace InputCommon::TasInput |
| 35 | 42 | ||
| 36 | namespace InputCommon { | 43 | namespace InputCommon { |
| 37 | namespace Polling { | 44 | namespace Polling { |
| 38 | 45 | /// Type of input desired for mapping purposes | |
| 39 | enum class DeviceType { Button, AnalogPreferred, Motion }; | 46 | enum class InputType { None, Button, Stick, Motion, Touch }; |
| 40 | |||
| 41 | /** | ||
| 42 | * A class that can be used to get inputs from an input device like controllers without having to | ||
| 43 | * poll the device's status yourself | ||
| 44 | */ | ||
| 45 | class DevicePoller { | ||
| 46 | public: | ||
| 47 | virtual ~DevicePoller() = default; | ||
| 48 | /// Setup and start polling for inputs, should be called before GetNextInput | ||
| 49 | /// If a device_id is provided, events should be filtered to only include events from this | ||
| 50 | /// device id | ||
| 51 | virtual void Start(const std::string& device_id = "") = 0; | ||
| 52 | /// Stop polling | ||
| 53 | virtual void Stop() = 0; | ||
| 54 | /** | ||
| 55 | * Every call to this function returns the next input recorded since calling Start | ||
| 56 | * @return A ParamPackage of the recorded input, which can be used to create an InputDevice. | ||
| 57 | * If there has been no input, the package is empty | ||
| 58 | */ | ||
| 59 | virtual Common::ParamPackage GetNextInput() = 0; | ||
| 60 | }; | ||
| 61 | } // namespace Polling | 47 | } // namespace Polling |
| 62 | 48 | ||
| 63 | class GCAnalogFactory; | ||
| 64 | class GCButtonFactory; | ||
| 65 | class UDPMotionFactory; | ||
| 66 | class UDPTouchFactory; | ||
| 67 | class MouseButtonFactory; | ||
| 68 | class MouseAnalogFactory; | ||
| 69 | class MouseMotionFactory; | ||
| 70 | class MouseTouchFactory; | ||
| 71 | class TasButtonFactory; | ||
| 72 | class TasAnalogFactory; | ||
| 73 | class Keyboard; | ||
| 74 | |||
| 75 | /** | 49 | /** |
| 76 | * Given a ParamPackage for a Device returned from `GetInputDevices`, attempt to get the default | 50 | * Given a ParamPackage for a Device returned from `GetInputDevices`, attempt to get the default |
| 77 | * mapping for the device. This is currently only implemented for the SDL backend devices. | 51 | * mapping for the device. |
| 78 | */ | 52 | */ |
| 79 | using AnalogMapping = std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage>; | 53 | using AnalogMapping = std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage>; |
| 80 | using ButtonMapping = std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage>; | 54 | using ButtonMapping = std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage>; |
| @@ -104,20 +78,27 @@ public: | |||
| 104 | [[nodiscard]] const Keyboard* GetKeyboard() const; | 78 | [[nodiscard]] const Keyboard* GetKeyboard() const; |
| 105 | 79 | ||
| 106 | /// Retrieves the underlying mouse device. | 80 | /// Retrieves the underlying mouse device. |
| 107 | [[nodiscard]] MouseInput::Mouse* GetMouse(); | 81 | [[nodiscard]] Mouse* GetMouse(); |
| 108 | 82 | ||
| 109 | /// Retrieves the underlying mouse device. | 83 | /// Retrieves the underlying mouse device. |
| 110 | [[nodiscard]] const MouseInput::Mouse* GetMouse() const; | 84 | [[nodiscard]] const Mouse* GetMouse() const; |
| 85 | |||
| 86 | /// Retrieves the underlying touch screen device. | ||
| 87 | [[nodiscard]] TouchScreen* GetTouchScreen(); | ||
| 111 | 88 | ||
| 112 | /// Retrieves the underlying tas device. | 89 | /// Retrieves the underlying touch screen device. |
| 90 | [[nodiscard]] const TouchScreen* GetTouchScreen() const; | ||
| 91 | |||
| 92 | /// Retrieves the underlying tas input device. | ||
| 113 | [[nodiscard]] TasInput::Tas* GetTas(); | 93 | [[nodiscard]] TasInput::Tas* GetTas(); |
| 114 | 94 | ||
| 115 | /// Retrieves the underlying tas device. | 95 | /// Retrieves the underlying tas input device. |
| 116 | [[nodiscard]] const TasInput::Tas* GetTas() const; | 96 | [[nodiscard]] const TasInput::Tas* GetTas() const; |
| 97 | |||
| 117 | /** | 98 | /** |
| 118 | * Returns all available input devices that this Factory can create a new device with. | 99 | * Returns all available input devices that this Factory can create a new device with. |
| 119 | * Each returned ParamPackage should have a `display` field used for display, a class field for | 100 | * Each returned ParamPackage should have a `display` field used for display, a `engine` field |
| 120 | * backends to determine if this backend is meant to service the request and any other | 101 | * for backends to determine if this backend is meant to service the request and any other |
| 121 | * information needed to identify this in the backend later. | 102 | * information needed to identify this in the backend later. |
| 122 | */ | 103 | */ |
| 123 | [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const; | 104 | [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const; |
| @@ -131,83 +112,34 @@ public: | |||
| 131 | /// Retrieves the motion mappings for the given device. | 112 | /// Retrieves the motion mappings for the given device. |
| 132 | [[nodiscard]] MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& device) const; | 113 | [[nodiscard]] MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& device) const; |
| 133 | 114 | ||
| 134 | /// Retrieves the underlying GameCube analog handler. | 115 | /// Returns an enum contaning the name to be displayed from the input engine. |
| 135 | [[nodiscard]] GCAnalogFactory* GetGCAnalogs(); | 116 | [[nodiscard]] Common::Input::ButtonNames GetButtonName( |
| 117 | const Common::ParamPackage& params) const; | ||
| 136 | 118 | ||
| 137 | /// Retrieves the underlying GameCube analog handler. | 119 | /// Returns true if device is a controller. |
| 138 | [[nodiscard]] const GCAnalogFactory* GetGCAnalogs() const; | 120 | [[nodiscard]] bool IsController(const Common::ParamPackage& params) const; |
| 139 | 121 | ||
| 140 | /// Retrieves the underlying GameCube button handler. | 122 | /// Reloads the input devices. |
| 141 | [[nodiscard]] GCButtonFactory* GetGCButtons(); | 123 | void ReloadInputDevices(); |
| 142 | |||
| 143 | /// Retrieves the underlying GameCube button handler. | ||
| 144 | [[nodiscard]] const GCButtonFactory* GetGCButtons() const; | ||
| 145 | |||
| 146 | /// Retrieves the underlying udp motion handler. | ||
| 147 | [[nodiscard]] UDPMotionFactory* GetUDPMotions(); | ||
| 148 | |||
| 149 | /// Retrieves the underlying udp motion handler. | ||
| 150 | [[nodiscard]] const UDPMotionFactory* GetUDPMotions() const; | ||
| 151 | |||
| 152 | /// Retrieves the underlying udp touch handler. | ||
| 153 | [[nodiscard]] UDPTouchFactory* GetUDPTouch(); | ||
| 154 | |||
| 155 | /// Retrieves the underlying udp touch handler. | ||
| 156 | [[nodiscard]] const UDPTouchFactory* GetUDPTouch() const; | ||
| 157 | |||
| 158 | /// Retrieves the underlying mouse button handler. | ||
| 159 | [[nodiscard]] MouseButtonFactory* GetMouseButtons(); | ||
| 160 | |||
| 161 | /// Retrieves the underlying mouse button handler. | ||
| 162 | [[nodiscard]] const MouseButtonFactory* GetMouseButtons() const; | ||
| 163 | |||
| 164 | /// Retrieves the underlying mouse analog handler. | ||
| 165 | [[nodiscard]] MouseAnalogFactory* GetMouseAnalogs(); | ||
| 166 | |||
| 167 | /// Retrieves the underlying mouse analog handler. | ||
| 168 | [[nodiscard]] const MouseAnalogFactory* GetMouseAnalogs() const; | ||
| 169 | |||
| 170 | /// Retrieves the underlying mouse motion handler. | ||
| 171 | [[nodiscard]] MouseMotionFactory* GetMouseMotions(); | ||
| 172 | |||
| 173 | /// Retrieves the underlying mouse motion handler. | ||
| 174 | [[nodiscard]] const MouseMotionFactory* GetMouseMotions() const; | ||
| 175 | |||
| 176 | /// Retrieves the underlying mouse touch handler. | ||
| 177 | [[nodiscard]] MouseTouchFactory* GetMouseTouch(); | ||
| 178 | |||
| 179 | /// Retrieves the underlying mouse touch handler. | ||
| 180 | [[nodiscard]] const MouseTouchFactory* GetMouseTouch() const; | ||
| 181 | |||
| 182 | /// Retrieves the underlying tas button handler. | ||
| 183 | [[nodiscard]] TasButtonFactory* GetTasButtons(); | ||
| 184 | |||
| 185 | /// Retrieves the underlying tas button handler. | ||
| 186 | [[nodiscard]] const TasButtonFactory* GetTasButtons() const; | ||
| 187 | |||
| 188 | /// Retrieves the underlying tas analogs handler. | ||
| 189 | [[nodiscard]] TasAnalogFactory* GetTasAnalogs(); | ||
| 190 | 124 | ||
| 191 | /// Retrieves the underlying tas analogs handler. | 125 | /// Start polling from all backends for a desired input type. |
| 192 | [[nodiscard]] const TasAnalogFactory* GetTasAnalogs() const; | 126 | void BeginMapping(Polling::InputType type); |
| 193 | 127 | ||
| 194 | /// Reloads the input devices | 128 | /// Returns an input event with mapping information. |
| 195 | void ReloadInputDevices(); | 129 | [[nodiscard]] const Common::ParamPackage GetNextInput() const; |
| 196 | 130 | ||
| 197 | /// Get all DevicePoller from all backends for a specific device type | 131 | /// Stop polling from all backends. |
| 198 | [[nodiscard]] std::vector<std::unique_ptr<Polling::DevicePoller>> GetPollers( | 132 | void StopMapping() const; |
| 199 | Polling::DeviceType type) const; | ||
| 200 | 133 | ||
| 201 | private: | 134 | private: |
| 202 | struct Impl; | 135 | struct Impl; |
| 203 | std::unique_ptr<Impl> impl; | 136 | std::unique_ptr<Impl> impl; |
| 204 | }; | 137 | }; |
| 205 | 138 | ||
| 206 | /// Generates a serialized param package for creating a keyboard button device | 139 | /// Generates a serialized param package for creating a keyboard button device. |
| 207 | std::string GenerateKeyboardParam(int key_code); | 140 | std::string GenerateKeyboardParam(int key_code); |
| 208 | 141 | ||
| 209 | /// Generates a serialized param package for creating an analog device taking input from keyboard | 142 | /// Generates a serialized param package for creating an analog device taking input from keyboard. |
| 210 | std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, | 143 | std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, |
| 211 | int key_modifier, float modifier_scale); | 144 | int key_modifier, float modifier_scale); |
| 212 | |||
| 213 | } // namespace InputCommon | 145 | } // namespace InputCommon |