BsRawInputHandler.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsInputFwd.h"
  4. #include "BsEvent.h"
  5. #include "BsVector2I.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Contains relative and absolute position
  10. * of an input axis. Relative state represents
  11. * the difference between current and last state.
  12. */
  13. struct RawAxisState
  14. {
  15. Vector2I rel;
  16. Vector2I abs;
  17. };
  18. /**
  19. * @brief Different types of input axes.
  20. */
  21. enum class RawInputAxis
  22. {
  23. Mouse_XY,
  24. Mouse_Z,
  25. Joy_1,
  26. Joy_2,
  27. Joy_3,
  28. Joy_4,
  29. Joy_5,
  30. Joy_6,
  31. Joy_7,
  32. Joy_8,
  33. Joy_9,
  34. Joy_10,
  35. Joy_11,
  36. Joy_12,
  37. Joy_13,
  38. Joy_14,
  39. Joy_15,
  40. Joy_16,
  41. Count
  42. };
  43. /**
  44. * @brief Represents a specific way of acquiring low-level input. InputManager (which provides a higher level input)
  45. * must have at least one RawInputHandler attached. Raw input handlers receive input as sent by the hardware
  46. * without OS modifications.
  47. *
  48. * Attach events handler to the provided signals to handle input.
  49. */
  50. class BS_CORE_EXPORT RawInputHandler
  51. {
  52. public:
  53. RawInputHandler() {}
  54. virtual ~RawInputHandler() {}
  55. /**
  56. * @brief Triggered when user presses a button. Parameters
  57. * include button code of the pressed button, and a timestamp of
  58. * the button press event.
  59. */
  60. Event<void(ButtonCode, UINT64)> onButtonDown;
  61. /**
  62. * @brief Triggered when user releases a button. Parameters
  63. * include button code of the released button, and a timestamp of
  64. * the button release event.
  65. */
  66. Event<void(ButtonCode, UINT64)> onButtonUp;
  67. /**
  68. * @brief Triggered whenever the specified axis state changes.
  69. */
  70. Event<void(const RawAxisState&, RawInputAxis)> onAxisMoved;
  71. /**
  72. * @brief Called once per frame. Capture input here if needed.
  73. *
  74. * @note Internal method.
  75. */
  76. virtual void _update() {}
  77. /**
  78. * @brief Called whenever the active window changes.
  79. *
  80. * @param win Newly active window.
  81. *
  82. * @note Internal method.
  83. */
  84. virtual void _inputWindowChanged(const RenderWindow& win) {}
  85. };
  86. }