From 441eac21951706bdd4bb0d2ef93b0650048b2c28 Mon Sep 17 00:00:00 2001 From: Daria Volvenkova Date: Tue, 19 Jul 2016 13:17:40 +0300 Subject: [PATCH] Pretty follow animation fixed on max zoom level. --- drape_frontend/screen_animations.cpp | 30 ++++++++++++++++++---------- drape_frontend/user_event_stream.cpp | 19 ++++++++++-------- drape_frontend/user_event_stream.hpp | 5 +++-- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/drape_frontend/screen_animations.cpp b/drape_frontend/screen_animations.cpp index b1d06014a9..b896fa2445 100644 --- a/drape_frontend/screen_animations.cpp +++ b/drape_frontend/screen_animations.cpp @@ -32,6 +32,8 @@ drape_ptr GetPrettyMoveAnimation(ScreenBase const & screen, d m2::PointD const & startPt, m2::PointD const & endPt) { double const moveDuration = PositionInterpolator::GetMoveDuration(startPt, endPt, screen.PixelRectIn3d(), startScale); + ASSERT_GREATER(moveDuration, 0.0, ()); + double const scaleFactor = moveDuration / kMaxAnimationTimeSec * 2.0; auto sequenceAnim = make_unique_dp(); @@ -65,32 +67,38 @@ drape_ptr GetPrettyFollowAnimation(ScreenBase const & startSc m2::RectD const viewportRect = startScreen.PixelRectIn3d(); ScreenBase tmp = startScreen; + tmp.SetAngle(targetAngle); tmp.MatchGandP3d(userPos, viewportRect.Center()); double const moveDuration = PositionInterpolator::GetMoveDuration(startScreen.GetOrg(), tmp.GetOrg(), startScreen); + ASSERT_GREATER(moveDuration, 0.0, ()); + double const scaleFactor = moveDuration / kMaxAnimationTimeSec * 2.0; tmp = startScreen; - tmp.SetScale(startScreen.GetScale() * scaleFactor); - auto zoomOutAnim = make_unique_dp(); - zoomOutAnim->SetScale(startScreen.GetScale(), tmp.GetScale()); - zoomOutAnim->SetMaxDuration(kMaxAnimationTimeSec * 0.5); + if (moveDuration > 0.0) + { + tmp.SetScale(startScreen.GetScale() * scaleFactor); - tmp.MatchGandP3d(userPos, viewportRect.Center()); + auto zoomOutAnim = make_unique_dp(); + zoomOutAnim->SetScale(startScreen.GetScale(), tmp.GetScale()); + zoomOutAnim->SetMaxDuration(kMaxAnimationTimeSec * 0.5); + sequenceAnim->AddAnimation(move(zoomOutAnim)); - auto moveAnim = make_unique_dp(); - moveAnim->SetMove(startScreen.GetOrg(), tmp.GetOrg(), viewportRect, tmp.GetScale()); - moveAnim->SetMaxDuration(kMaxAnimationTimeSec); + tmp.MatchGandP3d(userPos, viewportRect.Center()); + + auto moveAnim = make_unique_dp(); + moveAnim->SetMove(startScreen.GetOrg(), tmp.GetOrg(), viewportRect, tmp.GetScale()); + moveAnim->SetMaxDuration(kMaxAnimationTimeSec); + sequenceAnim->AddAnimation(move(moveAnim)); + } auto followAnim = make_unique_dp(tmp, userPos, endPixelPos, tmp.GetScale(), targetScale, tmp.GetAngle(), targetAngle, false /* isAutoZoom */); followAnim->SetMaxDuration(kMaxAnimationTimeSec * 0.5); - - sequenceAnim->AddAnimation(move(zoomOutAnim)); - sequenceAnim->AddAnimation(move(moveAnim)); sequenceAnim->AddAnimation(move(followAnim)); return sequenceAnim; } diff --git a/drape_frontend/user_event_stream.cpp b/drape_frontend/user_event_stream.cpp index ea9c49467d..63572d3a52 100644 --- a/drape_frontend/user_event_stream.cpp +++ b/drape_frontend/user_event_stream.cpp @@ -399,6 +399,10 @@ bool UserEventStream::SetFollowAndRotate(m2::PointD const & userPos, m2::PointD double azimuth, int preferredZoomLevel, double autoScale, bool isAnim, bool isAutoScale) { + // Reset current follow-and-rotate animation if possible. + if (isAnim && !InterruptFollowAnimations(false /* force */)) + return false; + ScreenBase const & currentScreen = GetCurrentScreen(); ScreenBase screen = currentScreen; @@ -417,10 +421,6 @@ bool UserEventStream::SetFollowAndRotate(m2::PointD const & userPos, m2::PointD if (isAnim) { - // Reset current follow-and-rotate animation if possible. - if (!InterruptFollowAnimations(false /* force */)) - return false; - auto onStartHandler = [this](ref_ptr animation) { if (m_listener) @@ -497,15 +497,18 @@ m2::AnyRectD UserEventStream::GetCurrentRect() const return m_navigator.Screen().GlobalRect(); } -void UserEventStream::GetTargetScreen(ScreenBase & screen) const +void UserEventStream::GetTargetScreen(ScreenBase & screen) { - m_animationSystem.GetTargetScreen(m_navigator.Screen(), screen); + m_animationSystem.FinishAnimations(Animation::KineticScroll, false /* rewind */, false /* finishAll */); + ApplyAnimations(); + + m_animationSystem.GetTargetScreen(m_navigator.Screen(), screen); } -m2::AnyRectD UserEventStream::GetTargetRect() const +m2::AnyRectD UserEventStream::GetTargetRect() { ScreenBase targetScreen; - m_animationSystem.GetTargetScreen(m_navigator.Screen(), targetScreen); + GetTargetScreen(targetScreen); return targetScreen.GlobalRect(); } diff --git a/drape_frontend/user_event_stream.hpp b/drape_frontend/user_event_stream.hpp index 0929bd0c06..0e1be71778 100644 --- a/drape_frontend/user_event_stream.hpp +++ b/drape_frontend/user_event_stream.hpp @@ -260,8 +260,9 @@ public: ScreenBase const & ProcessEvents(bool & modelViewChanged, bool & viewportChanged); ScreenBase const & GetCurrentScreen() const; - void GetTargetScreen(ScreenBase & screen) const; - m2::AnyRectD GetTargetRect() const; + void GetTargetScreen(ScreenBase & screen); + m2::AnyRectD GetTargetRect(); + bool IsInUserAction() const; bool IsWaitingForActionCompletion() const;