forked from organicmaps/organicmaps
UserEvent refactoring.
This commit is contained in:
parent
165814ca6b
commit
5543117f5b
9 changed files with 274 additions and 160 deletions
|
@ -258,25 +258,29 @@ void Framework::Touch(int action, Finger const & f1, Finger const & f2, uint8_t
|
|||
switch(eventType)
|
||||
{
|
||||
case MULTITOUCH_DOWN:
|
||||
event.m_type = df::TouchEvent::TOUCH_DOWN;
|
||||
event.SetTouchType(df::TouchEvent::TOUCH_DOWN);
|
||||
break;
|
||||
case MULTITOUCH_MOVE:
|
||||
event.m_type = df::TouchEvent::TOUCH_MOVE;
|
||||
event.SetTouchType(df::TouchEvent::TOUCH_MOVE);
|
||||
break;
|
||||
case MULTITOUCH_UP:
|
||||
event.m_type = df::TouchEvent::TOUCH_UP;
|
||||
event.SetTouchType(df::TouchEvent::TOUCH_UP);
|
||||
break;
|
||||
case MULTITOUCH_CANCEL:
|
||||
event.m_type = df::TouchEvent::TOUCH_CANCEL;
|
||||
event.SetTouchType(df::TouchEvent::TOUCH_CANCEL);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
event.m_touches[0].m_location = m2::PointD(f1.m_x, f1.m_y);
|
||||
event.m_touches[0].m_id = f1.m_id;
|
||||
event.m_touches[1].m_location = m2::PointD(f2.m_x, f2.m_y);
|
||||
event.m_touches[1].m_id = f2.m_id;
|
||||
df::Touch touch;
|
||||
touch.m_location = m2::PointD(f1.m_x, f1.m_y);
|
||||
touch.m_id = f1.m_id;
|
||||
event.SetFirstTouch(touch);
|
||||
|
||||
touch.m_location = m2::PointD(f2.m_x, f2.m_y);
|
||||
touch.m_id = f2.m_id;
|
||||
event.SetSecondTouch(touch);
|
||||
|
||||
event.SetFirstMaskedPointer(maskedPointer);
|
||||
m_work.TouchEvent(event);
|
||||
|
|
|
@ -107,27 +107,27 @@ void DrapeEngine::Invalidate()
|
|||
|
||||
void DrapeEngine::AddTouchEvent(TouchEvent const & event)
|
||||
{
|
||||
AddUserEvent(event);
|
||||
AddUserEvent(make_unique_dp<TouchEvent>(event));
|
||||
}
|
||||
|
||||
void DrapeEngine::Scale(double factor, m2::PointD const & pxPoint, bool isAnim)
|
||||
{
|
||||
AddUserEvent(ScaleEvent(factor, pxPoint, isAnim));
|
||||
AddUserEvent(make_unique_dp<ScaleEvent>(factor, pxPoint, isAnim));
|
||||
}
|
||||
|
||||
void DrapeEngine::SetModelViewCenter(m2::PointD const & centerPt, int zoom, bool isAnim)
|
||||
{
|
||||
AddUserEvent(SetCenterEvent(centerPt, zoom, isAnim));
|
||||
AddUserEvent(make_unique_dp<SetCenterEvent>(centerPt, zoom, isAnim));
|
||||
}
|
||||
|
||||
void DrapeEngine::SetModelViewRect(m2::RectD const & rect, bool applyRotation, int zoom, bool isAnim)
|
||||
{
|
||||
AddUserEvent(SetRectEvent(rect, applyRotation, zoom, isAnim));
|
||||
AddUserEvent(make_unique_dp<SetRectEvent>(rect, applyRotation, zoom, isAnim));
|
||||
}
|
||||
|
||||
void DrapeEngine::SetModelViewAnyRect(m2::AnyRectD const & rect, bool isAnim)
|
||||
{
|
||||
AddUserEvent(SetAnyRectEvent(rect, isAnim));
|
||||
AddUserEvent(make_unique_dp<SetAnyRectEvent>(rect, isAnim));
|
||||
}
|
||||
|
||||
void DrapeEngine::ClearUserMarksLayer(df::TileKey const & tileKey)
|
||||
|
@ -194,9 +194,9 @@ void DrapeEngine::RecacheGui(bool needResetOldGui)
|
|||
MessagePriority::High);
|
||||
}
|
||||
|
||||
void DrapeEngine::AddUserEvent(UserEvent const & e)
|
||||
void DrapeEngine::AddUserEvent(drape_ptr<UserEvent> && e)
|
||||
{
|
||||
m_frontend->AddUserEvent(e);
|
||||
m_frontend->AddUserEvent(move(e));
|
||||
}
|
||||
|
||||
void DrapeEngine::ModelViewChanged(ScreenBase const & screen)
|
||||
|
@ -228,7 +228,7 @@ void DrapeEngine::ResizeImpl(int w, int h)
|
|||
{
|
||||
gui::DrapeGui::Instance().SetSurfaceSize(m2::PointF(w, h));
|
||||
m_viewport.SetViewport(0, 0, w, h);
|
||||
AddUserEvent(ResizeEvent(w, h));
|
||||
AddUserEvent(make_unique_dp<ResizeEvent>(w, h));
|
||||
}
|
||||
|
||||
void DrapeEngine::SetCompassInfo(location::CompassInfo const & info)
|
||||
|
|
|
@ -157,7 +157,7 @@ public:
|
|||
TRequestSymbolsSizeCallback const & callback);
|
||||
|
||||
private:
|
||||
void AddUserEvent(UserEvent const & e);
|
||||
void AddUserEvent(drape_ptr<UserEvent> && e);
|
||||
void ModelViewChanged(ScreenBase const & screen);
|
||||
|
||||
void MyPositionModeChanged(location::EMyPositionMode mode, bool routingActive);
|
||||
|
|
|
@ -627,7 +627,7 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
|
|||
|
||||
case Message::EnablePerspective:
|
||||
{
|
||||
AddUserEvent(SetAutoPerspectiveEvent(true /* isAutoPerspective */));
|
||||
AddUserEvent(make_unique_dp<SetAutoPerspectiveEvent>(true /* isAutoPerspective */));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -640,7 +640,7 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
|
|||
if (m_enablePerspectiveInNavigation == msg->AllowPerspective() &&
|
||||
m_enablePerspectiveInNavigation != screen.isPerspective())
|
||||
{
|
||||
AddUserEvent(SetAutoPerspectiveEvent(m_enablePerspectiveInNavigation));
|
||||
AddUserEvent(make_unique_dp<SetAutoPerspectiveEvent>(m_enablePerspectiveInNavigation));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -657,7 +657,7 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
|
|||
m_myPositionController->EnablePerspectiveInRouting(m_enablePerspectiveInNavigation);
|
||||
if (m_myPositionController->IsInRouting())
|
||||
{
|
||||
AddUserEvent(SetAutoPerspectiveEvent(m_enablePerspectiveInNavigation));
|
||||
AddUserEvent(make_unique_dp<SetAutoPerspectiveEvent>(m_enablePerspectiveInNavigation));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -722,7 +722,7 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
|
|||
int zoom = kDoNotChangeZoom;
|
||||
if (m_currentZoomLevel < scales::GetAddNewPlaceScale())
|
||||
zoom = scales::GetAddNewPlaceScale();
|
||||
AddUserEvent(SetCenterEvent(pt, zoom, true));
|
||||
AddUserEvent(make_unique_dp<SetCenterEvent>(pt, zoom, true));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -759,7 +759,7 @@ void FrontendRenderer::FollowRoute(int preferredZoomLevel, int preferredZoomLeve
|
|||
enableAutoZoom);
|
||||
|
||||
if (m_enablePerspectiveInNavigation)
|
||||
AddUserEvent(SetAutoPerspectiveEvent(true /* isAutoPerspective */));
|
||||
AddUserEvent(make_unique_dp<SetAutoPerspectiveEvent>(true /* isAutoPerspective */));
|
||||
|
||||
m_overlayTree->SetFollowingMode(true);
|
||||
}
|
||||
|
@ -940,7 +940,7 @@ void FrontendRenderer::PullToBoundArea(bool randomPlace, bool applyZoom)
|
|||
int zoom = kDoNotChangeZoom;
|
||||
if (applyZoom && m_currentZoomLevel < scales::GetAddNewPlaceScale())
|
||||
zoom = scales::GetAddNewPlaceScale();
|
||||
AddUserEvent(SetCenterEvent(dest, zoom, true));
|
||||
AddUserEvent(make_unique_dp<SetCenterEvent>(dest, zoom, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1254,7 +1254,7 @@ void FrontendRenderer::RefreshBgColor()
|
|||
|
||||
void FrontendRenderer::DisablePerspective()
|
||||
{
|
||||
AddUserEvent(SetAutoPerspectiveEvent(false /* isAutoPerspective */));
|
||||
AddUserEvent(make_unique_dp<SetAutoPerspectiveEvent>(false /* isAutoPerspective */));
|
||||
}
|
||||
|
||||
void FrontendRenderer::CheckIsometryMinScale(ScreenBase const & screen)
|
||||
|
@ -1316,13 +1316,14 @@ void FrontendRenderer::OnForceTap(m2::PointD const & pt)
|
|||
|
||||
void FrontendRenderer::OnDoubleTap(m2::PointD const & pt)
|
||||
{
|
||||
m_userEventStream.AddEvent(ScaleEvent(2.0 /* scale factor */, pt, true /* animated */));
|
||||
m_userEventStream.AddEvent(make_unique_dp<ScaleEvent>(2.0 /* scale factor */, pt, true /* animated */));
|
||||
}
|
||||
|
||||
void FrontendRenderer::OnTwoFingersTap()
|
||||
{
|
||||
ScreenBase const & screen = m_userEventStream.GetCurrentScreen();
|
||||
m_userEventStream.AddEvent(ScaleEvent(0.5 /* scale factor */, screen.PixelRect().Center(), true /* animated */));
|
||||
m_userEventStream.AddEvent(make_unique_dp<ScaleEvent>(0.5 /* scale factor */, screen.PixelRect().Center(),
|
||||
true /* animated */));
|
||||
}
|
||||
|
||||
bool FrontendRenderer::OnSingleTouchFiltrate(m2::PointD const & pt, TouchEvent::ETouchType type)
|
||||
|
@ -1596,9 +1597,9 @@ void FrontendRenderer::ReleaseResources()
|
|||
m_contextFactory->getDrawContext()->doneCurrent();
|
||||
}
|
||||
|
||||
void FrontendRenderer::AddUserEvent(UserEvent const & event)
|
||||
void FrontendRenderer::AddUserEvent(drape_ptr<UserEvent> && event)
|
||||
{
|
||||
m_userEventStream.AddEvent(event);
|
||||
m_userEventStream.AddEvent(move(event));
|
||||
if (IsInInfinityWaiting())
|
||||
CancelMessageWaiting();
|
||||
}
|
||||
|
@ -1610,28 +1611,28 @@ void FrontendRenderer::PositionChanged(m2::PointD const & position)
|
|||
|
||||
void FrontendRenderer::ChangeModelView(m2::PointD const & center, int zoomLevel)
|
||||
{
|
||||
AddUserEvent(SetCenterEvent(center, zoomLevel, true));
|
||||
AddUserEvent(make_unique_dp<SetCenterEvent>(center, zoomLevel, true));
|
||||
}
|
||||
|
||||
void FrontendRenderer::ChangeModelView(double azimuth)
|
||||
{
|
||||
AddUserEvent(RotateEvent(azimuth));
|
||||
AddUserEvent(make_unique_dp<RotateEvent>(azimuth));
|
||||
}
|
||||
|
||||
void FrontendRenderer::ChangeModelView(m2::RectD const & rect)
|
||||
{
|
||||
AddUserEvent(SetRectEvent(rect, true, kDoNotChangeZoom, true));
|
||||
AddUserEvent(make_unique_dp<SetRectEvent>(rect, true, kDoNotChangeZoom, true));
|
||||
}
|
||||
|
||||
void FrontendRenderer::ChangeModelView(m2::PointD const & userPos, double azimuth,
|
||||
m2::PointD const & pxZero, int preferredZoomLevel)
|
||||
{
|
||||
AddUserEvent(FollowAndRotateEvent(userPos, pxZero, azimuth, preferredZoomLevel, true));
|
||||
AddUserEvent(make_unique_dp<FollowAndRotateEvent>(userPos, pxZero, azimuth, preferredZoomLevel, true));
|
||||
}
|
||||
|
||||
void FrontendRenderer::ChangeModelView(double autoScale, m2::PointD const & userPos, double azimuth, m2::PointD const & pxZero)
|
||||
{
|
||||
AddUserEvent(FollowAndRotateEvent(userPos, pxZero, azimuth, autoScale));
|
||||
AddUserEvent(make_unique_dp<FollowAndRotateEvent>(userPos, pxZero, azimuth, autoScale));
|
||||
}
|
||||
|
||||
ScreenBase const & FrontendRenderer::ProcessEvents(bool & modelViewChanged, bool & viewportChanged)
|
||||
|
|
|
@ -136,7 +136,7 @@ public:
|
|||
void AfterDrawFrame();
|
||||
#endif
|
||||
|
||||
void AddUserEvent(UserEvent const & event);
|
||||
void AddUserEvent(drape_ptr<UserEvent> && event);
|
||||
|
||||
/// MyPositionController::Listener
|
||||
void PositionChanged(m2::PointD const & position) override;
|
||||
|
|
|
@ -70,6 +70,16 @@ char const * UserEventStream::END_DOUBLE_TAP_AND_HOLD = "EndDoubleTapAndHold";
|
|||
|
||||
uint8_t const TouchEvent::INVALID_MASKED_POINTER = 0xFF;
|
||||
|
||||
void TouchEvent::SetFirstTouch(const Touch & touch)
|
||||
{
|
||||
m_touches[0] = touch;
|
||||
}
|
||||
|
||||
void TouchEvent::SetSecondTouch(const Touch & touch)
|
||||
{
|
||||
m_touches[1] = touch;
|
||||
}
|
||||
|
||||
void TouchEvent::PrepareTouches(array<Touch, 2> const & previousTouches)
|
||||
{
|
||||
if (GetValidTouchesCount(m_touches) == 2 && GetValidTouchesCount(previousTouches) > 0)
|
||||
|
@ -129,17 +139,16 @@ UserEventStream::UserEventStream()
|
|||
{
|
||||
}
|
||||
|
||||
void UserEventStream::AddEvent(UserEvent const & event)
|
||||
void UserEventStream::AddEvent(drape_ptr<UserEvent> && event)
|
||||
{
|
||||
lock_guard<mutex> guard(m_lock);
|
||||
UNUSED_VALUE(guard);
|
||||
m_events.push_back(event);
|
||||
m_events.emplace_back(move(event));
|
||||
}
|
||||
|
||||
ScreenBase const & UserEventStream::ProcessEvents(bool & modelViewChanged, bool & viewportChanged)
|
||||
{
|
||||
list<UserEvent> events;
|
||||
|
||||
TEventsList events;
|
||||
{
|
||||
lock_guard<mutex> guard(m_lock);
|
||||
UNUSED_VALUE(guard);
|
||||
|
@ -149,64 +158,89 @@ ScreenBase const & UserEventStream::ProcessEvents(bool & modelViewChanged, bool
|
|||
m2::RectD const prevPixelRect = GetCurrentScreen().PixelRect();
|
||||
|
||||
m_modelViewChanged = !events.empty() || m_state == STATE_SCALE || m_state == STATE_DRAG;
|
||||
for (UserEvent const & e : events)
|
||||
for (auto const & e : events)
|
||||
{
|
||||
bool breakAnim = false;
|
||||
|
||||
switch (e.m_type)
|
||||
switch (e->GetType())
|
||||
{
|
||||
case UserEvent::EVENT_SCALE:
|
||||
breakAnim = SetScale(e.m_scaleEvent.m_pxPoint, e.m_scaleEvent.m_factor, e.m_scaleEvent.m_isAnim);
|
||||
TouchCancel(m_touches);
|
||||
break;
|
||||
case UserEvent::EVENT_RESIZE:
|
||||
m_navigator.OnSize(e.m_resize.m_width, e.m_resize.m_height);
|
||||
breakAnim = true;
|
||||
TouchCancel(m_touches);
|
||||
if (m_state == STATE_DOUBLE_TAP_HOLD)
|
||||
EndDoubleTapAndHold(m_touches[0]);
|
||||
break;
|
||||
case UserEvent::EVENT_SET_ANY_RECT:
|
||||
breakAnim = SetRect(e.m_anyRect.m_rect, e.m_anyRect.m_isAnim);
|
||||
TouchCancel(m_touches);
|
||||
break;
|
||||
case UserEvent::EVENT_SET_RECT:
|
||||
breakAnim = SetRect(e.m_rectEvent.m_rect, e.m_rectEvent.m_zoom, e.m_rectEvent.m_applyRotation, e.m_rectEvent.m_isAnim);
|
||||
TouchCancel(m_touches);
|
||||
break;
|
||||
case UserEvent::EVENT_SET_CENTER:
|
||||
breakAnim = SetCenter(e.m_centerEvent.m_center, e.m_centerEvent.m_zoom, e.m_centerEvent.m_isAnim);
|
||||
TouchCancel(m_touches);
|
||||
break;
|
||||
case UserEvent::EVENT_TOUCH:
|
||||
breakAnim = ProcessTouch(e.m_touchEvent);
|
||||
break;
|
||||
case UserEvent::EVENT_ROTATE:
|
||||
case UserEvent::Scale:
|
||||
{
|
||||
ref_ptr<ScaleEvent> scaleEvent = make_ref(e);
|
||||
breakAnim = SetScale(scaleEvent->GetPxPoint(), scaleEvent->GetFactor(), scaleEvent->IsAnim());
|
||||
TouchCancel(m_touches);
|
||||
}
|
||||
break;
|
||||
case UserEvent::Resize:
|
||||
{
|
||||
ref_ptr<ResizeEvent> resizeEvent = make_ref(e);
|
||||
m_navigator.OnSize(resizeEvent->GetWidth(), resizeEvent->GetHeight());
|
||||
breakAnim = true;
|
||||
TouchCancel(m_touches);
|
||||
if (m_state == STATE_DOUBLE_TAP_HOLD)
|
||||
EndDoubleTapAndHold(m_touches[0]);
|
||||
}
|
||||
break;
|
||||
case UserEvent::SetAnyRect:
|
||||
{
|
||||
ref_ptr<SetAnyRectEvent> anyRectEvent = make_ref(e);
|
||||
breakAnim = SetRect(anyRectEvent->GetRect(), anyRectEvent->IsAnim());
|
||||
TouchCancel(m_touches);
|
||||
}
|
||||
break;
|
||||
case UserEvent::SetRect:
|
||||
{
|
||||
ref_ptr<SetRectEvent> rectEvent = make_ref(e);
|
||||
breakAnim = SetRect(rectEvent->GetRect(), rectEvent->GetZoom(),
|
||||
rectEvent->GetApplyRotation(), rectEvent->IsAnim());
|
||||
TouchCancel(m_touches);
|
||||
}
|
||||
break;
|
||||
case UserEvent::SetCenter:
|
||||
{
|
||||
ref_ptr<SetCenterEvent> centerEvent = make_ref(e);
|
||||
breakAnim = SetCenter(centerEvent->GetCenter(), centerEvent->GetZoom(), centerEvent->IsAnim());
|
||||
TouchCancel(m_touches);
|
||||
}
|
||||
break;
|
||||
case UserEvent::EventTouch:
|
||||
{
|
||||
ref_ptr<TouchEvent> touchEvent = make_ref(e);
|
||||
breakAnim = ProcessTouch(*touchEvent.get());
|
||||
}
|
||||
break;
|
||||
case UserEvent::Rotate:
|
||||
{
|
||||
ref_ptr<RotateEvent> rotateEvent = make_ref(e);
|
||||
ScreenBase const & screen = m_navigator.Screen();
|
||||
if (screen.isPerspective())
|
||||
{
|
||||
m2::PointD pt = screen.PixelRectIn3d().Center();
|
||||
breakAnim = SetFollowAndRotate(screen.PtoG(screen.P3dtoP(pt)), pt,
|
||||
e.m_rotate.m_targetAzimut, kDoNotChangeZoom, kDoNotAutoZoom,
|
||||
rotateEvent->GetTargetAzimuth(), kDoNotChangeZoom, kDoNotAutoZoom,
|
||||
true /* isAnim */, false /* isAutoScale */);
|
||||
}
|
||||
else
|
||||
{
|
||||
m2::AnyRectD dstRect = GetTargetRect();
|
||||
dstRect.SetAngle(e.m_rotate.m_targetAzimut);
|
||||
dstRect.SetAngle(rotateEvent->GetTargetAzimuth());
|
||||
breakAnim = SetRect(dstRect, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case UserEvent::EVENT_FOLLOW_AND_ROTATE:
|
||||
breakAnim = SetFollowAndRotate(e.m_followAndRotate.m_userPos, e.m_followAndRotate.m_pixelZero,
|
||||
e.m_followAndRotate.m_azimuth, e.m_followAndRotate.m_preferredZoomLevel,
|
||||
e.m_followAndRotate.m_autoScale,
|
||||
e.m_followAndRotate.m_isAnim, e.m_followAndRotate.m_isAutoScale);
|
||||
case UserEvent::FollowAndRotate:
|
||||
{
|
||||
ref_ptr<FollowAndRotateEvent> followEvent = make_ref(e);
|
||||
breakAnim = SetFollowAndRotate(followEvent->GetUserPos(), followEvent->GetPixelZero(),
|
||||
followEvent->GetAzimuth(), followEvent->GetPreferredZoomLelel(),
|
||||
followEvent->GetAutoScale(), followEvent->IsAnim(), followEvent->IsAutoScale());
|
||||
}
|
||||
break;
|
||||
case UserEvent::EVENT_AUTO_PERSPECTIVE:
|
||||
SetAutoPerspective(e.m_autoPerspective.m_isAutoPerspective);
|
||||
case UserEvent::AutoPerspective:
|
||||
{
|
||||
ref_ptr<SetAutoPerspectiveEvent> perspectiveEvent = make_ref(e);
|
||||
SetAutoPerspective(perspectiveEvent->IsAutoPerspective());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ASSERT(false, ());
|
||||
|
@ -515,25 +549,25 @@ m2::AnyRectD UserEventStream::GetTargetRect()
|
|||
|
||||
bool UserEventStream::ProcessTouch(TouchEvent const & touch)
|
||||
{
|
||||
ASSERT(touch.m_touches[0].m_id != -1, ());
|
||||
ASSERT(touch.GetFirstTouch().m_id != -1, ());
|
||||
|
||||
TouchEvent touchEvent = touch;
|
||||
touchEvent.PrepareTouches(m_touches);
|
||||
bool isMapTouch = false;
|
||||
|
||||
switch (touchEvent.m_type)
|
||||
switch (touchEvent.GetTouchType())
|
||||
{
|
||||
case TouchEvent::TOUCH_DOWN:
|
||||
isMapTouch = TouchDown(touchEvent.m_touches);
|
||||
isMapTouch = TouchDown(touchEvent.GetTouches());
|
||||
break;
|
||||
case TouchEvent::TOUCH_MOVE:
|
||||
isMapTouch = TouchMove(touchEvent.m_touches, touch.m_timeStamp);
|
||||
isMapTouch = TouchMove(touchEvent.GetTouches(), touch.GetTimeStamp());
|
||||
break;
|
||||
case TouchEvent::TOUCH_CANCEL:
|
||||
isMapTouch = TouchCancel(touchEvent.m_touches);
|
||||
isMapTouch = TouchCancel(touchEvent.GetTouches());
|
||||
break;
|
||||
case TouchEvent::TOUCH_UP:
|
||||
isMapTouch = TouchUp(touchEvent.m_touches);
|
||||
isMapTouch = TouchUp(touchEvent.GetTouches());
|
||||
break;
|
||||
default:
|
||||
ASSERT(false, ());
|
||||
|
|
|
@ -23,6 +23,26 @@ namespace df
|
|||
int const kDoNotChangeZoom = -1;
|
||||
double const kDoNotAutoZoom = -1.0;
|
||||
|
||||
class UserEvent
|
||||
{
|
||||
public:
|
||||
enum EEventType
|
||||
{
|
||||
EventTouch,
|
||||
Scale,
|
||||
SetCenter,
|
||||
SetRect,
|
||||
SetAnyRect,
|
||||
Resize,
|
||||
Rotate,
|
||||
FollowAndRotate,
|
||||
AutoPerspective
|
||||
};
|
||||
|
||||
virtual ~UserEvent() {}
|
||||
virtual EEventType GetType() const = 0;
|
||||
};
|
||||
|
||||
struct Touch
|
||||
{
|
||||
m2::PointF m_location = m2::PointF::Zero();
|
||||
|
@ -30,10 +50,9 @@ struct Touch
|
|||
float m_force = 0.0; // relative force of touch [0.0 - 1.0]
|
||||
};
|
||||
|
||||
struct TouchEvent
|
||||
class TouchEvent : public UserEvent
|
||||
{
|
||||
static uint8_t const INVALID_MASKED_POINTER;
|
||||
|
||||
public:
|
||||
TouchEvent()
|
||||
: m_type(TOUCH_CANCEL)
|
||||
, m_timeStamp(my::Timer::LocalTime())
|
||||
|
@ -49,9 +68,22 @@ struct TouchEvent
|
|||
TOUCH_CANCEL
|
||||
};
|
||||
|
||||
ETouchType m_type;
|
||||
array<Touch, 2> m_touches; // array of all touches
|
||||
double m_timeStamp; // seconds
|
||||
static uint8_t const INVALID_MASKED_POINTER;
|
||||
|
||||
EEventType GetType() const override { return UserEvent::EventTouch; }
|
||||
|
||||
ETouchType GetTouchType() const { return m_type; }
|
||||
void SetTouchType(ETouchType touchType) { m_type = touchType; }
|
||||
|
||||
double GetTimeStamp() const { return m_timeStamp; }
|
||||
|
||||
array<Touch, 2> const & GetTouches() const { return m_touches; }
|
||||
|
||||
Touch const & GetFirstTouch() const { return m_touches[0]; }
|
||||
Touch const & GetSecondTouch() const { return m_touches[1]; }
|
||||
|
||||
void SetFirstTouch(Touch const & touch);
|
||||
void SetSecondTouch(Touch const & touch);
|
||||
|
||||
void PrepareTouches(array<Touch, 2> const & previousToches);
|
||||
|
||||
|
@ -70,11 +102,16 @@ struct TouchEvent
|
|||
|
||||
private:
|
||||
void Swap();
|
||||
|
||||
ETouchType m_type;
|
||||
array<Touch, 2> m_touches; // array of all touches
|
||||
double m_timeStamp; // seconds
|
||||
uint16_t m_pointersMask;
|
||||
};
|
||||
|
||||
struct ScaleEvent
|
||||
class ScaleEvent : public UserEvent
|
||||
{
|
||||
public:
|
||||
ScaleEvent(double factor, m2::PointD const & pxPoint, bool isAnim)
|
||||
: m_factor(factor)
|
||||
, m_pxPoint(pxPoint)
|
||||
|
@ -82,13 +119,21 @@ struct ScaleEvent
|
|||
{
|
||||
}
|
||||
|
||||
EEventType GetType() const override { return UserEvent::Scale; }
|
||||
|
||||
double GetFactor() const { return m_factor; }
|
||||
m2::PointD const & GetPxPoint() const { return m_pxPoint; }
|
||||
bool IsAnim() const { return m_isAnim; }
|
||||
|
||||
private:
|
||||
double m_factor;
|
||||
m2::PointD m_pxPoint;
|
||||
bool m_isAnim;
|
||||
};
|
||||
|
||||
struct SetCenterEvent
|
||||
class SetCenterEvent : public UserEvent
|
||||
{
|
||||
public:
|
||||
SetCenterEvent(m2::PointD const & center, int zoom, bool isAnim)
|
||||
: m_center(center)
|
||||
, m_zoom(zoom)
|
||||
|
@ -96,13 +141,21 @@ struct SetCenterEvent
|
|||
{
|
||||
}
|
||||
|
||||
EEventType GetType() const override { return UserEvent::SetCenter; }
|
||||
|
||||
m2::PointD const & GetCenter() const { return m_center; }
|
||||
int GetZoom() const { return m_zoom; }
|
||||
bool IsAnim() const { return m_isAnim; }
|
||||
|
||||
private:
|
||||
m2::PointD m_center; // center point in mercator
|
||||
int m_zoom; // if zoom == -1, then zoom level will'n change
|
||||
bool m_isAnim;
|
||||
};
|
||||
|
||||
struct SetRectEvent
|
||||
class SetRectEvent : public UserEvent
|
||||
{
|
||||
public:
|
||||
SetRectEvent(m2::RectD const & rect, bool rotate, int zoom, bool isAnim)
|
||||
: m_rect(rect)
|
||||
, m_applyRotation(rotate)
|
||||
|
@ -111,25 +164,41 @@ struct SetRectEvent
|
|||
{
|
||||
}
|
||||
|
||||
EEventType GetType() const override { return UserEvent::SetRect; }
|
||||
|
||||
m2::RectD const & GetRect() const { return m_rect; }
|
||||
bool GetApplyRotation() const { return m_applyRotation; }
|
||||
int GetZoom() const { return m_zoom; }
|
||||
bool IsAnim() const { return m_isAnim; }
|
||||
|
||||
private:
|
||||
m2::RectD m_rect; // destination mercator rect
|
||||
bool m_applyRotation; // if true, current rotation will be apply to m_rect
|
||||
int m_zoom; // if zoom == -1, then zoom level will'n change
|
||||
bool m_isAnim;
|
||||
};
|
||||
|
||||
struct SetAnyRectEvent
|
||||
class SetAnyRectEvent : public UserEvent
|
||||
{
|
||||
public:
|
||||
SetAnyRectEvent(m2::AnyRectD const & rect, bool isAnim)
|
||||
: m_rect(rect)
|
||||
, m_isAnim(isAnim)
|
||||
{}
|
||||
|
||||
EEventType GetType() const override { return UserEvent::SetAnyRect; }
|
||||
|
||||
m2::AnyRectD const & GetRect() const { return m_rect; }
|
||||
bool IsAnim() const { return m_isAnim; }
|
||||
|
||||
private:
|
||||
m2::AnyRectD m_rect; // destination mercator rect
|
||||
bool m_isAnim;
|
||||
};
|
||||
|
||||
struct FollowAndRotateEvent
|
||||
class FollowAndRotateEvent : public UserEvent
|
||||
{
|
||||
public:
|
||||
FollowAndRotateEvent(m2::PointD const & userPos, m2::PointD const & pixelZero,
|
||||
double azimuth, double autoScale)
|
||||
: m_userPos(userPos)
|
||||
|
@ -143,7 +212,8 @@ struct FollowAndRotateEvent
|
|||
}
|
||||
|
||||
FollowAndRotateEvent(m2::PointD const & userPos, m2::PointD const & pixelZero,
|
||||
double azimuth, int preferredZoomLevel, bool isAnim)
|
||||
double azimuth, int preferredZoomLevel,
|
||||
bool isAnim)
|
||||
: m_userPos(userPos)
|
||||
, m_pixelZero(pixelZero)
|
||||
, m_azimuth(azimuth)
|
||||
|
@ -153,6 +223,17 @@ struct FollowAndRotateEvent
|
|||
, m_isAnim(isAnim)
|
||||
{}
|
||||
|
||||
EEventType GetType() const override { return UserEvent::FollowAndRotate; }
|
||||
|
||||
m2::PointD const & GetUserPos() const { return m_userPos; }
|
||||
m2::PointD const & GetPixelZero() const { return m_pixelZero; }
|
||||
double GetAzimuth() const { return m_azimuth; }
|
||||
int GetPreferredZoomLelel() const { return m_preferredZoomLevel; }
|
||||
double GetAutoScale() const { return m_autoScale; }
|
||||
bool IsAutoScale() const { return m_isAutoScale; }
|
||||
bool IsAnim() const { return m_isAnim; }
|
||||
|
||||
private:
|
||||
m2::PointD m_userPos;
|
||||
m2::PointD m_pixelZero;
|
||||
double m_azimuth;
|
||||
|
@ -162,70 +243,51 @@ struct FollowAndRotateEvent
|
|||
bool m_isAnim;
|
||||
};
|
||||
|
||||
struct SetAutoPerspectiveEvent
|
||||
class SetAutoPerspectiveEvent : public UserEvent
|
||||
{
|
||||
public:
|
||||
SetAutoPerspectiveEvent(bool isAutoPerspective)
|
||||
: m_isAutoPerspective(isAutoPerspective)
|
||||
{}
|
||||
|
||||
EEventType GetType() const override { return UserEvent::AutoPerspective; }
|
||||
|
||||
bool IsAutoPerspective() const { return m_isAutoPerspective; }
|
||||
|
||||
private:
|
||||
bool m_isAutoPerspective;
|
||||
};
|
||||
|
||||
struct RotateEvent
|
||||
class RotateEvent : public UserEvent
|
||||
{
|
||||
RotateEvent(double targetAzimut) : m_targetAzimut(targetAzimut) {}
|
||||
public:
|
||||
RotateEvent(double targetAzimut)
|
||||
: m_targetAzimut(targetAzimut)
|
||||
{}
|
||||
|
||||
EEventType GetType() const override { return UserEvent::Rotate; }
|
||||
|
||||
double GetTargetAzimuth() const { return m_targetAzimut; }
|
||||
|
||||
private:
|
||||
double m_targetAzimut;
|
||||
};
|
||||
|
||||
struct ResizeEvent
|
||||
class ResizeEvent : public UserEvent
|
||||
{
|
||||
public:
|
||||
ResizeEvent(uint32_t w, uint32_t h) : m_width(w), m_height(h) {}
|
||||
|
||||
EEventType GetType() const override { return UserEvent::Resize; }
|
||||
|
||||
uint32_t GetWidth() const { return m_width; }
|
||||
uint32_t GetHeight() const { return m_height; }
|
||||
|
||||
private:
|
||||
uint32_t m_width;
|
||||
uint32_t m_height;
|
||||
};
|
||||
|
||||
struct UserEvent
|
||||
{
|
||||
enum EEventType
|
||||
{
|
||||
EVENT_TOUCH,
|
||||
EVENT_SCALE,
|
||||
EVENT_SET_CENTER,
|
||||
EVENT_SET_RECT,
|
||||
EVENT_SET_ANY_RECT,
|
||||
EVENT_RESIZE,
|
||||
EVENT_ROTATE,
|
||||
EVENT_FOLLOW_AND_ROTATE,
|
||||
EVENT_AUTO_PERSPECTIVE
|
||||
};
|
||||
|
||||
UserEvent(TouchEvent const & e) : m_type(EVENT_TOUCH) { m_touchEvent = e; }
|
||||
UserEvent(ScaleEvent const & e) : m_type(EVENT_SCALE) { m_scaleEvent = e; }
|
||||
UserEvent(SetCenterEvent const & e) : m_type(EVENT_SET_CENTER) { m_centerEvent = e; }
|
||||
UserEvent(SetRectEvent const & e) : m_type(EVENT_SET_RECT) { m_rectEvent = e; }
|
||||
UserEvent(SetAnyRectEvent const & e) : m_type(EVENT_SET_ANY_RECT) { m_anyRect = e; }
|
||||
UserEvent(ResizeEvent const & e) : m_type(EVENT_RESIZE) { m_resize = e; }
|
||||
UserEvent(RotateEvent const & e) : m_type(EVENT_ROTATE) { m_rotate = e; }
|
||||
UserEvent(FollowAndRotateEvent const & e) : m_type(EVENT_FOLLOW_AND_ROTATE) { m_followAndRotate = e; }
|
||||
UserEvent(SetAutoPerspectiveEvent const & e) : m_type(EVENT_AUTO_PERSPECTIVE) { m_autoPerspective = e; }
|
||||
|
||||
EEventType m_type;
|
||||
union
|
||||
{
|
||||
TouchEvent m_touchEvent;
|
||||
ScaleEvent m_scaleEvent;
|
||||
SetCenterEvent m_centerEvent;
|
||||
SetRectEvent m_rectEvent;
|
||||
SetAnyRectEvent m_anyRect;
|
||||
ResizeEvent m_resize;
|
||||
RotateEvent m_rotate;
|
||||
FollowAndRotateEvent m_followAndRotate;
|
||||
SetAutoPerspectiveEvent m_autoPerspective;
|
||||
};
|
||||
};
|
||||
|
||||
class UserEventStream
|
||||
{
|
||||
public:
|
||||
|
@ -256,7 +318,7 @@ public:
|
|||
};
|
||||
|
||||
UserEventStream();
|
||||
void AddEvent(UserEvent const & event);
|
||||
void AddEvent(drape_ptr<UserEvent> && event);
|
||||
ScreenBase const & ProcessEvents(bool & modelViewChanged, bool & viewportChanged);
|
||||
ScreenBase const & GetCurrentScreen() const;
|
||||
|
||||
|
@ -351,7 +413,8 @@ private:
|
|||
|
||||
bool CheckDrag(array<Touch, 2> const & touches, double threshold) const;
|
||||
|
||||
list<UserEvent> m_events;
|
||||
using TEventsList = list<drape_ptr<UserEvent>>;
|
||||
TEventsList m_events;
|
||||
mutable mutex m_lock;
|
||||
|
||||
Navigator m_navigator;
|
||||
|
|
|
@ -147,9 +147,9 @@ BOOL gIsFirstMyPositionMode = YES;
|
|||
{
|
||||
int64_t id = reinterpret_cast<int64_t>(touch);
|
||||
int8_t pointerIndex = df::TouchEvent::INVALID_MASKED_POINTER;
|
||||
if (e.m_touches[0].m_id == id)
|
||||
if (e.GetFirstTouch().m_id == id)
|
||||
pointerIndex = 0;
|
||||
else if (e.m_touches[1].m_id == id)
|
||||
else if (e.GetSecondTouch().m_id == id)
|
||||
pointerIndex = 1;
|
||||
|
||||
if (e.GetFirstMaskedPointer() == df::TouchEvent::INVALID_MASKED_POINTER)
|
||||
|
@ -172,19 +172,27 @@ BOOL gIsFirstMyPositionMode = YES;
|
|||
df::TouchEvent e;
|
||||
UITouch * touch = [allTouches objectAtIndex:0];
|
||||
CGPoint const pt = [touch locationInView:v];
|
||||
e.m_type = type;
|
||||
e.m_touches[0].m_id = reinterpret_cast<int64_t>(touch);
|
||||
e.m_touches[0].m_location = m2::PointD(pt.x * scaleFactor, pt.y * scaleFactor);
|
||||
|
||||
e.SetTouchType(type);
|
||||
|
||||
df::Touch t0;
|
||||
t0.m_location = m2::PointD(pt.x * scaleFactor, pt.y * scaleFactor);
|
||||
t0.m_id = reinterpret_cast<int64_t>(touch);
|
||||
if ([self hasForceTouch])
|
||||
e.m_touches[0].m_force = touch.force / touch.maximumPossibleForce;
|
||||
t0.m_force = touch.force / touch.maximumPossibleForce;
|
||||
e.SetFirstTouch(t0);
|
||||
|
||||
if (allTouches.count > 1)
|
||||
{
|
||||
UITouch * touch = [allTouches objectAtIndex:1];
|
||||
CGPoint const pt = [touch locationInView:v];
|
||||
e.m_touches[1].m_id = reinterpret_cast<int64_t>(touch);
|
||||
e.m_touches[1].m_location = m2::PointD(pt.x * scaleFactor, pt.y * scaleFactor);
|
||||
|
||||
df::Touch t1;
|
||||
t1.m_location = m2::PointD(pt.x * scaleFactor, pt.y * scaleFactor);
|
||||
t1.m_id = reinterpret_cast<int64_t>(touch);
|
||||
if ([self hasForceTouch])
|
||||
e.m_touches[1].m_force = touch.force / touch.maximumPossibleForce;
|
||||
t1.m_force = touch.force / touch.maximumPossibleForce;
|
||||
e.SetSecondTouch(t1);
|
||||
}
|
||||
|
||||
NSArray * toggledTouches = [touches allObjects];
|
||||
|
|
|
@ -425,10 +425,12 @@ void DrawWidget::keyPressEvent(QKeyEvent * e)
|
|||
e->key() == Qt::Key_Control)
|
||||
{
|
||||
df::TouchEvent event;
|
||||
event.m_type = df::TouchEvent::TOUCH_DOWN;
|
||||
event.m_touches[0].m_id = 0;
|
||||
event.m_touches[0].m_location = m2::PointD(L2D(QCursor::pos().x()), L2D(QCursor::pos().y()));
|
||||
event.m_touches[1] = GetSymmetrical(event.m_touches[0]);
|
||||
event.SetTouchType(df::TouchEvent::TOUCH_DOWN);
|
||||
df::Touch touch;
|
||||
touch.m_id = 0;
|
||||
touch.m_location = m2::PointD(L2D(QCursor::pos().x()), L2D(QCursor::pos().y()));
|
||||
event.SetFirstTouch(touch);
|
||||
event.SetSecondTouch(GetSymmetrical(touch));
|
||||
|
||||
m_framework->TouchEvent(event);
|
||||
}
|
||||
|
@ -442,10 +444,12 @@ void DrawWidget::keyReleaseEvent(QKeyEvent * e)
|
|||
e->key() == Qt::Key_Control)
|
||||
{
|
||||
df::TouchEvent event;
|
||||
event.m_type = df::TouchEvent::TOUCH_UP;
|
||||
event.m_touches[0].m_id = 0;
|
||||
event.m_touches[0].m_location = m2::PointD(L2D(QCursor::pos().x()), L2D(QCursor::pos().y()));
|
||||
event.m_touches[1] = GetSymmetrical(event.m_touches[0]);
|
||||
event.SetTouchType(df::TouchEvent::TOUCH_UP);
|
||||
df::Touch touch;
|
||||
touch.m_id = 0;
|
||||
touch.m_location = m2::PointD(L2D(QCursor::pos().x()), L2D(QCursor::pos().y()));
|
||||
event.SetFirstTouch(touch);
|
||||
event.SetSecondTouch(GetSymmetrical(touch));
|
||||
|
||||
m_framework->TouchEvent(event);
|
||||
}
|
||||
|
@ -645,10 +649,10 @@ df::Touch DrawWidget::GetSymmetrical(df::Touch const & touch)
|
|||
df::TouchEvent DrawWidget::GetTouchEvent(QMouseEvent * e, df::TouchEvent::ETouchType type)
|
||||
{
|
||||
df::TouchEvent event;
|
||||
event.m_type = type;
|
||||
event.m_touches[0] = GetTouch(e);
|
||||
event.SetTouchType(type);
|
||||
event.SetFirstTouch(GetTouch(e));
|
||||
if (IsRotation(e))
|
||||
event.m_touches[1] = GetSymmetrical(event.m_touches[0]);
|
||||
event.SetSecondTouch(GetSymmetrical(event.GetFirstTouch()));
|
||||
|
||||
return event;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue