diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index 1a8c3c169..148a7f98c 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -11,7 +11,23 @@ void MessageBoxManager::createMessageBox (const std::string& message) { std::cout << "create non-interactive message box" << std::endl; MessageBox *box = new MessageBox(*this, message); - mMessageBoxes.push_back(box); + + mMessageBoxes.insert(mMessageBoxes.begin(), box); + int height = box->getHeight(); + std::vector::const_iterator it; + + int i = 0; + for(it = mMessageBoxes.begin(); it != mMessageBoxes.end(); ++it) { + if(i == 3) { + (*it)->del(); + break; + } + else { + (*it)->update(height); + height += (*it)->getHeight(); + i++; + } + } } void MessageBoxManager::createInteractiveMessageBox (const std::string& message, const std::vector& buttons) @@ -25,24 +41,44 @@ MessageBox::MessageBox(MessageBoxManager& parMessageBoxManager, const std::strin , mMessageBoxManager(parMessageBoxManager) { setText("message", message); - + update(0); +} + +void MessageBox::update (int height) +{ MyGUI::WidgetPtr messageWidget; getWidget(messageWidget, "message"); MyGUI::IntSize size = messageWidget->_getTextSize(); - size.width += 20; - size.height += 20; + messageWidget->setSize(size); + size.width += 20; // padding between text and border of the box + size.height += 20; // same here MyGUI::IntSize gameWindowSize = mMessageBoxManager.mWindowManager->getGui()->getViewSize(); MyGUI::IntCoord coord; coord.left = (gameWindowSize.width - size.width)/2; - coord.top = (gameWindowSize.height - size.height); + coord.top = (gameWindowSize.height - size.height - height); std::cout << "Setting MainWidget to position (" << coord.left << "|" << coord.top - << ") and size to (" << size.width << "|" << size.height << ")" << std::endl; + << ") and size to (" << size.width << "|" << size.height << ")" + << " while height is " << height << std::endl; mMainWidget->setCoord(coord); mMainWidget->setSize(size); + mHeight = size.height; +} + +void MessageBox::del () +{ + // i dont know how to destroy, but therefor i will just set height and width to zero + MyGUI::IntSize size; + size.width = size.height = 0; + mMainWidget->setSize(size); +} + +int MessageBox::getHeight () +{ + return mHeight+20; // 20 is the padding between this and the next MessageBox } diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp index 86e9cb28e..717ec5ab3 100644 --- a/apps/openmw/mwgui/messagebox.hpp +++ b/apps/openmw/mwgui/messagebox.hpp @@ -31,9 +31,13 @@ namespace MWGui public: MessageBox (MessageBoxManager& parMessageBoxManager, const std::string& message); void setMessage (const std::string& message); + int getHeight (); + void update (int height); + void del (); protected: MessageBoxManager& mMessageBoxManager; + int mHeight; }; }