From 667f03e020af445b5ff23b11251926e3b2e0daf5 Mon Sep 17 00:00:00 2001 From: ExMix Date: Mon, 15 Sep 2014 13:26:26 +0300 Subject: [PATCH] [core] copyright on first 3 second --- graphics/opengl/program_manager.cpp | 2 ++ gui/cached_text_view.cpp | 25 +++++++++++-- gui/cached_text_view.hpp | 8 +++++ map/framework.cpp | 2 +- map/information_display.cpp | 55 ++++++++++++++++++++++++++--- map/information_display.hpp | 5 +++ map/ruler.cpp | 2 +- 7 files changed, 89 insertions(+), 10 deletions(-) diff --git a/graphics/opengl/program_manager.cpp b/graphics/opengl/program_manager.cpp index bd9cc2655c..cd16bcffed 100644 --- a/graphics/opengl/program_manager.cpp +++ b/graphics/opengl/program_manager.cpp @@ -77,6 +77,8 @@ namespace graphics " " PRECISION " float t = color.a;\n" " if (t > Transparency)\n" " t = Transparency;\n" + " if (t < 0.05)\n" + " discard;\n" " gl_FragColor = vec4(color.rgb, t);\n" "}\n"; diff --git a/gui/cached_text_view.cpp b/gui/cached_text_view.cpp index 20433c2654..91b58e3c46 100644 --- a/gui/cached_text_view.cpp +++ b/gui/cached_text_view.cpp @@ -15,6 +15,7 @@ namespace gui { CachedTextView::CachedTextView(Params const & p) : Element(p) + , m_isAnimated(false) { setText(p.m_text); @@ -35,6 +36,12 @@ namespace gui } } + void CachedTextView::setAnimated(TAlfaGetterFn const & fn) + { + m_isAnimated = true; + m_alfaGetter = fn; + } + void CachedTextView::setFont(EState state, FontDesc const & desc) { setIsDirtyLayout(true); @@ -49,22 +56,34 @@ namespace gui back_inserter(rects)); } - void CachedTextView::draw(OverlayRenderer *r, math::Matrix const & m) const + void CachedTextView::draw(OverlayRenderer * r, math::Matrix const & m) const { if (isVisible()) { checkDirtyLayout(); math::Matrix id = math::Identity(); + UniformsHolder holder; + UniformsHolder * drawHolder = NULL; + + if (m_isAnimated) + { + r->applyVarAlfaStates(); + drawHolder = &holder; + ASSERT(m_alfaGetter, ()); + drawHolder->insertValue(graphics::ETransparency, m_alfaGetter()); + } if (m_maskedLayout) 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())); + math::Shift(id, m_maskedLayout->entries()[i].m_pt + m_maskedLayout->pivot()), + drawHolder); 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())); + math::Shift(id, m_layout->entries()[i].m_pt + m_layout->pivot()), + drawHolder); } } diff --git a/gui/cached_text_view.hpp b/gui/cached_text_view.hpp index 35feea0eec..57367363e7 100644 --- a/gui/cached_text_view.hpp +++ b/gui/cached_text_view.hpp @@ -8,6 +8,7 @@ #include "../std/vector.hpp" #include "../std/shared_ptr.hpp" #include "../std/unique_ptr.hpp" +#include "../std/function.hpp" namespace graphics @@ -38,6 +39,9 @@ namespace gui void setText(string const & text); + typedef function TAlfaGetterFn; + void setAnimated(TAlfaGetterFn const & fn); + /// @name Overrider from graphics::OverlayElement and gui::Element. //@{ virtual void GetMiniBoundRects(RectsT & rects) const; @@ -51,5 +55,9 @@ namespace gui void setPivot(m2::PointD const & pv); //@} + + private: + bool m_isAnimated; + TAlfaGetterFn m_alfaGetter; }; } diff --git a/map/framework.cpp b/map/framework.cpp index b26dc1e212..ba4faad489 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -677,7 +677,7 @@ void Framework::DrawAdditionalInfo(shared_ptr const & e) int const drawScale = GetDrawScale(); m_informationDisplay.setDebugInfo(0, drawScale); - m_informationDisplay.enableRuler(drawScale > 4); + m_informationDisplay.enableRuler(drawScale > 4 && !m_informationDisplay.isCopyrightActive()); #ifdef DEBUG m_informationDisplay.enableDebugInfo(true); #endif diff --git a/map/information_display.cpp b/map/information_display.cpp index 915bf230f9..52f653e66d 100644 --- a/map/information_display.cpp +++ b/map/information_display.cpp @@ -4,6 +4,10 @@ #include "compass_arrow.hpp" #include "framework.hpp" #include "ruler.hpp" +#include "alfa_animation_task.hpp" + +#include "../anim/task.hpp" +#include "../anim/controller.hpp" #include "../gui/controller.hpp" #include "../gui/button.hpp" @@ -20,23 +24,24 @@ using namespace graphics; namespace { - static int const RULLER_X_OFFSET = 10; - static int const RULLER_Y_OFFSET = 51; + static int const RULLER_X_OFFSET = 6; + static int const RULLER_Y_OFFSET = 42; static int const FONT_SIZE = 14; - static int const COMPASS_X_OFFSET = 21; - static int const COMPASS_Y_OFFSET = 53; + static int const COMPASS_X_OFFSET = 27; + static int const COMPASS_Y_OFFSET = 57; } InformationDisplay::InformationDisplay(Framework * fw) : m_visualScale(1) { - m_fontDesc.m_color = Color(0x44, 0x44, 0x44, 0xFF); + m_fontDesc.m_color = Color(0x4D, 0x4D, 0x4D, 0xCC); InitRuler(fw); InitCountryStatusDisplay(fw); InitCompassArrow(fw); InitLocationState(fw); InitDebugLabel(); + InitCopyright(fw); enableDebugPoints(false); enableDebugInfo(false); @@ -76,6 +81,33 @@ void InformationDisplay::InitCountryStatusDisplay(Framework * fw) m_countryStatusDisplay.reset(new CountryStatusDisplay(p)); } +void InformationDisplay::InitCopyright(Framework * fw) +{ + gui::CachedTextView::Params p; + + p.m_depth = rulerDepth; + p.m_position = EPosAboveLeft; + p.m_pivot = m2::PointD(0, 0); + p.m_text = "Map data © OpenStreetMap"; + + m_copyrightLabel.reset(new gui::CachedTextView(p)); + + shared_ptr task(new AlfaAnimationTask(1.0, 0.0, 0.15, 3.0, fw)); + task->AddCallback(anim::Task::EEnded, [this]() + { + m_controller->RemoveElement(m_copyrightLabel); + m_copyrightLabel.reset(); + }); + + m_copyrightLabel->setAnimated([task]() + { + AlfaAnimationTask * t = static_cast(task.get()); + return t->GetCurrentAlfa(); + }); + + fw->GetAnimController()->AddTask(task); +} + void InformationDisplay::InitCompassArrow(Framework * fw) { CompassArrow::Params p; @@ -120,6 +152,7 @@ void InformationDisplay::setController(gui::Controller * controller) m_controller->AddElement(m_locationState); m_controller->AddElement(m_ruler); m_controller->AddElement(m_debugLabel); + m_controller->AddElement(m_copyrightLabel); } void InformationDisplay::setDisplayRect(m2::RectI const & rect) @@ -135,6 +168,12 @@ void InformationDisplay::setDisplayRect(m2::RectI const & rect) m_ruler->setPivot(m2::PointD(rect.maxX() - RULLER_X_OFFSET * m_visualScale, rect.maxY() - RULLER_Y_OFFSET * m_visualScale)); + if (m_copyrightLabel) + { + m_copyrightLabel->setPivot(m2::PointD(rect.maxX() - RULLER_X_OFFSET * m_visualScale, + rect.maxY() - RULLER_Y_OFFSET * m_visualScale)); + } + m_debugLabel->setPivot(m2::PointD(rect.minX() + 10, rect.minY() + 50 + 5 * m_visualScale)); } @@ -159,6 +198,11 @@ void InformationDisplay::drawDebugPoints(Drawer * pDrawer) } } +bool InformationDisplay::isCopyrightActive() const +{ + return m_copyrightLabel != nullptr; +} + void InformationDisplay::enableRuler(bool doEnable) { if (doEnable) @@ -179,6 +223,7 @@ void InformationDisplay::setVisualScale(double visualScale) m_fontDesc.m_size = static_cast(FONT_SIZE * m_visualScale); m_ruler->setFont(gui::Element::EActive, m_fontDesc); + m_copyrightLabel->setFont(gui::Element::EActive, m_fontDesc); m_debugLabel->setFont(gui::Element::EActive, m_fontDesc); } diff --git a/map/information_display.hpp b/map/information_display.hpp index bf35bf0ab4..1f277f29c0 100644 --- a/map/information_display.hpp +++ b/map/information_display.hpp @@ -71,6 +71,7 @@ class InformationDisplay shared_ptr m_compassArrow; shared_ptr m_locationState; shared_ptr m_debugLabel; + shared_ptr m_copyrightLabel; void InitRuler(Framework * fw); void InitDebugLabel(); @@ -78,6 +79,8 @@ class InformationDisplay void InitCompassArrow(Framework * fw); void InitCountryStatusDisplay(Framework * fw); + void InitCopyright(Framework * fw); + public: InformationDisplay(Framework * framework); @@ -91,6 +94,8 @@ public: void setDebugPoint(int pos, m2::PointD const & pt); void drawDebugPoints(Drawer * pDrawer); + bool isCopyrightActive() const; + void enableRuler(bool doEnable); bool isRulerEnabled() const; diff --git a/map/ruler.cpp b/map/ruler.cpp index 2f8eedcd56..784b0fb2ec 100644 --- a/map/ruler.cpp +++ b/map/ruler.cpp @@ -172,7 +172,7 @@ void Ruler::RulerFrame::Cache(const string & text, FontDesc const & f) /*15*/ m2::PointD(CacheLength, 0.0 * k), }; - Brush::Info const brushInfo(Color(0, 0, 0, 0x99)); + Brush::Info const brushInfo(Color(0x4D, 0x4D, 0x4D, 0xCC)); Resource const * brushRes = cs->fromID(cs->mapInfo(brushInfo)); m2::PointF const brushCenter = cs->pipeline(brushRes->m_pipelineID).texture()->mapPixel(brushRes->m_texRect.Center());