MyGUI: MyGUI_ToolTipManager.cpp Source File

MyGUI 3.4.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
13namespace MyGUI
14{
15
16 MYGUI_SINGLETON_DEFINITION(ToolTipManager);
17
18 ToolTipManager::ToolTipManager() :
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
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 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
136 void ToolTipManager::_unlinkWidget(Widget* _widget)
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
193 void ToolTipManager::setDelayVisible(float _value)
194 {
195 mDelayVisible = _value;
196 }
197
198 float ToolTipManager::getDelayVisible() const
199 {
200 return mDelayVisible;
201 }
202
203} // namespace MyGUI
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:29
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:123
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:150
MyGUI::InputManager::isCaptureMouse
bool isCaptureMouse() const
Definition MyGUI_InputManager.cpp:632
MyGUI::InputManager::getMouseFocusWidget
Widget * getMouseFocusWidget() const
Definition MyGUI_InputManager.cpp:647
MyGUI::InputManager::getInstance
static InputManager & getInstance()
MyGUI::InputManager::getMousePositionByLayer
IntPoint getMousePositionByLayer() const
Definition MyGUI_InputManager.cpp:615
MyGUI::ToolTipManager
Definition MyGUI_ToolTipManager.h:19
MyGUI::ToolTipManager::getClassTypeName
static const char * getClassTypeName()
MyGUI::ToolTipManager::shutdown
void shutdown()
Definition MyGUI_ToolTipManager.cpp:49
MyGUI::ToolTipManager::setDelayVisible
void setDelayVisible(float _value)
Definition MyGUI_ToolTipManager.cpp:193
MyGUI::ToolTipManager::getDelayVisible
float getDelayVisible() const
Definition MyGUI_ToolTipManager.cpp:198
MyGUI::ToolTipManager::initialise
void initialise()
Definition MyGUI_ToolTipManager.cpp:30
MyGUI::ToolTipManager::ToolTipManager
ToolTipManager()
Definition MyGUI_ToolTipManager.cpp:18
MyGUI::ToolTipManager::_unlinkWidget
void _unlinkWidget(Widget *_widget) override
Definition MyGUI_ToolTipManager.cpp:136
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:37
MyGUI::Widget::_getContainer
Widget * _getContainer() const
Definition MyGUI_Widget.cpp:1315
MyGUI::WidgetInput::eventToolTip
EventHandle_WidgetToolTip eventToolTip
Definition MyGUI_WidgetInput.h:227
MyGUI::WidgetManager::unregisterUnlinker
void unregisterUnlinker(IUnlinkWidget *_unlink)
Definition MyGUI_WidgetManager.cpp:139
MyGUI::WidgetManager::getInstance
static WidgetManager & getInstance()
MyGUI::WidgetManager::registerUnlinker
void registerUnlinker(IUnlinkWidget *_unlink)
Definition MyGUI_WidgetManager.cpp:133
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::ITEM_NONE
const size_t ITEM_NONE
Definition MyGUI_Macros.h:18
MyGUI::newDelegate
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
Definition MyGUI_Delegate.h:99
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