diff options
author | vng <viktor.govako@gmail.com> | 2014-09-06 13:54:20 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:26:10 +0300 |
commit | d9ca6e56ef92b248221b66ab0f79437c573c469b (patch) | |
tree | 830f5d1ce26c3a0289fc2d8e7cfa04071d816c1c /gui | |
parent | 573e647de3a22282d0e993c30ffa05f4075c1e93 (diff) |
Minor refactoring of InformationDisplay:
- remove useless class data
- do not recalculate layout on every frame draw; do it when size changed only
- use unique_ptr instead of shared_ptr
- remove useless includes
Diffstat (limited to 'gui')
-rw-r--r-- | gui/button.cpp | 21 | ||||
-rw-r--r-- | gui/button.hpp | 32 | ||||
-rw-r--r-- | gui/cached_text_view.cpp | 67 | ||||
-rw-r--r-- | gui/cached_text_view.hpp | 15 | ||||
-rw-r--r-- | gui/display_list_cache.cpp | 42 | ||||
-rw-r--r-- | gui/display_list_cache.hpp | 17 | ||||
-rw-r--r-- | gui/element.cpp | 2 | ||||
-rw-r--r-- | gui/element.hpp | 8 |
8 files changed, 107 insertions, 97 deletions
diff --git a/gui/button.cpp b/gui/button.cpp index 57154c6990..71cbd2ef1c 100644 --- a/gui/button.cpp +++ b/gui/button.cpp @@ -1,10 +1,13 @@ #include "button.hpp" #include "controller.hpp" +#include "text_view.hpp" #include "../graphics/screen.hpp" +#include "../graphics/display_list.hpp" #include "../geometry/transformations.hpp" + namespace gui { Button::Params::Params() @@ -112,15 +115,15 @@ namespace gui cs->beginFrame(); - shared_ptr<graphics::DisplayList> & dl = m_dls[state]; + unique_ptr<graphics::DisplayList> & dl = m_dls[state]; dl.reset(); dl.reset(cs->createDisplayList()); cs->setDisplayList(dl.get()); - double k = visualScale(); - m2::RectD rr = roughBoundRect(); + double const k = visualScale(); + m2::RectD const rr = roughBoundRect(); cs->drawRoundedRectangle(m2::RectD(-rr.SizeX() / 2, -rr.SizeY() / 2, @@ -192,16 +195,9 @@ namespace gui checkDirtyLayout(); - math::Matrix<double, 3, 3> drawM = math::Shift(math::Identity<double, 3>(), - pivot()); - - map<EState, shared_ptr<graphics::DisplayList> >::const_iterator it; - it = m_dls.find(state()); + math::Matrix<double, 3, 3> const drawM = math::Shift(math::Identity<double, 3>(), pivot()); - if (it != m_dls.end()) - r->drawDisplayList(it->second.get(), drawM * m); - else - LOG(LDEBUG/*LWARNING*/, ("m_dls[state] is not set!")); + r->drawDisplayList(m_dls.at(state()).get(), drawM * m); m_textView->draw(r, m); } @@ -224,4 +220,3 @@ namespace gui Element::setColor(state, c); } } - diff --git a/gui/button.hpp b/gui/button.hpp index c63a510260..723965a69c 100644 --- a/gui/button.hpp +++ b/gui/button.hpp @@ -1,15 +1,16 @@ #pragma once #include "element.hpp" -#include "text_view.hpp" #include "../std/function.hpp" #include "../std/string.hpp" #include "../std/unique_ptr.hpp" + namespace graphics { class OverlayElement; + class DisplayList; namespace gl { @@ -19,6 +20,8 @@ namespace graphics namespace gui { + class TextView; + class Button : public Element { public: @@ -33,14 +36,12 @@ namespace gui unsigned m_minHeight; unique_ptr<TextView> m_textView; - map<EState, shared_ptr<graphics::DisplayList> > m_dls; + map<EState, unique_ptr<graphics::DisplayList> > m_dls; void cacheButtonBody(EState state); mutable vector<m2::AnyRectD> m_boundRects; - void cache(); - public: struct Params : Element::Params @@ -53,14 +54,8 @@ namespace gui Button(Params const & p); - bool onTapStarted(m2::PointD const & pt); - bool onTapMoved(m2::PointD const & pt); - bool onTapEnded(m2::PointD const & pt); - bool onTapCancelled(m2::PointD const & pt); - void setOnClickListener(TOnClickListener const & l); - void setPivot(m2::PointD const & pv); void setFont(EState state, graphics::FontDesc const & font); void setColor(EState state, graphics::Color const & c); @@ -73,17 +68,22 @@ namespace gui void setMinHeight(unsigned minHeightInDIP); unsigned minHeight() const; - void setController(Controller * controller); - - /// Inherited from OverlayElement - /// @{ - + /// @name Override from graphics::OverlayElement and gui::Element. + //@{ vector<m2::AnyRectD> const & boundRects() const; void draw(graphics::OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const; + void setPivot(m2::PointD const & pv); void purge(); void layout(); + void cache(); + + void setController(Controller * controller); - /// @} + bool onTapStarted(m2::PointD const & pt); + bool onTapMoved(m2::PointD const & pt); + bool onTapEnded(m2::PointD const & pt); + bool onTapCancelled(m2::PointD const & pt); + //@} }; } diff --git a/gui/cached_text_view.cpp b/gui/cached_text_view.cpp index 54dce2908c..9b23b1967f 100644 --- a/gui/cached_text_view.cpp +++ b/gui/cached_text_view.cpp @@ -5,6 +5,11 @@ #include "../graphics/glyph.hpp" #include "../graphics/screen.hpp" +#include "../graphics/display_list.hpp" +#include "../graphics/glyph_layout.hpp" + + +using namespace graphics; namespace gui { @@ -14,11 +19,11 @@ namespace gui m_text = p.m_text; m_uniText = strings::MakeUniString(p.m_text); - setFont(EActive, graphics::FontDesc(12, graphics::Color(0, 0, 0, 255))); - setFont(EPressed, graphics::FontDesc(12, graphics::Color(0, 0, 0, 255))); + setFont(EActive, FontDesc(12, Color(0, 0, 0, 255))); + setFont(EPressed, FontDesc(12, Color(0, 0, 0, 255))); - setColor(EActive, graphics::Color(graphics::Color(192, 192, 192, 255))); - setColor(EPressed, graphics::Color(graphics::Color(64, 64, 64, 255))); + setColor(EActive, Color(Color(192, 192, 192, 255))); + setColor(EPressed, Color(Color(64, 64, 64, 255))); } void CachedTextView::setText(string const & text) @@ -31,7 +36,7 @@ namespace gui } } - void CachedTextView::setFont(EState state, graphics::FontDesc const & desc) + void CachedTextView::setFont(EState state, FontDesc const & desc) { setIsDirtyLayout(true); Element::setFont(state, desc); @@ -57,7 +62,7 @@ namespace gui return m_boundRects; } - void CachedTextView::draw(graphics::OverlayRenderer *r, math::Matrix<double, 3, 3> const & m) const + void CachedTextView::draw(OverlayRenderer *r, math::Matrix<double, 3, 3> const & m) const { if (isVisible()) { @@ -66,11 +71,11 @@ namespace gui math::Matrix<double, 3, 3> id = math::Identity<double, 3>(); if (m_maskedLayout) - for (unsigned i = 0; i < m_uniText.size(); ++i) + for (size_t i = 0; i < m_uniText.size(); ++i) r->drawDisplayList(m_maskedDls[i].get(), math::Shift(id, m_maskedLayout->entries()[i].m_pt + m_maskedLayout->pivot())); - for (unsigned i = 0; i < m_uniText.size(); ++i) + for (size_t i = 0; i < m_uniText.size(); ++i) r->drawDisplayList(m_dls[i].get(), math::Shift(id, m_layout->entries()[i].m_pt + m_layout->pivot())); } @@ -81,29 +86,27 @@ namespace gui layout(); DisplayListCache * dlc = m_controller->GetDisplayListCache(); - graphics::FontDesc fontDesc = font(EActive); + FontDesc fontDesc = font(EActive); if (fontDesc.m_isMasked) { m_maskedDls.resize(m_uniText.size()); - for (unsigned i = 0; i < m_uniText.size(); ++i) - m_maskedDls[i] = dlc->FindGlyph(graphics::GlyphKey(m_uniText[i], - fontDesc.m_size, - fontDesc.m_isMasked, - fontDesc.m_isMasked ? fontDesc.m_maskColor : fontDesc.m_color)); + for (size_t i = 0; i < m_uniText.size(); ++i) + m_maskedDls[i] = dlc->FindGlyph(GlyphKey(m_uniText[i], + fontDesc.m_size, + fontDesc.m_isMasked, + fontDesc.m_isMasked ? fontDesc.m_maskColor : fontDesc.m_color)); fontDesc.m_isMasked = false; } m_dls.resize(m_uniText.size()); - for (unsigned i = 0; i < m_uniText.size(); ++i) - m_dls[i] = dlc->FindGlyph(graphics::GlyphKey(m_uniText[i], - fontDesc.m_size, - fontDesc.m_isMasked, - fontDesc.m_color)); - - + for (size_t i = 0; i < m_uniText.size(); ++i) + m_dls[i] = dlc->FindGlyph(GlyphKey(m_uniText[i], + fontDesc.m_size, + fontDesc.m_isMasked, + fontDesc.m_color)); } void CachedTextView::purge() @@ -116,23 +119,23 @@ namespace gui if (m_uniText.empty()) return; - graphics::FontDesc fontDesc = font(EActive); + FontDesc fontDesc = font(EActive); if (fontDesc.m_isMasked) { - m_maskedLayout.reset(new graphics::GlyphLayout(m_controller->GetGlyphCache(), - fontDesc, - pivot(), - m_uniText, - position())); + m_maskedLayout.reset(new GlyphLayout(m_controller->GetGlyphCache(), + fontDesc, + pivot(), + m_uniText, + position())); fontDesc.m_isMasked = false; } - m_layout.reset(new graphics::GlyphLayout(m_controller->GetGlyphCache(), - fontDesc, - pivot(), - m_uniText, - position())); + m_layout.reset(new GlyphLayout(m_controller->GetGlyphCache(), + fontDesc, + pivot(), + m_uniText, + position())); } void CachedTextView::setPivot(m2::PointD const & pv) diff --git a/gui/cached_text_view.hpp b/gui/cached_text_view.hpp index 90a531a49c..0ebb082eda 100644 --- a/gui/cached_text_view.hpp +++ b/gui/cached_text_view.hpp @@ -2,16 +2,19 @@ #include "element.hpp" -#include "../std/map.hpp" +#include "../base/string_utils.hpp" +#include "../base/matrix.hpp" + #include "../std/vector.hpp" #include "../std/shared_ptr.hpp" +#include "../std/unique_ptr.hpp" -#include "../base/string_utils.hpp" -#include "../base/matrix.hpp" -#include "../graphics/glyph_cache.hpp" -#include "../graphics/display_list.hpp" -#include "../graphics/glyph_layout.hpp" +namespace graphics +{ + class DisplayList; + class GlyphLayout; +} namespace gui { diff --git a/gui/display_list_cache.cpp b/gui/display_list_cache.cpp index d88d7bbbc2..19bfb4d364 100644 --- a/gui/display_list_cache.cpp +++ b/gui/display_list_cache.cpp @@ -1,41 +1,42 @@ #include "display_list_cache.hpp" +#include "../graphics/screen.hpp" #include "../graphics/display_list.hpp" #include "../graphics/glyph.hpp" #include "../graphics/depth_constants.hpp" -#include "../std/cstring.hpp" +using namespace graphics; namespace gui { - DisplayListCache::DisplayListCache(graphics::Screen * CacheScreen, - graphics::GlyphCache * GlyphCache) + DisplayListCache::DisplayListCache(Screen * CacheScreen, + GlyphCache * GlyphCache) : m_CacheScreen(CacheScreen), m_GlyphCache(GlyphCache) {} - shared_ptr<graphics::DisplayList> const & DisplayListCache::FindGlyph(graphics::GlyphKey const & key) + shared_ptr<DisplayList> const & DisplayListCache::FindGlyph(GlyphKey const & key) { TGlyphs::const_iterator it = m_Glyphs.find(key); if (it != m_Glyphs.end()) return it->second; - shared_ptr<graphics::DisplayList> & dl = m_Glyphs[key]; + shared_ptr<DisplayList> & dl = m_Glyphs[key]; dl.reset(m_CacheScreen->createDisplayList()); m_CacheScreen->beginFrame(); m_CacheScreen->setDisplayList(dl.get()); - uint32_t resID = m_CacheScreen->mapInfo(graphics::Glyph::Info(key, m_GlyphCache)); - graphics::Resource const * res = m_CacheScreen->fromID(resID); + uint32_t resID = m_CacheScreen->mapInfo(Glyph::Info(key, m_GlyphCache)); + Resource const * res = m_CacheScreen->fromID(resID); - ASSERT(res->m_cat == graphics::Resource::EGlyph, ()); - graphics::Glyph const * glyph = static_cast<graphics::Glyph const *>(res); + ASSERT(res->m_cat == Resource::EGlyph, ()); + Glyph const * glyph = static_cast<Glyph const *>(res); - m_CacheScreen->drawGlyph(m2::PointD(0, 0), m2::PointD(0, 0), ang::AngleD(0), 0, glyph, graphics::maxDepth - 10); + m_CacheScreen->drawGlyph(m2::PointD(0, 0), m2::PointD(0, 0), ang::AngleD(0), 0, glyph, maxDepth - 10); m_CacheScreen->setDisplayList(0); m_CacheScreen->endFrame(); @@ -43,16 +44,17 @@ namespace gui return dl; } - void DisplayListCache::TouchGlyph(graphics::GlyphKey const & key) + void DisplayListCache::TouchGlyph(GlyphKey const & key) { FindGlyph(key); } - bool DisplayListCache::HasGlyph(graphics::GlyphKey const & key) + bool DisplayListCache::HasGlyph(GlyphKey const & key) { return m_Glyphs.find(key) != m_Glyphs.end(); } + /* void DisplayListCache::TouchSymbol(char const * name) { FindSymbol(name); @@ -63,7 +65,7 @@ namespace gui return m_Symbols.find(name) != m_Symbols.end(); } - shared_ptr<graphics::DisplayList> const & DisplayListCache::FindSymbol(char const * name) + shared_ptr<DisplayList> const & DisplayListCache::FindSymbol(char const * name) { string s(name); TSymbols::const_iterator it = m_Symbols.find(s); @@ -71,27 +73,25 @@ namespace gui if (it != m_Symbols.end()) return it->second; - shared_ptr<graphics::DisplayList> & dl = m_Symbols[s]; + shared_ptr<DisplayList> & dl = m_Symbols[s]; dl.reset(m_CacheScreen->createDisplayList()); m_CacheScreen->beginFrame(); m_CacheScreen->setDisplayList(dl.get()); - graphics::EPosition pos = graphics::EPosAbove; - if (strcmp(name, "search-result") == 0) - { - LOG(LDEBUG, ("Position checked")); - pos = graphics::EPosCenter; - } + EPosition pos = EPosAbove; + if (s == "search-result") + pos = EPosCenter; /// @todo do not cache depth in display list. use separate vertex shader and uniform constant /// to specify it while rendering display list. - m_CacheScreen->drawSymbol(m2::PointD(0, 0), name, pos, graphics::poiDepth); + m_CacheScreen->drawSymbol(m2::PointD(0, 0), name, pos, poiDepth); m_CacheScreen->setDisplayList(0); m_CacheScreen->endFrame(); return dl; } + */ } diff --git a/gui/display_list_cache.hpp b/gui/display_list_cache.hpp index 1d25339a47..3921628604 100644 --- a/gui/display_list_cache.hpp +++ b/gui/display_list_cache.hpp @@ -1,8 +1,16 @@ #pragma once + +#include "../graphics/glyph_cache.hpp" + #include "../std/shared_ptr.hpp" -#include "../graphics/screen.hpp" + +namespace graphics +{ + class Screen; + class DisplayList; +} namespace gui { @@ -26,21 +34,20 @@ namespace gui DisplayListCache(graphics::Screen * CacheScreen, graphics::GlyphCache * GlyphCache); - /// Add element to cache if need be + /// Add element to cache if needed void TouchGlyph(graphics::GlyphKey const & key); /// Find glyph in cache, caching if needed. shared_ptr<graphics::DisplayList> const & FindGlyph(graphics::GlyphKey const & key); /// Check, whether the glyph is present in cache. bool HasGlyph(graphics::GlyphKey const & key); - /// @todo refactor to have common functions TouchInfo, FindInfo, HasInfo - /// taking as example ResourceCache mapInfo, findInfo, hasInfo functions - + /* /// Add symbol to cache if needed void TouchSymbol(char const * name); /// Find symbol in cache, caching if needed shared_ptr<graphics::DisplayList> const & FindSymbol(char const * name); /// Check, whether the display list for specified symbol is present in cache bool HasSymbol(char const * name); + */ }; } diff --git a/gui/element.cpp b/gui/element.cpp index 8b9d641cbe..585265111a 100644 --- a/gui/element.cpp +++ b/gui/element.cpp @@ -86,7 +86,7 @@ namespace gui void Element::draw(graphics::OverlayRenderer *r, math::Matrix<double, 3, 3> const & m) const { - for (unsigned i = 0; i < boundRects().size(); ++i) + for (size_t i = 0; i < boundRects().size(); ++i) r->drawRectangle(boundRects()[i], color(state()), depth()); } diff --git a/gui/element.hpp b/gui/element.hpp index 11124360f6..e24e0c620f 100644 --- a/gui/element.hpp +++ b/gui/element.hpp @@ -1,13 +1,12 @@ #pragma once -#include "../geometry/point2d.hpp" - #include "../graphics/overlay_element.hpp" #include "../graphics/color.hpp" #include "../graphics/font_desc.hpp" #include "../std/map.hpp" + namespace graphics { namespace gl @@ -83,12 +82,15 @@ namespace gui virtual void layout(); /// set the parent controller for this element. virtual void setController(Controller * controller); + /// check if the layout of element is dirty and re-layout element if needed. void checkDirtyLayout() const; + /// @name Override from OverlayElement. + //@{ void draw(graphics::OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const; double priority() const; - void setTransformation(const math::Matrix<double, 3, 3> & m); + //@} }; } |