Controller.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef CONTROLLER_H
  2. #define CONTROLLER_H
  3. #include <GL/glew.h>
  4. #include <GLFW/glfw3.h>
  5. #include "utils/Array.h"
  6. #include "input/Button.h"
  7. class Controller final {
  8. static constexpr int BUTTON_AMOUNT = 13;
  9. Array<Button, BUTTON_AMOUNT> buttons;
  10. Array<int, 1 + GLFW_KEY_LAST> keyToButton;
  11. Array<int, 1 + GLFW_JOYSTICK_LAST> gamepadToButton;
  12. struct Axis {
  13. int positive;
  14. int negative;
  15. Axis();
  16. };
  17. Array<Axis, 1 + GLFW_GAMEPAD_AXIS_LAST> axisToButton;
  18. public:
  19. static constexpr int A = 0;
  20. static constexpr int B = 1;
  21. static constexpr int X = 2;
  22. static constexpr int Y = 3;
  23. static constexpr int L = 4;
  24. static constexpr int R = 5;
  25. static constexpr int START = 6;
  26. static constexpr int SELECT = 7;
  27. static constexpr int LEFT = 8;
  28. static constexpr int RIGHT = 9;
  29. static constexpr int UP = 10;
  30. static constexpr int DOWN = 11;
  31. Controller();
  32. bool mapKey(int key, int button);
  33. bool mapGamepad(int gamepad, int button);
  34. bool mapAxis(int axis, int positiveButton, int negativeButton);
  35. void press(int key);
  36. void release(int key);
  37. void tick();
  38. int getButtonAmount() const;
  39. const char* getName(int button) const;
  40. bool isDown(int button) const;
  41. int getDownTime(int button) const;
  42. bool isUp(int button) const;
  43. int getUpTime(int button) const;
  44. private:
  45. int getRangeMask(int button) const;
  46. };
  47. #endif