From 8650c6cd814d6ac04d754689fd15b23701fc7776 Mon Sep 17 00:00:00 2001 From: rachytski Date: Thu, 24 Jan 2013 18:51:39 +0300 Subject: [PATCH] refactored gui::Button to use graphics::DisplayList's for faster rendering. --- gui/button.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++----- gui/button.hpp | 7 ++++++ 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/gui/button.cpp b/gui/button.cpp index 82e6cbb41a..a415bc83cc 100644 --- a/gui/button.cpp +++ b/gui/button.cpp @@ -1,5 +1,9 @@ #include "button.hpp" -#include "../graphics/overlay_renderer.hpp" +#include "controller.hpp" + +#include "../graphics/screen.hpp" + +#include "../geometry/transformations.hpp" namespace gui { @@ -97,6 +101,45 @@ namespace gui Element::setController(controller); } + void Button::cacheButtonBody(EState state) + { + graphics::Screen * cs = m_controller->GetCacheScreen(); + + cs->beginFrame(); + + shared_ptr & dl = m_dls[state]; + + dl.reset(); + dl.reset(cs->createDisplayList()); + + cs->setDisplayList(dl.get()); + + double k = visualScale(); + m2::RectD rr = roughBoundRect(); + + cs->drawRoundedRectangle(m2::RectD(-rr.SizeX() / 2, + -rr.SizeY() / 2, + rr.SizeX() / 2, + rr.SizeY() / 2), + 10 * k, color(state), depth()); + + cs->setDisplayList(0); + + cs->endFrame(); + } + + void Button::cache() + { + cacheButtonBody(EActive); + cacheButtonBody(EPressed); + } + + void Button::purge() + { + m_dls.clear(); + m_textView->purge(); + } + vector const & Button::boundRects() const { if (isDirtyRect()) @@ -137,17 +180,23 @@ namespace gui if (!isVisible()) return; - double k = visualScale(); + checkDirtyLayout(); - r->drawRoundedRectangle(roughBoundRect(), 10 * k, color(state()), depth()); + math::Matrix drawM = math::Shift(math::Identity(), + pivot()); - graphics::FontDesc desc = font(state()); - desc.m_size *= k; + map >::const_iterator it; + it = m_dls.find(state()); + + if (it != m_dls.end()) + r->drawDisplayList(it->second.get(), drawM * m); + else + LOG(LWARNING, ("m_dls[state] is not set!")); m_textView->draw(r, m); } - void Button::setPivot(m2::PointD const &pv) + void Button::setPivot(m2::PointD const & pv) { m_textView->setPivot(pv); Element::setPivot(pv); @@ -165,3 +214,4 @@ namespace gui Element::setColor(state, c); } } + diff --git a/gui/button.hpp b/gui/button.hpp index 049cf16df1..0be6bc233c 100644 --- a/gui/button.hpp +++ b/gui/button.hpp @@ -33,9 +33,14 @@ namespace gui unsigned m_minHeight; scoped_ptr m_textView; + map > m_dls; + + void cacheButtonBody(EState state); mutable vector m_boundRects; + void cache(); + public: struct Params : Element::Params @@ -75,6 +80,8 @@ namespace gui vector const & boundRects() const; void draw(graphics::OverlayRenderer * r, math::Matrix const & m) const; + void purge(); + /// @} }; }