1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-12 10:03:53 +02:00
vcmi/client/gui/EventDispatcher.h

86 lines
3.3 KiB
C++
Raw Normal View History

/*
2023-05-18 12:31:26 +02:00
* EventDispatcher.h, part of VCMI engine
*
* 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-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-20 00:51:10 +02:00
using EventReceiversList = std::list<AEventsReceiver *>;
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;
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;
EventReceiversList panningInterested;
2024-07-19 11:41:00 +02:00
EventReceiversList inputModeChangeInterested;
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-20 00:51:10 +02:00
template<typename Functor>
void processLists(ui16 activityFlag, const Functor & cb);
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-18 12:59:09 +02:00
/// Regular timer event
2023-05-18 01:09:42 +02:00
void dispatchTimer(uint32_t msPassed);
2023-05-18 12:59:09 +02:00
/// Shortcut events (e.g. keyboard keys)
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);
void dispatchMouseScrolled(const Point & distance, const Point & position);
2023-09-18 20:35:23 +02:00
void dispatchMouseDoubleClick(const Point & position, int tolerance);
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-09-06 00:06:01 +02:00
void dispatchShowPopup(const Point & position, int tolerance);
void dispatchClosePopup(const Point & position);
void dispatchGesturePanningStarted(const Point & initialPosition);
void dispatchGesturePanningEnded(const Point & initialPosition, const Point & finalPosition);
void dispatchGesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance);
void dispatchGesturePinch(const Point & initialPosition, double distance);
2023-05-18 12:59:09 +02:00
/// Text input events
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);
};