From 8403dcf857c9cc639e8162edd5d4df4af07274bc Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 26 Mar 2011 05:07:12 +0200 Subject: 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. --- src/gui/widgets/button.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) (limited to 'src/gui/widgets/button.cpp') 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)-> - 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)->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)->calcWindow(mVertexes, 0, 0, + getWidth(), getHeight(), button[mode]); + } + + static_cast(graphics)->drawImageRect2( + mVertexes, button[mode]); + +// static_cast(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; +} -- cgit v1.2.3-60-g2f50