EventDispatcher.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 draginterested;
  28. EventReceiversList timeinterested;
  29. EventReceiversList wheelInterested;
  30. EventReceiversList doubleClickInterested;
  31. EventReceiversList textInterested;
  32. EventReceiversList panningInterested;
  33. void handleLeftButtonClick(const Point & position, int tolerance, bool isPressed);
  34. AEventsReceiver * findElementInToleranceRange(const EventReceiversList & list, const Point & position, int eventToTest, int tolerance);
  35. template<typename Functor>
  36. void processLists(ui16 activityFlag, const Functor & cb);
  37. public:
  38. /// add specified UI element as interested. Uses unnamed enum from AEventsReceiver for activity flags
  39. void activateElement(AEventsReceiver * elem, ui16 activityFlag);
  40. /// removes specified UI element as interested for specified activities
  41. void deactivateElement(AEventsReceiver * elem, ui16 activityFlag);
  42. /// Regular timer event
  43. void dispatchTimer(uint32_t msPassed);
  44. /// Shortcut events (e.g. keyboard keys)
  45. void dispatchShortcutPressed(const std::vector<EShortcut> & shortcuts);
  46. void dispatchShortcutReleased(const std::vector<EShortcut> & shortcuts);
  47. /// Mouse events
  48. void dispatchMouseLeftButtonPressed(const Point & position, int tolerance);
  49. void dispatchMouseLeftButtonReleased(const Point & position, int tolerance);
  50. void dispatchMouseScrolled(const Point & distance, const Point & position);
  51. void dispatchMouseDoubleClick(const Point & position);
  52. void dispatchMouseMoved(const Point & distance, const Point & position);
  53. void dispatchMouseDragged(const Point & currentPosition, const Point & lastUpdateDistance);
  54. void dispatchShowPopup(const Point & position, int tolerance);
  55. void dispatchClosePopup(const Point & position);
  56. void dispatchGesturePanningStarted(const Point & initialPosition);
  57. void dispatchGesturePanningEnded(const Point & initialPosition, const Point & finalPosition);
  58. void dispatchGesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance);
  59. void dispatchGesturePinch(const Point & initialPosition, double distance);
  60. /// Text input events
  61. void dispatchTextInput(const std::string & text);
  62. void dispatchTextEditing(const std::string & text);
  63. };