forked from organicmaps/organicmaps
[drape] debug scale label
This commit is contained in:
parent
6a60f9d17d
commit
48e16528c1
6 changed files with 92 additions and 31 deletions
|
@ -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<dp::OverlayHandle> CreateHandle(CountryStatusHelper::ECountryState const state,
|
||||
|
|
|
@ -435,11 +435,12 @@ void MutableLabelHandle::GetAttributeMutation(dp::RefPointer<dp::AttributeBuffer
|
|||
{
|
||||
UNUSED_VALUE(screen);
|
||||
|
||||
if (!IsContentDirty())
|
||||
if (!m_isContentDirty)
|
||||
return;
|
||||
|
||||
m_isContentDirty = false;
|
||||
MutableLabel::LabelResult result;
|
||||
m_textView->SetText(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<MutableLabel> 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<dp::TextureManager> mng,
|
||||
dp::Batcher::TFlushFn const & flushFn)
|
||||
{
|
||||
|
|
|
@ -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<MutableLabel> m_textView;
|
||||
mutable bool m_isContentDirty;
|
||||
string m_content;
|
||||
};
|
||||
|
||||
class MutableLabelDrawer
|
||||
|
|
|
@ -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<LayerRenderer> 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<MutableLabelHandle>(new ScaleLabelHandle());
|
||||
};
|
||||
|
||||
dp::MasterPointer<ShapeRenderer> scaleRenderer(new ShapeRenderer());
|
||||
MutableLabelDrawer::Draw(params, textures, bind(&ShapeRenderer::AddShape, scaleRenderer.GetRaw(), _1, _2));
|
||||
|
||||
renderer->AddShapeRenderer(Skin::ScaleLabel, scaleRenderer.Move());
|
||||
#endif
|
||||
|
||||
return renderer.Move();
|
||||
}
|
||||
|
||||
|
|
|
@ -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(); }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Reader> const & reader);
|
||||
|
|
Loading…
Add table
Reference in a new issue