Input.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef ANKI_INPUT_INPUT_H
  2. #define ANKI_INPUT_INPUT_H
  3. #include "anki/Math.h"
  4. #include "anki/util/Singleton.h"
  5. #include "anki/util/Array.h"
  6. #include "anki/util/StdTypes.h"
  7. #include "anki/input/KeyCode.h"
  8. #include <memory>
  9. namespace anki {
  10. struct InputImpl;
  11. class NativeWindow;
  12. /// Handle the input and other events
  13. ///
  14. /// @note All positions are in NDC space
  15. class Input
  16. {
  17. public:
  18. Input()
  19. {
  20. reset();
  21. }
  22. ~Input();
  23. /// @name Acessors
  24. /// @{
  25. U32 getKey(U32 i) const
  26. {
  27. return keys[i];
  28. }
  29. U32 getMouseButton(U32 i) const
  30. {
  31. return mouseBtns[i];
  32. }
  33. const Vec2& getMousePosition() const
  34. {
  35. return mousePosNdc;
  36. }
  37. /// @}
  38. void init(NativeWindow* nativeWindow);
  39. void reset();
  40. void handleEvents();
  41. void moveMouse(const Vec2& posNdc);
  42. void hideCursor(Bool hide);
  43. private:
  44. NativeWindow* nativeWindow = nullptr;
  45. /// @name Keys and btns
  46. /// @{
  47. /// Shows the current key state
  48. /// - 0 times: unpressed
  49. /// - 1 times: pressed once
  50. /// - >1 times: Kept pressed 'n' times continuously
  51. Array<U32, KC_COUNT> keys;
  52. /// Mouse btns. Supporting 3 btns & wheel. @see keys
  53. Array<U32, 8> mouseBtns;
  54. /// @}
  55. Vec2 mousePosNdc; ///< The coords are in the NDC space
  56. Array<U16, 256> nativeKeyToAnki;
  57. std::shared_ptr<InputImpl> impl;
  58. };
  59. typedef Singleton<Input> InputSingleton;
  60. } // end namespace anki
  61. #endif