Buttons.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef BUTTONS_H
  2. #define BUTTONS_H
  3. #include <GL/glew.h>
  4. #include <GLFW/glfw3.h>
  5. #include "input/Button.h"
  6. #include "utils/Array.h"
  7. #include "utils/ArrayList.h"
  8. #include "utils/HashMap.h"
  9. class Buttons final {
  10. friend class Window;
  11. HashMap<int, Button*> buttons;
  12. HashMap<int, Button*> mouseButtons;
  13. double lastMouseX;
  14. double lastMouseY;
  15. double mouseX;
  16. double mouseY;
  17. int activeController;
  18. struct Axis {
  19. float less;
  20. float greater;
  21. Button* lessButton;
  22. Button* greaterButton;
  23. Axis();
  24. };
  25. Array<Axis, 1 + GLFW_GAMEPAD_AXIS_LAST> gamepadAxisToButton;
  26. Array<Button*, 1 + GLFW_GAMEPAD_BUTTON_LAST> gamepadToButton;
  27. public:
  28. Buttons();
  29. void add(Button& button);
  30. void addMouse(Button& button);
  31. void mapGamepadButton(Button& button, int mapping);
  32. void mapGamepadAxis(Button& button, float value, int index);
  33. void tick();
  34. double getLastMouseX() const;
  35. double getLastMouseY() const;
  36. double getMouseX() const;
  37. double getMouseY() const;
  38. private:
  39. void onButton(HashMap<int, Button*>& map, int key, int action);
  40. void onKey(int key, int scancode, int action, int mods);
  41. void onMouse(int button, int action, int mods);
  42. void onMouseMove(double x, double y);
  43. bool searchForGamepad();
  44. void checkGamepad();
  45. };
  46. #endif