From 376420445b46f41449ab8ea69ca2cf0128a03ff1 Mon Sep 17 00:00:00 2001 From: ExMix Date: Tue, 30 Sep 2014 11:41:44 +0300 Subject: [PATCH] [core] animations fix --- map/framework.cpp | 18 ++++++++++++------ map/location_state.cpp | 23 ++++++++++++++++++----- map/location_state.hpp | 3 ++- map/map_tests/navigator_test.cpp | 2 +- map/navigator.cpp | 4 ++-- map/navigator.hpp | 2 +- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/map/framework.cpp b/map/framework.cpp index bbc1404d3f..008901f3b1 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -943,7 +943,9 @@ void Framework::StopDrag(DragEvent const & e) void Framework::StartRotate(RotateEvent const & e) { - if (m_renderPolicy && m_renderPolicy->DoSupportRotation()) + if (m_renderPolicy && + m_renderPolicy->DoSupportRotation() && + GetLocationState()->IsRotationAllowed()) { m_navigator.StartRotate(e.Angle(), ElapsedSeconds()); m_renderPolicy->StartRotate(e.Angle(), ElapsedSeconds()); @@ -952,7 +954,9 @@ void Framework::StartRotate(RotateEvent const & e) void Framework::DoRotate(RotateEvent const & e) { - if (m_renderPolicy && m_renderPolicy->DoSupportRotation()) + if (m_renderPolicy && + m_renderPolicy->DoSupportRotation() && + GetLocationState()->IsRotationAllowed()) { m_navigator.DoRotate(e.Angle(), ElapsedSeconds()); m_renderPolicy->DoRotate(e.Angle(), ElapsedSeconds()); @@ -961,10 +965,12 @@ void Framework::DoRotate(RotateEvent const & e) void Framework::StopRotate(RotateEvent const & e) { - if (m_renderPolicy && m_renderPolicy->DoSupportRotation()) + if (m_renderPolicy && + m_renderPolicy->DoSupportRotation() && + GetLocationState()->IsRotationAllowed()) { m_navigator.StopRotate(e.Angle(), ElapsedSeconds()); - m_informationDisplay.locationState()->Rotated(); + GetLocationState()->Rotated(); m_renderPolicy->StopRotate(e.Angle(), ElapsedSeconds()); UpdateUserViewportChanged(); @@ -1023,7 +1029,7 @@ void Framework::StartScale(ScaleEvent const & e) m2::PointD pt1, pt2; CalcScalePoints(e, pt1, pt2); - m_navigator.StartScale(pt1, pt2, ElapsedSeconds()); + m_navigator.StartScale(pt1, pt2, ElapsedSeconds(), GetLocationState()->IsRotationAllowed()); if (m_renderPolicy) m_renderPolicy->StartScale(); } @@ -1038,7 +1044,7 @@ void Framework::DoScale(ScaleEvent const & e) m_renderPolicy->DoScale(); if (m_navigator.IsRotatingDuringScale()) - m_informationDisplay.locationState()->Rotated(); + GetLocationState()->Rotated(); } void Framework::StopScale(ScaleEvent const & e) diff --git a/map/location_state.cpp b/map/location_state.cpp index 8213b6187e..27e6c1e82c 100644 --- a/map/location_state.cpp +++ b/map/location_state.cpp @@ -283,6 +283,7 @@ void State::StartRoutingMode() void State::StopRoutingMode() { SetModeInfo(ExcludeModeBit(m_modeInfo, RoutingSessionBit)); + SetCurrentPixelBinding(GetModeDefaultPixelBinding(GetMode())); } void State::TurnOff() @@ -615,12 +616,15 @@ m2::PointD const State::GetRaFModeDefaultPxBind() const pixelRect.maxY() - POSITION_Y_OFFSET * visualScale()); } -void State::StopCompassFollowing(Mode mode) +void State::StopCompassFollowing(Mode mode, bool resetPxBinding) { if (GetMode() != RotateAndFollow) return; + EndAnimation(); SetModeInfo(ChangeMode(m_modeInfo, mode)); + if (resetPxBinding) + SetCurrentPixelBinding(GetModeDefaultPixelBinding(GetMode())); m_framework->GetAnimator().StopRotation(); m_framework->GetAnimator().StopChangeViewport(); @@ -631,7 +635,10 @@ void State::StopLocationFollow() { StopCompassFollowing(); if (GetMode() > NotFollow) + { SetModeInfo(ChangeMode(m_modeInfo, NotFollow)); + SetCurrentPixelBinding(GetModeDefaultPixelBinding(GetMode())); + } } void State::DragStarted() @@ -645,7 +652,7 @@ void State::Draged() if (!IsModeChangeViewport()) return; - StopCompassFollowing(); + StopCompassFollowing(NotFollow, false); SetModeInfo(ChangeMode(m_modeInfo, NotFollow)); } @@ -674,13 +681,13 @@ void State::DragEnded() void State::ScaleCorrection(m2::PointD & pt) { - if (IsModeChangeViewport()) + if (GetMode() == Follow) pt = m_framework->GetPixelCenter(); } void State::ScaleCorrection(m2::PointD & pt1, m2::PointD & pt2) { - if (IsModeChangeViewport()) + if (GetMode() == Follow) { m2::PointD const ptC = (pt1 + pt2) / 2; m2::PointD const ptDiff = m_framework->GetPixelCenter() - ptC; @@ -689,10 +696,16 @@ void State::ScaleCorrection(m2::PointD & pt1, m2::PointD & pt2) } } +bool State::IsRotationAllowed() const +{ + return !(IsInRouting() && GetMode() == RotateAndFollow); +} + void State::Rotated() { m_afterPendingMode = NotFollow; - StopCompassFollowing(IsInRouting() ? NotFollow : Follow); + ASSERT(!IsInRouting() || GetMode() != RotateAndFollow, ()); + StopCompassFollowing(NotFollow); } void State::OnSize(m2::RectD const & oldPixelRect) diff --git a/map/location_state.hpp b/map/location_state.hpp index 04c303841e..02adb944b5 100644 --- a/map/location_state.hpp +++ b/map/location_state.hpp @@ -71,7 +71,7 @@ namespace location void InvalidatePosition(); void TurnOff(); - void StopCompassFollowing(Mode mode = Follow); + void StopCompassFollowing(Mode mode = Follow, bool resetPxBinding = true); void StopLocationFollow(); /// @name User input notification block @@ -83,6 +83,7 @@ namespace location void ScaleCorrection(m2::PointD & pt); void ScaleCorrection(m2::PointD & pt1, m2::PointD & pt2); + bool IsRotationAllowed() const; void Rotated(); //@} diff --git a/map/map_tests/navigator_test.cpp b/map/map_tests/navigator_test.cpp index ce037c5838..217adefb97 100644 --- a/map/map_tests/navigator_test.cpp +++ b/map/map_tests/navigator_test.cpp @@ -40,7 +40,7 @@ UNIT_TEST(Navigator_Scale2Points) TEST_EQUAL(screen.ClipRect(), m2::RectD(0, 0, 8, 4), ()); navigator.StartScale(screen.GtoP(m2::PointD(1, 1)), - screen.GtoP(m2::PointD(7, 1)), 0); + screen.GtoP(m2::PointD(7, 1)), 0, true); navigator.StopScale(screen.GtoP(m2::PointD(1, 1)), screen.GtoP(m2::PointD(4, 1)), 1); TEST_EQUAL(screen.ClipRect(), m2::RectD(-1, -1, 15, 7), ()); diff --git a/map/navigator.cpp b/map/navigator.cpp index 9a0c97ac09..399415d36c 100644 --- a/map/navigator.cpp +++ b/map/navigator.cpp @@ -385,13 +385,13 @@ bool Navigator::InAction() const return m_InAction; } -void Navigator::StartScale(m2::PointD const & pt1, m2::PointD const & pt2, double /*timeInSec*/) +void Navigator::StartScale(m2::PointD const & pt1, m2::PointD const & pt2, double /*timeInSec*/, bool isRotationAllowed) { m_StartScreen = m_Screen; m_StartPt1 = m_LastPt1 = pt1; m_StartPt2 = m_LastPt2 = pt2; - m_DoCheckRotationThreshold = m_DoSupportRotation; + m_DoCheckRotationThreshold = m_DoSupportRotation && isRotationAllowed; m_IsRotatingDuringScale = false; m_InAction = true; } diff --git a/map/navigator.hpp b/map/navigator.hpp index 95becb2f43..92b36b2f63 100644 --- a/map/navigator.hpp +++ b/map/navigator.hpp @@ -47,7 +47,7 @@ public: void DoRotate(double Angle, double timeInSec); void StopRotate(double Angle, double timeInSec); - void StartScale(m2::PointD const & pt1, m2::PointD const & pt2, double timeInSec); + void StartScale(m2::PointD const & pt1, m2::PointD const & pt2, double timeInSec, bool isRotationAllowed); void DoScale(m2::PointD const & org, m2::PointD const & p1, m2::PointD const & p2); void DoScale(m2::PointD const & pt1, m2::PointD const & pt2, double timeInSec); void StopScale(m2::PointD const & pt1, m2::PointD const & pt2, double timeInSec);