From 83b80a02cdab5fc8664e91e79824573dbe945902 Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Mon, 15 Apr 2019 10:50:45 +0300 Subject: [PATCH] [drape] Added visible viewport usage in set-rect methods --- drape_frontend/drape_engine.cpp | 9 +++++---- drape_frontend/drape_engine.hpp | 5 +++-- drape_frontend/frontend_renderer.cpp | 5 +++-- drape_frontend/user_event_stream.cpp | 19 +++++++++++-------- drape_frontend/user_event_stream.hpp | 14 ++++++++++---- map/framework.cpp | 18 ++++++++++-------- map/framework.hpp | 5 +++-- map/routing_manager.cpp | 5 +++-- 8 files changed, 48 insertions(+), 32 deletions(-) diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index 635d5b9308..a8dfcb9e0e 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -199,14 +199,15 @@ void DrapeEngine::SetModelViewCenter(m2::PointD const & centerPt, int zoom, bool PostUserEvent(make_unique_dp(centerPt, zoom, isAnim, trackVisibleViewport)); } -void DrapeEngine::SetModelViewRect(m2::RectD const & rect, bool applyRotation, int zoom, bool isAnim) +void DrapeEngine::SetModelViewRect(m2::RectD const & rect, bool applyRotation, int zoom, bool isAnim, + bool useVisibleViewport) { - PostUserEvent(make_unique_dp(rect, applyRotation, zoom, isAnim)); + PostUserEvent(make_unique_dp(rect, applyRotation, zoom, isAnim, useVisibleViewport)); } -void DrapeEngine::SetModelViewAnyRect(m2::AnyRectD const & rect, bool isAnim) +void DrapeEngine::SetModelViewAnyRect(m2::AnyRectD const & rect, bool isAnim, bool useVisibleViewport) { - PostUserEvent(make_unique_dp(rect, isAnim, true /* fitInViewport */)); + PostUserEvent(make_unique_dp(rect, isAnim, true /* fitInViewport */, useVisibleViewport)); } void DrapeEngine::ClearUserMarksGroup(kml::MarkGroupId groupId) diff --git a/drape_frontend/drape_engine.hpp b/drape_frontend/drape_engine.hpp index 547c81cb40..6391bf24b1 100644 --- a/drape_frontend/drape_engine.hpp +++ b/drape_frontend/drape_engine.hpp @@ -132,8 +132,9 @@ public: // If zoom == -1 then current zoom will not be changed. void SetModelViewCenter(m2::PointD const & centerPt, int zoom, bool isAnim, bool trackVisibleViewport); - void SetModelViewRect(m2::RectD const & rect, bool applyRotation, int zoom, bool isAnim); - void SetModelViewAnyRect(m2::AnyRectD const & rect, bool isAnim); + void SetModelViewRect(m2::RectD const & rect, bool applyRotation, int zoom, bool isAnim, + bool useVisibleViewport); + void SetModelViewAnyRect(m2::AnyRectD const & rect, bool isAnim, bool useVisibleViewport); using TModelViewListenerFn = FrontendRenderer::TModelViewChanged; void SetModelViewListener(TModelViewListenerFn && fn); diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 041dc4bdc9..8b8394e78e 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -1278,7 +1278,7 @@ void FrontendRenderer::ProcessSelection(ref_ptr msg) if (!m_myPositionController->IsModeChangeViewport() && m_selectionTrackInfo.is_initialized()) { AddUserEvent(make_unique_dp(m_selectionTrackInfo.get().m_startRect, true /* isAnim */, - false /* fitInViewport */)); + false /* fitInViewport */, false /* useVisibleViewport */)); } m_selectionTrackInfo.reset(); } @@ -2420,7 +2420,8 @@ void FrontendRenderer::ChangeModelView(double azimuth, void FrontendRenderer::ChangeModelView(m2::RectD const & rect, TAnimationCreator const & parallelAnimCreator) { - AddUserEvent(make_unique_dp(rect, true, kDoNotChangeZoom, true, parallelAnimCreator)); + AddUserEvent(make_unique_dp(rect, true /* rotate */, kDoNotChangeZoom, true /* isAnim */, + false /* useVisibleViewport */, parallelAnimCreator)); } void FrontendRenderer::ChangeModelView(m2::PointD const & userPos, double azimuth, diff --git a/drape_frontend/user_event_stream.cpp b/drape_frontend/user_event_stream.cpp index 3ad71b1dcc..a458b974c5 100644 --- a/drape_frontend/user_event_stream.cpp +++ b/drape_frontend/user_event_stream.cpp @@ -384,13 +384,14 @@ bool UserEventStream::OnMove(ref_ptr moveEvent) bool UserEventStream::OnSetAnyRect(ref_ptr anyRectEvent) { - return SetRect(anyRectEvent->GetRect(), anyRectEvent->IsAnim(), anyRectEvent->FitInViewport()); + return SetRect(anyRectEvent->GetRect(), anyRectEvent->IsAnim(), anyRectEvent->FitInViewport(), + anyRectEvent->UseVisibleViewport()); } bool UserEventStream::OnSetRect(ref_ptr rectEvent) { - return SetRect(rectEvent->GetRect(), rectEvent->GetZoom(), - rectEvent->GetApplyRotation(), rectEvent->IsAnim(), + return SetRect(rectEvent->GetRect(), rectEvent->GetZoom(), rectEvent->GetApplyRotation(), + rectEvent->IsAnim(), rectEvent->UseVisibleViewport(), rectEvent->GetParallelAnimCreator()); } @@ -476,22 +477,24 @@ bool UserEventStream::SetAngle(double azimuth, TAnimationCreator const & paralle } bool UserEventStream::SetRect(m2::RectD rect, int zoom, bool applyRotation, bool isAnim, - TAnimationCreator const & parallelAnimCreator) + bool useVisibleViewport, TAnimationCreator const & parallelAnimCreator) { CheckMinGlobalRect(rect, kDefault3dScale); CheckMinMaxVisibleScale(rect, zoom, kDefault3dScale); m2::AnyRectD targetRect = applyRotation ? ToRotated(m_navigator, rect) : m2::AnyRectD(rect); - return SetRect(targetRect, isAnim, true /* fitInViewport */, parallelAnimCreator); + return SetRect(targetRect, isAnim, true /* fitInViewport */, useVisibleViewport, parallelAnimCreator); } bool UserEventStream::SetRect(m2::AnyRectD const & rect, bool isAnim, bool fitInViewport, - TAnimationCreator const & parallelAnimCreator) + bool useVisibleViewport, TAnimationCreator const & parallelAnimCreator) { ScreenBase tmp = GetCurrentScreen(); if (fitInViewport) { - tmp.SetFromRects(rect, tmp.PixelRectIn3d()); - tmp.MatchGandP3d(rect.GlobalCenter(), tmp.PixelRectIn3d().Center()); + auto const useVisViewport = useVisibleViewport && m_visibleViewport.IsValid(); + tmp.SetFromRects(rect, useVisViewport ? m_visibleViewport : tmp.PixelRectIn3d()); + tmp.MatchGandP3d(rect.GlobalCenter(), useVisViewport ? m_visibleViewport.Center() + : tmp.PixelRectIn3d().Center()); } else { diff --git a/drape_frontend/user_event_stream.hpp b/drape_frontend/user_event_stream.hpp index 09f7d3f4d1..c133faa8a5 100644 --- a/drape_frontend/user_event_stream.hpp +++ b/drape_frontend/user_event_stream.hpp @@ -189,11 +189,12 @@ class SetRectEvent : public UserEvent { public: SetRectEvent(m2::RectD const & rect, bool rotate, int zoom, bool isAnim, - TAnimationCreator const & parallelAnimCreator = nullptr) + bool useVisibleViewport, TAnimationCreator const & parallelAnimCreator = nullptr) : m_rect(rect) , m_applyRotation(rotate) , m_zoom(zoom) , m_isAnim(isAnim) + , m_useVisibleViewport(useVisibleViewport) , m_parallelAnimCreator(parallelAnimCreator) {} @@ -203,6 +204,7 @@ public: bool GetApplyRotation() const { return m_applyRotation; } int GetZoom() const { return m_zoom; } bool IsAnim() const { return m_isAnim; } + bool UseVisibleViewport() const { return m_useVisibleViewport; } TAnimationCreator const & GetParallelAnimCreator() const { return m_parallelAnimCreator; } private: @@ -210,16 +212,18 @@ private: 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; + bool m_useVisibleViewport; TAnimationCreator m_parallelAnimCreator; }; class SetAnyRectEvent : public UserEvent { public: - SetAnyRectEvent(m2::AnyRectD const & rect, bool isAnim, bool fitInViewport) + SetAnyRectEvent(m2::AnyRectD const & rect, bool isAnim, bool fitInViewport, bool useVisibleViewport) : m_rect(rect) , m_isAnim(isAnim) , m_fitInViewport(fitInViewport) + , m_useVisibleViewport(useVisibleViewport) {} EventType GetType() const override { return UserEvent::EventType::SetAnyRect; } @@ -227,11 +231,13 @@ public: m2::AnyRectD const & GetRect() const { return m_rect; } bool IsAnim() const { return m_isAnim; } bool FitInViewport() const { return m_fitInViewport; } + bool UseVisibleViewport() const { return m_useVisibleViewport; } private: m2::AnyRectD m_rect; // destination mercator rect bool m_isAnim; bool m_fitInViewport; + bool m_useVisibleViewport; }; class FollowAndRotateEvent : public UserEvent @@ -433,9 +439,9 @@ private: bool SetAngle(double azimuth, TAnimationCreator const & parallelAnimCreator = nullptr); bool SetRect(m2::RectD rect, int zoom, bool applyRotation, bool isAnim, - TAnimationCreator const & parallelAnimCreator = nullptr); + bool useVisibleViewport, TAnimationCreator const & parallelAnimCreator = nullptr); bool SetRect(m2::AnyRectD const & rect, bool isAnim, bool fitInViewport, - TAnimationCreator const & parallelAnimCreator = nullptr); + bool useVisibleViewport, TAnimationCreator const & parallelAnimCreator = nullptr); bool SetScreen(ScreenBase const & screen, bool isAnim, TAnimationCreator const & parallelAnimCreator = nullptr); diff --git a/map/framework.cpp b/map/framework.cpp index b6ee74669d..1b4a1092a2 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1184,7 +1184,7 @@ void Framework::LoadViewport() if (settings::Get("ScreenClipRect", rect) && df::GetWorldRect().IsRectInside(rect.GetGlobalRect())) { if (m_drapeEngine != nullptr) - m_drapeEngine->SetModelViewAnyRect(rect, false /* isAnim */); + m_drapeEngine->SetModelViewAnyRect(rect, false /* isAnim */, false /* useVisibleViewport */); } else { @@ -1194,8 +1194,10 @@ void Framework::LoadViewport() void Framework::ShowAll() { - if (m_drapeEngine != nullptr) - m_drapeEngine->SetModelViewAnyRect(m2::AnyRectD(m_model.GetWorldRect()), false /* isAnim */); + if (m_drapeEngine == nullptr) + return; + m_drapeEngine->SetModelViewAnyRect(m2::AnyRectD(m_model.GetWorldRect()), false /* isAnim */, + false /* useVisibleViewport */); } m2::PointD Framework::GetPixelCenter() const @@ -1242,19 +1244,19 @@ void Framework::SetVisibleViewport(m2::RectD const & rect) m_drapeEngine->SetVisibleViewport(rect); } -void Framework::ShowRect(m2::RectD const & rect, int maxScale, bool animation) +void Framework::ShowRect(m2::RectD const & rect, int maxScale, bool animation, bool useVisibleViewport) { if (m_drapeEngine == nullptr) return; - m_drapeEngine->SetModelViewRect(rect, true /* applyRotation */, - maxScale /* zoom */, animation); + m_drapeEngine->SetModelViewRect(rect, true /* applyRotation */, maxScale /* zoom */, animation, + useVisibleViewport); } -void Framework::ShowRect(m2::AnyRectD const & rect) +void Framework::ShowRect(m2::AnyRectD const & rect, bool useVisibleViewport) { if (m_drapeEngine != nullptr) - m_drapeEngine->SetModelViewAnyRect(rect, true /* isAnim */); + m_drapeEngine->SetModelViewAnyRect(rect, true /* isAnim */, useVisibleViewport); } void Framework::GetTouchRect(m2::PointD const & center, uint32_t pxRadius, m2::AnyRectD & rect) diff --git a/map/framework.hpp b/map/framework.hpp index 5a0697c85d..9ba4a7bfbc 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -632,8 +632,9 @@ public: void SetVisibleViewport(m2::RectD const & rect); /// - Check minimal visible scale according to downloaded countries. - void ShowRect(m2::RectD const & rect, int maxScale = -1, bool animation = true); - void ShowRect(m2::AnyRectD const & rect); + void ShowRect(m2::RectD const & rect, int maxScale = -1, bool animation = true, + bool useVisibleViewport = false); + void ShowRect(m2::AnyRectD const & rect, bool useVisibleViewport = false); void GetTouchRect(m2::PointD const & center, uint32_t pxRadius, m2::AnyRectD & rect); diff --git a/map/routing_manager.cpp b/map/routing_manager.cpp index c64162471a..5a1ebf3fd6 100644 --- a/map/routing_manager.cpp +++ b/map/routing_manager.cpp @@ -374,7 +374,8 @@ void RoutingManager::OnBuildRouteReady(Route const & route, RouterResultCode cod m2::RectD routeRect = route.GetPoly().GetLimitRect(); routeRect.Scale(kRouteScaleMultiplier); m_drapeEngine.SafeCall(&df::DrapeEngine::SetModelViewRect, routeRect, - true /* applyRotation */, -1 /* zoom */, true /* isAnim */); + true /* applyRotation */, -1 /* zoom */, true /* isAnim */, + true /* useVisibleViewport */); } CallRouteBuilded(hasWarnings ? RouterResultCode::HasWarnings : code, storage::CountriesVec()); @@ -1006,7 +1007,7 @@ void RoutingManager::BuildRoute(uint32_t timeoutSec) m2::RectD rect = ShowPreviewSegments(routePoints); rect.Scale(kRouteScaleMultiplier); m_drapeEngine.SafeCall(&df::DrapeEngine::SetModelViewRect, rect, true /* applyRotation */, - -1 /* zoom */, true /* isAnim */); + -1 /* zoom */, true /* isAnim */, true /* useVisibleViewport */); m_routingSession.SetUserCurrentPosition(routePoints.front().m_position);