EventDispatcher.h 3.2 KB

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