From 537b2bf9636a3c8581701f85c7538bdda46722f7 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 12 Jul 2011 17:57:16 +0200 Subject: [PATCH] set position on interactive MessageBox'es --- apps/openmw/mwgui/messagebox.cpp | 36 +++++++++++++++++++++----------- apps/openmw/mwgui/messagebox.hpp | 2 ++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index 61a359e7e..9c0196147 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -193,6 +193,7 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan int buttonLeftPadding = 10; // padding between the buttons if horizontal int buttonTopPadding = 5; // ^-- if vertical int buttonPadding = 5; // padding between button label and button itself + int buttonMainPadding = 10; // padding between buttons and bottom of the main widget getWidget(mMessageWidget, "message"); @@ -203,6 +204,7 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan MyGUI::IntSize textSize = mMessageWidget->_getTextSize(); + MyGUI::IntSize gameWindowSize = mMessageBoxManager.mWindowManager->getGui()->getViewSize(); int buttonsWidth = 0; int buttonHeight = 0; @@ -220,33 +222,43 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan mButtons.push_back(button); - buttonsWidth += button->_getTextSize().width + 2*buttonPadding + 2*buttonLeftPadding; - buttonHeight = button->_getTextSize().height + 2*buttonPadding + 2*buttonTopPadding; + buttonsWidth += button->_getTextSize().width + 2*buttonPadding + buttonLeftPadding; + buttonHeight = button->_getTextSize().height + 2*buttonPadding + buttonTopPadding; } + buttonsWidth += buttonLeftPadding; MyGUI::IntSize mainWidgetSize; if(buttonsWidth < fixedWidth) { // on one line - - int left; + std::cout << "on one line" << std::endl; + if(textSize.width + 2*textPadding < buttonsWidth) { + std::cout << "width = buttonsWidth" << std::endl; mainWidgetSize.width = buttonsWidth; - left = buttonLeftPadding; } else { - mainWidgetSize.width = textSize.width + 2*textPadding; - left = (textSize.width - buttonsWidth)/2; + mainWidgetSize.width = textSize.width + 3*textPadding; } - mainWidgetSize.height = textSize.height + textButtonPadding + buttonHeight; + mainWidgetSize.height = textSize.height + textButtonPadding + buttonHeight + buttonMainPadding; + + MyGUI::IntCoord absCoord; + absCoord.left = (gameWindowSize.width - mainWidgetSize.width)/2; + absCoord.top = (gameWindowSize.height - mainWidgetSize.height)/2; + + std::cout << "width " << mainWidgetSize.width << " height " << mainWidgetSize.height << std::endl; + std::cout << "left " << absCoord.left << " top " << absCoord.top << std::endl; + + mMainWidget->setCoord(absCoord); mMainWidget->setSize(mainWidgetSize); - + mMessageWidget->setSize(textSize); MyGUI::IntCoord buttonCord; MyGUI::IntSize buttonSize(0, buttonHeight); + int left = (mainWidgetSize.width - buttonsWidth)/2 + buttonPadding; std::vector::const_iterator button; for(button = mButtons.begin(); button != mButtons.end(); ++button) @@ -254,13 +266,13 @@ InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxMan buttonCord.left = left; buttonCord.top = textSize.height + textButtonPadding; - buttonSize.width = (*button)->_getTextSize().width + buttonPadding*2; - buttonSize.height = (*button)->_getTextSize().height + buttonPadding*2; + buttonSize.width = (*button)->_getTextSize().width + 2*buttonPadding; + buttonSize.height = (*button)->_getTextSize().height + 2*buttonPadding; (*button)->setCoord(buttonCord); (*button)->setSize(buttonSize); - left += buttonSize.width + 2*buttonLeftPadding; + left += buttonSize.width + buttonLeftPadding; } } else diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp index b8c205823..f7c7197fa 100644 --- a/apps/openmw/mwgui/messagebox.hpp +++ b/apps/openmw/mwgui/messagebox.hpp @@ -73,6 +73,8 @@ namespace MWGui MyGUI::EditPtr mMessageWidget; MyGUI::WidgetPtr mButtonsWidget; std::vector mButtons; + + int mTextButtonPadding; }; }