EventsReceiver.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * EventsReceiver.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "EventsReceiver.h"
  12. #include "MouseButton.h"
  13. #include "CGuiHandler.h"
  14. #include "EventDispatcher.h"
  15. AEventsReceiver::AEventsReceiver()
  16. : activeState(0)
  17. , hoveredState(false)
  18. , panningState(false)
  19. , mouseClickedState(false)
  20. {
  21. }
  22. bool AEventsReceiver::isHovered() const
  23. {
  24. return hoveredState;
  25. }
  26. bool AEventsReceiver::isPanning() const
  27. {
  28. return panningState;
  29. }
  30. bool AEventsReceiver::isActive() const
  31. {
  32. return activeState;
  33. }
  34. bool AEventsReceiver::isMouseLeftButtonPressed() const
  35. {
  36. return mouseClickedState;
  37. }
  38. void AEventsReceiver::activateEvents(ui16 what)
  39. {
  40. assert((what & GENERAL) || (activeState & GENERAL));
  41. activeState |= GENERAL;
  42. GH.events().activateElement(this, what);
  43. }
  44. void AEventsReceiver::deactivateEvents(ui16 what)
  45. {
  46. if (what & GENERAL)
  47. {
  48. assert((what & activeState) == activeState);
  49. activeState &= ~GENERAL;
  50. // sanity check to avoid unexpected behavior if assertion above fails (e.g. in release)
  51. // if element is deactivated (has GENERAL flag) then all existing active events should also be deactivated
  52. what = activeState;
  53. }
  54. GH.events().deactivateElement(this, what & activeState);
  55. }