summaryrefslogtreecommitdiff
path: root/src/gui/browserbox.cpp
diff options
context:
space:
mode:
authorJosé Ávila <linux@javila.net>2005-07-03 17:26:58 +0000
committerJosé Ávila <linux@javila.net>2005-07-03 17:26:58 +0000
commit24d6018cd908b95825e861a5c9df134060ff9286 (patch)
treeeaa051fe825cd5dbd132b62740c9c6f2ac1faf0f /src/gui/browserbox.cpp
parentdedaa5562180bd874afddb7dca909f45b75a5ca4 (diff)
downloadmana-24d6018cd908b95825e861a5c9df134060ff9286.tar.gz
mana-24d6018cd908b95825e861a5c9df134060ff9286.tar.bz2
mana-24d6018cd908b95825e861a5c9df134060ff9286.tar.xz
mana-24d6018cd908b95825e861a5c9df134060ff9286.zip
Implemented wrap text in chat box correctly ;)
Diffstat (limited to 'src/gui/browserbox.cpp')
-rw-r--r--src/gui/browserbox.cpp36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp
index 168708ad..a2b93c9d 100644
--- a/src/gui/browserbox.cpp
+++ b/src/gui/browserbox.cpp
@@ -328,14 +328,36 @@ void BrowserBox::draw(gcn::Graphics* graphics)
// Auto wrap mode
if (mMode == AUTO_WRAP)
{
- /** NOTE (by Javila): this is just a simple example and
- * will force text wrap at widget width!!!
- * Maybe it can need improvements.
- */
- if ((x + 2 * browserFont->getWidth('~')) > getWidth())
+ unsigned int nextChar = j + 1;
+ char hyphen = '~';
+ int hyphenWidth = browserFont->getWidth(hyphen);
+
+ // 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 ((x + nextWordWidth + 10) > getWidth())
+ {
+ x = 15; // Ident in new line
+ y += browserFont->getHeight();
+ wrappedLines++;
+ j++;
+ }
+ }
+
+ // Wrapping looong lines (brutal force)
+ else if ((x + 2 * hyphenWidth) > getWidth())
{
- browserFont->drawGlyph(graphics, '~',
- getWidth() - browserFont->getWidth('~'), y);
+ browserFont->drawGlyph(graphics, hyphen,
+ getWidth() - hyphenWidth, y);
x = 15; // Ident in new line
y += browserFont->getHeight();
wrappedLines++;