diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-02-09 23:47:02 +0100 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-02-09 23:47:02 +0100 |
commit | fa2f3ac593a792c32095c2e885665ec91bb4019d (patch) | |
tree | f44aee845f0229dfcc6b2ad3c74613e0352f36c2 /src/gui/textbox.cpp | |
parent | 07f7d52f661a74e6d0c780ca53e724651e3dcc48 (diff) | |
parent | 40edf4e91558cffd83d9015a2cf4a16360e27855 (diff) | |
download | mana-client-fa2f3ac593a792c32095c2e885665ec91bb4019d.tar.gz mana-client-fa2f3ac593a792c32095c2e885665ec91bb4019d.tar.bz2 mana-client-fa2f3ac593a792c32095c2e885665ec91bb4019d.tar.xz mana-client-fa2f3ac593a792c32095c2e885665ec91bb4019d.zip |
Merged with Aethyra master as of 2009-02-09
Conflicts:
A lot of files...
Diffstat (limited to 'src/gui/textbox.cpp')
-rw-r--r-- | src/gui/textbox.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp index ee03c79d..2a86d549 100644 --- a/src/gui/textbox.cpp +++ b/src/gui/textbox.cpp @@ -21,7 +21,6 @@ #include <sstream> -#include <guichan/basiccontainer.hpp> #include <guichan/font.hpp> #include "textbox.h" @@ -31,9 +30,10 @@ TextBox::TextBox(): { setOpaque(false); setFrameSize(0); + mMinWidth = getWidth(); } -void TextBox::setTextWrapped(const std::string &text) +void TextBox::setTextWrapped(const std::string &text, int minDimension) { // Make sure parent scroll area sets width of this widget if (getParent()) @@ -41,6 +41,9 @@ void TextBox::setTextWrapped(const std::string &text) getParent()->logic(); } + // Take the supplied minimum dimension as a starting point and try to beat it + mMinWidth = minDimension; + std::stringstream wrappedStream; std::string::size_type newlinePos, lastNewlinePos = 0; int minWidth = 0; @@ -61,6 +64,17 @@ void TextBox::setTextWrapped(const std::string &text) std::string::size_type spacePos, lastSpacePos = 0; xpos = 0; + spacePos = text.rfind(" ", text.size()); + + if (spacePos != std::string::npos) + { + const std::string word = text.substr(spacePos + 1); + const int length = getFont()->getWidth(word); + + if (length > mMinWidth) + mMinWidth = length; + } + do { spacePos = line.find(" ", lastSpacePos); @@ -88,9 +102,8 @@ void TextBox::setTextWrapped(const std::string &text) else { if (xpos > minWidth) - { minWidth = xpos; - } + // The window wasn't big enough. Resize it and try again. if (minWidth > mMinWidth) { @@ -100,6 +113,8 @@ void TextBox::setTextWrapped(const std::string &text) 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; @@ -116,17 +131,15 @@ void TextBox::setTextWrapped(const std::string &text) while (spacePos != line.size()); if (text.find("\n", lastNewlinePos) != std::string::npos) - { wrappedStream << "\n"; - } + lastNewlinePos = newlinePos + 1; } while (newlinePos != text.size()); if (xpos > minWidth) - { minWidth = xpos; - } + mMinWidth = minWidth; gcn::TextBox::setText(wrappedStream.str()); |