1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00
vcmi/client/gui/EventsReceiver.h

115 lines
3.6 KiB
C++
Raw Normal View History

2023-05-18 12:31:26 +02:00
/*
* EventsReceiver.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;
2023-09-06 00:06:01 +02:00
class Rect;
2023-05-18 12:31:26 +02:00
VCMI_LIB_NAMESPACE_END
class EventDispatcher;
enum class EShortcut;
2024-07-19 11:41:00 +02:00
enum class InputMode;
2023-05-18 12:31:26 +02:00
2023-05-18 12:59:09 +02:00
/// Class that is capable of subscribing and receiving input events
/// Acts as base class for all UI elements
2023-05-18 12:31:26 +02:00
class AEventsReceiver
{
friend class EventDispatcher;
ui16 activeState;
2023-05-18 12:59:09 +02:00
bool hoveredState;
bool panningState;
bool mouseClickedState;
2023-05-18 12:31:26 +02:00
protected:
2023-05-18 12:59:09 +02:00
/// Activates particular events for this UI element. Uses unnamed enum from this class
2023-05-18 12:31:26 +02:00
void activateEvents(ui16 what);
2023-05-18 12:59:09 +02:00
/// Deactivates particular events for this UI element. Uses unnamed enum from this class
2023-05-18 12:31:26 +02:00
void deactivateEvents(ui16 what);
/// allows capturing key input so it will be delivered only to this element
virtual bool captureThisKey(EShortcut key) = 0;
/// If true, event of selected type in selected position will be processed by this element
virtual bool receiveEvent(const Point & position, int eventType) const= 0;
2023-09-06 00:06:01 +02:00
virtual const Rect & getPosition() const= 0;
public:
virtual void clickPressed(const Point & cursorPosition) {}
virtual void clickReleased(const Point & cursorPosition) {}
2023-10-22 00:05:14 +02:00
virtual void clickPressed(const Point & cursorPosition, bool lastActivated);
virtual void clickReleased(const Point & cursorPosition, bool lastActivated);
virtual void clickCancel(const Point & cursorPosition) {}
virtual void showPopupWindow(const Point & cursorPosition) {}
virtual void clickDouble(const Point & cursorPosition) {}
2024-09-24 15:35:28 +02:00
virtual void notFocusedClick() {};
2023-05-18 12:31:26 +02:00
/// Called when user pans screen by specified distance
virtual void gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) {}
/// Called when user pitches screen, requesting scaling by specified factor
virtual void gesturePinch(const Point & centerPosition, double lastUpdateFactor) {}
virtual void wheelScrolled(int distance) {}
virtual void mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance) {}
virtual void mouseDragged(const Point & cursorPosition, const Point & lastUpdateDistance) {}
2024-08-28 22:17:05 +02:00
virtual void mouseDraggedPopup(const Point & cursorPosition, const Point & lastUpdateDistance) {}
/// Called when UI element hover status changes
2023-05-18 12:31:26 +02:00
virtual void hover(bool on) {}
/// Called when UI element gesture status changes
virtual void gesture(bool on, const Point & initialPosition, const Point & finalPosition) {}
virtual void textInputted(const std::string & enteredText) {}
virtual void textEdited(const std::string & enteredText) {}
2023-05-18 12:31:26 +02:00
virtual void keyPressed(EShortcut key) {}
virtual void keyReleased(EShortcut key) {}
virtual void tick(uint32_t msPassed) {}
2024-07-19 11:41:00 +02:00
virtual void inputModeChanged(InputMode modi) {}
2024-07-19 03:00:19 +02:00
2023-05-18 12:31:26 +02:00
public:
AEventsReceiver();
virtual ~AEventsReceiver() = default;
2023-05-18 12:59:09 +02:00
/// These are the arguments that can be used to determine what kind of input UI element will receive
enum
{
LCLICK = 1,
SHOW_POPUP = 2,
HOVER = 4,
MOVE = 8,
KEYBOARD = 16,
TIME = 32,
GENERAL = 64,
WHEEL = 128,
DOUBLECLICK = 256,
TEXTINPUT = 512,
GESTURE = 1024,
DRAG = 2048,
2024-08-28 22:17:05 +02:00
INPUT_MODE_CHANGE = 4096,
DRAG_POPUP = 8192
};
2023-05-18 12:31:26 +02:00
2023-05-18 12:59:09 +02:00
/// Returns true if element is currently hovered by mouse
2023-05-18 12:31:26 +02:00
bool isHovered() const;
2023-05-18 12:59:09 +02:00
/// Returns true if panning/swiping gesture is currently active
bool isGesturing() const;
2023-05-18 12:59:09 +02:00
/// Returns true if element is currently active and may receive events
2023-05-18 12:31:26 +02:00
bool isActive() const;
};