2
0

BsRawInputHandler.h 2.2 KB

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