diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-03-26 05:07:12 +0200 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-03-26 05:50:44 +0200 |
commit | 8403dcf857c9cc639e8162edd5d4df4af07274bc (patch) | |
tree | 2f127213e0df4691b06c549a8f20b3d5225b9220 /src/gui/widgets/button.cpp | |
parent | fc24490f1ecd186f3c294915fadee62c3053d841 (diff) | |
download | plus-8403dcf857c9cc639e8162edd5d4df4af07274bc.tar.gz plus-8403dcf857c9cc639e8162edd5d4df4af07274bc.tar.bz2 plus-8403dcf857c9cc639e8162edd5d4df4af07274bc.tar.xz plus-8403dcf857c9cc639e8162edd5d4df4af07274bc.zip |
Precalculation vertexes for improving draw speed.
Implemented in Software and fast OpenGL backends.
Not all controls using this mode because some limitations.
Known issue: impossible compile without opengl.
Will be fixed in next commits.
Diffstat (limited to 'src/gui/widgets/button.cpp')
-rw-r--r-- | src/gui/widgets/button.cpp | 64 |
1 files changed, 60 insertions, 4 deletions
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 89e270595..a8e8b656d 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -25,6 +25,7 @@ #include "client.h" #include "configuration.h" #include "graphics.h" +#include "graphicsvertexes.h" #include "log.h" #include "gui/palette.h" @@ -67,7 +68,12 @@ static ButtonData const data[BUTTON_COUNT] = ImageRect Button::button[BUTTON_COUNT]; Button::Button(): - mDescription(""), mClickCount(0) + mDescription(""), mClickCount(0), + mVertexes(new GraphicsVertexes()), + mRedraw(true), + mMode(0), + mXOffset(0), + mYOffset(0) { init(); } @@ -75,7 +81,9 @@ Button::Button(): Button::Button(const std::string &caption, const std::string &actionEventId, gcn::ActionListener *listener): gcn::Button(caption), - mDescription(""), mClickCount(0) + mDescription(""), mClickCount(0), + mVertexes(new GraphicsVertexes()), + mRedraw(true) { init(); setActionEventId(actionEventId); @@ -88,6 +96,8 @@ void Button::init() { setFrameSize(0); + addWidgetListener(this); + if (mInstances == 0) { // Load the skin @@ -175,8 +185,44 @@ void Button::draw(gcn::Graphics *graphics) updateAlpha(); - static_cast<Graphics*>(graphics)-> - drawImageRect(0, 0, getWidth(), getHeight(), button[mode]); + + bool recalc = false; + if (mRedraw) + { + recalc = true; + } + else + { + // because we dont know where parent windows was moved, + // need recalc vertexes + gcn::ClipRectangle &rect = static_cast<Graphics*>( + graphics)->getTopClip(); + if (rect.xOffset != mXOffset || rect.yOffset != mYOffset) + { + recalc = true; + mXOffset = rect.xOffset; + mYOffset = rect.yOffset; + } + else if (mMode != mode) + { + recalc = true; + mMode = mode; + } + } + + if (recalc) + { + mRedraw = false; + mMode = mode; + static_cast<Graphics*>(graphics)->calcWindow(mVertexes, 0, 0, + getWidth(), getHeight(), button[mode]); + } + + static_cast<Graphics*>(graphics)->drawImageRect2( + mVertexes, button[mode]); + +// static_cast<Graphics*>(graphics)-> +// drawImageRect(0, 0, getWidth(), getHeight(), button[mode]); if (mode == BUTTON_DISABLED) graphics->setColor(Theme::getThemeColor(Theme::BUTTON_DISABLED)); @@ -226,3 +272,13 @@ void Button::mouseReleased(gcn::MouseEvent& mouseEvent) mouseEvent.consume(); } } + +void Button::widgetResized(const gcn::Event &event _UNUSED_) +{ + mRedraw = true; +} + +void Button::widgetMoved(const gcn::Event &event _UNUSED_) +{ + mRedraw = true; +} |