1 | /** |
2 | * Copyright (c) 2006-2023 LOVE Development Team |
3 | * |
4 | * This software is provided 'as-is', without any express or implied |
5 | * warranty. In no event will the authors be held liable for any damages |
6 | * arising from the use of this software. |
7 | * |
8 | * Permission is granted to anyone to use this software for any purpose, |
9 | * including commercial applications, and to alter it and redistribute it |
10 | * freely, subject to the following restrictions: |
11 | * |
12 | * 1. The origin of this software must not be misrepresented; you must not |
13 | * claim that you wrote the original software. If you use this software |
14 | * in a product, an acknowledgment in the product documentation would be |
15 | * appreciated but is not required. |
16 | * 2. Altered source versions must be plainly marked as such, and must not be |
17 | * misrepresented as being the original software. |
18 | * 3. This notice may not be removed or altered from any source distribution. |
19 | **/ |
20 | |
21 | #ifndef LOVE_JOYSTICK_JOYSTICK_MODULE_H |
22 | #define LOVE_JOYSTICK_JOYSTICK_MODULE_H |
23 | |
24 | // LOVE |
25 | #include "common/Module.h" |
26 | #include "Joystick.h" |
27 | |
28 | namespace love |
29 | { |
30 | namespace joystick |
31 | { |
32 | |
33 | class JoystickModule : public Module |
34 | { |
35 | public: |
36 | |
37 | virtual ~JoystickModule() {} |
38 | |
39 | // Implements Module. |
40 | ModuleType getModuleType() const override { return M_JOYSTICK; } |
41 | |
42 | /** |
43 | * Adds a connected Joystick device and opens it for use. |
44 | * Returns NULL if the Joystick could not be added. |
45 | **/ |
46 | virtual Joystick *addJoystick(int deviceindex) = 0; |
47 | |
48 | /** |
49 | * Removes a disconnected Joystick device. |
50 | **/ |
51 | virtual void removeJoystick(Joystick *joystick) = 0; |
52 | |
53 | /** |
54 | * Gets a connected Joystick from its unique Instance ID. |
55 | * Returns NULL if the instance ID does not correspond to a connected stick. |
56 | **/ |
57 | virtual Joystick *getJoystickFromID(int instanceid) = 0; |
58 | |
59 | /** |
60 | * Gets a connected Joystick. |
61 | * Returns NULL if joyindex is not in the range of [0, getJoystickCount()). |
62 | **/ |
63 | virtual Joystick *getJoystick(int joyindex) = 0; |
64 | |
65 | /** |
66 | * Gets the index of a connected joystick. |
67 | * Returns -1 if the joystick is not connected. |
68 | **/ |
69 | virtual int getIndex(const Joystick *joystick) = 0; |
70 | |
71 | /** |
72 | * Gets the number of currently connected Joysticks. |
73 | **/ |
74 | virtual int getJoystickCount() const = 0; |
75 | |
76 | /** |
77 | * Sets the virtual Gamepad mapping for a joystick input value for all |
78 | * joystick devices with the specified joystick product GUID. |
79 | * If any joysticks with the specified GUID are connected, they will be |
80 | * added as Gamepads if they aren't already, otherwise their Gamepad mapping |
81 | * will be updated. |
82 | **/ |
83 | virtual bool setGamepadMapping(const std::string &pguid, Joystick::GamepadInput gpinput, Joystick::JoystickInput joyinput) = 0; |
84 | |
85 | /** |
86 | * Loads a newline-separated list of virtual Gamepad mapping strings for |
87 | * multiple joysticks at a time. The mapping strings must have been |
88 | * generated with saveGamepadMappings, via Steam, or some other tool which |
89 | * generates SDL GameController mappings. |
90 | **/ |
91 | virtual void loadGamepadMappings(const std::string &mappings) = 0; |
92 | |
93 | /** |
94 | * Gets a newline-separated list of virtual Gamepad mapping strings for |
95 | * all used or modified Joysticks which are identified as Gamepads. |
96 | **/ |
97 | virtual std::string saveGamepadMappings() = 0; |
98 | |
99 | /** |
100 | * Gets the gamepad mapping string for the given GUID. |
101 | **/ |
102 | virtual std::string getGamepadMappingString(const std::string &guid) const = 0; |
103 | |
104 | }; // JoystickModule |
105 | |
106 | } // joystick |
107 | } // love |
108 | |
109 | #endif // LOVE_JOYSTICK_JOYSTICK_MODULE_H |
110 | |