Input.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 "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. ~Input();
  21. /// @name Acessors
  22. /// @{
  23. U32 getKey(U32 i) const
  24. {
  25. return keys[i];
  26. }
  27. U32 getMouseButton(U32 i) const
  28. {
  29. return mouseBtns[i];
  30. }
  31. const Vec2& getMousePosition() const
  32. {
  33. return mousePosNdc;
  34. }
  35. /// @}
  36. void init(NativeWindow* nativeWindow);
  37. void reset();
  38. void handleEvents();
  39. void moveMouse(const Vec2& posNdc);
  40. void hideCursor(Bool hide);
  41. private:
  42. NativeWindow* nativeWindow = nullptr;
  43. /// @name Keys and btns
  44. /// @{
  45. /// Shows the current key state
  46. /// - 0 times: unpressed
  47. /// - 1 times: pressed once
  48. /// - >1 times: Kept pressed 'n' times continuously
  49. Array<U32, KC_COUNT> keys;
  50. /// Mouse btns. Supporting 3 btns & wheel. @see keys
  51. Array<U32, 8> mouseBtns;
  52. /// @}
  53. Vec2 mousePosNdc; ///< The coords are in the NDC space
  54. Array<U16, 256> nativeKeyToAnki;
  55. std::shared_ptr<InputImpl> impl;
  56. };
  57. typedef Singleton<Input> InputSingleton;
  58. } // end namespace anki
  59. #endif