From 14d43383605281885ed576664594343d167e57f1 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sat, 21 Jan 2006 20:16:40 +0000 Subject: Applied patch by Ar2ro that worked around scrolldown bug in the chatbox. --- ChangeLog | 6 ++++++ src/gui/browserbox.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index eacdd77d..9fe3489d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-01-21 Bjørn Lindeijer + + * src/gui/browserbox.cpp: Applied a patch by Ar2ro that works around + the problems with line wrapping in the chatbox. Note though that this + while code should be properly rewritten later. + 2006-01-19 Eugenio Favalli * INSTALL, README, The Mana World.dev, data/help/support.txt, 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() -- cgit v1.2.3-70-g09d2