MyGUI 3.4.1
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 mDelayVisible(0.5f),
20 mOldFocusWidget(nullptr),
21 mToolTipVisible(false),
22 mCurrentTime(0),
23 mOldIndex(ITEM_NONE),
24 mNeedToolTip(false),
25 mIsInitialise(false),
26 mSingletonHolder(this)
27 {
28 }
29
31 {
32 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
33 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
34
35 mDelayVisible = 0.5f;
36 mOldFocusWidget = nullptr;
37 mToolTipVisible = false;
38 mCurrentTime = 0;
39 mOldIndex = ITEM_NONE;
40 mNeedToolTip = false;
41
42 Gui::getInstance().eventFrameStart += newDelegate(this, &ToolTipManager::notifyEventFrameStart);
44
45 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
46 mIsInitialise = true;
47 }
48
50 {
51 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
52 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
53
55 Gui::getInstance().eventFrameStart -= newDelegate(this, &ToolTipManager::notifyEventFrameStart);
56
57 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
58 mIsInitialise = false;
59 }
60
61 void ToolTipManager::notifyEventFrameStart(float _time)
62 {
64 if (mOldFocusWidget != widget)
65 {
66 if (mToolTipVisible)
67 {
68 mToolTipVisible = false;
69 hideToolTip(mOldFocusWidget);
70 }
71 mOldFocusWidget = widget;
72 mNeedToolTip = false;
73
74 if (mOldFocusWidget != nullptr)
75 {
76 mCurrentTime = 0;
78 mOldIndex = getToolTipIndex(mOldFocusWidget);
79 mNeedToolTip = isNeedToolTip(mOldFocusWidget);
80 }
81 }
82 else if (mNeedToolTip)
83 {
85 if (capture)
86 {
87 if (mToolTipVisible)
88 {
89 mToolTipVisible = false;
90 hideToolTip(mOldFocusWidget);
91 }
92 }
93 else
94 {
96 if (!mToolTipVisible && point != mOldMousePoint)
97 {
98 mCurrentTime = 0;
99 mOldMousePoint = point;
100 mOldIndex = getToolTipIndex(mOldFocusWidget);
101 }
102 else
103 {
104 size_t index = getToolTipIndex(mOldFocusWidget);
105 if (mOldIndex != index)
106 {
107 if (mToolTipVisible)
108 {
109 mToolTipVisible = false;
110 hideToolTip(mOldFocusWidget);
111 }
112 mCurrentTime = 0;
113 mOldIndex = index;
114 }
115 else
116 {
117 if (!mToolTipVisible)
118 {
119 mCurrentTime += _time;
120 if (mCurrentTime >= mDelayVisible)
121 {
122 mToolTipVisible = true;
123 showToolTip(mOldFocusWidget, mOldIndex, point);
124 }
125 }
126 else if (point != mOldMousePoint)
127 {
128 moveToolTip(mOldFocusWidget, mOldIndex, point);
129 }
130 }
131 }
132 }
133 }
134 }
135
137 {
138 if (mOldFocusWidget == _widget)
139 {
140 if (mToolTipVisible)
141 {
142 mToolTipVisible = false;
143 hideToolTip(mOldFocusWidget);
144 }
145 mOldFocusWidget = nullptr;
146 mNeedToolTip = false;
147 }
148 }
149
150 void ToolTipManager::hideToolTip(Widget* _widget)
151 {
152 Widget* container = _widget->_getContainer();
153 if (container != nullptr)
154 container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Hide));
155 else
156 _widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Hide));
157 }
158
159 void ToolTipManager::showToolTip(Widget* _widget, size_t _index, const IntPoint& _point)
160 {
161 Widget* container = _widget->_getContainer();
162 if (container != nullptr)
163 container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Show, _index, _point));
164 else
165 _widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Show, ITEM_NONE, _point));
166 }
167
168 void ToolTipManager::moveToolTip(Widget* _widget, size_t _index, const IntPoint& _point)
169 {
170 Widget* container = _widget->_getContainer();
171 if (container != nullptr)
172 container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Move, _index, _point));
173 else
174 _widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Move, ITEM_NONE, _point));
175 }
176
177 bool ToolTipManager::isNeedToolTip(Widget* _widget)
178 {
179 Widget* container = _widget->_getContainer();
180 if (container != nullptr)
181 return container->getNeedToolTip();
182 return _widget->getNeedToolTip();
183 }
184
185 size_t ToolTipManager::getToolTipIndex(Widget* _widget) const
186 {
187 Widget* container = _widget->_getContainer();
188 if (container != nullptr)
189 return container->_getItemIndex(_widget);
190 return ITEM_NONE;
191 }
192
194 {
195 mDelayVisible = _value;
196 }
197
199 {
200 return mDelayVisible;
201 }
202
203} // namespace MyGUI
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_LOG(level, text)
static Gui & getInstance()
EventHandle_FrameEventDelegate eventFrameStart
Definition: MyGUI_Gui.h:150
Widget * getMouseFocusWidget() const
static InputManager & getInstance()
IntPoint getMousePositionByLayer() const
static const char * getClassTypeName()
void setDelayVisible(float _value)
void _unlinkWidget(Widget *_widget) override
widget description should be here.
Definition: MyGUI_Widget.h:37
Widget * _getContainer() const
EventHandle_WidgetToolTip eventToolTip
void unregisterUnlinker(IUnlinkWidget *_unlink)
static WidgetManager & getInstance()
void registerUnlinker(IUnlinkWidget *_unlink)
const size_t ITEM_NONE
Definition: MyGUI_Macros.h:17
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
types::TPoint< int > IntPoint
Definition: MyGUI_Types.h:26
MYGUI_SINGLETON_DEFINITION(ClipboardManager)