MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_ToolTipManager.cpp
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_ToolTipManager.h"
24 #include "MyGUI_Gui.h"
25 #include "MyGUI_InputManager.h"
26 #include "MyGUI_WidgetManager.h"
27
28 namespace MyGUI
29 {
30
31 template <> ToolTipManager* Singleton<ToolTipManager>::msInstance = nullptr;
32 template <> const char* Singleton<ToolTipManager>::mClassTypeName("ToolTipManager");
33
34 ToolTipManager::ToolTipManager() :
35 mDelayVisible(0.5f),
36 mOldFocusWidget(nullptr),
37 mToolTipVisible(false),
38 mCurrentTime(0),
39 mOldIndex(ITEM_NONE),
40 mNeedToolTip(false),
41 mIsInitialise(false)
42 {
43 }
44
45 void ToolTipManager::initialise()
46 {
47 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
48 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
49
50 mDelayVisible = 0.5f;
51 mOldFocusWidget = nullptr;
52 mToolTipVisible = false;
53 mCurrentTime = 0;
54 mOldIndex = ITEM_NONE;
55 mNeedToolTip = false;
56
57 Gui::getInstance().eventFrameStart += newDelegate(this, &ToolTipManager::notifyEventFrameStart);
58 WidgetManager::getInstance().registerUnlinker(this);
59
60 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
61 mIsInitialise = true;
62 }
63
64 void ToolTipManager::shutdown()
65 {
66 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
67 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
68
69 WidgetManager::getInstance().unregisterUnlinker(this);
70 Gui::getInstance().eventFrameStart -= newDelegate(this, &ToolTipManager::notifyEventFrameStart);
71
72 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
73 mIsInitialise = false;
74 }
75
76 void ToolTipManager::notifyEventFrameStart(float _time)
77 {
78 Widget* widget = InputManager::getInstance().getMouseFocusWidget();
79 if (mOldFocusWidget != widget)
80 {
81 if (mToolTipVisible)
82 {
83 mToolTipVisible = false;
84 hideToolTip(mOldFocusWidget);
85 }
86 mOldFocusWidget = widget;
87 mNeedToolTip = false;
88
89 if (mOldFocusWidget != nullptr)
90 {
91 mCurrentTime = 0;
92 mOldMousePoint = InputManager::getInstance().getMousePositionByLayer();
93 mOldIndex = getToolTipIndex(mOldFocusWidget);
94 mNeedToolTip = isNeedToolTip(mOldFocusWidget);
95 }
96 }
97 else if (mNeedToolTip)
98 {
99 bool capture = InputManager::getInstance().isCaptureMouse();
100 if (capture)
101 {
102 if (mToolTipVisible)
103 {
104 mToolTipVisible = false;
105 hideToolTip(mOldFocusWidget);
106 }
107 }
108 else
109 {
110 IntPoint point = InputManager::getInstance().getMousePositionByLayer();
111 if (!mToolTipVisible && point != mOldMousePoint)
112 {
113 if (mToolTipVisible)
114 {
115 mToolTipVisible = false;
116 hideToolTip(mOldFocusWidget);
117 }
118 mCurrentTime = 0;
119 mOldMousePoint = point;
120 mOldIndex = getToolTipIndex(mOldFocusWidget);
121 }
122 else
123 {
124 size_t index = getToolTipIndex(mOldFocusWidget);
125 if (mOldIndex != index)
126 {
127 if (mToolTipVisible)
128 {
129 mToolTipVisible = false;
130 hideToolTip(mOldFocusWidget);
131 }
132 mCurrentTime = 0;
133 mOldIndex = index;
134 }
135 else
136 {
137 if (!mToolTipVisible)
138 {
139 mCurrentTime += _time;
140 if (mCurrentTime >= mDelayVisible)
141 {
142 mToolTipVisible = true;
143 showToolTip(mOldFocusWidget, mOldIndex, point);
144 }
145 }
146 else if (point != mOldMousePoint)
147 {
148 moveToolTip(mOldFocusWidget, mOldIndex, point);
149 }
150 }
151 }
152 }
153 }
154 }
155
156 void ToolTipManager::_unlinkWidget(Widget* _widget)
157 {
158 if (mOldFocusWidget == _widget)
159 {
160 if (mToolTipVisible)
161 {
162 mToolTipVisible = false;
163 hideToolTip(mOldFocusWidget);
164 }
165 mOldFocusWidget = nullptr;
166 mNeedToolTip = false;
167 }
168 }
169
170 void ToolTipManager::hideToolTip(Widget* _widget)
171 {
172 Widget* container = _widget->_getContainer();
173 if (container != nullptr)
174 container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Hide));
175 else
176 _widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Hide));
177 }
178
179 void ToolTipManager::showToolTip(Widget* _widget, size_t _index, const IntPoint& _point)
180 {
181 Widget* container = _widget->_getContainer();
182 if (container != nullptr)
183 container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Show, _index, _point));
184 else
185 _widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Show, ITEM_NONE, _point));
186 }
187
188 void ToolTipManager::moveToolTip(Widget* _widget, size_t _index, const IntPoint& _point)
189 {
190 Widget* container = _widget->_getContainer();
191 if (container != nullptr)
192 container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Move, _index, _point));
193 else
194 _widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Move, ITEM_NONE, _point));
195 }
196
197 bool ToolTipManager::isNeedToolTip(Widget* _widget)
198 {
199 Widget* container = _widget->_getContainer();
200 if (container != nullptr)
201 return container->getNeedToolTip();
202 return _widget->getNeedToolTip();
203 }
204
205 size_t ToolTipManager::getToolTipIndex(Widget* _widget) const
206 {
207 Widget* container = _widget->_getContainer();
208 if (container != nullptr)
209 return container->_getItemIndex(_widget);
210 return ITEM_NONE;
211 }
212
213 void ToolTipManager::setDelayVisible(float _value)
214 {
215 mDelayVisible = _value;
216 }
217
218 float ToolTipManager::getDelayVisible() const
219 {
220 return mDelayVisible;
221 }
222
223 } // namespace MyGUI
MyGUI::Widget
Definition: MyGUI_Widget.h:41
MyGUI::ToolTipManager::initialise
void initialise()
Definition: MyGUI_ToolTipManager.cpp:45
MyGUI::Gui::eventFrameStart
EventHandle_FrameEventDelegate eventFrameStart
Definition: MyGUI_Gui.h:166
MyGUI::InputManager::getMousePositionByLayer
IntPoint getMousePositionByLayer()
Definition: MyGUI_InputManager.cpp:603
MyGUI_Precompiled.h
MyGUI::newDelegate
delegates::IDelegate0 * newDelegate(void(*_func)())
Definition: MyGUI_Delegate.h:150
MyGUI::Singleton< Gui >::getInstance
static Gui & getInstance()
Definition: MyGUI_Singleton.h:53
MyGUI::ToolTipManager::setDelayVisible
void setDelayVisible(float _value)
Definition: MyGUI_ToolTipManager.cpp:213
MyGUI_WidgetManager.h
MyGUI::ToolTipInfo
Definition: MyGUI_WidgetToolTip.h:32
MyGUI::ITEM_NONE
const size_t ITEM_NONE
Definition: MyGUI_Macros.h:32
MyGUI::Singleton< ToolTipManager >::getClassTypeName
static const char * getClassTypeName()
Definition: MyGUI_Singleton.h:64
nullptr
#define nullptr
Definition: MyGUI_Prerequest.h:47
MyGUI::ToolTipInfo::Show
Definition: MyGUI_WidgetToolTip.h:37
MyGUI::InputManager::isCaptureMouse
bool isCaptureMouse() const
Definition: MyGUI_InputManager.cpp:620
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition: MyGUI_Diagnostic.h:38
MyGUI::ToolTipInfo::Move
Definition: MyGUI_WidgetToolTip.h:38
MyGUI::ToolTipManager::ToolTipManager
ToolTipManager()
Definition: MyGUI_ToolTipManager.cpp:34
MyGUI::Widget::_getContainer
Widget * _getContainer()
Definition: MyGUI_Widget.cpp:1280
MyGUI::ToolTipManager::getDelayVisible
float getDelayVisible() const
Definition: MyGUI_ToolTipManager.cpp:218
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:58
MyGUI::ToolTipInfo::Hide
Definition: MyGUI_WidgetToolTip.h:36
MyGUI_InputManager.h
MyGUI::ToolTipManager::_unlinkWidget
void _unlinkWidget(Widget *_widget)
Definition: MyGUI_ToolTipManager.cpp:156
MyGUI::WidgetManager::registerUnlinker
void registerUnlinker(IUnlinkWidget *_unlink)
Definition: MyGUI_WidgetManager.cpp:147
MyGUI::InputManager::getMouseFocusWidget
Widget * getMouseFocusWidget() const
Definition: MyGUI_InputManager.cpp:635
MyGUI_ToolTipManager.h
MyGUI_Gui.h
MyGUI::Singleton::mClassTypeName
static const char * mClassTypeName
Definition: MyGUI_Singleton.h:73
MyGUI::ToolTipManager::shutdown
void shutdown()
Definition: MyGUI_ToolTipManager.cpp:64
MyGUI::WidgetManager::unregisterUnlinker
void unregisterUnlinker(IUnlinkWidget *_unlink)
Definition: MyGUI_WidgetManager.cpp:153
MyGUI::WidgetInput::eventToolTip
EventHandle_WidgetToolTip eventToolTip
Definition: MyGUI_WidgetInput.h:258
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition: MyGUI_Types.h:41