summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--src/gui/browserbox.cpp50
2 files changed, 55 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index eacdd77d..9fe3489d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-01-21 Bjørn Lindeijer <bjorn@lindeijer.nl>
+
+ * 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 <elvenprogrammer@gmail.com>
* 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()