BsRawInputHandler.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. RawAxisState()
  16. :rel(0.0f), abs(0.0f)
  17. { }
  18. float rel;
  19. float abs;
  20. };
  21. /**
  22. * @brief Represents a specific way of acquiring low-level input. InputManager (which provides a higher level input)
  23. * must have at least one RawInputHandler attached. Raw input handlers receive input as sent by the hardware
  24. * without OS modifications.
  25. *
  26. * Attach events handler to the provided signals to handle input.
  27. */
  28. class BS_CORE_EXPORT RawInputHandler
  29. {
  30. public:
  31. RawInputHandler()
  32. :mMouseSmoothingEnabled(false)
  33. {}
  34. virtual ~RawInputHandler() {}
  35. /**
  36. * @brief Triggered when user presses a button. Parameters
  37. * include device index, button code of the pressed button,
  38. * and a timestamp of the button press event.
  39. */
  40. Event<void(UINT32, ButtonCode, UINT64)> onButtonDown;
  41. /**
  42. * @brief Triggered when user releases a button. Parameters
  43. * include device index, button code of the released button,
  44. * and a timestamp of the button release event.
  45. */
  46. Event<void(UINT32, ButtonCode, UINT64)> onButtonUp;
  47. /**
  48. * @brief Triggered whenever the specified axis state changes.
  49. * Parameters include device index, axis state data, and axis type.
  50. */
  51. Event<void(UINT32, const RawAxisState&, UINT32)> onAxisMoved;
  52. /**
  53. * @brief Called once per frame. Capture input here if needed.
  54. *
  55. * @note Internal method.
  56. */
  57. virtual void _update() {}
  58. /**
  59. * @brief Called whenever the active window changes.
  60. *
  61. * @param win Newly active window.
  62. *
  63. * @note Internal method.
  64. */
  65. virtual void _inputWindowChanged(const RenderWindow& win) {}
  66. /**
  67. * @brief Enables or disables mouse smoothing. Smoothing makes the changes to
  68. * mouse axes more gradual.
  69. */
  70. void setMouseSmoothing(bool enabled) { mMouseSmoothingEnabled = enabled; }
  71. protected:
  72. bool mMouseSmoothingEnabled;
  73. };
  74. }