MyGUI: MyGUI_ToolTipManager.cpp Source File

MyGUI 3.4.3

MyGUI_ToolTipManager.cpp
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#include "MyGUI_Precompiled.h"
8#include "MyGUI_ToolTipManager.h"
9#include "MyGUI_Gui.h"
10#include "MyGUI_InputManager.h"
11#include "MyGUI_WidgetManager.h"
12
13namespace MyGUI
14{
15
16 MYGUI_SINGLETON_DEFINITION(ToolTipManager);
17
18 ToolTipManager::ToolTipManager() :
19 mSingletonHolder(this)
20 {
21 }
22
23 void ToolTipManager::initialise()
24 {
25 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
26 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
27
28 mDelayVisible = 0.5f;
29 mOldFocusWidget = nullptr;
30 mToolTipVisible = false;
31 mCurrentTime = 0;
32 mOldIndex = ITEM_NONE;
33 mNeedToolTip = false;
34
35 Gui::getInstance().eventFrameStart += newDelegate(this, &ToolTipManager::notifyEventFrameStart);
36 WidgetManager::getInstance().registerUnlinker(this);
37
38 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
39 mIsInitialise = true;
40 }
41
42 void ToolTipManager::shutdown()
43 {
44 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
45 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
46
47 WidgetManager::getInstance().unregisterUnlinker(this);
48 Gui::getInstance().eventFrameStart -= newDelegate(this, &ToolTipManager::notifyEventFrameStart);
49
50 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
51 mIsInitialise = false;
52 }
53
54 void ToolTipManager::notifyEventFrameStart(float _time)
55 {
56 Widget* widget = InputManager::getInstance().getMouseFocusWidget();
57 if (mOldFocusWidget != widget)
58 {
59 if (mToolTipVisible)
60 {
61 mToolTipVisible = false;
62 hideToolTip(mOldFocusWidget);
63 }
64 mOldFocusWidget = widget;
65 mNeedToolTip = false;
66
67 if (mOldFocusWidget != nullptr)
68 {
69 mCurrentTime = 0;
70 mOldMousePoint = InputManager::getInstance().getMousePositionByLayer();
71 mOldIndex = getToolTipIndex(mOldFocusWidget);
72 mNeedToolTip = isNeedToolTip(mOldFocusWidget);
73 }
74 }
75 else if (mNeedToolTip)
76 {
77 bool capture = InputManager::getInstance().isCaptureMouse();
78 if (capture)
79 {
80 if (mToolTipVisible)
81 {
82 mToolTipVisible = false;
83 hideToolTip(mOldFocusWidget);
84 }
85 }
86 else
87 {
88 IntPoint point = InputManager::getInstance().getMousePositionByLayer();
89 if (!mToolTipVisible && point != mOldMousePoint)
90 {
91 mCurrentTime = 0;
92 mOldMousePoint = point;
93 mOldIndex = getToolTipIndex(mOldFocusWidget);
94 }
95 else
96 {
97 size_t index = getToolTipIndex(mOldFocusWidget);
98 if (mOldIndex != index)
99 {
100 if (mToolTipVisible)
101 {
102 mToolTipVisible = false;
103 hideToolTip(mOldFocusWidget);
104 }
105 mCurrentTime = 0;
106 mOldIndex = index;
107 }
108 else
109 {
110 if (!mToolTipVisible)
111 {
112 mCurrentTime += _time;
113 if (mCurrentTime >= mDelayVisible)
114 {
115 mToolTipVisible = true;
116 showToolTip(mOldFocusWidget, mOldIndex, point);
117 }
118 }
119 else if (point != mOldMousePoint)
120 {
121 moveToolTip(mOldFocusWidget, mOldIndex, point);
122 }
123 }
124 }
125 }
126 }
127 }
128
129 void ToolTipManager::_unlinkWidget(Widget* _widget)
130 {
131 if (mOldFocusWidget == _widget)
132 {
133 if (mToolTipVisible)
134 {
135 mToolTipVisible = false;
136 hideToolTip(mOldFocusWidget);
137 }
138 mOldFocusWidget = nullptr;
139 mNeedToolTip = false;
140 }
141 }
142
143 void ToolTipManager::hideToolTip(Widget* _widget)
144 {
145 Widget* container = _widget->_getContainer();
146 if (container != nullptr)
147 container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Hide));
148 else
149 _widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Hide));
150 }
151
152 void ToolTipManager::showToolTip(Widget* _widget, size_t _index, const IntPoint& _point)
153 {
154 Widget* container = _widget->_getContainer();
155 if (container != nullptr)
156 container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Show, _index, _point));
157 else
158 _widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Show, ITEM_NONE, _point));
159 }
160
161 void ToolTipManager::moveToolTip(Widget* _widget, size_t _index, const IntPoint& _point)
162 {
163 Widget* container = _widget->_getContainer();
164 if (container != nullptr)
165 container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Move, _index, _point));
166 else
167 _widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Move, ITEM_NONE, _point));
168 }
169
170 bool ToolTipManager::isNeedToolTip(Widget* _widget)
171 {
172 Widget* container = _widget->_getContainer();
173 if (container != nullptr)
174 return container->getNeedToolTip();
175 return _widget->getNeedToolTip();
176 }
177
178 size_t ToolTipManager::getToolTipIndex(Widget* _widget) const
179 {
180 Widget* container = _widget->_getContainer();
181 if (container != nullptr)
182 return container->_getItemIndex(_widget);
183 return ITEM_NONE;
184 }
185
186 void ToolTipManager::setDelayVisible(float _value)
187 {
188 mDelayVisible = _value;
189 }
190
191 float ToolTipManager::getDelayVisible() const
192 {
193 return mDelayVisible;
194 }
195
196} // namespace MyGUI
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:31
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition MyGUI_Diagnostic.h:17
MyGUI_Gui.h
MyGUI_InputManager.h
MyGUI_Precompiled.h
MYGUI_SINGLETON_DEFINITION
#define MYGUI_SINGLETON_DEFINITION(ClassName)
Definition MyGUI_Singleton.h:126
MyGUI_ToolTipManager.h
MyGUI_WidgetManager.h
MyGUI::Gui::getInstance
static Gui & getInstance()
Definition MyGUI_Gui.cpp:34
MyGUI::Gui::eventFrameStart
EventHandle_FrameEventDelegate eventFrameStart
Definition MyGUI_Gui.h:215
MyGUI::InputManager::isCaptureMouse
bool isCaptureMouse() const
Definition MyGUI_InputManager.cpp:623
MyGUI::InputManager::getMouseFocusWidget
Widget * getMouseFocusWidget() const
Definition MyGUI_InputManager.cpp:638
MyGUI::InputManager::getInstance
static InputManager & getInstance()
MyGUI::InputManager::getMousePositionByLayer
IntPoint getMousePositionByLayer() const
Definition MyGUI_InputManager.cpp:606
MyGUI::ToolTipManager
Definition MyGUI_ToolTipManager.h:18
MyGUI::ToolTipManager::shutdown
void shutdown()
Definition MyGUI_ToolTipManager.cpp:42
MyGUI::ToolTipManager::setDelayVisible
void setDelayVisible(float _value)
Definition MyGUI_ToolTipManager.cpp:186
MyGUI::ToolTipManager::getDelayVisible
float getDelayVisible() const
Definition MyGUI_ToolTipManager.cpp:191
MyGUI::ToolTipManager::initialise
void initialise()
Definition MyGUI_ToolTipManager.cpp:23
MyGUI::ToolTipManager::ToolTipManager
ToolTipManager()
Definition MyGUI_ToolTipManager.cpp:18
MyGUI::ToolTipManager::getClassTypeName
static std::string_view getClassTypeName()
MyGUI::ToolTipManager::_unlinkWidget
void _unlinkWidget(Widget *_widget) override
Definition MyGUI_ToolTipManager.cpp:129
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::Widget::_getContainer
Widget * _getContainer() const
Definition MyGUI_Widget.cpp:1392
MyGUI::WidgetInput::eventToolTip
EventHandle_WidgetToolTip eventToolTip
Definition MyGUI_WidgetInput.h:226
MyGUI::WidgetManager::unregisterUnlinker
void unregisterUnlinker(IUnlinkWidget *_unlink)
Definition MyGUI_WidgetManager.cpp:144
MyGUI::WidgetManager::getInstance
static WidgetManager & getInstance()
MyGUI::WidgetManager::registerUnlinker
void registerUnlinker(IUnlinkWidget *_unlink)
Definition MyGUI_WidgetManager.cpp:138
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::ITEM_NONE
constexpr size_t ITEM_NONE
Definition MyGUI_Macros.h:19
MyGUI::newDelegate
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
Definition MyGUI_Delegate.h:100
MyGUI::ToolTipInfo
Definition MyGUI_WidgetToolTip.h:18
MyGUI::ToolTipInfo::Hide
@ Hide
Definition MyGUI_WidgetToolTip.h:21
MyGUI::ToolTipInfo::Move
@ Move
Definition MyGUI_WidgetToolTip.h:23
MyGUI::ToolTipInfo::Show
@ Show
Definition MyGUI_WidgetToolTip.h:22