summaryrefslogtreecommitdiff
path: root/src/gui/textbox.cpp
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2008-10-10 17:48:27 +0000
committerIra Rice <irarice@gmail.com>2008-10-10 17:48:27 +0000
commit7729faaadff2e6f92d24f43e52d085f4b11be315 (patch)
tree282a8dd26928a0b71ee0262ff6c9f0e491708026 /src/gui/textbox.cpp
parent8d27447b01407d6605b1fed89fcd556572d8cfca (diff)
downloadmana-7729faaadff2e6f92d24f43e52d085f4b11be315.tar.gz
mana-7729faaadff2e6f92d24f43e52d085f4b11be315.tar.bz2
mana-7729faaadff2e6f92d24f43e52d085f4b11be315.tar.xz
mana-7729faaadff2e6f92d24f43e52d085f4b11be315.zip
Did a little bit of code cleanup (mostly from TMW changes) as well as
properly implemented line wrapping. Now, there are no more visual artifacts for speech boxes, and it always chooses the most optimal box size (which required that npc_text use it also. Do any other gui classes use the textbox class?).
Diffstat (limited to 'src/gui/textbox.cpp')
-rw-r--r--src/gui/textbox.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp
index 4976549f..e779a9bb 100644
--- a/src/gui/textbox.cpp
+++ b/src/gui/textbox.cpp
@@ -45,6 +45,7 @@ void TextBox::setTextWrapped(const std::string &text)
std::stringstream wrappedStream;
std::string::size_type newlinePos, lastNewlinePos = 0;
+ int minWidth = 0;
do
{
@@ -60,8 +61,6 @@ void TextBox::setTextWrapped(const std::string &text)
text.substr(lastNewlinePos, newlinePos - lastNewlinePos);
std::string::size_type spacePos, lastSpacePos = 0;
int xpos = 0;
- mMinWidth = getWidth();
- bool longWord = false;
do
{
@@ -77,25 +76,26 @@ void TextBox::setTextWrapped(const std::string &text)
int width = getFont()->getWidth(word);
- if (xpos != 0 && xpos + width + getFont()->getWidth(" ") < getWidth())
+ if (xpos != 0 && xpos + width + getFont()->getWidth(" ") <= mMinWidth)
{
xpos += width + getFont()->getWidth(" ");
wrappedStream << " " << word;
}
else if (lastSpacePos == 0)
{
- if (xpos > mMinWidth)
- {
- longWord = true;
- mMinWidth = xpos;
- }
xpos += width;
wrappedStream << word;
}
else
{
- if ((xpos < mMinWidth) && !longWord && spacePos != line.size())
- mMinWidth = xpos;
+ if (xpos > minWidth)
+ {
+ minWidth = xpos;
+ if (minWidth > mMinWidth)
+ {
+ mMinWidth = minWidth;
+ }
+ }
xpos = width;
wrappedStream << "\n" << word;
}
@@ -107,10 +107,10 @@ void TextBox::setTextWrapped(const std::string &text)
{
wrappedStream << "\n";
}
-
lastNewlinePos = newlinePos + 1;
}
while (newlinePos != text.size());
+ mMinWidth = minWidth;
gcn::TextBox::setText(wrappedStream.str());
}