[drape] Added visible viewport usage in set-rect methods

This commit is contained in:
r.kuznetsov 2019-04-15 10:50:45 +03:00 committed by Daria Volvenkova
parent 4745d564c7
commit 83b80a02cd
8 changed files with 48 additions and 32 deletions

View file

@ -199,14 +199,15 @@ void DrapeEngine::SetModelViewCenter(m2::PointD const & centerPt, int zoom, bool
PostUserEvent(make_unique_dp<SetCenterEvent>(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<SetRectEvent>(rect, applyRotation, zoom, isAnim));
PostUserEvent(make_unique_dp<SetRectEvent>(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<SetAnyRectEvent>(rect, isAnim, true /* fitInViewport */));
PostUserEvent(make_unique_dp<SetAnyRectEvent>(rect, isAnim, true /* fitInViewport */, useVisibleViewport));
}
void DrapeEngine::ClearUserMarksGroup(kml::MarkGroupId groupId)

View file

@ -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);

View file

@ -1278,7 +1278,7 @@ void FrontendRenderer::ProcessSelection(ref_ptr<SelectObjectMessage> msg)
if (!m_myPositionController->IsModeChangeViewport() && m_selectionTrackInfo.is_initialized())
{
AddUserEvent(make_unique_dp<SetAnyRectEvent>(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<SetRectEvent>(rect, true, kDoNotChangeZoom, true, parallelAnimCreator));
AddUserEvent(make_unique_dp<SetRectEvent>(rect, true /* rotate */, kDoNotChangeZoom, true /* isAnim */,
false /* useVisibleViewport */, parallelAnimCreator));
}
void FrontendRenderer::ChangeModelView(m2::PointD const & userPos, double azimuth,

View file

@ -384,13 +384,14 @@ bool UserEventStream::OnMove(ref_ptr<MoveEvent> moveEvent)
bool UserEventStream::OnSetAnyRect(ref_ptr<SetAnyRectEvent> anyRectEvent)
{
return SetRect(anyRectEvent->GetRect(), anyRectEvent->IsAnim(), anyRectEvent->FitInViewport());
return SetRect(anyRectEvent->GetRect(), anyRectEvent->IsAnim(), anyRectEvent->FitInViewport(),
anyRectEvent->UseVisibleViewport());
}
bool UserEventStream::OnSetRect(ref_ptr<SetRectEvent> 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
{

View file

@ -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);

View file

@ -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)

View file

@ -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);

View file

@ -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);