diff --git a/drape_gui/country_status.cpp b/drape_gui/country_status.cpp index 6d4ca558a8..4522dfc766 100644 --- a/drape_gui/country_status.cpp +++ b/drape_gui/country_status.cpp @@ -49,29 +49,13 @@ public: CountryStatusHelper & helper = DrapeGui::GetCountryStatusHelper(); SetIsVisible(helper.IsVisibleForState(m_state)); if (IsVisible()) - { - string v = helper.GetProgressValue(); - if (m_value != v) - { - m_value = move(v); - m_contentDirty = true; - } - else - m_contentDirty = false; - } + SetContent(helper.GetProgressValue()); TBase::Update(screen); } -protected: - bool IsContentDirty() const override { return m_contentDirty; } - - string const & GetContent() const override { return m_value; } - private: CountryStatusHelper::ECountryState m_state; - bool m_contentDirty; - string m_value; }; dp::TransferPointer CreateHandle(CountryStatusHelper::ECountryState const state, diff --git a/drape_gui/gui_text.cpp b/drape_gui/gui_text.cpp index ab4e88eb60..c10dcd7886 100644 --- a/drape_gui/gui_text.cpp +++ b/drape_gui/gui_text.cpp @@ -435,11 +435,12 @@ void MutableLabelHandle::GetAttributeMutation(dp::RefPointerSetText(result, GetContent()); + m_textView->SetText(result, m_content); m_size = m2::PointF(result.m_boundRect.SizeX(), result.m_boundRect.SizeY()); size_t byteCount = result.m_buffer.size() * sizeof(MutableLabel::DynamicVertex); @@ -464,6 +465,24 @@ dp::RefPointer MutableLabelHandle::GetTextView() void MutableLabelHandle::UpdateSize(m2::PointF const & size) { m_size = size; } +void MutableLabelHandle::SetContent(string && content) +{ + if (m_content != content) + { + m_isContentDirty = true; + m_content = content; + } +} + +void MutableLabelHandle::SetContent(string const & content) +{ + if (m_content != content) + { + m_isContentDirty = true; + m_content = content; + } +} + void MutableLabelDrawer::Draw(Params const & params, dp::RefPointer mng, dp::Batcher::TFlushFn const & flushFn) { diff --git a/drape_gui/gui_text.hpp b/drape_gui/gui_text.hpp index d7fb26cfac..1cd463a1db 100644 --- a/drape_gui/gui_text.hpp +++ b/drape_gui/gui_text.hpp @@ -149,11 +149,13 @@ public: void UpdateSize(m2::PointF const & size); protected: - virtual bool IsContentDirty() const = 0; - virtual string const & GetContent() const = 0; + void SetContent(string && content); + void SetContent(string const & content); private: dp::MasterPointer m_textView; + mutable bool m_isContentDirty; + string m_content; }; class MutableLabelDrawer diff --git a/drape_gui/layer_render.cpp b/drape_gui/layer_render.cpp index ab120fcc31..d00b6f3903 100644 --- a/drape_gui/layer_render.cpp +++ b/drape_gui/layer_render.cpp @@ -1,6 +1,7 @@ #include "compass.hpp" #include "country_status.hpp" #include "drape_gui.hpp" +#include "gui_text.hpp" #include "layer_render.hpp" #include "ruler.hpp" #include "ruler_helper.hpp" @@ -15,6 +16,42 @@ namespace gui { +namespace +{ + +class ScaleLabelHandle : public MutableLabelHandle +{ + using TBase = MutableLabelHandle; +public: + ScaleLabelHandle() + : TBase(dp::LeftBottom, m2::PointF::Zero()) + , m_scale(0) + { + SetIsVisible(true); + } + + void Update(ScreenBase const & screen) override + { + int newScale = DrapeGui::Instance().GetGeneralization(screen); + if (m_scale != newScale) + { + m_scale = newScale; + SetContent("Scale : " + strings::to_string(m_scale)); + } + + float vs = DrapeGui::Instance().GetScaleFactor(); + m2::PointF offset(10.0f * vs, 30.0f * vs); + + SetPivot(glsl::ToVec2(m2::PointF(screen.PixelRect().LeftBottom()) + offset)); + TBase::Update(screen); + } + +private: + int m_scale; +}; + +} + LayerCacher::LayerCacher(string const & deviceType) { m_skin.reset(new Skin(ResolveGuiSkinFile(deviceType))); @@ -45,6 +82,24 @@ dp::TransferPointer LayerCacher::Recache(Skin::ElementName names, // TODO UVR } +#ifdef DEBUG + MutableLabelDrawer::Params params; + params.m_alphabet = "Scale: 1234567890"; + params.m_maxLength = 10; + params.m_anchor = dp::LeftBottom; + params.m_font = dp::FontDecl(dp::Color::Black(), 14); + params.m_pivot = m2::PointF::Zero(); + params.m_handleCreator = [](dp::Anchor, m2::PointF const &) + { + return dp::MovePointer(new ScaleLabelHandle()); + }; + + dp::MasterPointer scaleRenderer(new ShapeRenderer()); + MutableLabelDrawer::Draw(params, textures, bind(&ShapeRenderer::AddShape, scaleRenderer.GetRaw(), _1, _2)); + + renderer->AddShapeRenderer(Skin::ScaleLabel, scaleRenderer.Move()); +#endif + return renderer.Move(); } diff --git a/drape_gui/ruler.cpp b/drape_gui/ruler.cpp index 7bef47782d..3514b07140 100644 --- a/drape_gui/ruler.cpp +++ b/drape_gui/ruler.cpp @@ -86,20 +86,19 @@ class RulerTextHandle : public MutableLabelHandle typedef MutableLabelHandle TBase; public: - RulerTextHandle(dp::Anchor anchor, m2::PointF const & pivot) : MutableLabelHandle(anchor, pivot) + RulerTextHandle(dp::Anchor anchor, m2::PointF const & pivot) + : MutableLabelHandle(anchor, pivot) { - SetIsVisible(true); } void Update(ScreenBase const & screen) override { SetIsVisible(DrapeGui::GetRulerHelper().IsVisible(screen)); + if (IsVisible() && DrapeGui::GetRulerHelper().IsTextDirty()) + SetContent(DrapeGui::GetRulerHelper().GetRulerText()); + TBase::Update(screen); } - -protected: - bool IsContentDirty() const override { return DrapeGui::GetRulerHelper().IsTextDirty(); } - string const & GetContent() const override { return DrapeGui::GetRulerHelper().GetRulerText(); } }; } diff --git a/drape_gui/skin.hpp b/drape_gui/skin.hpp index 08ab2d37cc..b090154cf5 100644 --- a/drape_gui/skin.hpp +++ b/drape_gui/skin.hpp @@ -41,10 +41,12 @@ public: enum ElementName { CountryStatus = 0x1, - Ruler = CountryStatus << 1, - Compass = Ruler << 1, - Copyright = Compass << 1, - AllElements = CountryStatus | Ruler | Compass | Copyright + Ruler = 0x2, + Compass = 0x4, + Copyright = 0x8, + AllElements = CountryStatus | Ruler | Compass | Copyright, + // It's drawing only in debug and not depend from elements flag. It's not part of "AllElements" + ScaleLabel = 0x8000 }; explicit Skin(ReaderPtr const & reader);