summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-01-29 00:40:12 -0700
committerIra Rice <irarice@gmail.com>2009-01-29 00:40:12 -0700
commita48b3777b83f9703fb1dbde48bdc6d5f22f66a38 (patch)
treee9f103dee2b004add7a7287a57aeda49769ae7fe /src
parentf9cacf3f34db1ccf3b6aea0d1e58029a89bed78b (diff)
downloadmana-a48b3777b83f9703fb1dbde48bdc6d5f22f66a38.tar.gz
mana-a48b3777b83f9703fb1dbde48bdc6d5f22f66a38.tar.bz2
mana-a48b3777b83f9703fb1dbde48bdc6d5f22f66a38.tar.xz
mana-a48b3777b83f9703fb1dbde48bdc6d5f22f66a38.zip
Fixed a crash caused by getting the wrong string substring. In doing so,
the algorithm was optimized further, so that only one correction needs to be done if the last line is the longest. Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/gui/textbox.cpp37
1 files changed, 15 insertions, 22 deletions
diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp
index b36897d6..c04b4262 100644
--- a/src/gui/textbox.cpp
+++ b/src/gui/textbox.cpp
@@ -65,6 +65,19 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension)
std::string::size_type spacePos, lastSpacePos = 0;
xpos = 0;
+ spacePos = text.rfind(" ", text.size());
+ if (spacePos == std::string::npos)
+ {
+ spacePos = 0;
+ }
+ else
+ {
+ const std::string word = text.substr(spacePos + 1);
+ const int length = getFont()->getWidth(word);
+
+ if (length > mMinWidth)
+ mMinWidth = length;
+ }
do
{
spacePos = line.find(" ", lastSpacePos);
@@ -103,6 +116,8 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension)
spacePos = 0;
lastNewlinePos = 0;
newlinePos = text.find("\n", lastNewlinePos);
+ if (newlinePos == std::string::npos)
+ newlinePos = text.size();
line = text.substr(lastNewlinePos, newlinePos -
lastNewlinePos);
width = 0;
@@ -122,28 +137,6 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension)
wrappedStream << "\n";
lastNewlinePos = newlinePos + 1;
-
- // Is the last line we're trying to text wrap longer than the minimum
- // width we're trying to beat in the first place? If so, then rewrap
- // using that length.
- if (newlinePos == text.size())
- {
- spacePos = text.rfind(" ", text.size());
- const std::string word = line.substr(spacePos + 1);
- const int length = getFont()->getWidth(word);
-
- if ((length > xpos || length > minWidth) && length > mMinWidth)
- {
- mMinWidth = length;
- wrappedStream.clear();
- wrappedStream.str("");
- spacePos = 0;
- lastNewlinePos = 0;
- newlinePos = text.find("\n", lastNewlinePos);
- line = text.substr(lastNewlinePos, newlinePos -
- lastNewlinePos);
- }
- }
}
while (newlinePos != text.size());