EventDispatcher.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * EventDispatcher.h, 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. #pragma once
  11. VCMI_LIB_NAMESPACE_BEGIN
  12. class Point;
  13. VCMI_LIB_NAMESPACE_END
  14. class AEventsReceiver;
  15. enum class MouseButton;
  16. enum class EShortcut;
  17. /// Class that receives events from event producers and dispatches it to UI elements that are interested in this event
  18. class EventDispatcher
  19. {
  20. using EventReceiversList = std::list<AEventsReceiver *>;
  21. /// list of UI elements that are interested in particular event
  22. EventReceiversList lclickable;
  23. EventReceiversList rclickable;
  24. EventReceiversList hoverable;
  25. EventReceiversList keyinterested;
  26. EventReceiversList motioninterested;
  27. EventReceiversList timeinterested;
  28. EventReceiversList wheelInterested;
  29. EventReceiversList doubleClickInterested;
  30. EventReceiversList textInterested;
  31. EventReceiversList panningInterested;
  32. void handleLeftButtonClick(bool isPressed);
  33. template<typename Functor>
  34. void processLists(ui16 activityFlag, const Functor & cb);
  35. public:
  36. /// add specified UI element as interested. Uses unnamed enum from AEventsReceiver for activity flags
  37. void activateElement(AEventsReceiver * elem, ui16 activityFlag);
  38. /// removes specified UI element as interested for specified activities
  39. void deactivateElement(AEventsReceiver * elem, ui16 activityFlag);
  40. /// Regular timer event
  41. void dispatchTimer(uint32_t msPassed);
  42. /// Shortcut events (e.g. keyboard keys)
  43. void dispatchShortcutPressed(const std::vector<EShortcut> & shortcuts);
  44. void dispatchShortcutReleased(const std::vector<EShortcut> & shortcuts);
  45. /// Mouse events
  46. void dispatchMouseLeftButtonPressed(const Point & position);
  47. void dispatchMouseLeftButtonReleased(const Point & position);
  48. void dispatchMouseScrolled(const Point & distance, const Point & position);
  49. void dispatchMouseDoubleClick(const Point & position);
  50. void dispatchMouseMoved(const Point & distance);
  51. void dispatchShowPopup(const Point & position);
  52. void dispatchClosePopup(const Point & position);
  53. void dispatchGesturePanningStarted(const Point & initialPosition);
  54. void dispatchGesturePanningEnded(const Point & initialPosition, const Point & finalPosition);
  55. void dispatchGesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance);
  56. void dispatchGesturePinch(const Point & initialPosition, double distance);
  57. /// Text input events
  58. void dispatchTextInput(const std::string & text);
  59. void dispatchTextEditing(const std::string & text);
  60. };