JoystickModule.h 2.8 KB

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