1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-28 23:06:24 +02:00
vcmi/client/gui/EventDispatcher.h

79 lines
2.8 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;
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;
2023-05-20 00:51:10 +02:00
EventReceiversList timeinterested;
EventReceiversList wheelInterested;
EventReceiversList doubleClickInterested;
EventReceiversList textInterested;
EventReceiversList panningInterested;
void handleLeftButtonClick(const Point & position, bool isPressed);
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
void dispatchMouseLeftButtonPressed(const Point & position);
void dispatchMouseLeftButtonReleased(const Point & position);
void dispatchMouseScrolled(const Point & distance, const Point & position);
2023-05-18 01:09:42 +02:00
void dispatchMouseDoubleClick(const Point & position);
void dispatchMouseMoved(const Point & distance, const Point & position);
void dispatchMouseDragged(const Point & currentPosition, const Point & lastUpdateDistance);
void dispatchShowPopup(const Point & position);
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);
};