2023-05-17 22:22:45 +02:00
|
|
|
/*
|
2023-05-18 12:31:26 +02:00
|
|
|
* EventDispatcher.h, part of VCMI engine
|
2023-05-17 22:22:45 +02:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
class Point;
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
|
|
|
class AEventsReceiver;
|
|
|
|
enum class MouseButton;
|
|
|
|
enum class EShortcut;
|
2024-07-19 11:41:00 +02:00
|
|
|
enum class InputMode;
|
2023-05-17 22:22:45 +02:00
|
|
|
|
2023-05-18 12:59:09 +02:00
|
|
|
/// Class that receives events from event producers and dispatches it to UI elements that are interested in this event
|
2023-05-18 12:31:26 +02:00
|
|
|
class EventDispatcher
|
2023-05-17 22:22:45 +02:00
|
|
|
{
|
2023-05-20 00:51:10 +02:00
|
|
|
using EventReceiversList = std::list<AEventsReceiver *>;
|
2023-05-17 22:22:45 +02:00
|
|
|
|
2023-05-18 12:59:09 +02:00
|
|
|
/// list of UI elements that are interested in particular event
|
2023-05-20 00:51:10 +02:00
|
|
|
EventReceiversList lclickable;
|
|
|
|
EventReceiversList rclickable;
|
|
|
|
EventReceiversList hoverable;
|
|
|
|
EventReceiversList keyinterested;
|
|
|
|
EventReceiversList motioninterested;
|
2023-06-22 21:11:48 +02:00
|
|
|
EventReceiversList draginterested;
|
2024-08-28 22:17:05 +02:00
|
|
|
EventReceiversList dragPopupInterested;
|
2023-05-20 00:51:10 +02:00
|
|
|
EventReceiversList timeinterested;
|
|
|
|
EventReceiversList wheelInterested;
|
|
|
|
EventReceiversList doubleClickInterested;
|
|
|
|
EventReceiversList textInterested;
|
2023-05-26 20:46:09 +02:00
|
|
|
EventReceiversList panningInterested;
|
2024-07-19 11:41:00 +02:00
|
|
|
EventReceiversList inputModeChangeInterested;
|
2023-05-17 22:22:45 +02:00
|
|
|
|
2023-09-06 00:06:01 +02:00
|
|
|
void handleLeftButtonClick(const Point & position, int tolerance, bool isPressed);
|
2023-09-18 20:35:23 +02:00
|
|
|
void handleDoubleButtonClick(const Point & position, int tolerance);
|
2023-09-06 00:06:01 +02:00
|
|
|
AEventsReceiver * findElementInToleranceRange(const EventReceiversList & list, const Point & position, int eventToTest, int tolerance);
|
2023-05-17 22:22:45 +02:00
|
|
|
|
2023-05-20 00:51:10 +02:00
|
|
|
template<typename Functor>
|
|
|
|
void processLists(ui16 activityFlag, const Functor & cb);
|
2023-05-17 22:22:45 +02:00
|
|
|
|
|
|
|
public:
|
2023-05-18 12:59:09 +02:00
|
|
|
/// add specified UI element as interested. Uses unnamed enum from AEventsReceiver for activity flags
|
2023-05-20 00:51:10 +02:00
|
|
|
void activateElement(AEventsReceiver * elem, ui16 activityFlag);
|
2023-05-18 12:59:09 +02:00
|
|
|
|
|
|
|
/// removes specified UI element as interested for specified activities
|
2023-05-20 00:51:10 +02:00
|
|
|
void deactivateElement(AEventsReceiver * elem, ui16 activityFlag);
|
2023-05-17 22:22:45 +02:00
|
|
|
|
2023-05-18 12:59:09 +02:00
|
|
|
/// Regular timer event
|
2023-05-18 01:09:42 +02:00
|
|
|
void dispatchTimer(uint32_t msPassed);
|
2023-05-17 22:22:45 +02:00
|
|
|
|
2023-05-18 12:59:09 +02:00
|
|
|
/// Shortcut events (e.g. keyboard keys)
|
2023-05-17 22:22:45 +02:00
|
|
|
void dispatchShortcutPressed(const std::vector<EShortcut> & shortcuts);
|
|
|
|
void dispatchShortcutReleased(const std::vector<EShortcut> & shortcuts);
|
|
|
|
|
2023-05-18 12:59:09 +02:00
|
|
|
/// Mouse events
|
2023-09-06 00:06:01 +02:00
|
|
|
void dispatchMouseLeftButtonPressed(const Point & position, int tolerance);
|
|
|
|
void dispatchMouseLeftButtonReleased(const Point & position, int tolerance);
|
2023-05-17 22:22:45 +02:00
|
|
|
void dispatchMouseScrolled(const Point & distance, const Point & position);
|
2023-09-18 20:35:23 +02:00
|
|
|
void dispatchMouseDoubleClick(const Point & position, int tolerance);
|
2023-06-22 21:11:48 +02:00
|
|
|
void dispatchMouseMoved(const Point & distance, const Point & position);
|
|
|
|
|
|
|
|
void dispatchMouseDragged(const Point & currentPosition, const Point & lastUpdateDistance);
|
2024-08-28 22:17:05 +02:00
|
|
|
void dispatchMouseDraggedPopup(const Point & currentPosition, const Point & lastUpdateDistance);
|
2023-05-26 20:46:09 +02:00
|
|
|
|
2023-09-06 00:06:01 +02:00
|
|
|
void dispatchShowPopup(const Point & position, int tolerance);
|
2023-06-11 19:38:42 +02:00
|
|
|
void dispatchClosePopup(const Point & position);
|
|
|
|
|
2023-05-29 12:08:08 +02:00
|
|
|
void dispatchGesturePanningStarted(const Point & initialPosition);
|
2023-05-30 23:33:10 +02:00
|
|
|
void dispatchGesturePanningEnded(const Point & initialPosition, const Point & finalPosition);
|
|
|
|
void dispatchGesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance);
|
2023-05-31 15:15:15 +02:00
|
|
|
void dispatchGesturePinch(const Point & initialPosition, double distance);
|
2023-05-17 22:22:45 +02:00
|
|
|
|
2023-05-18 12:59:09 +02:00
|
|
|
/// Text input events
|
2023-05-17 22:22:45 +02:00
|
|
|
void dispatchTextInput(const std::string & text);
|
|
|
|
void dispatchTextEditing(const std::string & text);
|
2024-07-19 03:00:19 +02:00
|
|
|
|
2024-07-19 11:41:00 +02:00
|
|
|
void dispatchInputModeChanged(const InputMode & modi);
|
2023-05-17 22:22:45 +02:00
|
|
|
};
|