MyGUI_ToolTipManager.cpp
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_ToolTipManager.h"
#include "MyGUI_Gui.h"
#include "MyGUI_InputManager.h"
#include "MyGUI_WidgetManager.h"
namespace MyGUI
{
MYGUI_SINGLETON_DEFINITION(ToolTipManager);
ToolTipManager::ToolTipManager() :
mSingletonHolder(this)
{
}
void ToolTipManager::initialise()
{
MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
mDelayVisible = 0.5f;
mOldFocusWidget = nullptr;
mToolTipVisible = false;
mCurrentTime = 0;
mOldIndex = ITEM_NONE;
mNeedToolTip = false;
Gui::getInstance().eventFrameStart += newDelegate(this, &ToolTipManager::notifyEventFrameStart);
WidgetManager::getInstance().registerUnlinker(this);
MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
mIsInitialise = true;
}
void ToolTipManager::shutdown()
{
MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
WidgetManager::getInstance().unregisterUnlinker(this);
Gui::getInstance().eventFrameStart -= newDelegate(this, &ToolTipManager::notifyEventFrameStart);
MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
mIsInitialise = false;
}
void ToolTipManager::notifyEventFrameStart(float _time)
{
Widget* widget = InputManager::getInstance().getMouseFocusWidget();
if (mOldFocusWidget != widget)
{
if (mToolTipVisible)
{
mToolTipVisible = false;
hideToolTip(mOldFocusWidget);
}
mOldFocusWidget = widget;
mNeedToolTip = false;
if (mOldFocusWidget != nullptr)
{
mCurrentTime = 0;
mOldMousePoint = InputManager::getInstance().getMousePositionByLayer();
mOldIndex = getToolTipIndex(mOldFocusWidget);
mNeedToolTip = isNeedToolTip(mOldFocusWidget);
}
}
else if (mNeedToolTip)
{
bool capture = InputManager::getInstance().isCaptureMouse();
if (capture)
{
if (mToolTipVisible)
{
mToolTipVisible = false;
hideToolTip(mOldFocusWidget);
}
}
else
{
IntPoint point = InputManager::getInstance().getMousePositionByLayer();
if (!mToolTipVisible && point != mOldMousePoint)
{
mCurrentTime = 0;
mOldMousePoint = point;
mOldIndex = getToolTipIndex(mOldFocusWidget);
}
else
{
size_t index = getToolTipIndex(mOldFocusWidget);
if (mOldIndex != index)
{
if (mToolTipVisible)
{
mToolTipVisible = false;
hideToolTip(mOldFocusWidget);
}
mCurrentTime = 0;
mOldIndex = index;
}
else
{
if (!mToolTipVisible)
{
mCurrentTime += _time;
if (mCurrentTime >= mDelayVisible)
{
mToolTipVisible = true;
showToolTip(mOldFocusWidget, mOldIndex, point);
}
}
else if (point != mOldMousePoint)
{
moveToolTip(mOldFocusWidget, mOldIndex, point);
}
}
}
}
}
}
void ToolTipManager::_unlinkWidget(Widget* _widget)
{
if (mOldFocusWidget == _widget)
{
if (mToolTipVisible)
{
mToolTipVisible = false;
hideToolTip(mOldFocusWidget);
}
mOldFocusWidget = nullptr;
mNeedToolTip = false;
}
}
void ToolTipManager::hideToolTip(Widget* _widget)
{
Widget* container = _widget->_getContainer();
if (container != nullptr)
container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Hide));
else
_widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Hide));
}
void ToolTipManager::showToolTip(Widget* _widget, size_t _index, const IntPoint& _point)
{
Widget* container = _widget->_getContainer();
if (container != nullptr)
container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Show, _index, _point));
else
_widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Show, ITEM_NONE, _point));
}
void ToolTipManager::moveToolTip(Widget* _widget, size_t _index, const IntPoint& _point)
{
Widget* container = _widget->_getContainer();
if (container != nullptr)
container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Move, _index, _point));
else
_widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Move, ITEM_NONE, _point));
}
bool ToolTipManager::isNeedToolTip(Widget* _widget)
{
Widget* container = _widget->_getContainer();
if (container != nullptr)
return container->getNeedToolTip();
return _widget->getNeedToolTip();
}
size_t ToolTipManager::getToolTipIndex(Widget* _widget) const
{
Widget* container = _widget->_getContainer();
if (container != nullptr)
return container->_getItemIndex(_widget);
return ITEM_NONE;
}
void ToolTipManager::setDelayVisible(float _value)
{
mDelayVisible = _value;
}
float ToolTipManager::getDelayVisible() const
{
return mDelayVisible;
}
} // namespace MyGUI
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:31
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:126
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:215
MyGUI::InputManager::isCaptureMouse
bool isCaptureMouse() const
Definition MyGUI_InputManager.cpp:623
MyGUI::InputManager::getMouseFocusWidget
Widget * getMouseFocusWidget() const
Definition MyGUI_InputManager.cpp:638
MyGUI::InputManager::getInstance
static InputManager & getInstance()
MyGUI::InputManager::getMousePositionByLayer
IntPoint getMousePositionByLayer() const
Definition MyGUI_InputManager.cpp:606
MyGUI::ToolTipManager
Definition MyGUI_ToolTipManager.h:18
MyGUI::ToolTipManager::shutdown
void shutdown()
Definition MyGUI_ToolTipManager.cpp:42
MyGUI::ToolTipManager::setDelayVisible
void setDelayVisible(float _value)
Definition MyGUI_ToolTipManager.cpp:186
MyGUI::ToolTipManager::getDelayVisible
float getDelayVisible() const
Definition MyGUI_ToolTipManager.cpp:191
MyGUI::ToolTipManager::initialise
void initialise()
Definition MyGUI_ToolTipManager.cpp:23
MyGUI::ToolTipManager::ToolTipManager
ToolTipManager()
Definition MyGUI_ToolTipManager.cpp:18
MyGUI::ToolTipManager::getClassTypeName
static std::string_view getClassTypeName()
MyGUI::ToolTipManager::_unlinkWidget
void _unlinkWidget(Widget *_widget) override
Definition MyGUI_ToolTipManager.cpp:129
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::Widget::_getContainer
Widget * _getContainer() const
Definition MyGUI_Widget.cpp:1392
MyGUI::WidgetInput::eventToolTip
EventHandle_WidgetToolTip eventToolTip
Definition MyGUI_WidgetInput.h:226
MyGUI::WidgetManager::unregisterUnlinker
void unregisterUnlinker(IUnlinkWidget *_unlink)
Definition MyGUI_WidgetManager.cpp:144
MyGUI::WidgetManager::getInstance
static WidgetManager & getInstance()
MyGUI::WidgetManager::registerUnlinker
void registerUnlinker(IUnlinkWidget *_unlink)
Definition MyGUI_WidgetManager.cpp:138
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::ITEM_NONE
constexpr size_t ITEM_NONE
Definition MyGUI_Macros.h:19
MyGUI::newDelegate
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
Definition MyGUI_Delegate.h:100
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