EventDispatcher.h 3.3 KB

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