forked from organicmaps/organicmaps
Added binding actions on taps
This commit is contained in:
parent
6eed77d416
commit
2f8f23e903
10 changed files with 85 additions and 39 deletions
|
@ -26,13 +26,15 @@ namespace
|
|||
class CompassHandle : public TappableHandle
|
||||
{
|
||||
public:
|
||||
CompassHandle(m2::PointF const & pivot, m2::PointF const & size)
|
||||
CompassHandle(m2::PointF const & pivot, m2::PointF const & size, Compass::TTapHandler const & tapHandler)
|
||||
: TappableHandle(dp::Center, pivot, size)
|
||||
, m_tapHandler(tapHandler)
|
||||
{}
|
||||
|
||||
void OnTap() override
|
||||
{
|
||||
//TODO(@kuznetsov) implement
|
||||
if (m_tapHandler != nullptr)
|
||||
m_tapHandler();
|
||||
}
|
||||
|
||||
void Update(ScreenBase const & screen) override
|
||||
|
@ -49,10 +51,13 @@ namespace
|
|||
m_uniforms.SetMatrix4x4Value("modelView", glsl::value_ptr(m));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Compass::TTapHandler m_tapHandler;
|
||||
};
|
||||
}
|
||||
|
||||
drape_ptr<ShapeRenderer> Compass::Draw(ref_ptr<dp::TextureManager> tex) const
|
||||
drape_ptr<ShapeRenderer> Compass::Draw(ref_ptr<dp::TextureManager> tex, TTapHandler const & tapHandler) const
|
||||
{
|
||||
dp::TextureManager::SymbolRegion region;
|
||||
tex->GetSymbolRegion("compass-image", region);
|
||||
|
@ -91,7 +96,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);
|
||||
drape_ptr<dp::OverlayHandle> handle = make_unique_dp<CompassHandle>(m_position.m_pixelPivot, compassSize, tapHandler);
|
||||
|
||||
drape_ptr<ShapeRenderer> renderer = make_unique_dp<ShapeRenderer>();
|
||||
dp::Batcher batcher(dp::Batcher::IndexPerQuad, dp::Batcher::VertexPerQuad);
|
||||
|
|
|
@ -12,7 +12,8 @@ public:
|
|||
: Shape(position)
|
||||
{}
|
||||
|
||||
drape_ptr<ShapeRenderer> Draw(ref_ptr<dp::TextureManager> tex) const override;
|
||||
using TTapHandler = function<void()>;
|
||||
drape_ptr<ShapeRenderer> Draw(ref_ptr<dp::TextureManager> tex, TTapHandler const & tapHandler) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ class CopyrightLabel : public Shape
|
|||
using TBase = Shape;
|
||||
public:
|
||||
CopyrightLabel(gui::Position const & position);
|
||||
drape_ptr<ShapeRenderer> Draw(ref_ptr<dp::TextureManager> tex) const override;
|
||||
drape_ptr<ShapeRenderer> Draw(ref_ptr<dp::TextureManager> tex) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "button.hpp"
|
||||
#include "country_status.hpp"
|
||||
#include "country_status_helper.hpp"
|
||||
#include "drape_gui.hpp"
|
||||
#include "gui_text.hpp"
|
||||
|
||||
|
@ -21,30 +20,17 @@ class CountryStatusButtonHandle : public ButtonHandle
|
|||
|
||||
public:
|
||||
CountryStatusButtonHandle(CountryStatusHelper::ECountryState const state,
|
||||
CountryStatusHelper::EButtonType const buttonType,
|
||||
CountryStatus::TTapHandler const & tapHandler,
|
||||
dp::Anchor anchor, m2::PointF const & size)
|
||||
: TBase(anchor, size)
|
||||
, m_state(state)
|
||||
, m_buttonType(buttonType)
|
||||
, m_tapHandler(tapHandler)
|
||||
{}
|
||||
|
||||
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, ());
|
||||
}
|
||||
if (m_tapHandler != nullptr)
|
||||
m_tapHandler();
|
||||
}
|
||||
|
||||
void Update(ScreenBase const & screen) override
|
||||
|
@ -55,7 +41,7 @@ public:
|
|||
|
||||
private:
|
||||
CountryStatusHelper::ECountryState m_state;
|
||||
CountryStatusHelper::EButtonType m_buttonType;
|
||||
CountryStatus::TTapHandler m_tapHandler;
|
||||
};
|
||||
|
||||
class CountryStatusLabelHandle : public Handle
|
||||
|
@ -103,10 +89,10 @@ private:
|
|||
};
|
||||
|
||||
drape_ptr<dp::OverlayHandle> CreateButtonHandle(CountryStatusHelper::ECountryState const state,
|
||||
CountryStatusHelper::EButtonType const buttonType,
|
||||
CountryStatus::TTapHandler const & tapHandler,
|
||||
dp::Anchor anchor, m2::PointF const & size)
|
||||
{
|
||||
return make_unique_dp<CountryStatusButtonHandle>(state, buttonType, anchor, size);
|
||||
return make_unique_dp<CountryStatusButtonHandle>(state, tapHandler, anchor, size);
|
||||
}
|
||||
|
||||
drape_ptr<dp::OverlayHandle> CreateLabelHandle(CountryStatusHelper::ECountryState const state,
|
||||
|
@ -158,7 +144,8 @@ void DrawProgressControl(dp::Anchor anchor, dp::Batcher::TFlushFn const & flushF
|
|||
|
||||
}
|
||||
|
||||
drape_ptr<ShapeRenderer> CountryStatus::Draw(ref_ptr<dp::TextureManager> tex) const
|
||||
drape_ptr<ShapeRenderer> CountryStatus::Draw(ref_ptr<dp::TextureManager> tex,
|
||||
TButtonHandlers const & buttonHandlers) const
|
||||
{
|
||||
CountryStatusHelper & helper = DrapeGui::GetCountryStatusHelper();
|
||||
if (helper.GetComponentCount() == 0)
|
||||
|
@ -177,8 +164,9 @@ drape_ptr<ShapeRenderer> CountryStatus::Draw(ref_ptr<dp::TextureManager> tex) co
|
|||
{
|
||||
case CountryStatusHelper::CONTROL_TYPE_BUTTON:
|
||||
{
|
||||
CountryStatusHelper::EButtonType buttonType = control.m_buttonType;
|
||||
Button::THandleCreator buttonHandleCreator = bind(&CreateButtonHandle, state, buttonType, _1, _2);
|
||||
TButtonHandlers::const_iterator buttonHandlerIt = buttonHandlers.find(control.m_buttonType);
|
||||
CountryStatus::TTapHandler buttonHandler = (buttonHandlerIt != buttonHandlers.end() ? buttonHandlerIt->second : nullptr);
|
||||
Button::THandleCreator buttonHandleCreator = bind(&CreateButtonHandle, state, buttonHandler, _1, _2);
|
||||
Button::THandleCreator labelHandleCreator = bind(&CreateLabelHandle, state, _1, _2);
|
||||
|
||||
ShapeControl shapeControl;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "shape.hpp"
|
||||
#include "country_status_helper.hpp"
|
||||
|
||||
namespace gui
|
||||
{
|
||||
|
@ -11,7 +12,11 @@ public:
|
|||
: Shape(position)
|
||||
{}
|
||||
|
||||
drape_ptr<ShapeRenderer> Draw(ref_ptr<dp::TextureManager> tex) const override;
|
||||
using TTapHandler = function<void()>;
|
||||
using TButtonHandlers = map<CountryStatusHelper::EButtonType, TTapHandler>;
|
||||
|
||||
drape_ptr<ShapeRenderer> Draw(ref_ptr<dp::TextureManager> tex,
|
||||
TButtonHandlers const & buttonHandlers) const;
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
|
|
|
@ -132,4 +132,28 @@ CountryStatusHelper & DrapeGui::GetCountryStatusHelperImpl()
|
|||
return m_impl->m_countryHelper;
|
||||
}
|
||||
|
||||
void DrapeGui::ConnectOnCompassTappedHandler(Compass::TTapHandler const & handler)
|
||||
{
|
||||
m_onCompassTappedHandler = handler;
|
||||
}
|
||||
|
||||
void DrapeGui::ConnectOnButtonPressedHandler(CountryStatusHelper::EButtonType buttonType,
|
||||
CountryStatus::TTapHandler const & handler)
|
||||
{
|
||||
m_buttonHandlers[buttonType] = handler;
|
||||
}
|
||||
|
||||
void DrapeGui::CallOnCompassTappedHandler()
|
||||
{
|
||||
if(m_onCompassTappedHandler != nullptr)
|
||||
m_onCompassTappedHandler();
|
||||
}
|
||||
|
||||
void DrapeGui::CallOnButtonPressedHandler(CountryStatusHelper::EButtonType buttonType)
|
||||
{
|
||||
auto it = m_buttonHandlers.find(buttonType);
|
||||
if (it != m_buttonHandlers.end() && it->second != nullptr)
|
||||
it->second();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "skin.hpp"
|
||||
#include "compass.hpp"
|
||||
#include "country_status.hpp"
|
||||
|
||||
#include "storage/index.hpp"
|
||||
#include "storage/storage_defines.hpp"
|
||||
|
@ -71,6 +73,12 @@ public:
|
|||
bool IsCopyrightActive() const { return m_isCopyrightActive; }
|
||||
void DeactivateCopyright() { m_isCopyrightActive = false; }
|
||||
|
||||
void ConnectOnCompassTappedHandler(Compass::TTapHandler const & handler);
|
||||
void ConnectOnButtonPressedHandler(CountryStatusHelper::EButtonType buttonType,
|
||||
CountryStatus::TTapHandler const & handler);
|
||||
void CallOnCompassTappedHandler();
|
||||
void CallOnButtonPressedHandler(CountryStatusHelper::EButtonType buttonType);
|
||||
|
||||
private:
|
||||
RulerHelper & GetRulerHelperImpl();
|
||||
CountryStatusHelper & GetCountryStatusHelperImpl();
|
||||
|
@ -79,6 +87,9 @@ private:
|
|||
struct Impl;
|
||||
unique_ptr<Impl> m_impl;
|
||||
bool m_isCopyrightActive = true;
|
||||
|
||||
Compass::TTapHandler m_onCompassTappedHandler;
|
||||
CountryStatus::TButtonHandlers m_buttonHandlers;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -70,8 +70,9 @@ drape_ptr<LayerRenderer> LayerCacher::Recache(Skin::ElementName names,
|
|||
|
||||
if (names & Skin::Compass)
|
||||
{
|
||||
renderer->AddShapeRenderer(Skin::Compass,
|
||||
Compass(GetPos(Skin::Compass)).Draw(textures));
|
||||
Compass compass = Compass(GetPos(Skin::Compass));
|
||||
renderer->AddShapeRenderer(Skin::Compass, compass.Draw(textures, bind(&DrapeGui::CallOnCompassTappedHandler,
|
||||
&DrapeGui::Instance())));
|
||||
}
|
||||
|
||||
if (names & Skin::Ruler)
|
||||
|
@ -82,8 +83,22 @@ drape_ptr<LayerRenderer> LayerCacher::Recache(Skin::ElementName names,
|
|||
|
||||
if (names & Skin::CountryStatus)
|
||||
{
|
||||
renderer->AddShapeRenderer(Skin::CountryStatus,
|
||||
CountryStatus(GetPos(Skin::CountryStatus)).Draw(textures));
|
||||
CountryStatus countryStatus = CountryStatus(GetPos(Skin::CountryStatus));
|
||||
|
||||
CountryStatus::TButtonHandlers handlers;
|
||||
handlers[CountryStatusHelper::BUTTON_TYPE_MAP] = bind(&DrapeGui::CallOnButtonPressedHandler,
|
||||
&DrapeGui::Instance(),
|
||||
CountryStatusHelper::BUTTON_TYPE_MAP);
|
||||
|
||||
handlers[CountryStatusHelper::BUTTON_TYPE_MAP_ROUTING] = bind(&DrapeGui::CallOnButtonPressedHandler,
|
||||
&DrapeGui::Instance(),
|
||||
CountryStatusHelper::BUTTON_TYPE_MAP_ROUTING);
|
||||
|
||||
handlers[CountryStatusHelper::BUTTON_TRY_AGAIN] = bind(&DrapeGui::CallOnButtonPressedHandler,
|
||||
&DrapeGui::Instance(),
|
||||
CountryStatusHelper::BUTTON_TRY_AGAIN);
|
||||
|
||||
renderer->AddShapeRenderer(Skin::CountryStatus, countryStatus.Draw(textures, handlers));
|
||||
}
|
||||
|
||||
if (DrapeGui::Instance().IsCopyrightActive() && (names & Skin::Copyright))
|
||||
|
|
|
@ -9,7 +9,7 @@ class Ruler : public Shape
|
|||
{
|
||||
public:
|
||||
Ruler(gui::Position const & position) : Shape(position) {}
|
||||
drape_ptr<ShapeRenderer> Draw(ref_ptr<dp::TextureManager> tex) const override;
|
||||
drape_ptr<ShapeRenderer> Draw(ref_ptr<dp::TextureManager> tex) const;
|
||||
|
||||
private:
|
||||
void DrawRuler(ShapeControl & control, ref_ptr<dp::TextureManager> tex) const;
|
||||
|
|
|
@ -110,9 +110,6 @@ class Shape
|
|||
{
|
||||
public:
|
||||
Shape(gui::Position const & position) : m_position(position) {}
|
||||
virtual ~Shape() {}
|
||||
|
||||
virtual drape_ptr<ShapeRenderer> Draw(ref_ptr<dp::TextureManager> tex) const = 0;
|
||||
|
||||
protected:
|
||||
gui::Position m_position;
|
||||
|
|
Loading…
Add table
Reference in a new issue