mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
Added method descriptions
This commit is contained in:
@@ -17,8 +17,6 @@
|
|||||||
#include "../windows/CMessage.h"
|
#include "../windows/CMessage.h"
|
||||||
#include "../CMT.h"
|
#include "../CMT.h"
|
||||||
|
|
||||||
#include <SDL_pixels.h>
|
|
||||||
|
|
||||||
CIntObject::CIntObject(int used_, Point pos_):
|
CIntObject::CIntObject(int used_, Point pos_):
|
||||||
parent_m(nullptr),
|
parent_m(nullptr),
|
||||||
parent(parent_m),
|
parent(parent_m),
|
||||||
@@ -102,12 +100,12 @@ void CIntObject::deactivate()
|
|||||||
elem->deactivate();
|
elem->deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CIntObject::printAtMiddleLoc(const std::string & text, const Point &p, EFonts font, SDL_Color kolor, SDL_Surface * dst)
|
void CIntObject::printAtMiddleLoc(const std::string & text, const Point &p, EFonts font, const SDL_Color & kolor, SDL_Surface * dst)
|
||||||
{
|
{
|
||||||
graphics->fonts[font]->renderTextCenter(dst, text, kolor, pos.topLeft() + p);
|
graphics->fonts[font]->renderTextCenter(dst, text, kolor, pos.topLeft() + p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CIntObject::printAtMiddleWBLoc( const std::string & text, const Point &p, EFonts font, int charpr, SDL_Color kolor, SDL_Surface * dst)
|
void CIntObject::printAtMiddleWBLoc( const std::string & text, const Point &p, EFonts font, int charpr, const SDL_Color & kolor, SDL_Surface * dst)
|
||||||
{
|
{
|
||||||
graphics->fonts[font]->renderTextLinesCenter(dst, CMessage::breakText(text, charpr, font), kolor, pos.topLeft() + p);
|
graphics->fonts[font]->renderTextLinesCenter(dst, CMessage::breakText(text, charpr, font), kolor, pos.topLeft() + p);
|
||||||
}
|
}
|
||||||
@@ -310,6 +308,3 @@ void WindowBase::close()
|
|||||||
logGlobal->error("Only top interface must be closed");
|
logGlobal->error("Only top interface must be closed");
|
||||||
GH.windows().popWindows(1);
|
GH.windows().popWindows(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
IStatusBar::~IStatusBar()
|
|
||||||
{}
|
|
||||||
|
|||||||
@@ -114,8 +114,8 @@ public:
|
|||||||
|
|
||||||
/// functions for printing text.
|
/// functions for printing text.
|
||||||
/// Deprecated. Use CLabel where possible instead
|
/// Deprecated. Use CLabel where possible instead
|
||||||
void printAtMiddleLoc(const std::string & text, const Point &p, EFonts font, SDL_Color color, SDL_Surface * dst);
|
void printAtMiddleLoc(const std::string & text, const Point &p, EFonts font, const SDL_Color & color, SDL_Surface * dst);
|
||||||
void printAtMiddleWBLoc(const std::string & text, const Point &p, EFonts font, int charsPerLine, SDL_Color color, SDL_Surface * dst);
|
void printAtMiddleWBLoc(const std::string & text, const Point &p, EFonts font, int charsPerLine, const SDL_Color & color, SDL_Surface * dst);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Class for binding keys to left mouse button clicks
|
/// Class for binding keys to left mouse button clicks
|
||||||
@@ -143,7 +143,7 @@ protected:
|
|||||||
class IStatusBar
|
class IStatusBar
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~IStatusBar();
|
virtual ~IStatusBar() = default;
|
||||||
|
|
||||||
/// set current text for the status bar
|
/// set current text for the status bar
|
||||||
virtual void write(const std::string & text) = 0;
|
virtual void write(const std::string & text) = 0;
|
||||||
|
|||||||
@@ -17,11 +17,12 @@ class AEventsReceiver;
|
|||||||
enum class MouseButton;
|
enum class MouseButton;
|
||||||
enum class EShortcut;
|
enum class EShortcut;
|
||||||
|
|
||||||
|
/// Class that receives events from event producers and dispatches it to UI elements that are interested in this event
|
||||||
class EventDispatcher
|
class EventDispatcher
|
||||||
{
|
{
|
||||||
using CIntObjectList = std::list<AEventsReceiver *>;
|
using CIntObjectList = std::list<AEventsReceiver *>;
|
||||||
|
|
||||||
//active GUI elements (listening for events
|
/// list of UI elements that are interested in particular event
|
||||||
CIntObjectList lclickable;
|
CIntObjectList lclickable;
|
||||||
CIntObjectList rclickable;
|
CIntObjectList rclickable;
|
||||||
CIntObjectList mclickable;
|
CIntObjectList mclickable;
|
||||||
@@ -43,22 +44,30 @@ class EventDispatcher
|
|||||||
void processLists(ui16 activityFlag, std::function<void(CIntObjectList *)> cb);
|
void processLists(ui16 activityFlag, std::function<void(CIntObjectList *)> cb);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/// allows to interrupt event handling and abort any subsequent event processing
|
||||||
void allowEventHandling(bool enable);
|
void allowEventHandling(bool enable);
|
||||||
|
|
||||||
|
/// add specified UI element as interested. Uses unnamed enum from AEventsReceiver for activity flags
|
||||||
void handleElementActivate(AEventsReceiver * elem, ui16 activityFlag);
|
void handleElementActivate(AEventsReceiver * elem, ui16 activityFlag);
|
||||||
|
|
||||||
|
/// removes specified UI element as interested for specified activities
|
||||||
void handleElementDeActivate(AEventsReceiver * elem, ui16 activityFlag);
|
void handleElementDeActivate(AEventsReceiver * elem, ui16 activityFlag);
|
||||||
|
|
||||||
|
/// Regular timer event
|
||||||
void dispatchTimer(uint32_t msPassed);
|
void dispatchTimer(uint32_t msPassed);
|
||||||
|
|
||||||
|
/// Shortcut events (e.g. keyboard keys)
|
||||||
void dispatchShortcutPressed(const std::vector<EShortcut> & shortcuts);
|
void dispatchShortcutPressed(const std::vector<EShortcut> & shortcuts);
|
||||||
void dispatchShortcutReleased(const std::vector<EShortcut> & shortcuts);
|
void dispatchShortcutReleased(const std::vector<EShortcut> & shortcuts);
|
||||||
|
|
||||||
|
/// Mouse events
|
||||||
void dispatchMouseButtonPressed(const MouseButton & button, const Point & position);
|
void dispatchMouseButtonPressed(const MouseButton & button, const Point & position);
|
||||||
void dispatchMouseButtonReleased(const MouseButton & button, const Point & position);
|
void dispatchMouseButtonReleased(const MouseButton & button, const Point & position);
|
||||||
void dispatchMouseScrolled(const Point & distance, const Point & position);
|
void dispatchMouseScrolled(const Point & distance, const Point & position);
|
||||||
void dispatchMouseDoubleClick(const Point & position);
|
void dispatchMouseDoubleClick(const Point & position);
|
||||||
void dispatchMouseMoved(const Point & position);
|
void dispatchMouseMoved(const Point & position);
|
||||||
|
|
||||||
|
/// Text input events
|
||||||
void dispatchTextInput(const std::string & text);
|
void dispatchTextInput(const std::string & text);
|
||||||
void dispatchTextEditing(const std::string & text);
|
void dispatchTextEditing(const std::string & text);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,21 +18,26 @@ enum class MouseButton;
|
|||||||
enum class EShortcut;
|
enum class EShortcut;
|
||||||
using boost::logic::tribool;
|
using boost::logic::tribool;
|
||||||
|
|
||||||
|
/// Class that is capable of subscribing and receiving input events
|
||||||
|
/// Acts as base class for all UI elements
|
||||||
class AEventsReceiver
|
class AEventsReceiver
|
||||||
{
|
{
|
||||||
friend class EventDispatcher;
|
friend class EventDispatcher;
|
||||||
|
|
||||||
ui16 activeState;
|
ui16 activeState;
|
||||||
|
bool hoveredState;
|
||||||
|
bool strongInterestState;
|
||||||
std::map<MouseButton, bool> currentMouseState;
|
std::map<MouseButton, bool> currentMouseState;
|
||||||
|
|
||||||
bool hoveredState; //for determining if object is hovered
|
|
||||||
bool strongInterestState; //if true - report all mouse movements, if not - only when hovered
|
|
||||||
|
|
||||||
void click(MouseButton btn, tribool down, bool previousState);
|
void click(MouseButton btn, tribool down, bool previousState);
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
/// If set, UI element will receive all mouse movement events, even those outside this element
|
||||||
void setMoveEventStrongInterest(bool on);
|
void setMoveEventStrongInterest(bool on);
|
||||||
|
|
||||||
|
/// Activates particular events for this UI element. Uses unnamed enum from this class
|
||||||
void activateEvents(ui16 what);
|
void activateEvents(ui16 what);
|
||||||
|
/// Deactivates particular events for this UI element. Uses unnamed enum from this class
|
||||||
void deactivateEvents(ui16 what);
|
void deactivateEvents(ui16 what);
|
||||||
|
|
||||||
virtual void clickLeft(tribool down, bool previousState) {}
|
virtual void clickLeft(tribool down, bool previousState) {}
|
||||||
@@ -58,11 +63,18 @@ public:
|
|||||||
AEventsReceiver();
|
AEventsReceiver();
|
||||||
virtual ~AEventsReceiver() = default;
|
virtual ~AEventsReceiver() = default;
|
||||||
|
|
||||||
// These are the arguments that can be used to determine what kind of input the CIntObject will receive
|
/// These are the arguments that can be used to determine what kind of input UI element will receive
|
||||||
enum {LCLICK=1, RCLICK=2, HOVER=4, MOVE=8, KEYBOARD=16, TIME=32, GENERAL=64, WHEEL=128, DOUBLECLICK=256, TEXTINPUT=512, MCLICK=1024, ALL=0xffff};
|
enum {LCLICK=1, RCLICK=2, HOVER=4, MOVE=8, KEYBOARD=16, TIME=32, GENERAL=64, WHEEL=128, DOUBLECLICK=256, TEXTINPUT=512, MCLICK=1024, ALL=0xffff};
|
||||||
|
|
||||||
|
/// Returns true if element is currently hovered by mouse
|
||||||
bool isHovered() const;
|
bool isHovered() const;
|
||||||
|
|
||||||
|
/// Returns true if element is currently active and may receive events
|
||||||
bool isActive() const;
|
bool isActive() const;
|
||||||
|
|
||||||
|
/// Returns true if particular event(s) is active for this element
|
||||||
bool isActive(int flags) const;
|
bool isActive(int flags) const;
|
||||||
|
|
||||||
|
/// Returns true if particular mouse button was pressed when inside this element
|
||||||
bool isMouseButtonPressed(MouseButton btn) const;
|
bool isMouseButtonPressed(MouseButton btn) const;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user