diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-02-09 14:31:05 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-02-09 17:14:25 +0100 |
commit | b5e416f8cd52f69ff1edd832ee10bac550544ef6 (patch) | |
tree | 2df592038ba092e67f458fd9945999add7d50056 /src/gui/widgets/browserbox.h | |
parent | 1b041ecccfbe44a4f50ffc086e3996e2b6eea4f7 (diff) | |
download | mana-b5e416f8cd52f69ff1edd832ee10bac550544ef6.tar.gz mana-b5e416f8cd52f69ff1edd832ee10bac550544ef6.tar.bz2 mana-b5e416f8cd52f69ff1edd832ee10bac550544ef6.tar.xz mana-b5e416f8cd52f69ff1edd832ee10bac550544ef6.zip |
Some cleanups in UpdaterWindow and BrowserBox
Doing some cleanups before working towards optimizing this code.
Removed needless additional wrapping code in BrowserBox::addRow, since
the text will be relayouted anyway.
Simplified layouting code a little. For example, there's no need to keep
track of the number of wrapped lines.
Use more optimal data structures, like an std::deque for the text rows
and a plain std::vector for the line parts. Both have less fragmentation
than an std::list.
Diffstat (limited to 'src/gui/widgets/browserbox.h')
-rw-r--r-- | src/gui/widgets/browserbox.h | 57 |
1 files changed, 14 insertions, 43 deletions
diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h index 6d09f77b..83cdef7c 100644 --- a/src/gui/widgets/browserbox.h +++ b/src/gui/widgets/browserbox.h @@ -26,7 +26,7 @@ #include <guichan/mouselistener.hpp> #include <guichan/widget.hpp> -#include <list> +#include <deque> #include <vector> class LinkHandler; @@ -38,30 +38,12 @@ struct BrowserLink std::string caption; }; -class LinePart +struct 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; + int x; + int y; + gcn::Color color; + std::string text; }; /** @@ -132,14 +114,14 @@ class BrowserBox : public gcn::Widget, */ void draw(gcn::Graphics *graphics) override; - void updateHeight(); + void maybeRelayoutText(); /** * BrowserBox modes. */ enum { - AUTO_SIZE = 0, + AUTO_SIZE, AUTO_WRAP /**< Maybe it needs a fix or to be redone. */ }; @@ -176,27 +158,17 @@ class BrowserBox : public gcn::Widget, BACKGROUND = 2 }; - using TextRows = std::list<std::string>; - - TextRows &getRows() - { return mTextRows; } - void setAlwaysUpdate(bool n) { mAlwaysUpdate = n; } private: - int calcHeight(); - - using TextRowIterator = TextRows::iterator; - TextRows mTextRows; + void relayoutText(); + int layoutTextRow(const std::string &row, int y); - using LinePartList = std::list<LinePart>; - using LinePartIterator = LinePartList::iterator; - LinePartList mLineParts; + std::deque<std::string> mTextRows; - using Links = std::vector<BrowserLink>; - using LinkIterator = Links::iterator; - Links mLinks; + std::vector<LinePart> mLineParts; + std::vector<BrowserLink> mLinks; LinkHandler *mLinkHandler = nullptr; unsigned int mMode; @@ -207,8 +179,7 @@ class BrowserBox : public gcn::Widget, bool mUseLinksAndUserColors = true; int mSelectedLink = -1; unsigned int mMaxRows = 0; - int mHeight = 0; - int mWidth = 0; + int mLastLayoutWidth = 0; int mYStart = 0; int mUpdateTime = -1; bool mAlwaysUpdate = true; |