forked from organicmaps/organicmaps
[Tizen]
Scale on doubleclick. Rewrited navigation (move, rotate, etc). Now works more stable.
This commit is contained in:
parent
b06194d56c
commit
f0ec95b281
4 changed files with 142 additions and 64 deletions
|
@ -49,4 +49,7 @@ extern int const distanceWidth;
|
|||
// bookmark categories
|
||||
extern int const deleteWidth;
|
||||
|
||||
//timer
|
||||
extern int const double_click_timout;
|
||||
|
||||
}//consts
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "TouchProcessor.hpp"
|
||||
#include "MapsWithMeForm.hpp"
|
||||
#include "Framework.hpp"
|
||||
#include "Constants.hpp"
|
||||
|
||||
#include "../../../map/framework.hpp"
|
||||
#include "../../../gui/controller.hpp"
|
||||
|
@ -11,15 +12,15 @@
|
|||
using namespace Tizen::Ui;
|
||||
using Tizen::Ui::TouchEventManager;
|
||||
using namespace Tizen::Graphics;
|
||||
using namespace Tizen::Base::Runtime;
|
||||
using namespace consts;
|
||||
using Tizen::Base::Collection::IListT;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
typedef vector<pair<double, double> > TPointPairs;
|
||||
|
||||
TPointPairs GetTouchedPoints(Rectangle const & rect)
|
||||
TouchProcessor::TPointPairs GetTouchedPoints(Rectangle const & rect)
|
||||
{
|
||||
TPointPairs res;
|
||||
TouchProcessor::TPointPairs res;
|
||||
IListT<TouchEventInfo *> * pList = TouchEventManager::GetInstance()->GetTouchInfoListN();
|
||||
if (pList)
|
||||
{
|
||||
|
@ -41,32 +42,75 @@ TPointPairs GetTouchedPoints(Rectangle const & rect)
|
|||
|
||||
using namespace detail;
|
||||
|
||||
|
||||
TouchProcessor::TouchProcessor(MapsWithMeForm * pForm)
|
||||
:m_pForm(pForm)
|
||||
:m_state(st_empty),
|
||||
m_pForm(pForm)
|
||||
{
|
||||
|
||||
m_timer.Construct(*this);
|
||||
}
|
||||
|
||||
void TouchProcessor::StartMove(TPointPairs const & pts)
|
||||
{
|
||||
::Framework * pFramework = tizen::Framework::GetInstance();
|
||||
if (pts.size() == 1)
|
||||
{
|
||||
pFramework->StartDrag(DragEvent(m_startTouchPoint.first, m_startTouchPoint.second));
|
||||
pFramework->DoDrag(DragEvent(pts[0].first, pts[0].second));
|
||||
m_state = st_moving;
|
||||
}
|
||||
else if (pts.size() > 1)
|
||||
{
|
||||
pFramework->StartScale(ScaleEvent(pts[0].first, pts[0].second, pts[1].first, pts[1].second));
|
||||
m_state = st_rotating;
|
||||
}
|
||||
}
|
||||
|
||||
void TouchProcessor::OnTouchPressed(Tizen::Ui::Control const & source,
|
||||
Point const & currentPosition,
|
||||
Tizen::Ui::TouchEventInfo const & touchInfo)
|
||||
{
|
||||
|
||||
m_wasLongPress = false;
|
||||
TPointPairs pts = detail::GetTouchedPoints(m_pForm->GetClientAreaBounds());
|
||||
::Framework * pFramework = tizen::Framework::GetInstance();
|
||||
// pFramework->GetBalloonManager().OnShowMark(pFramework->GetUserMark(m2::PointD(pts[0].first, pts[0].second), false));
|
||||
m_bWasReleased = false;
|
||||
m_prev_pts = detail::GetTouchedPoints(m_pForm->GetClientAreaBounds());
|
||||
m_startTouchPoint = make_pair(m_prev_pts[0].first, m_prev_pts[0].second);
|
||||
|
||||
m_startTouchPoint = make_pair(pts[0].first, pts[0].second);
|
||||
if (!pFramework->GetGuiController()->OnTapStarted(m2::PointD(pts[0].first, pts[0].second)))
|
||||
if (m_state == st_waitTimer) // double click
|
||||
{
|
||||
if (pts.size() == 1)
|
||||
pFramework->StartDrag(DragEvent(pts[0].first, pts[0].second));
|
||||
else if (pts.size() > 1)
|
||||
pFramework->StartScale(ScaleEvent(pts[0].first, pts[0].second, pts[1].first, pts[1].second));
|
||||
m_state = st_empty;
|
||||
::Framework * pFramework = tizen::Framework::GetInstance();
|
||||
pFramework->ScaleToPoint(ScaleToPointEvent(m_prev_pts[0].first, m_prev_pts[0].second, 2.0));
|
||||
m_timer.Cancel();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_state = st_waitTimer;
|
||||
m_timer.Start(double_click_timout);
|
||||
}
|
||||
}
|
||||
|
||||
std::swap(m_prev_pts, pts);
|
||||
void TouchProcessor::OnTimerExpired (Timer &timer)
|
||||
{
|
||||
if (m_state != st_waitTimer)
|
||||
LOG(LERROR, ("Undefined behavior, on timer"));
|
||||
|
||||
m_state = st_empty;
|
||||
if (m_prev_pts.empty())
|
||||
return;
|
||||
::Framework * pFramework = tizen::Framework::GetInstance();
|
||||
if (pFramework->GetGuiController()->OnTapStarted(m2::PointD(m_startTouchPoint.first, m_startTouchPoint.second)))
|
||||
{
|
||||
pFramework->GetGuiController()->OnTapEnded(m2::PointD(m_startTouchPoint.first, m_startTouchPoint.second));
|
||||
}
|
||||
else if (m_bWasReleased)
|
||||
{
|
||||
pFramework->GetBalloonManager().OnShowMark(pFramework->GetUserMark(m2::PointD(m_startTouchPoint.first, m_startTouchPoint.second), false));
|
||||
m_bWasReleased = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
StartMove(m_prev_pts);
|
||||
}
|
||||
}
|
||||
|
||||
void TouchProcessor::OnTouchLongPressed(Tizen::Ui::Control const & source,
|
||||
|
@ -82,42 +126,58 @@ void TouchProcessor::OnTouchLongPressed(Tizen::Ui::Control const & source,
|
|||
}
|
||||
}
|
||||
|
||||
void TouchProcessor::OnTouchDoublePressed(Tizen::Ui::Control const & source,
|
||||
Tizen::Graphics::Point const & currentPosition,
|
||||
Tizen::Ui::TouchEventInfo const & touchInfo)
|
||||
{
|
||||
::Framework * pFramework = tizen::Framework::GetInstance();
|
||||
pFramework->ScaleDefault(true);
|
||||
|
||||
}
|
||||
|
||||
void TouchProcessor::OnTouchMoved(Tizen::Ui::Control const & source,
|
||||
Point const & currentPosition,
|
||||
Tizen::Ui::TouchEventInfo const & touchInfo)
|
||||
{
|
||||
TPointPairs pts = detail::GetTouchedPoints(m_pForm->GetClientAreaBounds());
|
||||
::Framework * pFramework = tizen::Framework::GetInstance();
|
||||
|
||||
if (!pFramework->GetGuiController()->OnTapMoved(m2::PointD(pts[0].first, pts[0].second)))
|
||||
if (m_state == st_empty)
|
||||
{
|
||||
if (pts.size() == 1 && m_prev_pts.size() > 1)
|
||||
LOG(LERROR, ("Undefined behavior, OnTouchMoved"));
|
||||
return;
|
||||
}
|
||||
|
||||
TPointPairs pts = detail::GetTouchedPoints(m_pForm->GetClientAreaBounds());
|
||||
if (pts.empty())
|
||||
return;
|
||||
|
||||
::Framework * pFramework = tizen::Framework::GetInstance();
|
||||
if (m_state == st_waitTimer)
|
||||
{
|
||||
double dist = sqrt(pow(pts[0].first - m_startTouchPoint.first, 2) + pow(pts[0].second - m_startTouchPoint.second, 2));
|
||||
if (dist > 20)
|
||||
{
|
||||
pFramework->StopScale(ScaleEvent(pts[0].first, pts[0].second, pts[1].first, pts[1].second));
|
||||
m_timer.Cancel();
|
||||
StartMove(pts);
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
if (pts.size() == 1)
|
||||
{
|
||||
if (m_state == st_rotating)
|
||||
{
|
||||
pFramework->StopScale(ScaleEvent(m_prev_pts[0].first, m_prev_pts[0].second, m_prev_pts[1].first, m_prev_pts[1].second));
|
||||
pFramework->StartDrag(DragEvent(pts[0].first, pts[0].second));
|
||||
}
|
||||
else if (pts.size() == 1)
|
||||
else if (m_state == st_moving)
|
||||
{
|
||||
pFramework->DoDrag(DragEvent(pts[0].first, pts[0].second));
|
||||
}
|
||||
else if (pts.size() > 1 && m_prev_pts.size() == 1)
|
||||
m_state = st_moving;
|
||||
}
|
||||
else if (pts.size() > 1)
|
||||
{
|
||||
if (m_state == st_rotating)
|
||||
{
|
||||
pFramework->DoScale(ScaleEvent(pts[0].first, pts[0].second, pts[1].first, pts[1].second));
|
||||
}
|
||||
else if (m_state == st_moving)
|
||||
{
|
||||
pFramework->StopDrag(DragEvent(m_prev_pts[0].first, m_prev_pts[0].second));
|
||||
pFramework->StartScale(ScaleEvent(pts[0].first, pts[0].second, pts[1].first, pts[1].second));
|
||||
}
|
||||
else if (pts.size() > 1)
|
||||
{
|
||||
pFramework->DoScale(ScaleEvent(pts[0].first, pts[0].second, pts[1].first, pts[1].second));
|
||||
}
|
||||
m_state = st_rotating;
|
||||
}
|
||||
std::swap(m_prev_pts, pts);
|
||||
}
|
||||
|
@ -126,27 +186,26 @@ void TouchProcessor::OnTouchReleased(Tizen::Ui::Control const & source,
|
|||
Point const & currentPosition,
|
||||
Tizen::Ui::TouchEventInfo const & touchInfo)
|
||||
{
|
||||
TPointPairs pts = detail::GetTouchedPoints(m_pForm->GetClientAreaBounds());
|
||||
::Framework * pFramework = tizen::Framework::GetInstance();
|
||||
|
||||
|
||||
//using prev_pts because pts contains not all points
|
||||
if (!m_prev_pts.empty())
|
||||
if (m_state == st_empty)
|
||||
{
|
||||
pair<double, double> cur = make_pair(m_prev_pts[0].first, m_prev_pts[0].second);
|
||||
double dist = sqrt(pow(cur.first - m_startTouchPoint.first, 2) + pow(cur.second - m_startTouchPoint.second, 2));
|
||||
if (dist < 20 && !m_wasLongPress)
|
||||
{
|
||||
::Framework * pFramework = tizen::Framework::GetInstance();
|
||||
pFramework->GetBalloonManager().OnShowMark(pFramework->GetUserMark(m2::PointD(m_startTouchPoint.first, m_startTouchPoint.second), false));
|
||||
}
|
||||
if (!pFramework->GetGuiController()->OnTapEnded(m2::PointD(m_prev_pts[0].first, m_prev_pts[0].second)))
|
||||
{
|
||||
if (m_prev_pts.size() == 1)
|
||||
pFramework->StopDrag(DragEvent(m_prev_pts[0].first, m_prev_pts[0].second));
|
||||
else if (m_prev_pts.size() > 1)
|
||||
pFramework->StopScale(ScaleEvent(m_prev_pts[0].first, m_prev_pts[0].second, m_prev_pts[1].first, m_prev_pts[1].second));
|
||||
}
|
||||
m_prev_pts.clear();
|
||||
LOG(LERROR, ("Undefined behavior"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_state == st_waitTimer)
|
||||
{
|
||||
m_bWasReleased = true;
|
||||
return;
|
||||
}
|
||||
|
||||
::Framework * pFramework = tizen::Framework::GetInstance();
|
||||
if (m_state == st_moving)
|
||||
{
|
||||
pFramework->StopDrag(DragEvent(m_prev_pts[0].first, m_prev_pts[0].second));
|
||||
}
|
||||
else if (m_state == st_rotating)
|
||||
{
|
||||
pFramework->StopScale(ScaleEvent(m_prev_pts[0].first, m_prev_pts[0].second, m_prev_pts[1].first, m_prev_pts[1].second));
|
||||
}
|
||||
m_state = st_empty;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <FUiITouchEventListener.h>
|
||||
|
||||
#include "../../../std/utility.hpp"
|
||||
#include "../../../std/vector.hpp"
|
||||
|
||||
class MapsWithMeForm;
|
||||
|
||||
class TouchProcessor: public Tizen::Ui::ITouchEventListener
|
||||
, public Tizen::Base::Runtime::ITimerEventListener
|
||||
{
|
||||
public:
|
||||
TouchProcessor(MapsWithMeForm * pForm);
|
||||
|
@ -29,14 +31,26 @@ public:
|
|||
virtual void OnTouchLongPressed(Tizen::Ui::Control const & source,
|
||||
Tizen::Graphics::Point const & currentPosition,
|
||||
Tizen::Ui::TouchEventInfo const & touchInfo);
|
||||
virtual void OnTouchDoublePressed(Tizen::Ui::Control const & source,
|
||||
Tizen::Graphics::Point const & currentPosition,
|
||||
Tizen::Ui::TouchEventInfo const & touchInfo);
|
||||
// ITimerEventListener
|
||||
virtual void OnTimerExpired (Tizen::Base::Runtime::Timer & timer);
|
||||
|
||||
typedef vector<pair<double, double> > TPointPairs;
|
||||
private:
|
||||
|
||||
MapsWithMeForm * m_pForm;
|
||||
void StartMove(TPointPairs const & pts);
|
||||
enum EState
|
||||
{
|
||||
st_waitTimer,
|
||||
st_moving,
|
||||
st_rotating,
|
||||
st_empty
|
||||
};
|
||||
|
||||
EState m_state;
|
||||
MapsWithMeForm * m_pForm;
|
||||
bool m_wasLongPress;
|
||||
bool m_bWasReleased;
|
||||
pair<double, double> m_startTouchPoint;
|
||||
vector<pair<double, double> > m_prev_pts;
|
||||
Tizen::Base::Runtime::Timer m_timer;
|
||||
};
|
||||
|
|
|
@ -46,4 +46,6 @@ const char * BM_COLOR_PINK = "placemark-pink";
|
|||
int const distanceWidth = 200;
|
||||
// bookmark categories
|
||||
int const deleteWidth = 200;
|
||||
|
||||
int const double_click_timout = 200;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue