2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* CGuiHandler.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
|
|
|
|
*
|
|
|
|
*/
|
2011-12-17 21:59:59 +03:00
|
|
|
#pragma once
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
template <typename T> struct CondSh;
|
2023-05-18 22:31:05 +02:00
|
|
|
class Point;
|
2023-02-02 16:15:39 +02:00
|
|
|
class Rect;
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
2023-05-18 22:31:05 +02:00
|
|
|
enum class MouseButton;
|
2023-04-27 19:21:06 +02:00
|
|
|
class ShortcutHandler;
|
2023-05-12 23:15:48 +02:00
|
|
|
class FramerateManager;
|
2022-11-18 17:54:10 +02:00
|
|
|
class IStatusBar;
|
2011-12-17 21:59:59 +03:00
|
|
|
class CIntObject;
|
|
|
|
class IUpdateable;
|
|
|
|
class IShowActivatable;
|
2023-05-08 12:22:01 +02:00
|
|
|
class IScreenHandler;
|
2023-05-16 14:10:26 +02:00
|
|
|
class WindowHandler;
|
2023-05-18 12:31:26 +02:00
|
|
|
class EventDispatcher;
|
2023-05-18 19:32:29 +02:00
|
|
|
class InputHandler;
|
2011-12-17 21:59:59 +03:00
|
|
|
|
2023-05-18 19:32:29 +02:00
|
|
|
// TODO: event handling need refactoring. Perhaps convert into delayed function call?
|
2023-02-02 18:15:05 +02:00
|
|
|
enum class EUserEvent
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-05-18 19:32:29 +02:00
|
|
|
RETURN_TO_MAIN_MENU,
|
|
|
|
RESTART_GAME,
|
2018-01-05 19:21:07 +02:00
|
|
|
RETURN_TO_MENU_LOAD,
|
|
|
|
FULLSCREEN_TOGGLED,
|
|
|
|
CAMPAIGN_START_SCENARIO,
|
2023-05-18 19:32:29 +02:00
|
|
|
FORCE_QUIT,
|
2023-05-26 14:55:31 +02:00
|
|
|
FAKE_MOUSE_MOVE,
|
2018-01-05 19:21:07 +02:00
|
|
|
};
|
|
|
|
|
2011-12-17 21:59:59 +03:00
|
|
|
// Handles GUI logic and drawing
|
|
|
|
class CGuiHandler
|
|
|
|
{
|
2012-10-06 23:35:04 +03:00
|
|
|
private:
|
2023-05-16 17:34:23 +02:00
|
|
|
/// Fake no-op version status bar, for use in windows that have no status bar
|
|
|
|
std::shared_ptr<IStatusBar> fakeStatusBar;
|
|
|
|
|
|
|
|
/// Status bar of current window, if any. Uses weak_ptr to allow potential hanging reference after owned window has been deleted
|
|
|
|
std::weak_ptr<IStatusBar> currentStatusBar;
|
|
|
|
|
2023-04-28 13:22:03 +02:00
|
|
|
std::unique_ptr<ShortcutHandler> shortcutsHandlerInstance;
|
2023-05-16 14:10:26 +02:00
|
|
|
std::unique_ptr<WindowHandler> windowHandlerInstance;
|
2023-04-27 19:21:06 +02:00
|
|
|
|
2023-05-08 12:22:01 +02:00
|
|
|
std::unique_ptr<IScreenHandler> screenHandlerInstance;
|
2023-05-12 23:15:48 +02:00
|
|
|
std::unique_ptr<FramerateManager> framerateManagerInstance;
|
2023-05-18 12:31:26 +02:00
|
|
|
std::unique_ptr<EventDispatcher> eventDispatcherInstance;
|
2023-05-18 19:32:29 +02:00
|
|
|
std::unique_ptr<InputHandler> inputHandlerInstance;
|
2023-05-17 16:16:09 +02:00
|
|
|
|
2012-10-06 23:35:04 +03:00
|
|
|
public:
|
2023-02-02 15:49:23 +02:00
|
|
|
/// returns current position of mouse cursor, relative to vcmi window
|
2023-01-27 00:27:06 +02:00
|
|
|
const Point & getCursorPosition() const;
|
|
|
|
|
2023-05-18 19:32:29 +02:00
|
|
|
ShortcutHandler & shortcuts();
|
|
|
|
FramerateManager & framerate();
|
|
|
|
EventDispatcher & events();
|
|
|
|
InputHandler & input();
|
2023-05-13 00:12:11 +02:00
|
|
|
|
|
|
|
/// Returns current logical screen dimensions
|
|
|
|
/// May not match size of window if user has UI scaling different from 100%
|
2023-02-03 18:23:53 +02:00
|
|
|
Point screenDimensions() const;
|
|
|
|
|
2023-02-02 15:49:23 +02:00
|
|
|
/// returns true if specified mouse button is pressed
|
|
|
|
bool isMouseButtonPressed(MouseButton button) const;
|
|
|
|
|
2023-02-02 16:15:39 +02:00
|
|
|
/// returns true if chosen keyboard key is currently pressed down
|
|
|
|
bool isKeyboardAltDown() const;
|
|
|
|
bool isKeyboardCtrlDown() const;
|
|
|
|
bool isKeyboardShiftDown() const;
|
|
|
|
|
|
|
|
void startTextInput(const Rect & where);
|
|
|
|
void stopTextInput();
|
|
|
|
|
2023-05-08 12:22:01 +02:00
|
|
|
IScreenHandler & screenHandler();
|
2023-04-30 00:03:50 +02:00
|
|
|
|
2023-05-16 14:10:26 +02:00
|
|
|
WindowHandler & windows();
|
|
|
|
|
2023-05-16 17:34:23 +02:00
|
|
|
/// Returns currently active status bar. Guaranteed to be non-null
|
|
|
|
std::shared_ptr<IStatusBar> statusbar();
|
|
|
|
|
|
|
|
/// Set currently active status bar
|
|
|
|
void setStatusbar(std::shared_ptr<IStatusBar>);
|
|
|
|
|
2015-06-22 20:53:47 +02:00
|
|
|
IUpdateable *curInt;
|
2011-12-17 21:59:59 +03:00
|
|
|
|
2016-11-27 16:48:18 +02:00
|
|
|
ui8 defActionsDef; //default auto actions
|
|
|
|
bool captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list
|
|
|
|
std::list<CIntObject *> createdObj; //stack of objs being created
|
|
|
|
|
2011-12-17 21:59:59 +03:00
|
|
|
CGuiHandler();
|
|
|
|
~CGuiHandler();
|
2016-11-27 16:48:18 +02:00
|
|
|
|
2023-01-16 12:26:43 +02:00
|
|
|
void init();
|
2014-06-01 18:31:37 +03:00
|
|
|
void renderFrame();
|
2011-12-17 21:59:59 +03:00
|
|
|
|
2023-05-04 21:33:25 +02:00
|
|
|
/// called whenever user selects different resolution, requiring to center/resize all windows
|
|
|
|
void onScreenResize();
|
|
|
|
|
2011-12-17 21:59:59 +03:00
|
|
|
void handleEvents(); //takes events from queue and calls interested objects
|
|
|
|
void fakeMouseMove();
|
|
|
|
void drawFPSCounter(); // draws the FPS to the upper left corner of the screen
|
2012-09-15 22:16:16 +03:00
|
|
|
|
2023-05-18 19:32:29 +02:00
|
|
|
bool amIGuiThread();
|
|
|
|
void pushUserEvent(EUserEvent usercode);
|
|
|
|
void pushUserEvent(EUserEvent usercode, void * userdata);
|
2016-11-27 16:48:18 +02:00
|
|
|
|
2017-08-13 16:44:41 +02:00
|
|
|
CondSh<bool> * terminate_cond; // confirm termination
|
2011-12-17 21:59:59 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
extern CGuiHandler GH; //global gui handler
|
|
|
|
|
|
|
|
struct SObjectConstruction
|
|
|
|
{
|
|
|
|
CIntObject *myObj;
|
|
|
|
SObjectConstruction(CIntObject *obj);
|
|
|
|
~SObjectConstruction();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SSetCaptureState
|
|
|
|
{
|
|
|
|
bool previousCapture;
|
|
|
|
ui8 prevActions;
|
|
|
|
SSetCaptureState(bool allow, ui8 actions);
|
|
|
|
~SSetCaptureState();
|
|
|
|
};
|
|
|
|
|
|
|
|
#define OBJ_CONSTRUCTION SObjectConstruction obj__i(this)
|
2022-12-21 22:54:06 +02:00
|
|
|
#define OBJ_CONSTRUCTION_TARGETED(obj) SObjectConstruction obj__i(obj)
|
2017-11-14 09:50:04 +02:00
|
|
|
#define OBJECT_CONSTRUCTION_CAPTURING(actions) defActions = actions; SSetCaptureState obj__i1(true, actions); SObjectConstruction obj__i(this)
|
2018-04-07 13:34:11 +02:00
|
|
|
#define OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(actions) SSetCaptureState obj__i1(true, actions); SObjectConstruction obj__i(this)
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
#define OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE defActions = 255 - DISPOSE; SSetCaptureState obj__i1(true, 255 - DISPOSE); SObjectConstruction obj__i(this)
|