mirror of
https://github.com/glest/glest-source.git
synced 2025-09-01 04:01:47 +02:00
- added another patch from cygal (he's on fire people!) to word wrap messagebox text
- remove newlines from english text where appropriate
This commit is contained in:
@@ -3529,6 +3529,15 @@ void Renderer::renderMessageBox(GraphicMessageBox *messageBox) {
|
|||||||
messageBox->setFont(CoreData::getInstance().getMenuFontNormal());
|
messageBox->setFont(CoreData::getInstance().getMenuFontNormal());
|
||||||
messageBox->setFont3D(CoreData::getInstance().getMenuFontNormal3D());
|
messageBox->setFont3D(CoreData::getInstance().getMenuFontNormal3D());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string wrappedText = messageBox->getText();
|
||||||
|
if(renderText3DEnabled == false) {
|
||||||
|
wrappedText = messageBox->getFont()->getMetrics()->wordWrapText(wrappedText,messageBox->getW() * 0.90);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wrappedText = messageBox->getFont3D()->getMetrics()->wordWrapText(wrappedText,messageBox->getW() * 0.90);
|
||||||
|
}
|
||||||
|
|
||||||
//background
|
//background
|
||||||
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT);
|
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
@@ -3598,7 +3607,7 @@ void Renderer::renderMessageBox(GraphicMessageBox *messageBox) {
|
|||||||
if(renderText3DEnabled == true) {
|
if(renderText3DEnabled == true) {
|
||||||
//text
|
//text
|
||||||
renderTextShadow3D(
|
renderTextShadow3D(
|
||||||
messageBox->getText(), messageBox->getFont3D(), fontColor,
|
wrappedText, messageBox->getFont3D(), fontColor,
|
||||||
messageBox->getX()+15, messageBox->getY()+7*messageBox->getH()/10,
|
messageBox->getX()+15, messageBox->getY()+7*messageBox->getH()/10,
|
||||||
false );
|
false );
|
||||||
|
|
||||||
@@ -3611,7 +3620,7 @@ void Renderer::renderMessageBox(GraphicMessageBox *messageBox) {
|
|||||||
else {
|
else {
|
||||||
//text
|
//text
|
||||||
renderTextShadow(
|
renderTextShadow(
|
||||||
messageBox->getText(), messageBox->getFont(), fontColor,
|
wrappedText, messageBox->getFont(), fontColor,
|
||||||
messageBox->getX()+15, messageBox->getY()+7*messageBox->getH()/10,
|
messageBox->getX()+15, messageBox->getY()+7*messageBox->getH()/10,
|
||||||
false );
|
false );
|
||||||
|
|
||||||
|
@@ -52,6 +52,9 @@ public:
|
|||||||
|
|
||||||
float getTextWidth(const string &str);
|
float getTextWidth(const string &str);
|
||||||
float getHeight(const string &str) const;
|
float getHeight(const string &str) const;
|
||||||
|
|
||||||
|
string wordWrapText(string text, int maxWidth);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
@@ -176,6 +176,31 @@ float FontMetrics::getHeight(const string &str) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string FontMetrics::wordWrapText(string text, int maxWidth) {
|
||||||
|
// Strip newlines from source
|
||||||
|
//replaceAll(text, "\n", " ");
|
||||||
|
|
||||||
|
// Get all words (space separated text)
|
||||||
|
vector<string> words;
|
||||||
|
Tokenize(text,words," ");
|
||||||
|
|
||||||
|
string wrappedText = "";
|
||||||
|
float lineWidth = 0.0f;
|
||||||
|
|
||||||
|
for(unsigned int i = 0; i < words.size(); ++i) {
|
||||||
|
string word = words[i];
|
||||||
|
float wordWidth = this->getTextWidth(word);
|
||||||
|
if (lineWidth + wordWidth > maxWidth) {
|
||||||
|
wrappedText += "\n";
|
||||||
|
lineWidth = 0;
|
||||||
|
}
|
||||||
|
lineWidth += wordWidth;
|
||||||
|
wrappedText += word + " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
return wrappedText;
|
||||||
|
}
|
||||||
|
|
||||||
// ===============================================
|
// ===============================================
|
||||||
// class Font
|
// class Font
|
||||||
// ===============================================
|
// ===============================================
|
||||||
|
Reference in New Issue
Block a user