MyGUI  3.2.0
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 
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 
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);
59 
60  MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
61  mIsInitialise = true;
62  }
63 
65  {
66  MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
67  MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
68 
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  {
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;
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  {
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 
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 
214  {
215  mDelayVisible = _value;
216  }
217 
219  {
220  return mDelayVisible;
221  }
222 
223 } // namespace MyGUI
EventHandle_FrameEventDelegate eventFrameStart
Definition: MyGUI_Gui.h:166
delegates::IDelegate0 * newDelegate(void(*_func)())
static Gui & getInstance()
void setDelayVisible(float _value)
const size_t ITEM_NONE
Definition: MyGUI_Macros.h:32
static const char * getClassTypeName()
#define nullptr
#define MYGUI_LOG(level, text)
Widget * _getContainer()
#define MYGUI_ASSERT(exp, dest)
void _unlinkWidget(Widget *_widget)
void registerUnlinker(IUnlinkWidget *_unlink)
Widget * getMouseFocusWidget() const
void unregisterUnlinker(IUnlinkWidget *_unlink)
EventHandle_WidgetToolTip eventToolTip
types::TPoint< int > IntPoint
Definition: MyGUI_Types.h:41