Otclient  14/8/2020
uimanager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef UIMANAGER_H
24 #define UIMANAGER_H
25 
26 #include "declarations.h"
27 #include "uiwidget.h"
30 
31 //@bindsingleton g_ui
32 class UIManager
33 {
34 public:
35  void init();
36  void terminate();
37 
38  void render(Fw::DrawPane drawPane);
39  void resize(const Size& size);
40  void inputEvent(const InputEvent& event);
41 
42  void updatePressedWidget(const UIWidgetPtr& newPressedWidget, const Point& clickedPos = Point(), bool fireClicks = true);
43  bool updateDraggingWidget(const UIWidgetPtr& draggingWidget, const Point& clickedPos = Point());
44  void updateHoveredWidget(bool now = false);
45 
46  void clearStyles();
47  bool importStyle(std::string file);
48  void importStyleFromOTML(const OTMLNodePtr& styleNode);
49  OTMLNodePtr getStyle(const std::string& styleName);
50  std::string getStyleClass(const std::string& styleName);
51 
52  UIWidgetPtr loadUI(std::string file, const UIWidgetPtr& parent);
53  UIWidgetPtr displayUI(const std::string& file) { return loadUI(file, m_rootWidget); }
54  UIWidgetPtr createWidget(const std::string& styleName, const UIWidgetPtr& parent);
55  UIWidgetPtr createWidgetFromOTML(const OTMLNodePtr& widgetNode, const UIWidgetPtr& parent);
56 
57  void setMouseReceiver(const UIWidgetPtr& widget) { m_mouseReceiver = widget; }
58  void setKeyboardReceiver(const UIWidgetPtr& widget) { m_keyboardReceiver = widget; }
59  void setDebugBoxesDrawing(bool enabled) { m_drawDebugBoxes = enabled; }
60  void resetMouseReceiver() { m_mouseReceiver = m_rootWidget; }
61  void resetKeyboardReceiver() { m_keyboardReceiver = m_rootWidget; }
62  UIWidgetPtr getMouseReceiver() { return m_mouseReceiver; }
63  UIWidgetPtr getKeyboardReceiver() { return m_keyboardReceiver; }
64  UIWidgetPtr getDraggingWidget() { return m_draggingWidget; }
65  UIWidgetPtr getHoveredWidget() { return m_hoveredWidget; }
66  UIWidgetPtr getPressedWidget() { return m_pressedWidget; }
67  UIWidgetPtr getRootWidget() { return m_rootWidget; }
68  bool isMouseGrabbed() { return m_mouseReceiver != m_rootWidget; }
69  bool isKeyboardGrabbed() { return m_keyboardReceiver != m_rootWidget; }
70 
71  bool isDrawingDebugBoxes() { return m_drawDebugBoxes; }
72 
73 protected:
74  void onWidgetAppear(const UIWidgetPtr& widget);
75  void onWidgetDisappear(const UIWidgetPtr& widget);
76  void onWidgetDestroy(const UIWidgetPtr& widget);
77 
78  friend class UIWidget;
79 
80 private:
81  UIWidgetPtr m_rootWidget;
82  UIWidgetPtr m_mouseReceiver;
83  UIWidgetPtr m_keyboardReceiver;
84  UIWidgetPtr m_draggingWidget;
85  UIWidgetPtr m_hoveredWidget;
86  UIWidgetPtr m_pressedWidget;
87  stdext::boolean<false> m_hoverUpdateScheduled;
88  stdext::boolean<false> m_drawDebugBoxes;
89  std::unordered_map<std::string, OTMLNodePtr> m_styles;
90  UIWidgetList m_destroyedWidgets;
91  ScheduledEventPtr m_checkEvent;
92 
93 };
94 
95 extern UIManager g_ui;
96 
97 #endif
UIManager::getHoveredWidget
UIWidgetPtr getHoveredWidget()
Definition: uimanager.h:65
UIManager::onWidgetAppear
void onWidgetAppear(const UIWidgetPtr &widget)
Definition: uimanager.cpp:258
UIWidget
Definition: uiwidget.h:47
UIManager::onWidgetDisappear
void onWidgetDisappear(const UIWidgetPtr &widget)
Definition: uimanager.cpp:264
UIManager::getStyle
OTMLNodePtr getStyle(const std::string &styleName)
Definition: uimanager.cpp:377
UIManager::resize
void resize(const Size &size)
Definition: uimanager.cpp:64
inputevent.h
UIManager::updateHoveredWidget
void updateHoveredWidget(bool now=false)
Definition: uimanager.cpp:219
UIManager::getPressedWidget
UIWidgetPtr getPressedWidget()
Definition: uimanager.h:66
UIManager::getStyleClass
std::string getStyleClass(const std::string &styleName)
Definition: uimanager.cpp:394
declarations.h
Point
TPoint< int > Point
Definition: point.h:86
uiwidget.h
stdext::boolean< false >
UIManager::setKeyboardReceiver
void setKeyboardReceiver(const UIWidgetPtr &widget)
Definition: uimanager.h:58
UIManager::clearStyles
void clearStyles()
Definition: uimanager.cpp:312
UIManager::getDraggingWidget
UIWidgetPtr getDraggingWidget()
Definition: uimanager.h:64
InputEvent
Definition: inputevent.h:28
UIManager::setDebugBoxesDrawing
void setDebugBoxesDrawing(bool enabled)
Definition: uimanager.h:59
UIManager
Definition: uimanager.h:32
UIManager::isMouseGrabbed
bool isMouseGrabbed()
Definition: uimanager.h:68
UIManager::createWidgetFromOTML
UIWidgetPtr createWidgetFromOTML(const OTMLNodePtr &widgetNode, const UIWidgetPtr &parent)
Definition: uimanager.cpp:440
UIManager::importStyleFromOTML
void importStyleFromOTML(const OTMLNodePtr &styleNode)
Definition: uimanager.cpp:333
UIManager::resetMouseReceiver
void resetMouseReceiver()
Definition: uimanager.h:60
UIManager::getKeyboardReceiver
UIWidgetPtr getKeyboardReceiver()
Definition: uimanager.h:63
UIManager::resetKeyboardReceiver
void resetKeyboardReceiver()
Definition: uimanager.h:61
UIManager::render
void render(Fw::DrawPane drawPane)
Definition: uimanager.cpp:59
UIManager::loadUI
UIWidgetPtr loadUI(std::string file, const UIWidgetPtr &parent)
Definition: uimanager.cpp:402
g_ui
UIManager g_ui
Definition: uimanager.cpp:33
UIManager::displayUI
UIWidgetPtr displayUI(const std::string &file)
Definition: uimanager.h:53
Fw::DrawPane
DrawPane
Definition: const.h:285
stdext::shared_object_ptr< UIWidget >
UIManager::updatePressedWidget
void updatePressedWidget(const UIWidgetPtr &newPressedWidget, const Point &clickedPos=Point(), bool fireClicks=true)
Definition: uimanager.cpp:170
UIManager::init
void init()
Definition: uimanager.cpp:35
UIManager::onWidgetDestroy
void onWidgetDestroy(const UIWidgetPtr &widget)
Definition: uimanager.cpp:270
UIManager::inputEvent
void inputEvent(const InputEvent &event)
Definition: uimanager.cpp:69
UIManager::terminate
void terminate()
Definition: uimanager.cpp:44
UIManager::updateDraggingWidget
bool updateDraggingWidget(const UIWidgetPtr &draggingWidget, const Point &clickedPos=Point())
Definition: uimanager.cpp:186
UIManager::isDrawingDebugBoxes
bool isDrawingDebugBoxes()
Definition: uimanager.h:71
TPoint< int >
UIManager::isKeyboardGrabbed
bool isKeyboardGrabbed()
Definition: uimanager.h:69
UIManager::importStyle
bool importStyle(std::string file)
Definition: uimanager.cpp:317
UIManager::setMouseReceiver
void setMouseReceiver(const UIWidgetPtr &widget)
Definition: uimanager.h:57
TSize< int >
UIManager::getMouseReceiver
UIWidgetPtr getMouseReceiver()
Definition: uimanager.h:62
UIWidgetList
std::deque< UIWidgetPtr > UIWidgetList
Definition: declarations.h:53
UIManager::createWidget
UIWidgetPtr createWidget(const std::string &styleName, const UIWidgetPtr &parent)
Definition: uimanager.cpp:429
UIManager::getRootWidget
UIWidgetPtr getRootWidget()
Definition: uimanager.h:67