diff options
Diffstat (limited to 'src/input_common/main.h')
| -rw-r--r-- | src/input_common/main.h | 132 |
1 files changed, 99 insertions, 33 deletions
diff --git a/src/input_common/main.h b/src/input_common/main.h index 0e32856f6..f3fbf696e 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h | |||
| @@ -6,45 +6,25 @@ | |||
| 6 | 6 | ||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <string> | 8 | #include <string> |
| 9 | #include <unordered_map> | ||
| 9 | #include <vector> | 10 | #include <vector> |
| 10 | #include "input_common/gcadapter/gc_poller.h" | ||
| 11 | 11 | ||
| 12 | namespace Common { | 12 | namespace Common { |
| 13 | class ParamPackage; | 13 | class ParamPackage; |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | namespace InputCommon { | 16 | namespace Settings::NativeAnalog { |
| 17 | 17 | enum Values : int; | |
| 18 | /// Initializes and registers all built-in input device factories. | 18 | } |
| 19 | void Init(); | ||
| 20 | |||
| 21 | /// Deregisters all built-in input device factories and shuts them down. | ||
| 22 | void Shutdown(); | ||
| 23 | |||
| 24 | class Keyboard; | ||
| 25 | |||
| 26 | /// Gets the keyboard button device factory. | ||
| 27 | Keyboard* GetKeyboard(); | ||
| 28 | |||
| 29 | class MotionEmu; | ||
| 30 | |||
| 31 | /// Gets the motion emulation factory. | ||
| 32 | MotionEmu* GetMotionEmu(); | ||
| 33 | |||
| 34 | GCButtonFactory* GetGCButtons(); | ||
| 35 | |||
| 36 | GCAnalogFactory* GetGCAnalogs(); | ||
| 37 | |||
| 38 | /// Generates a serialized param package for creating a keyboard button device | ||
| 39 | std::string GenerateKeyboardParam(int key_code); | ||
| 40 | 19 | ||
| 41 | /// Generates a serialized param package for creating an analog device taking input from keyboard | 20 | namespace Settings::NativeButton { |
| 42 | std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, | 21 | enum Values : int; |
| 43 | int key_modifier, float modifier_scale); | 22 | } |
| 44 | 23 | ||
| 24 | namespace InputCommon { | ||
| 45 | namespace Polling { | 25 | namespace Polling { |
| 46 | 26 | ||
| 47 | enum class DeviceType { Button, Analog }; | 27 | enum class DeviceType { Button, AnalogPreferred }; |
| 48 | 28 | ||
| 49 | /** | 29 | /** |
| 50 | * A class that can be used to get inputs from an input device like controllers without having to | 30 | * A class that can be used to get inputs from an input device like controllers without having to |
| @@ -54,7 +34,9 @@ class DevicePoller { | |||
| 54 | public: | 34 | public: |
| 55 | virtual ~DevicePoller() = default; | 35 | virtual ~DevicePoller() = default; |
| 56 | /// Setup and start polling for inputs, should be called before GetNextInput | 36 | /// Setup and start polling for inputs, should be called before GetNextInput |
| 57 | virtual void Start() = 0; | 37 | /// If a device_id is provided, events should be filtered to only include events from this |
| 38 | /// device id | ||
| 39 | virtual void Start(const std::string& device_id = "") = 0; | ||
| 58 | /// Stop polling | 40 | /// Stop polling |
| 59 | virtual void Stop() = 0; | 41 | virtual void Stop() = 0; |
| 60 | /** | 42 | /** |
| @@ -64,8 +46,92 @@ public: | |||
| 64 | */ | 46 | */ |
| 65 | virtual Common::ParamPackage GetNextInput() = 0; | 47 | virtual Common::ParamPackage GetNextInput() = 0; |
| 66 | }; | 48 | }; |
| 67 | |||
| 68 | // Get all DevicePoller from all backends for a specific device type | ||
| 69 | std::vector<std::unique_ptr<DevicePoller>> GetPollers(DeviceType type); | ||
| 70 | } // namespace Polling | 49 | } // namespace Polling |
| 50 | |||
| 51 | class GCAnalogFactory; | ||
| 52 | class GCButtonFactory; | ||
| 53 | class Keyboard; | ||
| 54 | class MotionEmu; | ||
| 55 | |||
| 56 | /** | ||
| 57 | * Given a ParamPackage for a Device returned from `GetInputDevices`, attempt to get the default | ||
| 58 | * mapping for the device. This is currently only implemented for the SDL backend devices. | ||
| 59 | */ | ||
| 60 | using AnalogMapping = std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage>; | ||
| 61 | using ButtonMapping = std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage>; | ||
| 62 | |||
| 63 | class InputSubsystem { | ||
| 64 | public: | ||
| 65 | explicit InputSubsystem(); | ||
| 66 | ~InputSubsystem(); | ||
| 67 | |||
| 68 | InputSubsystem(const InputSubsystem&) = delete; | ||
| 69 | InputSubsystem& operator=(const InputSubsystem&) = delete; | ||
| 70 | |||
| 71 | InputSubsystem(InputSubsystem&&) = delete; | ||
| 72 | InputSubsystem& operator=(InputSubsystem&&) = delete; | ||
| 73 | |||
| 74 | /// Initializes and registers all built-in input device factories. | ||
| 75 | void Initialize(); | ||
| 76 | |||
| 77 | /// Unregisters all built-in input device factories and shuts them down. | ||
| 78 | void Shutdown(); | ||
| 79 | |||
| 80 | /// Retrieves the underlying keyboard device. | ||
| 81 | [[nodiscard]] Keyboard* GetKeyboard(); | ||
| 82 | |||
| 83 | /// Retrieves the underlying keyboard device. | ||
| 84 | [[nodiscard]] const Keyboard* GetKeyboard() const; | ||
| 85 | |||
| 86 | /// Retrieves the underlying motion emulation factory. | ||
| 87 | [[nodiscard]] MotionEmu* GetMotionEmu(); | ||
| 88 | |||
| 89 | /// Retrieves the underlying motion emulation factory. | ||
| 90 | [[nodiscard]] const MotionEmu* GetMotionEmu() const; | ||
| 91 | |||
| 92 | /** | ||
| 93 | * Returns all available input devices that this Factory can create a new device with. | ||
| 94 | * Each returned ParamPackage should have a `display` field used for display, a class field for | ||
| 95 | * backends to determine if this backend is meant to service the request and any other | ||
| 96 | * information needed to identify this in the backend later. | ||
| 97 | */ | ||
| 98 | [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const; | ||
| 99 | |||
| 100 | /// Retrieves the analog mappings for the given device. | ||
| 101 | [[nodiscard]] AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& device) const; | ||
| 102 | |||
| 103 | /// Retrieves the button mappings for the given device. | ||
| 104 | [[nodiscard]] ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& device) const; | ||
| 105 | |||
| 106 | /// Retrieves the underlying GameCube analog handler. | ||
| 107 | [[nodiscard]] GCAnalogFactory* GetGCAnalogs(); | ||
| 108 | |||
| 109 | /// Retrieves the underlying GameCube analog handler. | ||
| 110 | [[nodiscard]] const GCAnalogFactory* GetGCAnalogs() const; | ||
| 111 | |||
| 112 | /// Retrieves the underlying GameCube button handler. | ||
| 113 | [[nodiscard]] GCButtonFactory* GetGCButtons(); | ||
| 114 | |||
| 115 | /// Retrieves the underlying GameCube button handler. | ||
| 116 | [[nodiscard]] const GCButtonFactory* GetGCButtons() const; | ||
| 117 | |||
| 118 | /// Reloads the input devices | ||
| 119 | void ReloadInputDevices(); | ||
| 120 | |||
| 121 | /// Get all DevicePoller from all backends for a specific device type | ||
| 122 | [[nodiscard]] std::vector<std::unique_ptr<Polling::DevicePoller>> GetPollers( | ||
| 123 | Polling::DeviceType type) const; | ||
| 124 | |||
| 125 | private: | ||
| 126 | struct Impl; | ||
| 127 | std::unique_ptr<Impl> impl; | ||
| 128 | }; | ||
| 129 | |||
| 130 | /// Generates a serialized param package for creating a keyboard button device | ||
| 131 | std::string GenerateKeyboardParam(int key_code); | ||
| 132 | |||
| 133 | /// Generates a serialized param package for creating an analog device taking input from keyboard | ||
| 134 | std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, | ||
| 135 | int key_modifier, float modifier_scale); | ||
| 136 | |||
| 71 | } // namespace InputCommon | 137 | } // namespace InputCommon |