Input.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef ANKI_INPUT_INPUT_H
  2. #define ANKI_INPUT_INPUT_H
  3. #include "anki/math/Math.h"
  4. #include "anki/util/Singleton.h"
  5. #include <SDL/SDL_scancode.h>
  6. #include <array>
  7. namespace anki {
  8. /// Handle the SDL input
  9. class Input
  10. {
  11. public:
  12. Input()
  13. {
  14. init();
  15. }
  16. /// @name Acessors
  17. /// @{
  18. short getKey(uint32_t i) const
  19. {
  20. return keys[i];
  21. }
  22. short getMouseBtn(uint32_t i) const
  23. {
  24. return mouseBtns[i];
  25. }
  26. bool getWarpMouse() const
  27. {
  28. return warpMouseFlag;
  29. }
  30. bool& getWarpMouse()
  31. {
  32. return warpMouseFlag;
  33. }
  34. void setWarpMouse(const bool x)
  35. {
  36. warpMouseFlag = x;
  37. }
  38. /// @}
  39. void reset();
  40. void handleEvents();
  41. private:
  42. /// @name Keys and btns
  43. /// @{
  44. /// Shows the current key state
  45. /// - 0 times: unpressed
  46. /// - 1 times: pressed once
  47. /// - >1 times: Kept pressed 'n' times continuously
  48. std::array<short, SDL_NUM_SCANCODES> keys;
  49. /// Mouse btns. Supporting 3 btns & wheel. @see keys
  50. std::array<short, 8> mouseBtns;
  51. /// @}
  52. bool warpMouseFlag;
  53. // mouse stuff
  54. Vec2 mousePosNdc; ///< The coords are in the NDC space
  55. /// The coords are in the window space. (0, 0) is in the upper left
  56. /// corner
  57. Vec2 mousePos;
  58. Vec2 mouseVelocity;
  59. bool hideCursor;
  60. void init();
  61. };
  62. typedef Singleton<Input> InputSingleton;
  63. } // end namespace
  64. #endif