- 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:
parent
6cf46898d9
commit
16b85dbe79
|
@ -3529,6 +3529,15 @@ void Renderer::renderMessageBox(GraphicMessageBox *messageBox) {
|
|||
messageBox->setFont(CoreData::getInstance().getMenuFontNormal());
|
||||
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
|
||||
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT);
|
||||
glEnable(GL_BLEND);
|
||||
|
@ -3598,7 +3607,7 @@ void Renderer::renderMessageBox(GraphicMessageBox *messageBox) {
|
|||
if(renderText3DEnabled == true) {
|
||||
//text
|
||||
renderTextShadow3D(
|
||||
messageBox->getText(), messageBox->getFont3D(), fontColor,
|
||||
wrappedText, messageBox->getFont3D(), fontColor,
|
||||
messageBox->getX()+15, messageBox->getY()+7*messageBox->getH()/10,
|
||||
false );
|
||||
|
||||
|
@ -3611,7 +3620,7 @@ void Renderer::renderMessageBox(GraphicMessageBox *messageBox) {
|
|||
else {
|
||||
//text
|
||||
renderTextShadow(
|
||||
messageBox->getText(), messageBox->getFont(), fontColor,
|
||||
wrappedText, messageBox->getFont(), fontColor,
|
||||
messageBox->getX()+15, messageBox->getY()+7*messageBox->getH()/10,
|
||||
false );
|
||||
|
||||
|
|
|
@ -52,6 +52,9 @@ public:
|
|||
|
||||
float getTextWidth(const string &str);
|
||||
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
|
||||
// ===============================================
|
||||
|
|
Loading…
Reference in New Issue