diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-09-02 22:04:34 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-09-02 22:04:34 +0300 |
commit | 99a07142cccf792dd35b611edd1b41cb307b5847 (patch) | |
tree | 58734795019f1da88e8aa5aa12b7cc4043878fbc /src/gui/widgets | |
parent | 370cb1fa897604e5d7bf9543881afad80f45f3ba (diff) | |
download | manaverse-99a07142cccf792dd35b611edd1b41cb307b5847.tar.gz manaverse-99a07142cccf792dd35b611edd1b41cb307b5847.tar.bz2 manaverse-99a07142cccf792dd35b611edd1b41cb307b5847.tar.xz manaverse-99a07142cccf792dd35b611edd1b41cb307b5847.zip |
improve chat emote window draw speed.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/emotepage.cpp | 63 | ||||
-rw-r--r-- | src/gui/widgets/emotepage.h | 10 |
2 files changed, 63 insertions, 10 deletions
diff --git a/src/gui/widgets/emotepage.cpp b/src/gui/widgets/emotepage.cpp index 0ab05b6e3..ce61a865f 100644 --- a/src/gui/widgets/emotepage.cpp +++ b/src/gui/widgets/emotepage.cpp @@ -20,6 +20,8 @@ #include "gui/widgets/emotepage.h" +#include "graphicsvertexes.h" + #include "resources/imageset.h" #include "resources/resourcemanager.h" @@ -34,11 +36,16 @@ namespace EmotePage::EmotePage(const Widget2 *const widget) : gcn::Widget(), Widget2(widget), + gcn::MouseListener(), + gcn::WidgetListener(), mEmotes(ResourceManager::getInstance()->getImageSet( "graphics/sprites/chatemotes.png", emoteWidth, emoteHeight)), - mSelectedIndex(-1) + mVertexes(new ImageCollection), + mSelectedIndex(-1), + mRedraw(true) { addMouseListener(this); + addWidgetListener(this); } EmotePage::~EmotePage() @@ -48,6 +55,8 @@ EmotePage::~EmotePage() mEmotes->decRef(); mEmotes = nullptr; } + delete mVertexes; + mVertexes = nullptr; } void EmotePage::draw(gcn::Graphics *graphics) @@ -64,17 +73,43 @@ void EmotePage::draw(gcn::Graphics *graphics) unsigned int x = 0; unsigned int y = 0; - FOR_EACH (std::vector<Image*>::const_iterator, it, images) + if (openGLMode != RENDER_SAFE_OPENGL) + { + if (mRedraw) + { + mRedraw = false; + mVertexes->clear(); + FOR_EACH (std::vector<Image*>::const_iterator, it, images) + { + const Image *const image = *it; + if (image) + { + g->calcTile(mVertexes, image, x, y); + x += emoteWidth; + if (x + emoteWidth > width) + { + x = 0; + y += emoteHeight; + } + } + } + } + g->drawTile(mVertexes); + } + else { - const Image *const image = *it; - if (image) + FOR_EACH (std::vector<Image*>::const_iterator, it, images) { - g->drawImage(image, x, y); - x += emoteWidth; - if (x + emoteWidth > width) + const Image *const image = *it; + if (image) { - x = 0; - y += emoteHeight; + g->drawImage(image, x, y); + x += emoteWidth; + if (x + emoteWidth > width) + { + x = 0; + y += emoteHeight; + } } } } @@ -104,3 +139,13 @@ void EmotePage::resetAction() { mSelectedIndex = -1; } + +void EmotePage::widgetResized(const gcn::Event &event A_UNUSED) +{ + mRedraw = true; +} + +void EmotePage::widgetMoved(const gcn::Event &event A_UNUSED) +{ + mRedraw = true; +} diff --git a/src/gui/widgets/emotepage.h b/src/gui/widgets/emotepage.h index 0c2582318..f553fa750 100644 --- a/src/gui/widgets/emotepage.h +++ b/src/gui/widgets/emotepage.h @@ -25,12 +25,14 @@ #include <guichan/mouselistener.hpp> #include <guichan/widget.hpp> +#include <guichan/widgetlistener.hpp> #include "localconsts.h" class EmotePage final : public gcn::Widget, public Widget2, - public gcn::MouseListener + public gcn::MouseListener, + public gcn::WidgetListener { public: explicit EmotePage(const Widget2 *const widget); @@ -45,6 +47,10 @@ class EmotePage final : public gcn::Widget, int getIndexFromGrid(const int x, const int y) const; + void widgetResized(const gcn::Event &event A_UNUSED); + + void widgetMoved(const gcn::Event &event A_UNUSED); + void resetAction(); int getSelectedIndex() @@ -52,7 +58,9 @@ class EmotePage final : public gcn::Widget, private: ImageSet *mEmotes; + ImageCollection *mVertexes; int mSelectedIndex; + bool mRedraw; }; #endif // GUI_WIDGETS_EMOTEPAGE_H |