InputSourceGameController.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * InputSourceGameController.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include <SDL.h>
  12. #include "../gui/Shortcut.h"
  13. const int AXIS_DEAD_ZOOM = 6000;
  14. const int AXIS_MAX_ZOOM = 32000;
  15. const int AXIS_MOVE_SPEED = 500;
  16. const int AXIS_CURSOR_MOVE_INTERVAL = 1000;
  17. const int TRIGGER_PRESS_THRESHOLD = 8000;
  18. /// Class that handles game controller input from SDL events
  19. class InputSourceGameController
  20. {
  21. static void gameControllerDeleter(SDL_GameController * gameController);
  22. using GameControllerPtr = std::unique_ptr<SDL_GameController, decltype(&gameControllerDeleter)>;
  23. std::map<int, GameControllerPtr> gameControllerMap;
  24. long long lastCheckTime;
  25. int axisValueX;
  26. int axisValueY;
  27. float planDisX;
  28. float planDisY;
  29. void openGameController(int index);
  30. int getJoystickIndex(SDL_GameController * controller);
  31. int getRealAxisValue(int value);
  32. void dispatchTriggerShortcuts(const std::vector<EShortcut> & shortcutsVector, int axisValue);
  33. void doCursorMove(int deltaX, int deltaY);
  34. int getMoveDis(float planDis);
  35. public:
  36. InputSourceGameController();
  37. void tryOpenAllGameControllers();
  38. void handleEventDeviceAdded(const SDL_ControllerDeviceEvent & device);
  39. void handleEventDeviceRemoved(const SDL_ControllerDeviceEvent & device);
  40. void handleEventDeviceRemapped(const SDL_ControllerDeviceEvent & device);
  41. void handleEventAxisMotion(const SDL_ControllerAxisEvent & axis);
  42. void handleEventButtonDown(const SDL_ControllerButtonEvent & button);
  43. void handleEventButtonUp(const SDL_ControllerButtonEvent & button);
  44. void handleUpdate();
  45. };