From 6014a900025cd45b13325c0d1f9d896e856defe5 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 28 May 2012 09:46:05 +0200 Subject: [PATCH] added tooltip delay option --- apps/openmw/mwgui/settingswindow.cpp | 6 ++++ apps/openmw/mwgui/settingswindow.hpp | 1 + apps/openmw/mwgui/tooltips.cpp | 30 +++++++++++++++++++ apps/openmw/mwgui/tooltips.hpp | 8 +++++ apps/openmw/mwgui/window_manager.cpp | 1 + files/mygui/openmw_settings_window_layout.xml | 15 ++++++++++ files/settings-default.cfg | 3 ++ 7 files changed, 64 insertions(+) diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index c8337d74c..428e0e862 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -37,6 +37,7 @@ namespace MWGui getWidget(mOkButton, "OkButton"); getWidget(mResolutionList, "ResolutionList"); getWidget(mMenuTransparencySlider, "MenuTransparencySlider"); + getWidget(mToolTipDelaySlider, "ToolTipDelaySlider"); getWidget(mViewDistanceSlider, "ViewDistanceSlider"); getWidget(mFullscreenButton, "FullscreenButton"); getWidget(mVSyncButton, "VSyncButton"); @@ -52,6 +53,7 @@ namespace MWGui mVSyncButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); mFPSButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onFpsToggled); mMenuTransparencySlider->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition); + mToolTipDelaySlider->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition); mViewDistanceSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition); mResolutionList->eventListChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onResolutionSelected); @@ -79,6 +81,8 @@ namespace MWGui // read settings int menu_transparency = (mMenuTransparencySlider->getScrollRange()-1) * Settings::Manager::getFloat("menu transparency", "GUI"); mMenuTransparencySlider->setScrollPosition(menu_transparency); + int tooltip_delay = (mToolTipDelaySlider->getScrollRange()-1) * Settings::Manager::getFloat("tooltip delay", "GUI"); + mToolTipDelaySlider->setScrollPosition(tooltip_delay); float val = (Settings::Manager::getFloat("max viewing distance", "Viewing distance")-2000)/(5600-2000); int viewdist = (mViewDistanceSlider->getScrollRange()-1) * val; @@ -170,6 +174,8 @@ namespace MWGui float val = pos / float(scroller->getScrollRange()-1); if (scroller == mMenuTransparencySlider) Settings::Manager::setFloat("menu transparency", "GUI", val); + else if (scroller == mToolTipDelaySlider) + Settings::Manager::setFloat("tooltip delay", "GUI", val); else if (scroller == mViewDistanceSlider) Settings::Manager::setFloat("max viewing distance", "Viewing distance", (1-val) * 2000 + val * 5600); else if (scroller == mMasterVolumeSlider) diff --git a/apps/openmw/mwgui/settingswindow.hpp b/apps/openmw/mwgui/settingswindow.hpp index 79af03994..09a93264d 100644 --- a/apps/openmw/mwgui/settingswindow.hpp +++ b/apps/openmw/mwgui/settingswindow.hpp @@ -19,6 +19,7 @@ namespace MWGui MyGUI::Button* mOkButton; MyGUI::ScrollBar* mMenuTransparencySlider; + MyGUI::ScrollBar* mToolTipDelaySlider; // graphics MyGUI::ListBox* mResolutionList; diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index c6d8e2c8c..bdce61a44 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -8,6 +8,8 @@ #include +#include + using namespace MWGui; using namespace MyGUI; @@ -19,6 +21,10 @@ ToolTips::ToolTips(WindowManager* windowManager) : , mEnabled(true) , mFocusToolTipX(0.0) , mFocusToolTipY(0.0) + , mDelay(0.0) + , mRemainingDelay(0.0) + , mLastMouseX(0) + , mLastMouseY(0) { getWidget(mDynamicToolTipBox, "DynamicToolTipBox"); @@ -28,6 +34,9 @@ ToolTips::ToolTips(WindowManager* windowManager) : // even if the mouse is over the tooltip mDynamicToolTipBox->setNeedMouseFocus(false); mMainWidget->setNeedMouseFocus(false); + + mDelay = Settings::Manager::getFloat("tooltip delay", "GUI"); + mRemainingDelay = mDelay; } void ToolTips::setEnabled(bool enabled) @@ -57,6 +66,21 @@ void ToolTips::onFrame(float frameDuration) if (!mGameMode) { + const MyGUI::IntPoint& mousePos = InputManager::getInstance().getMousePosition(); + if (mousePos.left == mLastMouseX && mousePos.top == mLastMouseY) + { + mRemainingDelay -= frameDuration; + } + else + { + mRemainingDelay = mDelay; + } + mLastMouseX = mousePos.left; + mLastMouseY = mousePos.top; + + if (mRemainingDelay > 0) + return; + Widget* focus = InputManager::getInstance().getMouseFocusWidget(); if (focus == 0) { @@ -621,3 +645,9 @@ void ToolTips::createClassToolTip(MyGUI::Widget* widget, const ESM::Class& playe widget->setUserString("ToolTipType", "Layout"); widget->setUserString("ToolTipLayout", "ClassToolTip"); } + +void ToolTips::setDelay(float delay) +{ + mDelay = delay; + mRemainingDelay = mDelay; +} diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp index 1925a4f14..036bdfaa3 100644 --- a/apps/openmw/mwgui/tooltips.hpp +++ b/apps/openmw/mwgui/tooltips.hpp @@ -41,6 +41,8 @@ namespace MWGui void toggleFullHelp(); ///< show extra info in item tooltips (owner, script) bool getFullHelp() const; + void setDelay(float delay); + void setFocusObject(const MWWorld::Ptr& focus); void setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y); ///< set the screen-space position of the tooltip for focused object @@ -84,6 +86,12 @@ namespace MWGui float mFocusToolTipX; float mFocusToolTipY; + float mDelay; + float mRemainingDelay; // remaining time until tooltip will show + + int mLastMouseX; + int mLastMouseY; + bool mGameMode; bool mEnabled; diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 891f85ca2..c3dc5d801 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -605,6 +605,7 @@ void WindowManager::onRetrieveTag(const MyGUI::UString& _tag, MyGUI::UString& _r void WindowManager::processChangedSettings(const Settings::CategorySettingVector& changed) { hud->setFpsLevel(Settings::Manager::getInt("fps", "HUD")); + mToolTips->setDelay(Settings::Manager::getFloat("tooltip delay", "GUI")); bool changeRes = false; for (Settings::CategorySettingVector::const_iterator it = changed.begin(); diff --git a/files/mygui/openmw_settings_window_layout.xml b/files/mygui/openmw_settings_window_layout.xml index 9b5826765..2e53c2a4a 100644 --- a/files/mygui/openmw_settings_window_layout.xml +++ b/files/mygui/openmw_settings_window_layout.xml @@ -23,6 +23,21 @@ + + + + + + + + + + + + + + + diff --git a/files/settings-default.cfg b/files/settings-default.cfg index a6623656c..883f32ae0 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -28,6 +28,9 @@ vsync = false # 1 is fully opaque menu transparency = 0.84 +# 0 - instantly, 1 - max. delay +tooltip delay = 0.2 + [General] # Camera field of view field of view = 55