Buttons.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef BUTTONS_H
  2. #define BUTTONS_H
  3. #include "input/Button.h"
  4. #include "utils/Array.h"
  5. #include "utils/ArrayList.h"
  6. #include "rendering/Window.h"
  7. typedef ArrayList<Button, 32> ButtonList;
  8. class Buttons final {
  9. typedef Array<bool, 32> DownArray;
  10. const Window& window;
  11. Button dummy;
  12. int activeController;
  13. ButtonList buttons;
  14. struct Axis {
  15. float less;
  16. float greater;
  17. int lessIndex;
  18. int greaterIndex;
  19. Axis();
  20. };
  21. Array<int, 1 + GLFW_GAMEPAD_BUTTON_LAST> gamepadToButton;
  22. Array<Axis, 1 + GLFW_GAMEPAD_AXIS_LAST> gamepadAxisToButton;
  23. public:
  24. Buttons(const Window& window);
  25. Button& add(int key, const char* name);
  26. void mapGamepadButton(const Button& button, int mapping);
  27. void mapGamepadAxis(const Button& button, float value, int index);
  28. void tick();
  29. const ButtonList& get() const;
  30. private:
  31. bool searchForGamepad();
  32. void checkGamepad(DownArray& down);
  33. int searchButton(const Button& button) const;
  34. };
  35. #endif