BsRawInputHandler.h 2.3 KB

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