From fdcbdbf35df7f3401b5db0dd990927e1479387eb Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 13 Mar 2013 19:44:34 +0100 Subject: [PATCH] Rewrote layout tooltips to use the new box layout system, fixes word wrapping delay --- apps/openmw/mwgui/tooltips.cpp | 68 ++++------- apps/openmw/mwgui/widgets.cpp | 2 + files/mygui/openmw_tooltips.layout | 179 ++++++++++++++--------------- 3 files changed, 112 insertions(+), 137 deletions(-) diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 8dcf398ca..8eb0336a7 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -44,6 +44,11 @@ ToolTips::ToolTips(MWBase::WindowManager* windowManager) : mDelay = Settings::Manager::getFloat("tooltip delay", "GUI"); mRemainingDelay = mDelay; + + for (unsigned int i=0; i < mMainWidget->getChildCount(); ++i) + { + mMainWidget->getChildAt(i)->setVisible(false); + } } void ToolTips::setEnabled(bool enabled) @@ -115,7 +120,7 @@ void ToolTips::onFrame(float frameDuration) } else { - mHorizontalScrollIndex = 0; + mHorizontalScrollIndex = 0; mRemainingDelay = mDelay; } mLastMouseX = mousePos.left; @@ -215,14 +220,6 @@ void ToolTips::onFrame(float frameDuration) getWidget(tooltip, focus->getUserString("ToolTipLayout")); tooltip->setVisible(true); - if (!tooltip->isUserString("DontResize")) - { - tooltip->setCoord(0, 0, 450, 300); // this is the maximum width of the tooltip before it starts word-wrapping - - tooltipSize = MyGUI::IntSize(0, tooltip->getSize().height); - } - else - tooltipSize = tooltip->getSize(); std::map userStrings = focus->getUserStrings(); for (std::map::iterator it = userStrings.begin(); @@ -243,32 +240,8 @@ void ToolTips::onFrame(float frameDuration) w->setProperty(propertyKey, it->second); } - for (unsigned int i=0; igetChildCount(); ++i) - { - MyGUI::Widget* w = tooltip->getChildAt(i); + tooltipSize = tooltip->getSize(); - if (w->isUserString("AutoResizeHorizontal")) - { - MyGUI::TextBox* text = w->castType(); - tooltipSize.width = std::max(tooltipSize.width, w->getLeft() + text->getTextSize().width + 8); - } - else if (!tooltip->isUserString("DontResize")) - tooltipSize.width = std::max(tooltipSize.width, w->getLeft() + w->getWidth() + 8); - - if (w->isUserString("AutoResizeVertical")) - { - MyGUI::TextBox* text = w->castType(); - int height = text->getTextSize().height; - if (height > w->getHeight()) - { - tooltipSize += MyGUI::IntSize(0, height - w->getHeight()); - } - if (height < w->getHeight()) - { - tooltipSize -= MyGUI::IntSize(0, w->getHeight() - height); - } - } - } tooltip->setCoord(0, 0, tooltipSize.width, tooltipSize.height); } else @@ -509,20 +482,21 @@ IntSize ToolTips::createToolTip(const MWGui::ToolTipInfo& info) captionSize.height); //if its too long we do hscroll with the caption - if (captionSize.width > maximumWidth){ - mHorizontalScrollIndex = mHorizontalScrollIndex + 2; - if (mHorizontalScrollIndex > captionSize.width){ - mHorizontalScrollIndex = -totalSize.width; - } - int horizontal_scroll = mHorizontalScrollIndex; - if (horizontal_scroll < 40){ - horizontal_scroll = 40; - }else{ - horizontal_scroll = 80 - mHorizontalScrollIndex; - } - captionWidget->setPosition (IntPoint(horizontal_scroll, captionWidget->getPosition().top + padding.top)); + if (captionSize.width > maximumWidth) + { + mHorizontalScrollIndex = mHorizontalScrollIndex + 2; + if (mHorizontalScrollIndex > captionSize.width){ + mHorizontalScrollIndex = -totalSize.width; + } + int horizontal_scroll = mHorizontalScrollIndex; + if (horizontal_scroll < 40){ + horizontal_scroll = 40; + }else{ + horizontal_scroll = 80 - mHorizontalScrollIndex; + } + captionWidget->setPosition (IntPoint(horizontal_scroll, captionWidget->getPosition().top + padding.top)); } else { - captionWidget->setPosition (captionWidget->getPosition() + padding); + captionWidget->setPosition (captionWidget->getPosition() + padding); } textWidget->setPosition (textWidget->getPosition() + IntPoint(0, padding.top)); // only apply vertical padding, the horizontal works automatically due to Align::HCenter diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index b0f7e6293..259099017 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -588,6 +588,8 @@ void AutoSizedTextBox::setPropertyOverride(const std::string& _key, const std::s MyGUI::IntSize AutoSizedEditBox::getRequestedSize() { + if (getAlign().isHStretch()) + throw std::runtime_error("AutoSizedEditBox can't have HStretch align (" + getName() + ")"); return MyGUI::IntSize(getSize().width, getTextSize().height); } diff --git a/files/mygui/openmw_tooltips.layout b/files/mygui/openmw_tooltips.layout index 514d1a25b..f554e2b0d 100644 --- a/files/mygui/openmw_tooltips.layout +++ b/files/mygui/openmw_tooltips.layout @@ -5,124 +5,124 @@ - - - + + + - + - - - - + + + - + - - + - - - - + + + - + - - + - - - + - - - + + + - + + + + + + + - + - - - - + + + - + + + - - - + + + - + - - - - + + + - + + + - - - + + + + + + + + + - - - - - - + - - - - + @@ -135,37 +135,36 @@ - - + + + - + + - - - + + + + + + + + + + + - - - - - - + - - - - - - @@ -181,43 +180,43 @@ - - + + + - + - - - - + + + - + + - - - + + + + + + + + + - - - - - - + - -