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"
9#include "MyGUI_Gui.h"
10#include "MyGUI_InputManager.h"
11#include "MyGUI_WidgetManager.h"
12
13namespace MyGUI
14{
15
17
19 mSingletonHolder(this)
20 {
21 }
22
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);
37
38 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
39 mIsInitialise = true;
40 }
41
43 {
44 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
45 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
46
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 {
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;
71 mOldIndex = getToolTipIndex(mOldFocusWidget);
72 mNeedToolTip = isNeedToolTip(mOldFocusWidget);
73 }
74 }
75 else if (mNeedToolTip)
76 {
78 if (capture)
79 {
80 if (mToolTipVisible)
81 {
82 mToolTipVisible = false;
83 hideToolTip(mOldFocusWidget);
84 }
85 }
86 else
87 {
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
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
187 {
188 mDelayVisible = _value;
189 }
190
192 {
193 return mDelayVisible;
194 }
195
196} // namespace MyGUI
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_LOG(level, text)
#define MYGUI_SINGLETON_DEFINITION(ClassName)
static Gui & getInstance()
Definition MyGUI_Gui.cpp:34
EventHandle_FrameEventDelegate eventFrameStart
Definition MyGUI_Gui.h:215
Widget * getMouseFocusWidget() const
static InputManager & getInstance()
IntPoint getMousePositionByLayer() const
void setDelayVisible(float _value)
static std::string_view getClassTypeName()
void _unlinkWidget(Widget *_widget) override
widget description should be here.
Widget * _getContainer() const
EventHandle_WidgetToolTip eventToolTip
void unregisterUnlinker(IUnlinkWidget *_unlink)
static WidgetManager & getInstance()
void registerUnlinker(IUnlinkWidget *_unlink)
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
constexpr size_t ITEM_NONE
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))