summaryrefslogtreecommitdiff
path: root/src/input_common/main.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/main.h')
-rw-r--r--src/input_common/main.h89
1 files changed, 51 insertions, 38 deletions
diff --git a/src/input_common/main.h b/src/input_common/main.h
index b504ebe54..a4a24d076 100644
--- a/src/input_common/main.h
+++ b/src/input_common/main.h
@@ -25,47 +25,26 @@ namespace Settings::NativeMotion {
25enum Values : int; 25enum Values : int;
26} 26}
27 27
28namespace MouseInput { 28namespace InputCommon {
29class Keyboard;
29class Mouse; 30class Mouse;
30} 31class TouchScreen;
32struct MappingData;
33} // namespace InputCommon
31 34
32namespace TasInput { 35namespace InputCommon::TasInput {
33class Tas; 36class Tas;
34} 37} // namespace InputCommon::TasInput
35 38
36namespace InputCommon { 39namespace InputCommon {
37namespace Polling { 40namespace Polling {
38
39enum class DeviceType { Button, AnalogPreferred, Motion };
40
41/// Type of input desired for mapping purposes 41/// Type of input desired for mapping purposes
42enum class InputType { None, Button, Stick, Motion, Touch }; 42enum class InputType { None, Button, Stick, Motion, Touch };
43
44/**
45 * A class that can be used to get inputs from an input device like controllers without having to
46 * poll the device's status yourself
47 */
48class DevicePoller {
49public:
50 virtual ~DevicePoller() = default;
51 /// Setup and start polling for inputs, should be called before GetNextInput
52 /// If a device_id is provided, events should be filtered to only include events from this
53 /// device id
54 virtual void Start(const std::string& device_id = "") = 0;
55 /// Stop polling
56 virtual void Stop() = 0;
57 /**
58 * Every call to this function returns the next input recorded since calling Start
59 * @return A ParamPackage of the recorded input, which can be used to create an InputDevice.
60 * If there has been no input, the package is empty
61 */
62 virtual Common::ParamPackage GetNextInput() = 0;
63};
64} // namespace Polling 43} // namespace Polling
65 44
66/** 45/**
67 * Given a ParamPackage for a Device returned from `GetInputDevices`, attempt to get the default 46 * Given a ParamPackage for a Device returned from `GetInputDevices`, attempt to get the default
68 * mapping for the device. This is currently only implemented for the SDL backend devices. 47 * mapping for the device.
69 */ 48 */
70using AnalogMapping = std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage>; 49using AnalogMapping = std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage>;
71using ButtonMapping = std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage>; 50using ButtonMapping = std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage>;
@@ -88,10 +67,34 @@ public:
88 /// Unregisters all built-in input device factories and shuts them down. 67 /// Unregisters all built-in input device factories and shuts them down.
89 void Shutdown(); 68 void Shutdown();
90 69
70 /// Retrieves the underlying keyboard device.
71 [[nodiscard]] Keyboard* GetKeyboard();
72
73 /// Retrieves the underlying keyboard device.
74 [[nodiscard]] const Keyboard* GetKeyboard() const;
75
76 /// Retrieves the underlying mouse device.
77 [[nodiscard]] Mouse* GetMouse();
78
79 /// Retrieves the underlying mouse device.
80 [[nodiscard]] const Mouse* GetMouse() const;
81
82 /// Retrieves the underlying touch screen device.
83 [[nodiscard]] TouchScreen* GetTouchScreen();
84
85 /// Retrieves the underlying touch screen device.
86 [[nodiscard]] const TouchScreen* GetTouchScreen() const;
87
88 /// Retrieves the underlying tas input device.
89 [[nodiscard]] TasInput::Tas* GetTas();
90
91 /// Retrieves the underlying tas input device.
92 [[nodiscard]] const TasInput::Tas* GetTas() const;
93
91 /** 94 /**
92 * Returns all available input devices that this Factory can create a new device with. 95 * Returns all available input devices that this Factory can create a new device with.
93 * Each returned ParamPackage should have a `display` field used for display, a class field for 96 * Each returned ParamPackage should have a `display` field used for display, a `engine` field
94 * backends to determine if this backend is meant to service the request and any other 97 * for backends to determine if this backend is meant to service the request and any other
95 * information needed to identify this in the backend later. 98 * information needed to identify this in the backend later.
96 */ 99 */
97 [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const; 100 [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const;
@@ -105,23 +108,33 @@ public:
105 /// Retrieves the motion mappings for the given device. 108 /// Retrieves the motion mappings for the given device.
106 [[nodiscard]] MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& device) const; 109 [[nodiscard]] MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& device) const;
107 110
108 /// Reloads the input devices 111 /// Returns a string contaning the name of the button from the input engine.
112 [[nodiscard]] std::string GetButtonName(const Common::ParamPackage& params) const;
113
114 /// Returns true if device is a controller.
115 [[nodiscard]] bool IsController(const Common::ParamPackage& params) const;
116
117 /// Reloads the input devices.
109 void ReloadInputDevices(); 118 void ReloadInputDevices();
110 119
111 /// Get all DevicePoller from all backends for a specific device type 120 /// Start polling from all backends for a desired input type.
112 [[nodiscard]] std::vector<std::unique_ptr<Polling::DevicePoller>> GetPollers( 121 void BeginMapping(Polling::InputType type);
113 Polling::DeviceType type) const; 122
123 /// Returns an input event with mapping information.
124 [[nodiscard]] const Common::ParamPackage GetNextInput() const;
125
126 /// Stop polling from all backends.
127 void StopMapping() const;
114 128
115private: 129private:
116 struct Impl; 130 struct Impl;
117 std::unique_ptr<Impl> impl; 131 std::unique_ptr<Impl> impl;
118}; 132};
119 133
120/// Generates a serialized param package for creating a keyboard button device 134/// Generates a serialized param package for creating a keyboard button device.
121std::string GenerateKeyboardParam(int key_code); 135std::string GenerateKeyboardParam(int key_code);
122 136
123/// Generates a serialized param package for creating an analog device taking input from keyboard 137/// Generates a serialized param package for creating an analog device taking input from keyboard.
124std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, 138std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right,
125 int key_modifier, float modifier_scale); 139 int key_modifier, float modifier_scale);
126
127} // namespace InputCommon 140} // namespace InputCommon