From 74f89c500d278b6ac668c313b63d0f1e76f4acaf Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 30 Dec 2013 13:17:52 +0300 Subject: fix overhead text popups order. Now it drawed always below any windows. --- src/being/being.cpp | 1 + src/gui/popups/speechbubble.cpp | 7 +++++++ src/gui/popups/speechbubble.h | 2 ++ src/gui/widgets/windowcontainer.cpp | 20 ++++++++++++++++++++ src/gui/widgets/windowcontainer.h | 3 +++ 5 files changed, 33 insertions(+) (limited to 'src') diff --git a/src/being/being.cpp b/src/being/being.cpp index 2640379aa..439cbd2c9 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -1789,6 +1789,7 @@ void Being::drawSpeech(const int offsetX, const int offsetY) mSpeechBubble->setPosition(px - (mSpeechBubble->getWidth() / 2), py - getHeight() - (mSpeechBubble->getHeight())); mSpeechBubble->setVisible(true); + mSpeechBubble->requestMoveToBackground(); } else if (mSpeechTime > 0 && speech == TEXT_OVERHEAD) { diff --git a/src/gui/popups/speechbubble.cpp b/src/gui/popups/speechbubble.cpp index 0c40676f6..f1c7c0b9c 100644 --- a/src/gui/popups/speechbubble.cpp +++ b/src/gui/popups/speechbubble.cpp @@ -24,10 +24,12 @@ #include "gui/popups/speechbubble.h" #include "gui/sdlfont.h" +#include "gui/viewport.h" #include "gui/widgets/browserbox.h" #include "gui/widgets/label.h" #include "gui/widgets/textbox.h" +#include "gui/widgets/windowcontainer.h" #include @@ -89,3 +91,8 @@ void SpeechBubble::setText(const std::string &text, const bool showName) mCaption->setPosition(0, 0); mSpeechBox->setPosition(0, nameHeight); } + +void SpeechBubble::requestMoveToBackground() +{ + windowContainer->moveWidgetAfter(viewport, this); +} diff --git a/src/gui/popups/speechbubble.h b/src/gui/popups/speechbubble.h index 41c210eab..153c1e954 100644 --- a/src/gui/popups/speechbubble.h +++ b/src/gui/popups/speechbubble.h @@ -57,6 +57,8 @@ class SpeechBubble final : public Popup */ void setText(const std::string &text, const bool showName = true); + void requestMoveToBackground(); + private: std::string mText; int mSpacing; diff --git a/src/gui/widgets/windowcontainer.cpp b/src/gui/widgets/windowcontainer.cpp index cba565cc4..d420e1183 100644 --- a/src/gui/widgets/windowcontainer.cpp +++ b/src/gui/widgets/windowcontainer.cpp @@ -58,6 +58,26 @@ void WindowContainer::adjustAfterResize(const int oldScreenWidth, } } +void WindowContainer::moveWidgetAfter(gcn::Widget *const after, + gcn::Widget *const widget) +{ + WidgetListIterator widgetIter = std::find( + mWidgets.begin(), mWidgets.end(), widget); + + if (widgetIter == mWidgets.end()) + return; + + WidgetListIterator afterIter = std::find( + mWidgets.begin(), mWidgets.end(), after); + + if (afterIter == mWidgets.end()) + return; + + ++ afterIter; + mWidgets.erase(widgetIter); + mWidgets.insert(afterIter, widget); +} + #ifdef USE_PROFILER void WindowContainer::draw(gcn::Graphics* graphics) { diff --git a/src/gui/widgets/windowcontainer.h b/src/gui/widgets/windowcontainer.h index 3645b94b6..c11d1b238 100644 --- a/src/gui/widgets/windowcontainer.h +++ b/src/gui/widgets/windowcontainer.h @@ -53,6 +53,9 @@ class WindowContainer : public Container void adjustAfterResize(const int oldScreenWidth, const int oldScreenHeight); + void moveWidgetAfter(gcn::Widget *const before, + gcn::Widget *const widget); + #ifdef USE_PROFILER void draw(gcn::Graphics* graphics); #endif -- cgit v1.2.3-70-g09d2