From 9da7effa3dd8bbacbc58d2be47a17d631e261c81 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 12 Sep 2010 20:49:11 +0300 Subject: Improve chat speed. Parse chat lines in BrowserBox once after changes. Reviewed-by: Thorbjorn --- src/gui/widgets/browserbox.h | 60 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 10 deletions(-) (limited to 'src/gui/widgets/browserbox.h') diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h index b71f30d7..54a2a8cc 100644 --- a/src/gui/widgets/browserbox.h +++ b/src/gui/widgets/browserbox.h @@ -2,6 +2,7 @@ * The Mana Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2009 Aethyra Development Team * * This file is part of The Mana Client. * @@ -30,12 +31,39 @@ class LinkHandler; -struct BROWSER_LINK { +struct BROWSER_LINK +{ int x1, x2, y1, y2; /**< Where link is placed */ std::string link; std::string caption; }; +class LinePart +{ + public: + LinePart(int x, int y, gcn::Color color, std::string text) : + mX(x), mY(y), mColor(color), mText(text) + { + } + + int getX() const + { return mX; } + + int getY() const + { return mY; } + + const std::string &getText() const + { return mText; } + + const gcn::Color &getColor() const + { return mColor; } + + private: + int mX, mY; + gcn::Color mColor; + std::string mText; +}; + /** * A simple browser box able to handle links and forward events to the * parent conteiner. @@ -72,7 +100,7 @@ class BrowserBox : public gcn::Widget, /** * Sets the maximum numbers of rows in the browser box. 0 = no limit. */ - void setMaxRow(int max) {mMaxRows = max; }; + void setMaxRow(unsigned max) {mMaxRows = max; }; /** * Disable links & user defined colors to be used in chat input. @@ -111,8 +139,9 @@ class BrowserBox : public gcn::Widget, /** * BrowserBox modes. */ - enum { - AUTO_SIZE, + enum + { + AUTO_SIZE = 0, AUTO_WRAP /**< Maybe it needs a fix or to be redone. */ }; @@ -126,7 +155,8 @@ class BrowserBox : public gcn::Widget, * windows and widgets. So, I think it's better keep BrowserBox * opaque (white background) by default. */ - enum { + enum + { RED = 0xff0000, /**< Color 1 */ GREEN = 0x009000, /**< Color 2 */ BLUE = 0x0000ff, /**< Color 3 */ @@ -142,21 +172,29 @@ class BrowserBox : public gcn::Widget, * Highlight modes for links. * This can be used for a bitmask. */ - enum { + enum + { UNDERLINE = 1, BACKGROUND = 2 }; + typedef std::list TextRows; + + TextRows &getRows() + { return mTextRows; } + + void setAlwaysUpdate(bool n) + { mAlwaysUpdate = n; } + private: int calcHeight(); - typedef std::list TextRows; typedef TextRows::iterator TextRowIterator; TextRows mTextRows; - typedef std::list TextRowsHeights; - typedef TextRowsHeights::iterator TextRowsHeightIterator; - TextRowsHeights mTextRowsHeights; + typedef std::list LinePartList; + typedef LinePartList::iterator LinePartIterator; + LinePartList mLineParts; typedef std::vector Links; typedef Links::iterator LinkIterator; @@ -172,6 +210,8 @@ class BrowserBox : public gcn::Widget, int mHeight; int mWidth; int mYStart; + int mUpdateTime; + bool mAlwaysUpdate; }; #endif -- cgit v1.2.3-70-g09d2