From 6d361300ba2b72211ab2ad4830448d7fc1b34be9 Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Tue, 1 Sep 2015 10:35:40 +0300 Subject: [PATCH] Tuned kinetic scroll --- drape_frontend/kinetic_scroller.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drape_frontend/kinetic_scroller.cpp b/drape_frontend/kinetic_scroller.cpp index ea2eb31394..91d3bb923c 100644 --- a/drape_frontend/kinetic_scroller.cpp +++ b/drape_frontend/kinetic_scroller.cpp @@ -5,6 +5,12 @@ namespace df { +double const kKineticDuration = 0.375; +double const kKineticFeedback = 0.2; +double const kKineticFadeoff = 5.0; +double const kKineticThreshold = 10.0; +double const kKineticInertia = 0.8; + class KineticScrollAnimation : public BaseModelViewAnimation { public: @@ -23,7 +29,7 @@ public: { // current position = target position - amplutide * e ^ (elapsed / duration) // we calculate current position not based on start position, but based on target position - return m2::AnyRectD(m_targetCenter - m_direction * exp(-GetT()), m_angle, m_localRect); + return m2::AnyRectD(m_targetCenter - m_direction * exp(-kKineticFadeoff * GetT()), m_angle, m_localRect); } m2::AnyRectD GetTargetRect() const override @@ -75,7 +81,7 @@ void KineticScroller::GrabViewRect(ScreenBase const & modelView, double timeStam // velocity on pixels double v = pxDeltaLength / elapsed; // at this point length(m_direction) already in pixel space, and delta normalized - m_direction = delta * 0.8 * v + m_direction * 0.2; + m_direction = delta * kKineticInertia * v + m_direction * (1.0 - kKineticInertia); m_lastTimestamp = timeStamp; m_lastRect = modelView.GlobalRect(); @@ -89,17 +95,16 @@ void KineticScroller::CancelGrab() unique_ptr KineticScroller::CreateKineticAnimation(ScreenBase const & modelView) { - static double VELOCITY_THRESHOLD = 10.0 * VisualParams::Instance().GetVisualScale(); - if (m_direction.Length() < VELOCITY_THRESHOLD) + static double kVelocityThreshold = kKineticThreshold * VisualParams::Instance().GetVisualScale(); + if (m_direction.Length() < kVelocityThreshold) return unique_ptr(); - double const KINETIC_DURATION = 0.375; // Before we start animation we have to convert length(m_direction) from pixel space to mercator space m2::PointD center = m_lastRect.GlobalCenter(); - double glbLength = 0.5 * (modelView.PtoG(modelView.GtoP(center) + m_direction) - center).Length(); + double glbLength = kKineticFeedback * (modelView.PtoG(modelView.GtoP(center) + m_direction) - center).Length(); return unique_ptr(new KineticScrollAnimation(m_lastRect, m_direction.Normalize() * glbLength, - KINETIC_DURATION)); + kKineticDuration)); } } // namespace df