BsRawInputHandler.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #pragma once
  5. #include "BsCorePrerequisites.h"
  6. #include "BsInputFwd.h"
  7. #include "BsEvent.h"
  8. #include "BsVector2I.h"
  9. namespace BansheeEngine
  10. {
  11. /**
  12. * @brief Contains relative and absolute position
  13. * of an input axis. Relative state represents
  14. * the difference between current 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. * @brief Represents a specific way of acquiring low-level input. InputManager (which provides a higher level input)
  26. * must have at least one RawInputHandler attached. Raw input handlers receive input as sent by the hardware
  27. * without OS modifications.
  28. *
  29. * Attach events handler to the provided signals to handle input.
  30. */
  31. class BS_CORE_EXPORT RawInputHandler
  32. {
  33. public:
  34. RawInputHandler()
  35. :mMouseSmoothingEnabled(false)
  36. {}
  37. virtual ~RawInputHandler() {}
  38. /**
  39. * @brief Triggered when user presses a button. Parameters
  40. * include device index, button code of the pressed button,
  41. * and a timestamp of the button press event.
  42. */
  43. Event<void(UINT32, ButtonCode, UINT64)> onButtonDown;
  44. /**
  45. * @brief Triggered when user releases a button. Parameters
  46. * include device index, button code of the released button,
  47. * and a timestamp of the button release event.
  48. */
  49. Event<void(UINT32, ButtonCode, UINT64)> onButtonUp;
  50. /**
  51. * @brief Triggered whenever the specified axis state changes.
  52. * Parameters include device index, axis state data, and axis type.
  53. */
  54. Event<void(UINT32, const RawAxisState&, UINT32)> onAxisMoved;
  55. /**
  56. * @brief Called once per frame. Capture input here if needed.
  57. *
  58. * @note Internal method.
  59. */
  60. virtual void _update() {}
  61. /**
  62. * @brief Called whenever the active window changes.
  63. *
  64. * @param win Newly active window.
  65. *
  66. * @note Internal method.
  67. */
  68. virtual void _inputWindowChanged(const RenderWindow& win) {}
  69. /**
  70. * @brief Enables or disables mouse smoothing. Smoothing makes the changes to
  71. * mouse axes more gradual.
  72. */
  73. void setMouseSmoothing(bool enabled) { mMouseSmoothingEnabled = enabled; }
  74. protected:
  75. bool mMouseSmoothingEnabled;
  76. };
  77. }