- 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:
Mark Vejvoda
2012-11-07 21:24:44 +00:00
parent 6cf46898d9
commit 16b85dbe79
3 changed files with 39 additions and 2 deletions

View File

@@ -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
// ===============================================