MyGUI
3.2.0
|
00001 00006 /* 00007 This file is part of MyGUI. 00008 00009 MyGUI is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU Lesser General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 MyGUI is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00021 */ 00022 #include "MyGUI_Precompiled.h" 00023 #include "MyGUI_ToolTipManager.h" 00024 #include "MyGUI_Gui.h" 00025 #include "MyGUI_InputManager.h" 00026 #include "MyGUI_WidgetManager.h" 00027 00028 namespace MyGUI 00029 { 00030 00031 template <> ToolTipManager* Singleton<ToolTipManager>::msInstance = nullptr; 00032 template <> const char* Singleton<ToolTipManager>::mClassTypeName("ToolTipManager"); 00033 00034 ToolTipManager::ToolTipManager() : 00035 mDelayVisible(0.5f), 00036 mOldFocusWidget(nullptr), 00037 mToolTipVisible(false), 00038 mCurrentTime(0), 00039 mOldIndex(ITEM_NONE), 00040 mNeedToolTip(false), 00041 mIsInitialise(false) 00042 { 00043 } 00044 00045 void ToolTipManager::initialise() 00046 { 00047 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice"); 00048 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName()); 00049 00050 mDelayVisible = 0.5f; 00051 mOldFocusWidget = nullptr; 00052 mToolTipVisible = false; 00053 mCurrentTime = 0; 00054 mOldIndex = ITEM_NONE; 00055 mNeedToolTip = false; 00056 00057 Gui::getInstance().eventFrameStart += newDelegate(this, &ToolTipManager::notifyEventFrameStart); 00058 WidgetManager::getInstance().registerUnlinker(this); 00059 00060 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized"); 00061 mIsInitialise = true; 00062 } 00063 00064 void ToolTipManager::shutdown() 00065 { 00066 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised"); 00067 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName()); 00068 00069 WidgetManager::getInstance().unregisterUnlinker(this); 00070 Gui::getInstance().eventFrameStart -= newDelegate(this, &ToolTipManager::notifyEventFrameStart); 00071 00072 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown"); 00073 mIsInitialise = false; 00074 } 00075 00076 void ToolTipManager::notifyEventFrameStart(float _time) 00077 { 00078 Widget* widget = InputManager::getInstance().getMouseFocusWidget(); 00079 if (mOldFocusWidget != widget) 00080 { 00081 if (mToolTipVisible) 00082 { 00083 mToolTipVisible = false; 00084 hideToolTip(mOldFocusWidget); 00085 } 00086 mOldFocusWidget = widget; 00087 mNeedToolTip = false; 00088 00089 if (mOldFocusWidget != nullptr) 00090 { 00091 mCurrentTime = 0; 00092 mOldMousePoint = InputManager::getInstance().getMousePositionByLayer(); 00093 mOldIndex = getToolTipIndex(mOldFocusWidget); 00094 mNeedToolTip = isNeedToolTip(mOldFocusWidget); 00095 } 00096 } 00097 else if (mNeedToolTip) 00098 { 00099 bool capture = InputManager::getInstance().isCaptureMouse(); 00100 if (capture) 00101 { 00102 if (mToolTipVisible) 00103 { 00104 mToolTipVisible = false; 00105 hideToolTip(mOldFocusWidget); 00106 } 00107 } 00108 else 00109 { 00110 IntPoint point = InputManager::getInstance().getMousePositionByLayer(); 00111 if (!mToolTipVisible && point != mOldMousePoint) 00112 { 00113 if (mToolTipVisible) 00114 { 00115 mToolTipVisible = false; 00116 hideToolTip(mOldFocusWidget); 00117 } 00118 mCurrentTime = 0; 00119 mOldMousePoint = point; 00120 mOldIndex = getToolTipIndex(mOldFocusWidget); 00121 } 00122 else 00123 { 00124 size_t index = getToolTipIndex(mOldFocusWidget); 00125 if (mOldIndex != index) 00126 { 00127 if (mToolTipVisible) 00128 { 00129 mToolTipVisible = false; 00130 hideToolTip(mOldFocusWidget); 00131 } 00132 mCurrentTime = 0; 00133 mOldIndex = index; 00134 } 00135 else 00136 { 00137 if (!mToolTipVisible) 00138 { 00139 mCurrentTime += _time; 00140 if (mCurrentTime >= mDelayVisible) 00141 { 00142 mToolTipVisible = true; 00143 showToolTip(mOldFocusWidget, mOldIndex, point); 00144 } 00145 } 00146 else if (point != mOldMousePoint) 00147 { 00148 moveToolTip(mOldFocusWidget, mOldIndex, point); 00149 } 00150 } 00151 } 00152 } 00153 } 00154 } 00155 00156 void ToolTipManager::_unlinkWidget(Widget* _widget) 00157 { 00158 if (mOldFocusWidget == _widget) 00159 { 00160 if (mToolTipVisible) 00161 { 00162 mToolTipVisible = false; 00163 hideToolTip(mOldFocusWidget); 00164 } 00165 mOldFocusWidget = nullptr; 00166 mNeedToolTip = false; 00167 } 00168 } 00169 00170 void ToolTipManager::hideToolTip(Widget* _widget) 00171 { 00172 Widget* container = _widget->_getContainer(); 00173 if (container != nullptr) 00174 container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Hide)); 00175 else 00176 _widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Hide)); 00177 } 00178 00179 void ToolTipManager::showToolTip(Widget* _widget, size_t _index, const IntPoint& _point) 00180 { 00181 Widget* container = _widget->_getContainer(); 00182 if (container != nullptr) 00183 container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Show, _index, _point)); 00184 else 00185 _widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Show, ITEM_NONE, _point)); 00186 } 00187 00188 void ToolTipManager::moveToolTip(Widget* _widget, size_t _index, const IntPoint& _point) 00189 { 00190 Widget* container = _widget->_getContainer(); 00191 if (container != nullptr) 00192 container->eventToolTip(container, ToolTipInfo(ToolTipInfo::Move, _index, _point)); 00193 else 00194 _widget->eventToolTip(_widget, ToolTipInfo(ToolTipInfo::Move, ITEM_NONE, _point)); 00195 } 00196 00197 bool ToolTipManager::isNeedToolTip(Widget* _widget) 00198 { 00199 Widget* container = _widget->_getContainer(); 00200 if (container != nullptr) 00201 return container->getNeedToolTip(); 00202 return _widget->getNeedToolTip(); 00203 } 00204 00205 size_t ToolTipManager::getToolTipIndex(Widget* _widget) const 00206 { 00207 Widget* container = _widget->_getContainer(); 00208 if (container != nullptr) 00209 return container->_getItemIndex(_widget); 00210 return ITEM_NONE; 00211 } 00212 00213 float ToolTipManager::getDelayVisible() const 00214 { 00215 return mDelayVisible; 00216 } 00217 00218 } // namespace MyGUI