MyGUI 3.2.2

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

- File List
- Globals

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
13 namespace MyGUI
14 {
15
16 template <> ToolTipManager* Singleton<ToolTipManager>::msInstance = nullptr;
17 template <> const char* Singleton<ToolTipManager>::mClassTypeName = "ToolTipManager";
18
19 ToolTipManager::ToolTipManager() :
20 mDelayVisible(0.5f),
21 mOldFocusWidget(nullptr),
22 mToolTipVisible(false),
23 mCurrentTime(0),
24 mOldIndex(ITEM_NONE),
25 mNeedToolTip(false),
26 mIsInitialise(false)
27 {
28 }
29
30 void ToolTipManager::initialise()
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);
43 WidgetManager::getInstance().registerUnlinker(this);
44
45 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
46 mIsInitialise = true;
47 }
48
49 void ToolTipManager::shutdown()
50 {
51 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
52 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
53
54 WidgetManager::getInstance().unregisterUnlinker(this);
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 {
63 Widget* widget = InputManager::getInstance().getMouseFocusWidget();
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;
77 mOldMousePoint = InputManager::getInstance().getMousePositionByLayer();
78 mOldIndex = getToolTipIndex(mOldFocusWidget);
79 mNeedToolTip = isNeedToolTip(mOldFocusWidget);
80 }
81 }
82 else if (mNeedToolTip)
83 {
84 bool capture = InputManager::getInstance().isCaptureMouse();
85 if (capture)
86 {
87 if (mToolTipVisible)
88 {
89 mToolTipVisible = false;
90 hideToolTip(mOldFocusWidget);
91 }
92 }
93 else
94 {
95 IntPoint point = InputManager::getInstance().getMousePositionByLayer();
96 if (!mToolTipVisible && point != mOldMousePoint)
97 {
98 if (mToolTipVisible)
99 {
100 mToolTipVisible = false;
101 hideToolTip(mOldFocusWidget);
102 }
103 mCurrentTime = 0;
104 mOldMousePoint = point;
105 mOldIndex = getToolTipIndex(mOldFocusWidget);
106 }
107 else
108 {
109 size_t index = getToolTipIndex(mOldFocusWidget);
110 if (mOldIndex != index)
111 {
112 if (mToolTipVisible)
113 {
114 mToolTipVisible = false;
115 hideToolTip(mOldFocusWidget);
116 }
117 mCurrentTime = 0;
118 mOldIndex = index;
119 }
120 else
121 {
122 if (!mToolTipVisible)
123 {
124 mCurrentTime += _time;
125 if (mCurrentTime >= mDelayVisible)
126 {
127 mToolTipVisible = true;
128 showToolTip(mOldFocusWidget, mOldIndex, point);
129 }
130 }
131 else if (point != mOldMousePoint)
132 {
133 moveToolTip(mOldFocusWidget, mOldIndex, point);
134 }
135 }
136 }
137 }
138 }
139 }
140
141 void ToolTipManager::_unlinkWidget(Widget* _widget)
142 {
143 if (mOldFocusWidget == _widget)
144 {
145 if (mToolTipVisible)
146 {
147 mToolTipVisible = false;
148 hideToolTip(mOldFocusWidget);
149 }
150 mOldFocusWidget = nullptr;
151 mNeedToolTip = false;
152 }
153 }
154
155 void ToolTipManager::hideToolTip(Widget* _widget)
156 {
157 Widget* container = _widget->_getContainer();
158 if (container != nullptr)
159 container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Hide));
160 else
161 _widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Hide));
162 }
163
164 void ToolTipManager::showToolTip(Widget* _widget, size_t _index, const IntPoint& _point)
165 {
166 Widget* container = _widget->_getContainer();
167 if (container != nullptr)
168 container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Show, _index, _point));
169 else
170 _widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Show, ITEM_NONE, _point));
171 }
172
173 void ToolTipManager::moveToolTip(Widget* _widget, size_t _index, const IntPoint& _point)
174 {
175 Widget* container = _widget->_getContainer();
176 if (container != nullptr)
177 container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Move, _index, _point));
178 else
179 _widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Move, ITEM_NONE, _point));
180 }
181
182 bool ToolTipManager::isNeedToolTip(Widget* _widget)
183 {
184 Widget* container = _widget->_getContainer();
185 if (container != nullptr)
186 return container->getNeedToolTip();
187 return _widget->getNeedToolTip();
188 }
189
190 size_t ToolTipManager::getToolTipIndex(Widget* _widget) const
191 {
192 Widget* container = _widget->_getContainer();
193 if (container != nullptr)
194 return container->_getItemIndex(_widget);
195 return ITEM_NONE;
196 }
197
198 void ToolTipManager::setDelayVisible(float _value)
199 {
200 mDelayVisible = _value;
201 }
202
203 float ToolTipManager::getDelayVisible() const
204 {
205 return mDelayVisible;
206 }
207
208 } // namespace MyGUI
MyGUI::Widget
Widget properties. Widget_skin_childs Skin childs. Widget widget description should be here...
Definition: MyGUI_Widget.h:29
MyGUI::ToolTipManager::initialise
void initialise()
Definition: MyGUI_ToolTipManager.cpp:30
MyGUI::Gui::eventFrameStart
EventHandle_FrameEventDelegate eventFrameStart
Definition: MyGUI_Gui.h:150
MyGUI::InputManager::getMousePositionByLayer
IntPoint getMousePositionByLayer()
Definition: MyGUI_InputManager.cpp:596
MyGUI_Precompiled.h
MyGUI::newDelegate
delegates::IDelegate0 * newDelegate(void(*_func)())
Definition: MyGUI_Delegate.h:118
MyGUI::Singleton< Gui >::getInstance
static Gui & getInstance()
Definition: MyGUI_Singleton.h:38
MyGUI::ToolTipManager::setDelayVisible
void setDelayVisible(float _value)
Definition: MyGUI_ToolTipManager.cpp:198
MyGUI_WidgetManager.h
MyGUI::ToolTipInfo
Definition: MyGUI_WidgetToolTip.h:17
MyGUI::ITEM_NONE
const size_t ITEM_NONE
Definition: MyGUI_Macros.h:17
MyGUI::Singleton< ToolTipManager >::getClassTypeName
static const char * getClassTypeName()
Definition: MyGUI_Singleton.h:49
nullptr
#define nullptr
Definition: MyGUI_Prerequest.h:29
MyGUI::ToolTipInfo::Show
Definition: MyGUI_WidgetToolTip.h:22
MyGUI::InputManager::isCaptureMouse
bool isCaptureMouse() const
Definition: MyGUI_InputManager.cpp:613
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition: MyGUI_Diagnostic.h:22
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI::ToolTipInfo::Move
Definition: MyGUI_WidgetToolTip.h:23
MyGUI::ToolTipManager::ToolTipManager
ToolTipManager()
Definition: MyGUI_ToolTipManager.cpp:19
MyGUI::Widget::_getContainer
Widget * _getContainer()
Definition: MyGUI_Widget.cpp:1310
MyGUI::ToolTipManager::getDelayVisible
float getDelayVisible() const
Definition: MyGUI_ToolTipManager.cpp:203
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:42
MyGUI::ToolTipInfo::Hide
Definition: MyGUI_WidgetToolTip.h:21
MyGUI_InputManager.h
MyGUI::ToolTipManager::_unlinkWidget
void _unlinkWidget(Widget *_widget)
Definition: MyGUI_ToolTipManager.cpp:141
MyGUI::WidgetManager::registerUnlinker
void registerUnlinker(IUnlinkWidget *_unlink)
Definition: MyGUI_WidgetManager.cpp:133
MyGUI::InputManager::getMouseFocusWidget
Widget * getMouseFocusWidget() const
Definition: MyGUI_InputManager.cpp:628
MyGUI_ToolTipManager.h
MyGUI_Gui.h
MyGUI::ToolTipManager::shutdown
void shutdown()
Definition: MyGUI_ToolTipManager.cpp:49
MyGUI::WidgetManager::unregisterUnlinker
void unregisterUnlinker(IUnlinkWidget *_unlink)
Definition: MyGUI_WidgetManager.cpp:139
MyGUI::WidgetInput::eventToolTip
EventHandle_WidgetToolTip eventToolTip
Definition: MyGUI_WidgetInput.h:227
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition: MyGUI_Types.h:26