forked from organicmaps/organicmaps
Review fixes
This commit is contained in:
parent
8b4f680455
commit
533352665c
23 changed files with 179 additions and 321 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "geometry/point2d.hpp"
|
||||
|
||||
#include "drape/color.hpp"
|
||||
|
||||
#include <glm_config.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
|
@ -54,6 +56,14 @@ inline vec2 ToVec2(m2::PointD const & pt)
|
|||
return glsl::vec2(pt.x, pt.y);
|
||||
}
|
||||
|
||||
inline vec4 ToVec4(dp::Color const & color)
|
||||
{
|
||||
return glsl::vec4(double(color.GetRed()) / 255,
|
||||
double(color.GetGreen()) / 255,
|
||||
double(color.GetBlue()) / 255,
|
||||
double(color.GetAlfa()) / 255);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline uint8_t GetComponentCount()
|
||||
{
|
||||
|
|
|
@ -107,14 +107,6 @@ OverlayHandle::TOffsetNode const & OverlayHandle::GetOffsetNode(uint8_t bufferID
|
|||
return *it;
|
||||
}
|
||||
|
||||
void OverlayHandle::FinishTapEvent(bool executeAction)
|
||||
{
|
||||
if (executeAction)
|
||||
OnTap();
|
||||
|
||||
OnTapEnd();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SquareHandle::SquareHandle(FeatureID const & id, dp::Anchor anchor,
|
||||
|
|
|
@ -13,13 +13,9 @@
|
|||
|
||||
#include "base/buffer_vector.hpp"
|
||||
|
||||
#include "std/function.hpp"
|
||||
|
||||
namespace dp
|
||||
{
|
||||
|
||||
using TOverlayHandler = function<void ()>;
|
||||
|
||||
class OverlayHandle
|
||||
{
|
||||
public:
|
||||
|
@ -38,15 +34,9 @@ public:
|
|||
|
||||
virtual void Update(ScreenBase const & /*screen*/) {}
|
||||
virtual m2::RectD GetPixelRect(ScreenBase const & screen) const = 0;
|
||||
|
||||
virtual void GetPixelShape(ScreenBase const & screen, Rects & rects) const = 0;
|
||||
|
||||
virtual bool IsTapped(m2::PointD const & pt) const { return false; }
|
||||
virtual void OnTapBegin(){}
|
||||
virtual void OnTap(){}
|
||||
virtual void OnTapEnd(){}
|
||||
|
||||
void FinishTapEvent(bool executeAction);
|
||||
|
||||
bool IsIntersect(ScreenBase const & screen, ref_ptr<OverlayHandle> const h) const;
|
||||
|
||||
virtual bool IndexesRequired() const { return true; }
|
||||
|
|
9
drape/shaders/button_fragment_shader.fsh
Normal file
9
drape/shaders/button_fragment_shader.fsh
Normal file
|
@ -0,0 +1,9 @@
|
|||
uniform vec4 u_color;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
if (u_color.a < 0.1)
|
||||
discard;
|
||||
|
||||
gl_FragColor = u_color;
|
||||
}
|
10
drape/shaders/button_vertex_shader.vsh
Normal file
10
drape/shaders/button_vertex_shader.vsh
Normal file
|
@ -0,0 +1,10 @@
|
|||
attribute vec3 a_position;
|
||||
attribute vec2 a_normal;
|
||||
|
||||
uniform mat4 modelView;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_Position = (vec4(a_normal, 0, 0) + vec4(a_position, 1) * modelView) * projection;
|
||||
}
|
|
@ -5,3 +5,4 @@ COMPASS_PROGRAM compass_vertex_shader.vsh texturing_fragment_shader.fsh
|
|||
RULER_PROGRAM ruler_vertex_shader.vsh texturing_fragment_shader.fsh
|
||||
ACCURACY_PROGRAM position_accuracy_shader.vsh texturing_fragment_shader.fsh
|
||||
MY_POSITION_PROGRAM my_position_shader.vsh texturing_fragment_shader.fsh
|
||||
BUTTON_PROGRAM button_vertex_shader.vsh button_fragment_shader.fsh
|
||||
|
|
|
@ -24,7 +24,6 @@ namespace df
|
|||
BackendRenderer::BackendRenderer(Params const & params)
|
||||
: BaseRenderer(ThreadsCommutator::ResourceUploadThread, params)
|
||||
, m_model(params.m_model)
|
||||
, m_guiHandlers(params.m_guiHandlers)
|
||||
, m_batchersPool(make_unique_dp<BatchersPool>(ReadManager::ReadCount(), bind(&BackendRenderer::FlushGeometry, this, _1)))
|
||||
, m_readManager(make_unique_dp<ReadManager>(params.m_commutator, m_model))
|
||||
, m_guiCacher("default")
|
||||
|
@ -42,8 +41,6 @@ BackendRenderer::BackendRenderer(Params const & params)
|
|||
BackendRenderer::~BackendRenderer()
|
||||
{
|
||||
gui::DrapeGui::Instance().ClearRecacheSlot();
|
||||
m_guiHandlers.Reset();
|
||||
|
||||
StopThread();
|
||||
}
|
||||
|
||||
|
@ -54,7 +51,7 @@ unique_ptr<threads::IRoutine> BackendRenderer::CreateRoutine()
|
|||
|
||||
void BackendRenderer::RecacheGui(gui::Skin::ElementName elements)
|
||||
{
|
||||
drape_ptr<gui::LayerRenderer> layerRenderer = m_guiCacher.Recache(elements, m_texMng, m_guiHandlers);
|
||||
drape_ptr<gui::LayerRenderer> layerRenderer = m_guiCacher.Recache(elements, m_texMng);
|
||||
drape_ptr<Message> outputMsg = make_unique_dp<GuiLayerRecachedMessage>(move(layerRenderer));
|
||||
m_commutator->PostMessage(ThreadsCommutator::RenderThread, move(outputMsg), MessagePriority::High);
|
||||
}
|
||||
|
|
|
@ -25,19 +25,16 @@ class ReadManager;
|
|||
class BackendRenderer : public BaseRenderer
|
||||
{
|
||||
public:
|
||||
|
||||
struct Params : BaseRenderer::Params
|
||||
{
|
||||
Params(ref_ptr<ThreadsCommutator> commutator, ref_ptr<dp::OGLContextFactory> factory,
|
||||
ref_ptr<dp::TextureManager> texMng, MapDataProvider const & model,
|
||||
gui::Handlers const & guiHandlers)
|
||||
ref_ptr<dp::TextureManager> texMng, MapDataProvider const & model)
|
||||
: BaseRenderer::Params(commutator, factory, texMng)
|
||||
, m_model(model)
|
||||
, m_guiHandlers(guiHandlers)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
MapDataProvider const & m_model;
|
||||
gui::Handlers m_guiHandlers;
|
||||
};
|
||||
|
||||
BackendRenderer(Params const & params);
|
||||
|
@ -55,7 +52,6 @@ private:
|
|||
drape_ptr<BatchersPool> m_batchersPool;
|
||||
drape_ptr<ReadManager> m_readManager;
|
||||
gui::LayerCacher m_guiCacher;
|
||||
gui::Handlers m_guiHandlers;
|
||||
|
||||
/////////////////////////////////////////
|
||||
// MessageAcceptor //
|
||||
|
|
|
@ -44,8 +44,7 @@ DrapeEngine::DrapeEngine(Params const & params)
|
|||
m_frontend = make_unique_dp<FrontendRenderer>(frParams);
|
||||
|
||||
BackendRenderer::Params brParams(frParams.m_commutator, frParams.m_oglContextFactory,
|
||||
frParams.m_texMng, params.m_model,
|
||||
params.m_guiHandlers);
|
||||
frParams.m_texMng, params.m_model);
|
||||
m_backend = make_unique_dp<BackendRenderer>(brParams);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include "drape_frontend/threads_commutator.hpp"
|
||||
|
||||
#include "drape/pointers.hpp"
|
||||
#include "drape/overlay_handle.hpp"
|
||||
#include "drape/texture_manager.hpp"
|
||||
|
||||
#include "geometry/screenbase.hpp"
|
||||
|
@ -35,16 +34,15 @@ public:
|
|||
ref_ptr<gui::StorageAccessor> storageAccessor,
|
||||
Viewport const & viewport,
|
||||
MapDataProvider const & model,
|
||||
double vs,
|
||||
gui::Handlers const & guiHandlers)
|
||||
double vs)
|
||||
: m_factory(factory)
|
||||
, m_stringsBundle(stringBundle)
|
||||
, m_storageAccessor(storageAccessor)
|
||||
, m_viewport(viewport)
|
||||
, m_model(model)
|
||||
, m_vs(vs)
|
||||
, m_guiHandlers(guiHandlers)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
ref_ptr<dp::OGLContextFactory> m_factory;
|
||||
ref_ptr<StringsBundle> m_stringsBundle;
|
||||
|
@ -52,8 +50,6 @@ public:
|
|||
Viewport m_viewport;
|
||||
MapDataProvider m_model;
|
||||
double m_vs;
|
||||
|
||||
gui::Handlers m_guiHandlers;
|
||||
};
|
||||
|
||||
DrapeEngine(Params const & params);
|
||||
|
|
|
@ -391,19 +391,21 @@ void FrontendRenderer::TapDetected(m2::PointD const & pt, bool isLongTap)
|
|||
|
||||
bool FrontendRenderer::SingleTouchFiltration(m2::PointD const & pt, TouchEvent::ETouchType type)
|
||||
{
|
||||
if (type == TouchEvent::ETouchType::TOUCH_DOWN)
|
||||
switch(type)
|
||||
{
|
||||
ASSERT(m_activeOverlay == nullptr, ());
|
||||
m_activeOverlay = m_guiRenderer->ProcessTapEvent(pt);
|
||||
return true; // enable filtration
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_activeOverlay != nullptr)
|
||||
{
|
||||
m_activeOverlay->FinishTapEvent(type == TouchEvent::ETouchType::TOUCH_UP);
|
||||
m_activeOverlay = nullptr;
|
||||
}
|
||||
case TouchEvent::ETouchType::TOUCH_DOWN:
|
||||
return m_guiRenderer->OnTouchDown(pt);
|
||||
|
||||
case TouchEvent::ETouchType::TOUCH_UP:
|
||||
m_guiRenderer->OnTouchUp(pt);
|
||||
return false;
|
||||
|
||||
case TouchEvent::ETouchType::TOUCH_CANCEL:
|
||||
m_guiRenderer->OnTouchCancel(pt);
|
||||
return false;
|
||||
|
||||
case TouchEvent::ETouchType::TOUCH_MOVE:
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -139,7 +139,6 @@ private:
|
|||
|
||||
drape_ptr<gui::LayerRenderer> m_guiRenderer;
|
||||
drape_ptr<MyPosition> m_myPositionMark;
|
||||
ref_ptr<dp::OverlayHandle> m_activeOverlay;
|
||||
|
||||
dp::UniformValuesStorage m_generalUniforms;
|
||||
|
||||
|
|
|
@ -10,79 +10,32 @@
|
|||
namespace gui
|
||||
{
|
||||
|
||||
ButtonHandle::ButtonHandle(dp::Anchor anchor, m2::PointF const & size,
|
||||
dp::TextureManager::ColorRegion const & normalColor,
|
||||
dp::TextureManager::ColorRegion const & pressedColor,
|
||||
dp::TOverlayHandler const & tapHandler)
|
||||
: TBase(anchor, m2::PointF::Zero(), size, tapHandler)
|
||||
, m_normalColor(normalColor)
|
||||
, m_pressedColor(pressedColor)
|
||||
ButtonHandle::ButtonHandle(dp::Anchor anchor, m2::PointF const & size)
|
||||
: TBase(anchor, m2::PointF::Zero(), size)
|
||||
, m_isInPressedState(false)
|
||||
, m_isContentDirty(false)
|
||||
{}
|
||||
|
||||
void ButtonHandle::OnTapBegin()
|
||||
{
|
||||
m_isInPressedState = true;
|
||||
m_isContentDirty = true;
|
||||
}
|
||||
|
||||
void ButtonHandle::OnTapEnd()
|
||||
{
|
||||
m_isInPressedState = false;
|
||||
m_isContentDirty = true;
|
||||
}
|
||||
|
||||
void ButtonHandle::GetAttributeMutation(ref_ptr<dp::AttributeBufferMutator> mutator,
|
||||
ScreenBase const & screen) const
|
||||
void ButtonHandle::Update(ScreenBase const & screen)
|
||||
{
|
||||
UNUSED_VALUE(screen);
|
||||
|
||||
if (!m_isContentDirty)
|
||||
return;
|
||||
|
||||
m_isContentDirty = false;
|
||||
|
||||
size_t const byteCount = sizeof(Button::DynamicVertex) * Button::VerticesCount();
|
||||
Button::DynamicVertex * dataPointer =
|
||||
reinterpret_cast<Button::DynamicVertex *>(mutator->AllocateMutationBuffer(byteCount));
|
||||
for (int i = 0; i < Button::VerticesCount(); ++i)
|
||||
dataPointer[i].m_texCoord = m_isInPressedState ? glsl::ToVec2(m_pressedColor.GetTexRect().Center()) :
|
||||
glsl::ToVec2(m_normalColor.GetTexRect().Center());
|
||||
|
||||
dp::BindingInfo const & binding = Button::DynamicVertex::GetBindingInfo();
|
||||
dp::OverlayHandle::TOffsetNode offsetNode = GetOffsetNode(binding.GetID());
|
||||
|
||||
dp::MutateNode mutateNode;
|
||||
mutateNode.m_data = make_ref(dataPointer);
|
||||
mutateNode.m_region = offsetNode.second;
|
||||
mutator->AddMutation(offsetNode.first, mutateNode);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
dp::TextureManager::ColorRegion GetNormalColor(ref_ptr<dp::TextureManager> texMgr)
|
||||
{
|
||||
dp::Color const buttonColor = dp::Color(0x0, 0x0, 0x0, 0x99);
|
||||
dp::TextureManager::ColorRegion region;
|
||||
texMgr->GetColorRegion(buttonColor, region);
|
||||
return region;
|
||||
}
|
||||
|
||||
dp::TextureManager::ColorRegion GetPressedColor(ref_ptr<dp::TextureManager> texMgr)
|
||||
{
|
||||
dp::Color const buttonColor = dp::Color(0x0, 0x0, 0x0, 0xCC);
|
||||
dp::TextureManager::ColorRegion region;
|
||||
texMgr->GetColorRegion(buttonColor, region);
|
||||
return region;
|
||||
}
|
||||
|
||||
glsl::vec4 color = glsl::ToVec4(m_isInPressedState ? dp::Color(0x0, 0x0, 0x0, 0xCC) :
|
||||
dp::Color(0x0, 0x0, 0x0, 0x99));
|
||||
m_uniforms.SetFloatValue("u_color", color.r, color.g, color.b, color.a);
|
||||
TBase::Update(screen);
|
||||
}
|
||||
|
||||
constexpr int Button::VerticesCount()
|
||||
{
|
||||
return 4;
|
||||
return dp::Batcher::VertexPerQuad;
|
||||
}
|
||||
|
||||
void Button::Draw(Params const & params, ShapeControl & control, ref_ptr<dp::TextureManager> texMgr)
|
||||
|
@ -99,22 +52,17 @@ void Button::Draw(Params const & params, ShapeControl & control, ref_ptr<dp::Tex
|
|||
|
||||
// Cache button
|
||||
{
|
||||
dp::TextureManager::ColorRegion normalColor = GetNormalColor(texMgr);
|
||||
dp::TextureManager::ColorRegion pressedColor = GetPressedColor(texMgr);
|
||||
|
||||
dp::GLState state(gpu::TEXTURING_PROGRAM, dp::GLState::Gui);
|
||||
state.SetColorTexture(normalColor.GetTexture());
|
||||
dp::GLState state(gpu::BUTTON_PROGRAM, dp::GLState::Gui);
|
||||
|
||||
glsl::vec3 position(0.0f, 0.0f, 0.0f);
|
||||
glsl::vec2 texCoord(glsl::ToVec2(normalColor.GetTexRect().Center()));
|
||||
|
||||
int const verticesCount = VerticesCount();
|
||||
StaticVertex vertexes[verticesCount]
|
||||
ButtonVertex vertexes[verticesCount]
|
||||
{
|
||||
StaticVertex(position, glsl::vec2(-halfWM, halfHM)),
|
||||
StaticVertex(position, glsl::vec2(-halfWM, -halfHM)),
|
||||
StaticVertex(position, glsl::vec2(halfWM, halfHM)),
|
||||
StaticVertex(position, glsl::vec2(halfWM, -halfHM))
|
||||
ButtonVertex(position, glsl::vec2(-halfWM, halfHM)),
|
||||
ButtonVertex(position, glsl::vec2(-halfWM, -halfHM)),
|
||||
ButtonVertex(position, glsl::vec2(halfWM, halfHM)),
|
||||
ButtonVertex(position, glsl::vec2(halfWM, -halfHM))
|
||||
};
|
||||
|
||||
glsl::vec2 normalOffset(0.0f, 0.0f);
|
||||
|
@ -128,26 +76,19 @@ void Button::Draw(Params const & params, ShapeControl & control, ref_ptr<dp::Tex
|
|||
else if (params.m_anchor & dp::Bottom)
|
||||
normalOffset.x = -halfHeight;
|
||||
|
||||
for (StaticVertex & v : vertexes)
|
||||
for (ButtonVertex & v : vertexes)
|
||||
v.m_normal = v.m_normal + normalOffset;
|
||||
|
||||
buffer_vector<DynamicVertex, verticesCount> dynData;
|
||||
for (int i = 0; i < verticesCount; ++i)
|
||||
dynData.push_back(texCoord);
|
||||
|
||||
dp::AttributeProvider provider(2 /* stream count */, verticesCount);
|
||||
provider.InitStream(0 /*stream index*/, StaticVertex::GetBindingInfo(),
|
||||
dp::AttributeProvider provider(1 /* stream count */, verticesCount);
|
||||
provider.InitStream(0 /*stream index*/, ButtonVertex::GetBindingInfo(),
|
||||
make_ref(vertexes));
|
||||
provider.InitStream(1 /*stream index*/, DynamicVertex::GetBindingInfo(),
|
||||
make_ref(dynData.data()));
|
||||
|
||||
m2::PointF buttonSize(halfWM + halfWM, halfHM + halfHM);
|
||||
ASSERT(params.m_bodyHandleCreator, ());
|
||||
dp::Batcher batcher(dp::Batcher::IndexPerQuad, dp::Batcher::VertexPerQuad);
|
||||
dp::SessionGuard guard(batcher, bind(&ShapeControl::AddShape, &control, _1, _2));
|
||||
batcher.InsertTriangleStrip(state, make_ref(&provider),
|
||||
params.m_bodyHandleCreator(params.m_anchor, buttonSize,
|
||||
normalColor, pressedColor));
|
||||
params.m_bodyHandleCreator(params.m_anchor, buttonSize));
|
||||
}
|
||||
|
||||
// Cache text
|
||||
|
@ -171,7 +112,7 @@ void Button::Draw(Params const & params, ShapeControl & control, ref_ptr<dp::Tex
|
|||
}
|
||||
}
|
||||
|
||||
dp::BindingInfo const & Button::StaticVertex::GetBindingInfo()
|
||||
dp::BindingInfo const & Button::ButtonVertex::GetBindingInfo()
|
||||
{
|
||||
static unique_ptr<dp::BindingInfo> info;
|
||||
|
||||
|
@ -184,7 +125,7 @@ dp::BindingInfo const & Button::StaticVertex::GetBindingInfo()
|
|||
posDecl.m_componentCount = 3;
|
||||
posDecl.m_componentType = gl_const::GLFloatType;
|
||||
posDecl.m_offset = 0;
|
||||
posDecl.m_stride = sizeof(StaticVertex);
|
||||
posDecl.m_stride = sizeof(ButtonVertex);
|
||||
|
||||
dp::BindingDecl & normalDecl = info->GetBindingDecl(1);
|
||||
normalDecl.m_attributeName = "a_normal";
|
||||
|
@ -197,23 +138,4 @@ dp::BindingInfo const & Button::StaticVertex::GetBindingInfo()
|
|||
return *info.get();
|
||||
}
|
||||
|
||||
dp::BindingInfo const & Button::DynamicVertex::GetBindingInfo()
|
||||
{
|
||||
static unique_ptr<dp::BindingInfo> info;
|
||||
|
||||
if (info == nullptr)
|
||||
{
|
||||
info.reset(new dp::BindingInfo(1, 1));
|
||||
|
||||
dp::BindingDecl & colorTexCoordDecl = info->GetBindingDecl(0);
|
||||
colorTexCoordDecl.m_attributeName = "a_colorTexCoords";
|
||||
colorTexCoordDecl.m_componentCount = 2;
|
||||
colorTexCoordDecl.m_componentType = gl_const::GLFloatType;
|
||||
colorTexCoordDecl.m_offset = 0;
|
||||
colorTexCoordDecl.m_stride = sizeof(DynamicVertex);
|
||||
}
|
||||
|
||||
return *info.get();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,31 +13,23 @@ class ButtonHandle : public TappableHandle
|
|||
typedef TappableHandle TBase;
|
||||
|
||||
public:
|
||||
ButtonHandle(dp::Anchor anchor, m2::PointF const & size,
|
||||
dp::TextureManager::ColorRegion const & normalColor,
|
||||
dp::TextureManager::ColorRegion const & pressedColor,
|
||||
dp::TOverlayHandler const & tapHandler);
|
||||
ButtonHandle(dp::Anchor anchor, m2::PointF const & size);
|
||||
|
||||
void OnTapBegin() override;
|
||||
void OnTapEnd() override;
|
||||
|
||||
void GetAttributeMutation(ref_ptr<dp::AttributeBufferMutator> mutator,
|
||||
ScreenBase const & screen) const override;
|
||||
void Update(ScreenBase const & screen) override;
|
||||
|
||||
private:
|
||||
dp::TextureManager::ColorRegion m_normalColor;
|
||||
dp::TextureManager::ColorRegion m_pressedColor;
|
||||
bool m_isInPressedState;
|
||||
mutable bool m_isContentDirty;
|
||||
};
|
||||
|
||||
class Button
|
||||
{
|
||||
public:
|
||||
struct StaticVertex
|
||||
struct ButtonVertex
|
||||
{
|
||||
StaticVertex() = default;
|
||||
StaticVertex(glsl::vec3 const & position, glsl::vec2 const & normal)
|
||||
ButtonVertex() = default;
|
||||
ButtonVertex(glsl::vec3 const & position, glsl::vec2 const & normal)
|
||||
: m_position(position)
|
||||
, m_normal(normal)
|
||||
{
|
||||
|
@ -49,26 +41,10 @@ public:
|
|||
glsl::vec2 m_normal;
|
||||
};
|
||||
|
||||
struct DynamicVertex
|
||||
{
|
||||
DynamicVertex() = default;
|
||||
DynamicVertex(glsl::vec2 const & texCoord)
|
||||
: m_texCoord(texCoord)
|
||||
{
|
||||
}
|
||||
|
||||
static dp::BindingInfo const & GetBindingInfo();
|
||||
|
||||
glsl::vec2 m_texCoord;
|
||||
};
|
||||
|
||||
static constexpr int VerticesCount();
|
||||
|
||||
using TCreatorResult = drape_ptr<dp::OverlayHandle>;
|
||||
using TLabelHandleCreator = function<TCreatorResult (dp::Anchor, m2::PointF const &)>;
|
||||
using TBodyHandleCreator = function<TCreatorResult (dp::Anchor, m2::PointF const &,
|
||||
dp::TextureManager::ColorRegion const &,
|
||||
dp::TextureManager::ColorRegion const &)>;
|
||||
using THandleCreator = function<TCreatorResult (dp::Anchor, m2::PointF const &)>;
|
||||
|
||||
struct Params
|
||||
{
|
||||
|
@ -79,8 +55,8 @@ public:
|
|||
float m_minWidth = 0.0f;
|
||||
float m_maxWidth = 0.0f;
|
||||
float m_margin = 0.0f;
|
||||
TBodyHandleCreator m_bodyHandleCreator;
|
||||
TLabelHandleCreator m_labelHandleCreator;
|
||||
THandleCreator m_bodyHandleCreator;
|
||||
THandleCreator m_labelHandleCreator;
|
||||
};
|
||||
|
||||
static void Draw(Params const & params, ShapeControl & control, ref_ptr<dp::TextureManager> texMgr);
|
||||
|
|
|
@ -26,10 +26,15 @@ namespace
|
|||
class CompassHandle : public TappableHandle
|
||||
{
|
||||
public:
|
||||
CompassHandle(m2::PointF const & pivot, m2::PointF const & size, dp::TOverlayHandler const & tapHandler)
|
||||
: TappableHandle(dp::Center, pivot, size, tapHandler)
|
||||
CompassHandle(m2::PointF const & pivot, m2::PointF const & size)
|
||||
: TappableHandle(dp::Center, pivot, size)
|
||||
{}
|
||||
|
||||
void OnTap() override
|
||||
{
|
||||
//TODO(@kuznetsov) implement
|
||||
}
|
||||
|
||||
void Update(ScreenBase const & screen) override
|
||||
{
|
||||
float angle = ang::AngleIn2PI(screen.GetAngle());
|
||||
|
@ -86,7 +91,7 @@ drape_ptr<ShapeRenderer> Compass::Draw(ref_ptr<dp::TextureManager> tex) const
|
|||
provider.InitStream(0, info, make_ref(&vertexes));
|
||||
|
||||
m2::PointF compassSize = region.GetPixelSize();
|
||||
drape_ptr<dp::OverlayHandle> handle = make_unique_dp<CompassHandle>(m_position.m_pixelPivot, compassSize, m_tapHandler);
|
||||
drape_ptr<dp::OverlayHandle> handle = make_unique_dp<CompassHandle>(m_position.m_pixelPivot, compassSize);
|
||||
|
||||
drape_ptr<ShapeRenderer> renderer = make_unique_dp<ShapeRenderer>();
|
||||
dp::Batcher batcher(dp::Batcher::IndexPerQuad, dp::Batcher::VertexPerQuad);
|
||||
|
|
|
@ -8,14 +8,11 @@ namespace gui
|
|||
class Compass : public Shape
|
||||
{
|
||||
public:
|
||||
Compass(gui::Position const & position, dp::TOverlayHandler const & tapHandler)
|
||||
Compass(gui::Position const & position)
|
||||
: Shape(position)
|
||||
, m_tapHandler(tapHandler)
|
||||
{}
|
||||
drape_ptr<ShapeRenderer> Draw(ref_ptr<dp::TextureManager> tex) const override;
|
||||
|
||||
private:
|
||||
dp::TOverlayHandler m_tapHandler;
|
||||
drape_ptr<ShapeRenderer> Draw(ref_ptr<dp::TextureManager> tex) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -21,14 +21,32 @@ class CountryStatusButtonHandle : public ButtonHandle
|
|||
|
||||
public:
|
||||
CountryStatusButtonHandle(CountryStatusHelper::ECountryState const state,
|
||||
dp::Anchor anchor, m2::PointF const & size,
|
||||
dp::TextureManager::ColorRegion const & normalColor,
|
||||
dp::TextureManager::ColorRegion const & pressedColor,
|
||||
dp::TOverlayHandler const & tapHandler)
|
||||
: TBase(anchor, size, normalColor, pressedColor, tapHandler)
|
||||
, m_state(state)
|
||||
CountryStatusHelper::EButtonType const buttonType,
|
||||
dp::Anchor anchor, m2::PointF const & size)
|
||||
: TBase(anchor, size)
|
||||
, m_state(state)
|
||||
, m_buttonType(buttonType)
|
||||
{}
|
||||
|
||||
void OnTap() override
|
||||
{
|
||||
//TODO(@kuznetsov) implement
|
||||
switch(m_buttonType)
|
||||
{
|
||||
case CountryStatusHelper::BUTTON_TYPE_MAP:
|
||||
break;
|
||||
|
||||
case CountryStatusHelper::BUTTON_TYPE_MAP_ROUTING:
|
||||
break;
|
||||
|
||||
case CountryStatusHelper::BUTTON_TRY_AGAIN:
|
||||
break;
|
||||
|
||||
default:
|
||||
ASSERT(false, ());
|
||||
}
|
||||
}
|
||||
|
||||
void Update(ScreenBase const & screen) override
|
||||
{
|
||||
SetIsVisible(DrapeGui::GetCountryStatusHelper().IsVisibleForState(m_state));
|
||||
|
@ -37,6 +55,7 @@ public:
|
|||
|
||||
private:
|
||||
CountryStatusHelper::ECountryState m_state;
|
||||
CountryStatusHelper::EButtonType m_buttonType;
|
||||
};
|
||||
|
||||
class CountryStatusLabelHandle : public Handle
|
||||
|
@ -46,8 +65,8 @@ class CountryStatusLabelHandle : public Handle
|
|||
public:
|
||||
CountryStatusLabelHandle(CountryStatusHelper::ECountryState const state,
|
||||
dp::Anchor anchor, m2::PointF const & size)
|
||||
: TBase(anchor, m2::PointF::Zero(), size)
|
||||
, m_state(state)
|
||||
: TBase(anchor, m2::PointF::Zero(), size)
|
||||
, m_state(state)
|
||||
{}
|
||||
|
||||
void Update(ScreenBase const & screen) override
|
||||
|
@ -84,13 +103,10 @@ private:
|
|||
};
|
||||
|
||||
drape_ptr<dp::OverlayHandle> CreateButtonHandle(CountryStatusHelper::ECountryState const state,
|
||||
dp::Anchor anchor,
|
||||
m2::PointF const & size,
|
||||
dp::TextureManager::ColorRegion const & normalColor,
|
||||
dp::TextureManager::ColorRegion const & pressedColor,
|
||||
dp::TOverlayHandler const & tapHandler)
|
||||
CountryStatusHelper::EButtonType const buttonType,
|
||||
dp::Anchor anchor, m2::PointF const & size)
|
||||
{
|
||||
return make_unique_dp<CountryStatusButtonHandle>(state, anchor, size, normalColor, pressedColor, tapHandler);
|
||||
return make_unique_dp<CountryStatusButtonHandle>(state, buttonType, anchor, size);
|
||||
}
|
||||
|
||||
drape_ptr<dp::OverlayHandle> CreateLabelHandle(CountryStatusHelper::ECountryState const state,
|
||||
|
@ -162,34 +178,8 @@ drape_ptr<ShapeRenderer> CountryStatus::Draw(ref_ptr<dp::TextureManager> tex) co
|
|||
case CountryStatusHelper::CONTROL_TYPE_BUTTON:
|
||||
{
|
||||
CountryStatusHelper::EButtonType buttonType = control.m_buttonType;
|
||||
auto buttonHandleCreator = [this, buttonType, state](dp::Anchor anchor, m2::PointF const & size,
|
||||
dp::TextureManager::ColorRegion const & normalColor,
|
||||
dp::TextureManager::ColorRegion const & pressedColor)
|
||||
-> drape_ptr<dp::OverlayHandle>
|
||||
{
|
||||
switch(buttonType)
|
||||
{
|
||||
case CountryStatusHelper::BUTTON_TYPE_MAP:
|
||||
return CreateButtonHandle(state, anchor, size,
|
||||
normalColor, pressedColor,
|
||||
m_downloadMapHandler);
|
||||
|
||||
case CountryStatusHelper::BUTTON_TYPE_MAP_ROUTING:
|
||||
return CreateButtonHandle(state, anchor, size,
|
||||
normalColor, pressedColor,
|
||||
m_downloadMapRoutingHandler);
|
||||
|
||||
case CountryStatusHelper::BUTTON_TRY_AGAIN:
|
||||
return CreateButtonHandle(state, anchor, size,
|
||||
normalColor, pressedColor,
|
||||
m_tryAgainHandler);
|
||||
default:
|
||||
ASSERT(false, ());
|
||||
}
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
auto labelHandleCreator = bind(&CreateLabelHandle, state, _1, _2);
|
||||
Button::THandleCreator buttonHandleCreator = bind(&CreateButtonHandle, state, buttonType, _1, _2);
|
||||
Button::THandleCreator labelHandleCreator = bind(&CreateLabelHandle, state, _1, _2);
|
||||
|
||||
ShapeControl shapeControl;
|
||||
Button::Params params;
|
||||
|
|
|
@ -7,22 +7,11 @@ namespace gui
|
|||
class CountryStatus : public Shape
|
||||
{
|
||||
public:
|
||||
CountryStatus(Position const & position,
|
||||
dp::TOverlayHandler const & downloadMapHandler,
|
||||
dp::TOverlayHandler const & downloadMapRoutingHandler,
|
||||
dp::TOverlayHandler const & tryAgainHandler)
|
||||
CountryStatus(Position const & position)
|
||||
: Shape(position)
|
||||
, m_downloadMapHandler(downloadMapHandler)
|
||||
, m_downloadMapRoutingHandler(downloadMapRoutingHandler)
|
||||
, m_tryAgainHandler(tryAgainHandler)
|
||||
{}
|
||||
|
||||
drape_ptr<ShapeRenderer> Draw(ref_ptr<dp::TextureManager> tex) const override;
|
||||
|
||||
private:
|
||||
dp::TOverlayHandler m_downloadMapHandler;
|
||||
dp::TOverlayHandler m_downloadMapRoutingHandler;
|
||||
dp::TOverlayHandler m_tryAgainHandler;
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
|
|
|
@ -64,15 +64,14 @@ void LayerCacher::Resize(int w, int h)
|
|||
}
|
||||
|
||||
drape_ptr<LayerRenderer> LayerCacher::Recache(Skin::ElementName names,
|
||||
ref_ptr<dp::TextureManager> textures,
|
||||
Handlers const & handlers)
|
||||
ref_ptr<dp::TextureManager> textures)
|
||||
{
|
||||
drape_ptr<LayerRenderer> renderer = make_unique_dp<LayerRenderer>();
|
||||
|
||||
if (names & Skin::Compass)
|
||||
{
|
||||
renderer->AddShapeRenderer(Skin::Compass,
|
||||
Compass(GetPos(Skin::Compass), handlers.m_onCompassTapped).Draw(textures));
|
||||
Compass(GetPos(Skin::Compass)).Draw(textures));
|
||||
}
|
||||
|
||||
if (names & Skin::Ruler)
|
||||
|
@ -84,10 +83,7 @@ drape_ptr<LayerRenderer> LayerCacher::Recache(Skin::ElementName names,
|
|||
if (names & Skin::CountryStatus)
|
||||
{
|
||||
renderer->AddShapeRenderer(Skin::CountryStatus,
|
||||
CountryStatus(GetPos(Skin::CountryStatus),
|
||||
handlers.m_onDownloadMapTapped,
|
||||
handlers.m_onDownloadMapRoutingTapped,
|
||||
handlers.m_onTryAgainTapped).Draw(textures));
|
||||
CountryStatus(GetPos(Skin::CountryStatus)).Draw(textures));
|
||||
}
|
||||
|
||||
if (DrapeGui::Instance().IsCopyrightActive() && (names & Skin::Copyright))
|
||||
|
@ -123,14 +119,6 @@ Position LayerCacher::GetPos(Skin::ElementName name)
|
|||
return m_skin->ResolvePosition(name);
|
||||
}
|
||||
|
||||
void Handlers::Reset()
|
||||
{
|
||||
m_onCompassTapped = nullptr;
|
||||
m_onDownloadMapTapped = nullptr;
|
||||
m_onDownloadMapRoutingTapped = nullptr;
|
||||
m_onTryAgainTapped = nullptr;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LayerRenderer::~LayerRenderer()
|
||||
|
@ -165,18 +153,6 @@ void LayerRenderer::Merge(ref_ptr<LayerRenderer> other)
|
|||
other->m_renderers.clear();
|
||||
}
|
||||
|
||||
ref_ptr<dp::OverlayHandle> LayerRenderer::ProcessTapEvent(m2::PointD const & pt)
|
||||
{
|
||||
for (TRenderers::value_type & r : m_renderers)
|
||||
{
|
||||
ref_ptr<dp::OverlayHandle> handle = r.second->ProcessTapEvent(pt);
|
||||
if (handle != nullptr)
|
||||
return handle;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void LayerRenderer::DestroyRenderers()
|
||||
{
|
||||
m_renderers.clear();
|
||||
|
@ -190,4 +166,41 @@ void LayerRenderer::AddShapeRenderer(Skin::ElementName name, drape_ptr<ShapeRend
|
|||
VERIFY(m_renderers.insert(make_pair(name, move(shape))).second, ());
|
||||
}
|
||||
|
||||
bool LayerRenderer::OnTouchDown(m2::PointD const & pt)
|
||||
{
|
||||
for (TRenderers::value_type & r : m_renderers)
|
||||
{
|
||||
m_activeOverlay = r.second->ProcessTapEvent(pt);
|
||||
if (m_activeOverlay != nullptr)
|
||||
{
|
||||
m_activeOverlay->OnTapBegin();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void LayerRenderer::OnTouchUp(m2::PointD const & pt)
|
||||
{
|
||||
if (m_activeOverlay != nullptr)
|
||||
{
|
||||
if (m_activeOverlay->IsTapped(pt))
|
||||
m_activeOverlay->OnTap();
|
||||
|
||||
m_activeOverlay->OnTapEnd();
|
||||
m_activeOverlay = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void LayerRenderer::OnTouchCancel(m2::PointD const & pt)
|
||||
{
|
||||
UNUSED_VALUE(pt);
|
||||
if (m_activeOverlay != nullptr)
|
||||
{
|
||||
m_activeOverlay->OnTapEnd();
|
||||
m_activeOverlay = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include "shape.hpp"
|
||||
|
||||
#include "drape/gpu_program_manager.hpp"
|
||||
#include "drape/overlay_handle.hpp"
|
||||
#include "drape/texture_manager.hpp"
|
||||
|
||||
#include "geometry/screenbase.hpp"
|
||||
|
@ -31,7 +30,9 @@ public:
|
|||
void Render(ref_ptr<dp::GpuProgramManager> mng, ScreenBase const & screen);
|
||||
void Merge(ref_ptr<LayerRenderer> other);
|
||||
|
||||
ref_ptr<dp::OverlayHandle> ProcessTapEvent(m2::PointD const & pt);
|
||||
bool OnTouchDown(m2::PointD const & pt);
|
||||
void OnTouchUp(m2::PointD const & pt);
|
||||
void OnTouchCancel(m2::PointD const & pt);
|
||||
|
||||
private:
|
||||
void DestroyRenderers();
|
||||
|
@ -42,16 +43,8 @@ private:
|
|||
private:
|
||||
typedef map<Skin::ElementName, drape_ptr<ShapeRenderer> > TRenderers;
|
||||
TRenderers m_renderers;
|
||||
};
|
||||
|
||||
struct Handlers
|
||||
{
|
||||
dp::TOverlayHandler m_onCompassTapped;
|
||||
dp::TOverlayHandler m_onDownloadMapTapped;
|
||||
dp::TOverlayHandler m_onDownloadMapRoutingTapped;
|
||||
dp::TOverlayHandler m_onTryAgainTapped;
|
||||
|
||||
void Reset();
|
||||
ref_ptr<gui::Handle> m_activeOverlay;
|
||||
};
|
||||
|
||||
class LayerCacher
|
||||
|
@ -61,7 +54,7 @@ public:
|
|||
|
||||
void Resize(int w, int h);
|
||||
/// @param names - can be combinations of single flags, or equal AllElements
|
||||
drape_ptr<LayerRenderer> Recache(Skin::ElementName names, ref_ptr<dp::TextureManager> textures, Handlers const & handlers);
|
||||
drape_ptr<LayerRenderer> Recache(Skin::ElementName names, ref_ptr<dp::TextureManager> textures);
|
||||
|
||||
private:
|
||||
Position GetPos(Skin::ElementName name);
|
||||
|
|
|
@ -56,12 +56,6 @@ bool TappableHandle::IsTapped(m2::PointD const & pt) const
|
|||
return false;
|
||||
}
|
||||
|
||||
void TappableHandle::OnTap()
|
||||
{
|
||||
if (m_tapHandler != nullptr)
|
||||
m_tapHandler();
|
||||
}
|
||||
|
||||
ShapeRenderer::~ShapeRenderer()
|
||||
{
|
||||
ForEachShapeInfo([](ShapeControl::ShapeInfo & info)
|
||||
|
@ -136,9 +130,9 @@ void ShapeRenderer::ForEachShapeInfo(ShapeRenderer::TShapeInfoEditFn const & fn)
|
|||
});
|
||||
}
|
||||
|
||||
ref_ptr<dp::OverlayHandle> ShapeRenderer::ProcessTapEvent(m2::PointD const & pt)
|
||||
ref_ptr<Handle> ShapeRenderer::ProcessTapEvent(m2::PointD const & pt)
|
||||
{
|
||||
ref_ptr<dp::OverlayHandle> resultHandle = nullptr;
|
||||
ref_ptr<Handle> resultHandle = nullptr;
|
||||
ForEachShapeInfo([&resultHandle, &pt](ShapeControl::ShapeInfo & shapeInfo)
|
||||
{
|
||||
if (shapeInfo.m_handle->IsTapped(pt))
|
||||
|
@ -148,9 +142,6 @@ ref_ptr<dp::OverlayHandle> ShapeRenderer::ProcessTapEvent(m2::PointD const & pt)
|
|||
}
|
||||
});
|
||||
|
||||
if (resultHandle != nullptr)
|
||||
resultHandle->OnTapBegin();
|
||||
|
||||
return resultHandle;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,11 @@ public:
|
|||
|
||||
void Update(ScreenBase const & screen) override;
|
||||
|
||||
virtual bool IsTapped(m2::PointD const & pt) const { return false; }
|
||||
virtual void OnTapBegin(){}
|
||||
virtual void OnTap(){}
|
||||
virtual void OnTapEnd(){}
|
||||
|
||||
virtual bool IndexesRequired() const override;
|
||||
virtual m2::RectD GetPixelRect(ScreenBase const & screen) const override;
|
||||
virtual void GetPixelShape(ScreenBase const & screen, Rects & rects) const override;
|
||||
|
@ -38,16 +43,11 @@ protected:
|
|||
class TappableHandle : public Handle
|
||||
{
|
||||
public:
|
||||
TappableHandle(dp::Anchor anchor, m2::PointF const & pivot, m2::PointF const & size, dp::TOverlayHandler const & tapHandler)
|
||||
TappableHandle(dp::Anchor anchor, m2::PointF const & pivot, m2::PointF const & size)
|
||||
: Handle(anchor, pivot, size)
|
||||
, m_tapHandler(tapHandler)
|
||||
{}
|
||||
|
||||
bool IsTapped(m2::PointD const & pt) const override;
|
||||
void OnTap() override;
|
||||
|
||||
private:
|
||||
dp::TOverlayHandler m_tapHandler;
|
||||
};
|
||||
|
||||
struct ShapeControl
|
||||
|
@ -89,7 +89,7 @@ public:
|
|||
void AddShape(dp::GLState const & state, drape_ptr<dp::RenderBucket> && bucket);
|
||||
void AddShapeControl(ShapeControl && control);
|
||||
|
||||
ref_ptr<dp::OverlayHandle> ProcessTapEvent(m2::PointD const & pt);
|
||||
ref_ptr<Handle> ProcessTapEvent(m2::PointD const & pt);
|
||||
|
||||
private:
|
||||
friend void ArrangeShapes(ref_ptr<ShapeRenderer>,
|
||||
|
|
|
@ -1291,31 +1291,12 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::OGLContextFactory> contextFactory,
|
|||
|
||||
TIsCountryLoadedFn isCountryLoadedFn = bind(&Framework::IsCountryLoaded, this, _1);
|
||||
|
||||
gui::Handlers guiHandlers;
|
||||
guiHandlers.m_onCompassTapped = [this]()
|
||||
{
|
||||
LOG(LINFO, ("Compass tapped!"));
|
||||
//m_informationDisplay.locationState()->OnCompassTaped();
|
||||
};
|
||||
guiHandlers.m_onDownloadMapTapped = [this]()
|
||||
{
|
||||
LOG(LINFO, ("Download map tapped!"));
|
||||
};
|
||||
guiHandlers.m_onDownloadMapRoutingTapped = [this]()
|
||||
{
|
||||
LOG(LINFO, ("Download map and routing tapped!"));
|
||||
};
|
||||
guiHandlers.m_onTryAgainTapped = [this]()
|
||||
{
|
||||
LOG(LINFO, ("Try again tapped!"));
|
||||
};
|
||||
|
||||
df::DrapeEngine::Params p(contextFactory,
|
||||
make_ref(&m_stringsBundle),
|
||||
make_ref(m_storageAccessor),
|
||||
df::Viewport(0, 0, w, h),
|
||||
df::MapDataProvider(idReadFn, featureReadFn, resolveCountry,isCountryLoadedFn),
|
||||
vs, guiHandlers);
|
||||
vs);
|
||||
|
||||
m_drapeEngine = make_unique_dp<df::DrapeEngine>(p);
|
||||
AddViewportListener([this](ScreenBase const & screen)
|
||||
|
|
Loading…
Add table
Reference in a new issue