[drape] copyright

This commit is contained in:
ExMix 2015-03-29 19:17:03 +03:00 committed by r.kuznetsov
parent a208d78fbb
commit 511af842b2
10 changed files with 156 additions and 25 deletions

View file

@ -241,10 +241,7 @@ public:
}
Type GetType() const override { return Message::GuiRecache;}
gui::Skin::ElementName GetElements() const
{
return m_elements;
}
gui::Skin::ElementName GetElements() const { return m_elements; }
private:
gui::Skin::ElementName m_elements;

View file

@ -0,0 +1,87 @@
#include "copyright_label.hpp"
#include "drape_gui.hpp"
#include "gui_text.hpp"
#include "ruler_helper.hpp"
#include "../base/timer.hpp"
#include "../std/bind.hpp"
namespace gui
{
namespace
{
float const CopyrightVisibleTime = 3.0f;
class CopyrightHandle : public Handle
{
using TBase = Handle;
public:
CopyrightHandle(dp::Anchor anchor, m2::PointF const & pivot, m2::PointF const & size)
: TBase(anchor, pivot, size)
, m_timer(false)
, m_firstRender(true)
{
SetIsVisible(true);
}
void Update(ScreenBase const & screen) override
{
if (!IsVisible())
return;
if (m_firstRender == true)
{
m_firstRender = false;
m_timer.Reset();
}
else if (m_timer.ElapsedSeconds() > CopyrightVisibleTime)
{
DrapeGui::Instance().DeactivateCopyright();
SetIsVisible(false);
}
TBase::Update(screen);
}
private:
my::Timer m_timer;
bool m_firstRender;
};
}
CopyrightLabel::CopyrightLabel(Position const & position)
: TBase(position)
{
}
dp::TransferPointer<ShapeRenderer> CopyrightLabel::Draw(dp::RefPointer<dp::TextureManager> tex) const
{
StaticLabel::LabelResult result;
StaticLabel::CacheStaticText("Map data © OpenStreetMap", "", m_position.m_anchor,
DrapeGui::GetGuiTextFont(), tex, result);
dp::AttributeProvider provider(1 /*stream count*/, result.m_buffer.size());
provider.InitStream(0 /*stream index*/, StaticLabel::Vertex::GetBindingInfo(),
dp::StackVoidRef(result.m_buffer.data()));
size_t vertexCount = result.m_buffer.size();
ASSERT(vertexCount % dp::Batcher::VertexPerQuad == 0, ());
size_t indexCount = dp::Batcher::IndexPerQuad * vertexCount / dp::Batcher::VertexPerQuad;
m2::PointF size(result.m_boundRect.SizeX(), result.m_boundRect.SizeY());
dp::MasterPointer<dp::OverlayHandle> handle(new CopyrightHandle(m_position.m_anchor,
m_position.m_pixelPivot,
size));
dp::MasterPointer<ShapeRenderer> renderer(new ShapeRenderer());
dp::Batcher batcher(indexCount, vertexCount);
dp::SessionGuard guard(batcher, bind(&ShapeRenderer::AddShape, renderer.GetRaw(), _1, _2));
batcher.InsertListOfStrip(result.m_state, dp::MakeStackRefPointer(&provider),
handle.Move(), dp::Batcher::VertexPerQuad);
return renderer.Move();
}
}

View file

@ -0,0 +1,16 @@
#pragma once
#include "shape.hpp"
namespace gui
{
class CopyrightLabel : public Shape
{
using TBase = Shape;
public:
CopyrightLabel(gui::Position const & position);
dp::TransferPointer<ShapeRenderer> Draw(dp::RefPointer<dp::TextureManager> tex) const override;
};
}

View file

@ -40,6 +40,12 @@ CountryStatusHelper & DrapeGui::GetCountryStatusHelper()
return Instance().GetCountryStatusHelperImpl();
}
dp::FontDecl const & DrapeGui::GetGuiTextFont()
{
static dp::FontDecl font(dp::Color(0x4D, 0x4D, 0x4D, 0xDD), 7 * DrapeGui::Instance().GetScaleFactor());
return font;
}
void DrapeGui::Init(TScaleFactorFn const & scaleFn, TGeneralizationLevelFn const & gnLvlFn)
{
ASSERT(m_impl == nullptr, ());

View file

@ -51,6 +51,8 @@ public:
static RulerHelper & GetRulerHelper();
static CountryStatusHelper & GetCountryStatusHelper();
static dp::FontDecl const & GetGuiTextFont();
void Init(TScaleFactorFn const & scaleFn, TGeneralizationLevelFn const & gnLvlFn);
void SetLocalizator(TLocalizeStringFn const & fn);
void SetStorageAccessor(dp::RefPointer<gui::StorageAccessor> accessor);
@ -65,6 +67,9 @@ public:
void EmitRecacheSignal(Skin::ElementName elements);
void ClearRecacheSlot();
bool IsCopyrightActive() const { return m_isCopyrightActive; }
void DeactivateCopyright() { m_isCopyrightActive = false; }
private:
RulerHelper & GetRulerHelperImpl();
CountryStatusHelper & GetCountryStatusHelperImpl();
@ -72,6 +77,7 @@ private:
private:
struct Impl;
unique_ptr<Impl> m_impl;
bool m_isCopyrightActive = true;
};
}

View file

@ -10,6 +10,8 @@ INCLUDEPATH *= $$ROOT_DIR/3party/expat/lib
HEADERS += \
button.hpp \
compass.hpp \
copyright_label.hpp \
country_status.hpp \
country_status_helper.hpp \
drape_gui.hpp \
@ -19,10 +21,11 @@ HEADERS += \
ruler_helper.hpp \
shape.hpp \
skin.hpp \
compass.hpp \
SOURCES += \
button.cpp \
compass.cpp \
copyright_label.cpp \
country_status.cpp \
country_status_helper.cpp \
drape_gui.cpp \
@ -32,5 +35,4 @@ SOURCES += \
ruler_helper.cpp \
shape.cpp \
skin.cpp \
compass.cpp \

View file

@ -1,4 +1,5 @@
#include "compass.hpp"
#include "copyright_label.hpp"
#include "country_status.hpp"
#include "drape_gui.hpp"
#include "gui_text.hpp"
@ -68,26 +69,36 @@ dp::TransferPointer<LayerRenderer> LayerCacher::Recache(Skin::ElementName names,
dp::MasterPointer<LayerRenderer> renderer(new LayerRenderer());
if (names & Skin::Compass)
renderer->AddShapeRenderer(Skin::Compass,
Compass(m_skin->ResolvePosition(Skin::Compass)).Draw(textures));
if (names & Skin::Ruler)
renderer->AddShapeRenderer(Skin::Ruler,
Ruler(m_skin->ResolvePosition(Skin::Ruler)).Draw(textures));
if (names & Skin::CountryStatus)
renderer->AddShapeRenderer(
Skin::CountryStatus,
CountryStatus(m_skin->ResolvePosition(Skin::CountryStatus)).Draw(textures));
if (names & Skin::Copyright)
{
// TODO UVR
renderer->AddShapeRenderer(Skin::Compass,
Compass(GetPos(Skin::Compass)).Draw(textures));
}
if (names & Skin::Ruler)
{
renderer->AddShapeRenderer(Skin::Ruler,
Ruler(GetPos(Skin::Ruler)).Draw(textures));
}
if (names & Skin::CountryStatus)
{
renderer->AddShapeRenderer(Skin::CountryStatus,
CountryStatus(GetPos(Skin::CountryStatus)).Draw(textures));
}
if (DrapeGui::Instance().IsCopyrightActive() && (names & Skin::Copyright))
{
renderer->AddShapeRenderer(Skin::Copyright,
CopyrightLabel(GetPos(Skin::Copyright)).Draw(textures));
}
#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_font = DrapeGui::GetGuiTextFont();
params.m_pivot = m2::PointF::Zero();
params.m_handleCreator = [](dp::Anchor, m2::PointF const &)
{
@ -103,6 +114,11 @@ dp::TransferPointer<LayerRenderer> LayerCacher::Recache(Skin::ElementName names,
return renderer.Move();
}
Position LayerCacher::GetPos(Skin::ElementName name)
{
return m_skin->ResolvePosition(name);
}
//////////////////////////////////////////////////////////////////////////////////////////
LayerRenderer::~LayerRenderer()

View file

@ -51,6 +51,9 @@ public:
dp::TransferPointer<LayerRenderer> Recache(Skin::ElementName names,
dp::RefPointer<dp::TextureManager> textures);
private:
Position GetPos(Skin::ElementName name);
private:
unique_ptr<Skin> m_skin;
};

View file

@ -15,9 +15,6 @@ namespace gui
namespace
{
static size_t const FontSize = 7;
static dp::Color const FontColor = dp::Color(0x4D, 0x4D, 0x4D, 0xCC);
struct RulerVertex
{
RulerVertex() = default;
@ -119,7 +116,7 @@ void Ruler::DrawRuler(ShapeControl & control, dp::RefPointer<dp::TextureManager>
buffer_vector<RulerVertex, 4> data;
dp::TextureManager::ColorRegion reg;
tex->GetColorRegion(dp::Color(0x4D, 0x4D, 0x4D, 0xCC), reg);
tex->GetColorRegion(DrapeGui::GetGuiTextFont().m_color, reg);
glsl::vec2 pivot = glsl::ToVec2(m_position.m_pixelPivot);
glsl::vec2 texCoord = glsl::ToVec2(reg.GetTexRect().Center());
@ -169,7 +166,7 @@ void Ruler::DrawText(ShapeControl & control, dp::RefPointer<dp::TextureManager>
static_cast<dp::Anchor>((m_position.m_anchor & (dp::Right | dp::Left)) | dp::Bottom);
params.m_alphabet = alphabet;
params.m_maxLength = maxTextLength;
params.m_font = dp::FontDecl(FontColor, FontSize * DrapeGui::Instance().GetScaleFactor());
params.m_font = DrapeGui::GetGuiTextFont();
params.m_pivot = m_position.m_pixelPivot + m2::PointF(0.0, helper.GetVerticalTextOffset());
params.m_handleCreator = [](dp::Anchor anchor, m2::PointF const & pivot)
{

View file

@ -132,9 +132,10 @@ void RulerHelper::Update(ScreenBase const & screen)
}
}
bool RulerHelper::IsVisible(const ScreenBase & screen) const
bool RulerHelper::IsVisible(ScreenBase const & screen) const
{
return DrapeGui::Instance().GetGeneralization(screen) > 4;
DrapeGui & gui = DrapeGui::Instance();
return !gui.IsCopyrightActive() && gui.GetGeneralization(screen) > 4;
}
float RulerHelper::GetRulerHalfHeight() const