Input.h 1.2 KB

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