2
0

Controls.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Core/Variant.h"
  5. namespace Urho3D
  6. {
  7. /// %Controls sent over the network.
  8. class URHO3D_API Controls
  9. {
  10. public:
  11. /// Construct.
  12. Controls();
  13. /// Destruct.
  14. ~Controls();
  15. /// Reset to initial state.
  16. void Reset();
  17. /// Set or release buttons.
  18. void Set(unsigned buttons, bool down = true)
  19. {
  20. if (down)
  21. buttons_ |= buttons;
  22. else
  23. buttons_ &= ~buttons;
  24. }
  25. /// Check if a button is held down.
  26. bool IsDown(unsigned button) const
  27. {
  28. return (buttons_ & button) != 0;
  29. }
  30. /// Check if a button was pressed on this frame. Requires previous frame's controls.
  31. bool IsPressed(unsigned button, const Controls& previousControls) const
  32. {
  33. return (buttons_ & button) != 0 && (previousControls.buttons_ & button) == 0;
  34. }
  35. /// Button state.
  36. unsigned buttons_;
  37. /// Mouse yaw.
  38. float yaw_;
  39. /// Mouse pitch.
  40. float pitch_;
  41. /// Extra control data.
  42. VariantMap extraData_;
  43. };
  44. }