BsRawInputHandler.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsInputFwd.h"
  4. #include "BsEvent.h"
  5. namespace BansheeEngine
  6. {
  7. /** @cond INTERNAL */
  8. /** @addtogroup Input
  9. * @{
  10. */
  11. /**
  12. * Contains relative and absolute position of an input axis. Relative state represents the difference between current
  13. * and last state.
  14. */
  15. struct RawAxisState
  16. {
  17. RawAxisState()
  18. :rel(0.0f), abs(0.0f)
  19. { }
  20. float rel;
  21. float abs;
  22. };
  23. /**
  24. * Represents a specific way of acquiring low-level input. Input class (which provides a higher level input) must have
  25. * at least one RawInputHandler attached. Raw input handlers receive input as sent by the hardware without OS
  26. * modifications.
  27. */
  28. class BS_CORE_EXPORT RawInputHandler
  29. {
  30. public:
  31. RawInputHandler()
  32. :mMouseSmoothingEnabled(false)
  33. {}
  34. virtual ~RawInputHandler() {}
  35. /**
  36. * Triggered when user presses a button. Parameters include device index, button code of the pressed button,
  37. * and a timestamp of the button press event.
  38. */
  39. Event<void(UINT32, ButtonCode, UINT64)> onButtonDown;
  40. /**
  41. * Triggered when user releases a button. Parameters include device index, button code of the released button,
  42. * and a timestamp of the button release event.
  43. */
  44. Event<void(UINT32, ButtonCode, UINT64)> onButtonUp;
  45. /**
  46. * Triggered whenever the specified axis state changes. Parameters include device index, axis state data, and axis
  47. * type.
  48. */
  49. Event<void(UINT32, const RawAxisState&, UINT32)> onAxisMoved;
  50. /**
  51. * Called once per frame. Capture input here if needed.
  52. *
  53. * @note Internal method.
  54. */
  55. virtual void _update() {}
  56. /**
  57. * Called whenever the active window changes.
  58. *
  59. * @param[in] win Newly active window.
  60. *
  61. * @note Internal method.
  62. */
  63. virtual void _inputWindowChanged(const RenderWindow& win) {}
  64. /** Enables or disables mouse smoothing. Smoothing makes the changes to mouse axes more gradual. */
  65. void setMouseSmoothing(bool enabled) { mMouseSmoothingEnabled = enabled; }
  66. protected:
  67. bool mMouseSmoothingEnabled;
  68. };
  69. /** @} */
  70. /** @endcond */
  71. }