diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-01-21 20:16:40 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2006-01-21 20:16:40 +0000 |
commit | 14d43383605281885ed576664594343d167e57f1 (patch) | |
tree | 2bfff062cf78dcb64b9e140f078e791e3039dd7c /src/gui/browserbox.cpp | |
parent | 43ef3719e12fd01befbf8c7d7605b346f6d6a25e (diff) | |
download | mana-14d43383605281885ed576664594343d167e57f1.tar.gz mana-14d43383605281885ed576664594343d167e57f1.tar.bz2 mana-14d43383605281885ed576664594343d167e57f1.tar.xz mana-14d43383605281885ed576664594343d167e57f1.zip |
Applied patch by Ar2ro that worked around scrolldown bug in the chatbox.
Diffstat (limited to 'src/gui/browserbox.cpp')
-rw-r--r-- | src/gui/browserbox.cpp | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index 94978200..9fab4f52 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -172,7 +172,55 @@ void BrowserBox::addRow(const std::string& row) if (w > getWidth()) setWidth(w); } - setHeight(browserFont->getHeight() * mTextRows.size()); + + if (mMode == AUTO_WRAP) + { + unsigned int i, j, x = 0, y = 0; + unsigned int nextChar; + char hyphen = '~'; + int hyphenWidth = browserFont->getWidth(hyphen); + for (i = 0; i < mTextRows.size(); i++) + { + std::string row = mTextRows[i]; + for (j = 0; j < row.size(); j++) + { + x += browserFont->getWidth(row.at(j)); + nextChar = j + 1; + + // Wraping between words (at blank spaces) + if ((nextChar < row.size()) && (row.at(nextChar) == ' ')) + { + int nextSpacePos = row.find(" ", (nextChar + 1)); + if (nextSpacePos <= 0) + { + nextSpacePos = row.size() - 1; + } + int nextWordWidth = browserFont->getWidth( + row.substr(nextChar, + (nextSpacePos - nextChar))); + + if ((int)(x + nextWordWidth + 10) > getWidth()) + { + x = 15; // Ident in new line + y += 1; + j++; + } + } + // Wrapping looong lines (brutal force) + else if ((int)(x + 2 * hyphenWidth) > getWidth()) + { + x = 15; // Ident in new line + y += 1; + } + } + } + + setHeight(browserFont->getHeight() * (mTextRows.size() + y)); + } + else + { + setHeight(browserFont->getHeight() * mTextRows.size()); + } } void BrowserBox::clearRows() |