Word wrap for MessageBox

pull/21/head
Sebastian Wick 14 years ago
parent 9c56031ee2
commit 6dc35247da

@ -17,8 +17,8 @@ void MessageBoxManager::createMessageBox (const std::string& message)
std::vector<MessageBox*>::const_iterator it;
int i = 0;
for(it = mMessageBoxes.begin(); it != mMessageBoxes.end(); ++it) {
if(i == 3) {
for(it = mMessageBoxes.begin()+1; it != mMessageBoxes.end(); ++it) {
if(i == 2) {
(*it)->del();
break;
}
@ -39,35 +39,50 @@ void MessageBoxManager::createInteractiveMessageBox (const std::string& message,
MessageBox::MessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message)
: Layout("openmw_messagebox_layout.xml")
, mMessageBoxManager(parMessageBoxManager)
, cMessage(message)
{
setText("message", message);
mFixedWidth = 300;
mBottomPadding = 20;
getWidget(mMessageWidget, "message");
mMessageWidget->setOverflowToTheLeft(true);
mMessageWidget->addText(cMessage);
MyGUI::IntSize size;
size.width = mFixedWidth; // fiexd width
size.height = 100; // dummy
MyGUI::IntCoord coord;
coord.left = 10; // dummy
coord.top = 10; // dummy
mMessageWidget->setSize(size);
MyGUI::IntSize textSize = mMessageWidget->_getTextSize();
size.height = mHeight = textSize.height + 20; // this is the padding between the text and the box
mMainWidget->setSize(size);
size.width -= 5; // this is to center the text (see messagebox_layout.xml, Widget type="Edit" position="-2 -3 0 0")
mMessageWidget->setSize(size);
update(0);
}
void MessageBox::update (int height)
{
MyGUI::WidgetPtr messageWidget;
getWidget(messageWidget, "message");
MyGUI::IntSize size = messageWidget->_getTextSize();
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 - height);
coord.left = (gameWindowSize.width - mFixedWidth)/2;
coord.top = (gameWindowSize.height - mHeight - height - mBottomPadding);
std::cout << "Setting MainWidget to position (" << coord.left << "|" << coord.top
<< ") and size to (" << size.width << "|" << size.height << ")"
<< " while height is " << height << std::endl;
MyGUI::IntSize size;
size.width = mFixedWidth;
size.height = mHeight;
mMainWidget->setCoord(coord);
mMainWidget->setSize(size);
mHeight = size.height;
mMainWidget->setVisible(true);
}
void MessageBox::del ()

@ -38,6 +38,10 @@ namespace MWGui
protected:
MessageBoxManager& mMessageBoxManager;
int mHeight;
const std::string& cMessage;
MyGUI::EditPtr mMessageWidget;
int mFixedWidth;
int mBottomPadding;
};
}

@ -1,7 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Layout">
<Widget type="Window" skin="MW_Dialog" layer="Windows" position="0 0 491 302" name="_Main">
<Widget type="StaticText" skin="NormalText" position="4 4 70 18" name="message"/>
<!--Widget type="Window" skin="MW_Dialog" layer="Windows" position="0 0 0 0" name="_Main">
<Widget type="StaticText" skin="StaticText" position="4 4 4 4" name="message" />
</Widget-->
<Widget type="Window" skin="MW_Dialog" layer="Windows" position="0 0 0 0" name="_Main">
<Widget type="Edit" skin="MW_TextEditClient" position="-2 -3 0 0" name="message" align="ALIGN_LEFT ALIGN_TOP STRETCH">
<Property key="Edit_Static" value="true"/>
<Property key="Edit_WordWrap" value="true"/>
<Property key="Text_FontHeight" value="18"/>
<Property key="Edit_MultiLine" value="1" />
<Property key="Edit_VisibleVScroll" value="1" />
<Property key="Widget_AlignText" value="ALIGN_CENTER" />
</Widget>
</Widget>
</MyGUI>

Loading…
Cancel
Save