diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index a64574303a..f17dde014a 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -222,6 +222,13 @@ void DrapeEngine::CancelMyPosition() MessagePriority::High); } +void DrapeEngine::StopLocationFollow() +{ + m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread, + make_unique_dp(ChangeMyPositionModeMessage::TYPE_STOP_FOLLOW), + MessagePriority::High); +} + void DrapeEngine::InvalidateMyPosition() { m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread, diff --git a/drape_frontend/drape_engine.hpp b/drape_frontend/drape_engine.hpp index e380a550e2..6776cd1c39 100644 --- a/drape_frontend/drape_engine.hpp +++ b/drape_frontend/drape_engine.hpp @@ -79,6 +79,7 @@ public: void SetGpsInfo(location::GpsInfo const & info, bool isNavigable, location::RouteMatchingInfo const & routeInfo); void MyPositionNextMode(); void CancelMyPosition(); + void StopLocationFollow(); void InvalidateMyPosition(); void SetMyPositionModeListener(location::TMyPositionModeChanged const & fn); diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 219dd69eb8..f0c40fff36 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -198,6 +198,9 @@ void FrontendRenderer::AcceptMessage(ref_ptr message) case ChangeMyPositionModeMessage::TYPE_NEXT: m_myPositionController->NextMode(); break; + case ChangeMyPositionModeMessage::TYPE_STOP_FOLLOW: + m_myPositionController->StopLocationFollow(); + break; case ChangeMyPositionModeMessage::TYPE_INVALIDATE: m_myPositionController->Invalidate(); break; @@ -238,6 +241,7 @@ unique_ptr FrontendRenderer::CreateRoutine() void FrontendRenderer::OnResize(ScreenBase const & screen) { m_viewport.SetViewport(0, 0, screen.GetWidth(), screen.GetHeight()); + m_myPositionController->SetPixelRect(screen.PixelRect()); m_contextFactory->getDrawContext()->resize(m_viewport.GetWidth(), m_viewport.GetHeight()); RefreshProjection(); @@ -307,6 +311,7 @@ void FrontendRenderer::OnRemoveTile(TileKey const & tileKey) void FrontendRenderer::OnCompassTapped() { + m_myPositionController->StopCompassFollow(); m_userEventStream.AddEvent(RotateEvent(0.0)); } @@ -617,9 +622,9 @@ void FrontendRenderer::ChangeModelView(m2::RectD const & rect) AddUserEvent(SetRectEvent(rect, true, scales::GetUpperComfortScale(), true)); } -void FrontendRenderer::ChangeModelView(m2::PointD const & userPos, double azimuth, - m2::PointD const & pxZero, ScreenBase const & screen) +void FrontendRenderer::ChangeModelView(m2::PointD const & userPos, double azimuth, m2::PointD const & pxZero) { + ScreenBase const & screen = m_userEventStream.GetCurrentScreen(); double offset = (screen.PtoG(screen.PixelRect().Center()) - screen.PtoG(pxZero)).Length(); m2::PointD viewVector = userPos.Move(1.0, -azimuth + math::pi2) - userPos; viewVector.Normalize(); diff --git a/drape_frontend/frontend_renderer.hpp b/drape_frontend/frontend_renderer.hpp index 3f31fe81a3..bb08d165ae 100755 --- a/drape_frontend/frontend_renderer.hpp +++ b/drape_frontend/frontend_renderer.hpp @@ -93,8 +93,7 @@ public: void ChangeModelView(m2::PointD const & center) override; void ChangeModelView(double azimuth) override; void ChangeModelView(m2::RectD const & rect) override; - void ChangeModelView(m2::PointD const & userPos, double azimuth, - m2::PointD const & pxZero, ScreenBase const & screen) override; + void ChangeModelView(m2::PointD const & userPos, double azimuth, m2::PointD const & pxZero) override; protected: virtual void AcceptMessage(ref_ptr message); diff --git a/drape_frontend/message_subclasses.hpp b/drape_frontend/message_subclasses.hpp index 3b99f912ea..c7d2bf79ed 100644 --- a/drape_frontend/message_subclasses.hpp +++ b/drape_frontend/message_subclasses.hpp @@ -299,6 +299,7 @@ public: { TYPE_NEXT, TYPE_CANCEL, + TYPE_STOP_FOLLOW, TYPE_INVALIDATE }; diff --git a/drape_frontend/my_position_controller.cpp b/drape_frontend/my_position_controller.cpp index 330afef9d4..d023f5f731 100644 --- a/drape_frontend/my_position_controller.cpp +++ b/drape_frontend/my_position_controller.cpp @@ -58,6 +58,12 @@ MyPositionController::MyPositionController(location::EMyPositionMode initMode) m_modeInfo = location::MODE_UNKNOWN_POSITION; } +void MyPositionController::SetPixelRect(m2::RectD const & pixelRect) +{ + m_pixelRect = pixelRect; + Follow(); +} + void MyPositionController::SetListener(ref_ptr listener) { m_listener = listener; @@ -197,17 +203,7 @@ void MyPositionController::Render(ScreenBase const & screen, ref_ptrChangeModelView(userPos, azimuth, pxZero, screen); + m_listener->ChangeModelView(userPos, azimuth, pxZero); +} + +void MyPositionController::Follow() +{ + location::EMyPositionMode currentMode = GetMode(); + if (currentMode == location::MODE_FOLLOW) + { + ChangeModelView(m_position); + } + else if (currentMode == location::MODE_ROTATE_AND_FOLLOW) + { + m2::PointD pxZero(m_pixelRect.Center().x, + m_pixelRect.maxY() - POSITION_Y_OFFSET * VisualParams::Instance().GetVisualScale()); + ChangeModelView(m_position, m_drawDirection, pxZero); + } } } diff --git a/drape_frontend/my_position_controller.hpp b/drape_frontend/my_position_controller.hpp index 369fdd24fe..cfc3909e8a 100644 --- a/drape_frontend/my_position_controller.hpp +++ b/drape_frontend/my_position_controller.hpp @@ -28,12 +28,12 @@ public: /// Somehow show map that "rect" will see virtual void ChangeModelView(m2::RectD const & rect) = 0; /// Show map where "usePos" (mercator) placed in "pxZero" on screen and map rotated around "userPos" - virtual void ChangeModelView(m2::PointD const & userPos, double azimuth, - m2::PointD const & pxZero, ScreenBase const & screen) = 0; + virtual void ChangeModelView(m2::PointD const & userPos, double azimuth, m2::PointD const & pxZero) = 0; }; MyPositionController(location::EMyPositionMode initMode); + void SetPixelRect(m2::RectD const & pixelRect); void SetListener(ref_ptr listener); m2::PointD const & Position() const; @@ -46,6 +46,8 @@ public: void SetFixedZoom(); + void StopLocationFollow(); + void StopCompassFollow(); void NextMode(); void TurnOff(); void Invalidate(); @@ -72,17 +74,15 @@ private: bool IsInRouting() const; bool IsRotationActive() const; - void StopLocationFollow(); - void StopCompassFollow(); - bool IsVisible() const { return m_isVisible; } void SetIsVisible(bool isVisible) { m_isVisible = isVisible; } void ChangeModelView(m2::PointD const & center); void ChangeModelView(double azimuth); void ChangeModelView(m2::RectD const & rect); - void ChangeModelView(m2::PointD const & userPos, double azimuth, - m2::PointD const & pxZero, ScreenBase const & screen); + void ChangeModelView(m2::PointD const & userPos, double azimuth, m2::PointD const & pxZero); + + void Follow(); private: // Mode bits @@ -104,6 +104,8 @@ private: double m_drawDirection; my::HighResTimer m_lastGPSBearing; + m2::RectD m_pixelRect; + bool m_isVisible; bool m_isDirtyViewport; }; diff --git a/drape_frontend/user_event_stream.cpp b/drape_frontend/user_event_stream.cpp index f36d89dece..947d5fc8d4 100644 --- a/drape_frontend/user_event_stream.cpp +++ b/drape_frontend/user_event_stream.cpp @@ -124,6 +124,11 @@ ScreenBase const & UserEventStream::ProcessEvents(bool & modelViewChange, bool & return m_navigator.Screen(); } +ScreenBase const & UserEventStream::GetCurrentScreen() const +{ + return m_navigator.Screen(); +} + void UserEventStream::SetTapListener(TTapDetectedFn const & tapCallback, TSingleTouchFilterFn const & filterFn) { m_tapDetectedFn = tapCallback; diff --git a/drape_frontend/user_event_stream.hpp b/drape_frontend/user_event_stream.hpp index 7d3a0bb006..0603721858 100644 --- a/drape_frontend/user_event_stream.hpp +++ b/drape_frontend/user_event_stream.hpp @@ -153,6 +153,7 @@ public: UserEventStream(TIsCountryLoaded const & fn); void AddEvent(UserEvent const & event); ScreenBase const & ProcessEvents(bool & modelViewChange, bool & viewportChanged); + ScreenBase const & GetCurrentScreen() const; using TTapDetectedFn = function; using TSingleTouchFilterFn = function; diff --git a/map/framework.cpp b/map/framework.cpp index a5a704a3a0..2f762f4ecf 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -171,7 +171,7 @@ void Framework::CallDrapeFunction(TDrapeFunction const & fn) void Framework::StopLocationFollow() { - CallDrapeFunction(bind(&df::DrapeEngine::CancelMyPosition, _1)); + CallDrapeFunction(bind(&df::DrapeEngine::StopLocationFollow, _1)); } Framework::Framework() @@ -220,10 +220,6 @@ Framework::Framework() m_stringsBundle.SetDefaultString("routing_failed_route_not_found", "There is no route found between the selected origin and destination.Please select a different start or end point."); m_stringsBundle.SetDefaultString("routing_failed_internal_error", "Internal error occurred. Please try to delete and download the map again. If problem persist please contact us at support@maps.me."); - // Init information display. - ///@TODO UVR - //m_informationDisplay.setController(m_guiController.get()); - #ifdef DRAW_TOUCH_POINTS m_informationDisplay.enableDebugPoints(true); #endif