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;
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
|
|
|
class EventDispatcher;
|
|
|
|
enum class MouseButton;
|
|
|
|
enum class EShortcut;
|
|
|
|
using boost::logic::tribool;
|
|
|
|
|
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;
|
|
|
|
|
2023-05-29 12:08:08 +02:00
|
|
|
std::map<MouseButton, bool> currentMouseState;
|
2023-05-18 12:31:26 +02:00
|
|
|
ui16 activeState;
|
2023-05-18 12:59:09 +02:00
|
|
|
bool hoveredState;
|
2023-05-29 12:08:08 +02:00
|
|
|
bool panningState;
|
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);
|
|
|
|
|
|
|
|
virtual void clickLeft(tribool down, bool previousState) {}
|
2023-06-11 17:20:10 +02:00
|
|
|
virtual void showPopupWindow() {}
|
2023-05-26 20:46:09 +02:00
|
|
|
virtual void clickDouble() {}
|
2023-05-18 12:31:26 +02:00
|
|
|
|
2023-05-29 12:08:08 +02:00
|
|
|
/// Called when user pans screen by specified distance
|
2023-05-30 23:33:10 +02:00
|
|
|
virtual void gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) {}
|
2023-05-29 12:08:08 +02:00
|
|
|
|
2023-05-31 15:15:15 +02:00
|
|
|
virtual void gesturePinch(const Point & centerPosition, double lastUpdateFactor) {}
|
|
|
|
|
2023-05-29 12:08:08 +02:00
|
|
|
virtual void wheelScrolled(int distance) {}
|
2023-05-18 12:31:26 +02:00
|
|
|
virtual void mouseMoved(const Point & cursorPosition) {}
|
2023-05-29 12:08:08 +02:00
|
|
|
|
|
|
|
/// Called when UI element hover status changes
|
2023-05-18 12:31:26 +02:00
|
|
|
virtual void hover(bool on) {}
|
2023-05-26 20:46:09 +02:00
|
|
|
|
2023-05-29 12:08:08 +02:00
|
|
|
/// Called when UI element panning gesture status changes
|
2023-05-30 23:33:10 +02:00
|
|
|
virtual void panning(bool on, const Point & initialPosition, const Point & finalPosition) {}
|
2023-05-29 12:08:08 +02:00
|
|
|
|
2023-05-26 20:46:09 +02:00
|
|
|
virtual void textInputed(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) {}
|
|
|
|
|
2023-05-26 20:46:09 +02:00
|
|
|
virtual void tick(uint32_t msPassed) {}
|
|
|
|
|
2023-05-18 12:31:26 +02:00
|
|
|
virtual bool captureThisKey(EShortcut key) = 0;
|
2023-05-29 12:08:08 +02:00
|
|
|
|
|
|
|
/// 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-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
|
2023-05-26 20:46:09 +02:00
|
|
|
enum {LCLICK=1, RCLICK=2, HOVER=4, MOVE=8, KEYBOARD=16, TIME=32, GENERAL=64, WHEEL=128, DOUBLECLICK=256, TEXTINPUT=512, GESTURE_PANNING=1024, ALL=0xffff};
|
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
|
|
|
|
2023-05-29 12:08:08 +02:00
|
|
|
/// Returns true if panning/swiping gesture is currently active
|
|
|
|
bool isPanning() 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;
|
2023-05-18 12:59:09 +02:00
|
|
|
|
|
|
|
/// Returns true if particular mouse button was pressed when inside this element
|
2023-05-18 12:31:26 +02:00
|
|
|
bool isMouseButtonPressed(MouseButton btn) const;
|
|
|
|
};
|