diff options
author | Ira Rice <irarice@gmail.com> | 2009-02-24 23:03:31 -0700 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2009-02-24 23:03:31 -0700 |
commit | a1e483913672e55704e8fbafeff5ea0ccc0c9b07 (patch) | |
tree | 47cd4487c4b3e14d3bbb1b94c25cef4c55b10ef3 /src/gui/textbox.cpp | |
parent | e85269ffe1fe91f5cf44ccfec01252343643ef1d (diff) | |
download | mana-a1e483913672e55704e8fbafeff5ea0ccc0c9b07.tar.gz mana-a1e483913672e55704e8fbafeff5ea0ccc0c9b07.tar.bz2 mana-a1e483913672e55704e8fbafeff5ea0ccc0c9b07.tar.xz mana-a1e483913672e55704e8fbafeff5ea0ccc0c9b07.zip |
Cleaned up some code, as well as removed redundant talk client requesting
(which would happen from using the keyboard instead of the mouse).
Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/gui/textbox.cpp')
-rw-r--r-- | src/gui/textbox.cpp | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp index dc94ead2..589986cd 100644 --- a/src/gui/textbox.cpp +++ b/src/gui/textbox.cpp @@ -38,52 +38,46 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension) { // Make sure parent scroll area sets width of this widget if (getParent()) - { 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; + std::string::size_type spacePos, newlinePos, lastNewlinePos = 0; int minWidth = 0; int xpos; + 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 { // Determine next piece of string to wrap newlinePos = text.find("\n", lastNewlinePos); if (newlinePos == std::string::npos) - { newlinePos = text.size(); - } std::string line = text.substr(lastNewlinePos, newlinePos - lastNewlinePos); - std::string::size_type spacePos, lastSpacePos = 0; + std::string::size_type 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); if (spacePos == std::string::npos) - { spacePos = line.size(); - } std::string word = line.substr(lastSpacePos, spacePos - lastSpacePos); |