forked from organicmaps/organicmaps
Exchanged point to rectangle in tap detection
This commit is contained in:
parent
02a0b5a7d1
commit
6cf89a7e35
5 changed files with 24 additions and 20 deletions
|
@ -452,17 +452,21 @@ void FrontendRenderer::TapDetected(m2::PointD const & pt, bool isLongTap)
|
|||
|
||||
bool FrontendRenderer::SingleTouchFiltration(m2::PointD const & pt, TouchEvent::ETouchType type)
|
||||
{
|
||||
float const rectHalfSize = 5;
|
||||
m2::RectD r(-rectHalfSize, -rectHalfSize, rectHalfSize, rectHalfSize);
|
||||
r.SetCenter(pt);
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case TouchEvent::ETouchType::TOUCH_DOWN:
|
||||
return m_guiRenderer->OnTouchDown(pt);
|
||||
return m_guiRenderer->OnTouchDown(r);
|
||||
|
||||
case TouchEvent::ETouchType::TOUCH_UP:
|
||||
m_guiRenderer->OnTouchUp(pt);
|
||||
m_guiRenderer->OnTouchUp(r);
|
||||
return false;
|
||||
|
||||
case TouchEvent::ETouchType::TOUCH_CANCEL:
|
||||
m_guiRenderer->OnTouchCancel(pt);
|
||||
m_guiRenderer->OnTouchCancel(r);
|
||||
return false;
|
||||
|
||||
case TouchEvent::ETouchType::TOUCH_MOVE:
|
||||
|
|
|
@ -180,11 +180,11 @@ 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)
|
||||
bool LayerRenderer::OnTouchDown(m2::RectD const & touchArea)
|
||||
{
|
||||
for (TRenderers::value_type & r : m_renderers)
|
||||
{
|
||||
m_activeOverlay = r.second->ProcessTapEvent(pt);
|
||||
m_activeOverlay = r.second->ProcessTapEvent(touchArea);
|
||||
if (m_activeOverlay != nullptr)
|
||||
{
|
||||
m_activeOverlay->OnTapBegin();
|
||||
|
@ -195,11 +195,11 @@ bool LayerRenderer::OnTouchDown(m2::PointD const & pt)
|
|||
return false;
|
||||
}
|
||||
|
||||
void LayerRenderer::OnTouchUp(m2::PointD const & pt)
|
||||
void LayerRenderer::OnTouchUp(m2::RectD const & touchArea)
|
||||
{
|
||||
if (m_activeOverlay != nullptr)
|
||||
{
|
||||
if (m_activeOverlay->IsTapped(pt))
|
||||
if (m_activeOverlay->IsTapped(touchArea))
|
||||
m_activeOverlay->OnTap();
|
||||
|
||||
m_activeOverlay->OnTapEnd();
|
||||
|
@ -207,9 +207,9 @@ void LayerRenderer::OnTouchUp(m2::PointD const & pt)
|
|||
}
|
||||
}
|
||||
|
||||
void LayerRenderer::OnTouchCancel(m2::PointD const & pt)
|
||||
void LayerRenderer::OnTouchCancel(m2::RectD const & touchArea)
|
||||
{
|
||||
UNUSED_VALUE(pt);
|
||||
UNUSED_VALUE(touchArea);
|
||||
if (m_activeOverlay != nullptr)
|
||||
{
|
||||
m_activeOverlay->OnTapEnd();
|
||||
|
|
|
@ -30,9 +30,9 @@ public:
|
|||
void Render(ref_ptr<dp::GpuProgramManager> mng, ScreenBase const & screen);
|
||||
void Merge(ref_ptr<LayerRenderer> other);
|
||||
|
||||
bool OnTouchDown(m2::PointD const & pt);
|
||||
void OnTouchUp(m2::PointD const & pt);
|
||||
void OnTouchCancel(m2::PointD const & pt);
|
||||
bool OnTouchDown(m2::RectD const & touchArea);
|
||||
void OnTouchUp(m2::RectD const & touchArea);
|
||||
void OnTouchCancel(m2::RectD const & touchArea);
|
||||
|
||||
private:
|
||||
void DestroyRenderers();
|
||||
|
|
|
@ -37,7 +37,7 @@ void Handle::GetPixelShape(const ScreenBase & screen, dp::OverlayHandle::Rects &
|
|||
UNUSED_VALUE(rects);
|
||||
}
|
||||
|
||||
bool TappableHandle::IsTapped(m2::PointD const & pt) const
|
||||
bool TappableHandle::IsTapped(m2::RectD const & touchArea) const
|
||||
{
|
||||
if (!IsVisible() || !IsValid())
|
||||
return false;
|
||||
|
@ -46,7 +46,7 @@ bool TappableHandle::IsTapped(m2::PointD const & pt) const
|
|||
{
|
||||
m2::RectD rect(m_pivot.x - m_size.x * 0.5, m_pivot.y - m_size.y * 0.5,
|
||||
m_pivot.x + m_size.x * 0.5, m_pivot.y + m_size.y * 0.5);
|
||||
return rect.IsPointInside(pt);
|
||||
return rect.Intersect(touchArea);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -131,12 +131,12 @@ void ShapeRenderer::ForEachShapeInfo(ShapeRenderer::TShapeInfoEditFn const & fn)
|
|||
});
|
||||
}
|
||||
|
||||
ref_ptr<Handle> ShapeRenderer::ProcessTapEvent(m2::PointD const & pt)
|
||||
ref_ptr<Handle> ShapeRenderer::ProcessTapEvent(m2::RectD const & touchArea)
|
||||
{
|
||||
ref_ptr<Handle> resultHandle = nullptr;
|
||||
ForEachShapeInfo([&resultHandle, &pt](ShapeControl::ShapeInfo & shapeInfo)
|
||||
ForEachShapeInfo([&resultHandle, &touchArea](ShapeControl::ShapeInfo & shapeInfo)
|
||||
{
|
||||
if (shapeInfo.m_handle->IsTapped(pt))
|
||||
if (shapeInfo.m_handle->IsTapped(touchArea))
|
||||
{
|
||||
ASSERT(resultHandle == nullptr, ("Overlays cannot be intersected"));
|
||||
resultHandle = make_ref(shapeInfo.m_handle);
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
|
||||
void Update(ScreenBase const & screen) override;
|
||||
|
||||
virtual bool IsTapped(m2::PointD const & pt) const { return false; }
|
||||
virtual bool IsTapped(m2::RectD const & touchArea) const { return false; }
|
||||
virtual void OnTapBegin(){}
|
||||
virtual void OnTap(){}
|
||||
virtual void OnTapEnd(){}
|
||||
|
@ -47,7 +47,7 @@ public:
|
|||
: Handle(anchor, pivot, size)
|
||||
{}
|
||||
|
||||
bool IsTapped(m2::PointD const & pt) const override;
|
||||
bool IsTapped(m2::RectD const & touchArea) const override;
|
||||
};
|
||||
|
||||
struct ShapeControl
|
||||
|
@ -89,7 +89,7 @@ public:
|
|||
void AddShape(dp::GLState const & state, drape_ptr<dp::RenderBucket> && bucket);
|
||||
void AddShapeControl(ShapeControl && control);
|
||||
|
||||
ref_ptr<Handle> ProcessTapEvent(m2::PointD const & pt);
|
||||
ref_ptr<Handle> ProcessTapEvent(m2::RectD const & touchArea);
|
||||
|
||||
private:
|
||||
friend void ArrangeShapes(ref_ptr<ShapeRenderer>,
|
||||
|
|
Loading…
Add table
Reference in a new issue