| 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_SDL_JOYSTICK_MODULE_H |
| 22 | #define LOVE_JOYSTICK_SDL_JOYSTICK_MODULE_H |
| 23 | |
| 24 | // LOVE |
| 25 | #include "joystick/JoystickModule.h" |
| 26 | |
| 27 | // C++ |
| 28 | #include <string> |
| 29 | #include <vector> |
| 30 | #include <list> |
| 31 | #include <map> |
| 32 | |
| 33 | namespace love |
| 34 | { |
| 35 | namespace joystick |
| 36 | { |
| 37 | namespace sdl |
| 38 | { |
| 39 | |
| 40 | class JoystickModule : public love::joystick::JoystickModule |
| 41 | { |
| 42 | public: |
| 43 | |
| 44 | JoystickModule(); |
| 45 | virtual ~JoystickModule(); |
| 46 | |
| 47 | // Implements Module. |
| 48 | const char *getName() const override; |
| 49 | |
| 50 | // Implements JoystickModule. |
| 51 | love::joystick::Joystick *addJoystick(int deviceindex) override; |
| 52 | void removeJoystick(love::joystick::Joystick *joystick) override; |
| 53 | love::joystick::Joystick *getJoystickFromID(int instanceid) override; |
| 54 | love::joystick::Joystick *getJoystick(int joyindex) override; |
| 55 | int getIndex(const love::joystick::Joystick *joystick) override; |
| 56 | int getJoystickCount() const override; |
| 57 | |
| 58 | bool setGamepadMapping(const std::string &guid, Joystick::GamepadInput gpinput, Joystick::JoystickInput joyinput) override; |
| 59 | void loadGamepadMappings(const std::string &mappings) override; |
| 60 | |
| 61 | std::string getGamepadMappingString(const std::string &guid) const override; |
| 62 | std::string saveGamepadMappings() override; |
| 63 | |
| 64 | private: |
| 65 | |
| 66 | std::string stringFromGamepadInput(Joystick::GamepadInput gpinput) const; |
| 67 | void removeBindFromMapString(std::string &mapstr, const std::string &joybindstr) const; |
| 68 | |
| 69 | void checkGamepads(const std::string &guid) const; |
| 70 | |
| 71 | // SDL2's GUIDs identify *classes* of devices, instead of unique devices. |
| 72 | std::string getDeviceGUID(int deviceindex) const; |
| 73 | |
| 74 | // Lists of currently connected Joysticks. |
| 75 | std::vector<Joystick *> activeSticks; |
| 76 | |
| 77 | // Persistent list of all Joysticks which have been connected at some point. |
| 78 | std::list<Joystick *> joysticks; |
| 79 | |
| 80 | // Persistent map indicating GUIDs for Gamepads which have been connected or |
| 81 | // modified at some point. |
| 82 | std::map<std::string, bool> recentGamepadGUIDs; |
| 83 | |
| 84 | }; // JoystickModule |
| 85 | |
| 86 | } // sdl |
| 87 | } // joystick |
| 88 | } // love |
| 89 | |
| 90 | #endif // LOVE_JOYSTICK_SDL_JOYSTICK_MODULE_H |
| 91 | |