Buttons.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef BUTTONS_H
  2. #define BUTTONS_H
  3. #include "input/Button.h"
  4. #include "rendering/Window.h"
  5. #include "utils/Array.h"
  6. #include "utils/ArrayList.h"
  7. typedef ArrayList<Button, 32> ButtonList;
  8. typedef ArrayList<Button, 1 + GLFW_MOUSE_BUTTON_LAST> MouseList;
  9. class Buttons final {
  10. typedef Array<bool, 32> DownArray;
  11. const Window& window;
  12. Button dummy;
  13. int activeController;
  14. ButtonList buttons;
  15. MouseList mouseButtons;
  16. double lastMouseX;
  17. double lastMouseY;
  18. double mouseX;
  19. double mouseY;
  20. struct Axis {
  21. float less;
  22. float greater;
  23. int lessIndex;
  24. int greaterIndex;
  25. Axis();
  26. };
  27. Array<Axis, 1 + GLFW_GAMEPAD_AXIS_LAST> gamepadAxisToButton;
  28. Array<int, 1 + GLFW_GAMEPAD_BUTTON_LAST> gamepadToButton;
  29. public:
  30. Buttons(const Window& window);
  31. Button& add(int key, const char* name);
  32. Button& addMouse(int mouse, const char* name);
  33. void mapGamepadButton(const Button& button, int mapping);
  34. void mapGamepadAxis(const Button& button, float value, int index);
  35. void tick();
  36. const ButtonList& get() const;
  37. const MouseList& getMouse() const;
  38. double getLastMouseX() const;
  39. double getLastMouseY() const;
  40. double getMouseX() const;
  41. double getMouseY() const;
  42. private:
  43. bool searchForGamepad();
  44. void checkGamepad(DownArray& down);
  45. int searchButton(const Button& button) const;
  46. };
  47. #endif