diff --git a/drape_frontend/animation/base_modelview_animation.hpp b/drape_frontend/animation/base_modelview_animation.hpp deleted file mode 100644 index bf9f61c30d..0000000000 --- a/drape_frontend/animation/base_modelview_animation.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "drape_frontend/animation/base_interpolator.hpp" -#include "drape_frontend/navigator.hpp" - -namespace df -{ - -class BaseModeViewAnimation : public BaseInterpolator -{ -public: - BaseModeViewAnimation(double duration) : BaseInterpolator(duration) {} - virtual void Apply(Navigator & navigator) = 0; -}; - -} diff --git a/drape_frontend/animation/model_view_animation.cpp b/drape_frontend/animation/model_view_animation.cpp new file mode 100644 index 0000000000..0b40eb48fd --- /dev/null +++ b/drape_frontend/animation/model_view_animation.cpp @@ -0,0 +1,67 @@ +#include "model_view_animation.hpp" + +namespace df +{ + +namespace +{ + +double GetMoveDuration(m2::PointD const & startPx, m2::PointD const & endPt, int minDisplaySize) +{ + double const length = (endPt - startPx).Length(); + return (length / minDisplaySize); +} + +double GetRotateDuration(double const & startAngle, double const & endAngle) +{ + return fabs(ang::GetShortestDistance(startAngle, endAngle) / math::twicePi * 2.0); +} + +double GetScaleDuration(m2::RectD const & startRect, m2::RectD const & endRect) +{ + double const startSizeX = startRect.SizeX(); + double const startSizeY = startRect.SizeY(); + double const endSizeX = endRect.SizeX(); + double const endSizeY = endRect.SizeY(); + + double const maxSizeX = max(startSizeX, endSizeX); + double const minSizeX = min(startSizeX, endSizeX); + double const maxSizeY = max(startSizeY, endSizeY); + double const minSizeY = min(startSizeY, endSizeY); + + return min(minSizeX / maxSizeX, minSizeY / maxSizeY); +} + +} // namespace + +ModelViewAnimation::ModelViewAnimation(m2::AnyRectD const & startRect, m2::AnyRectD const & endRect, double duration) + : BaseInterpolator(duration) + , m_interpolator(startRect, endRect) +{ +} + +m2::AnyRectD ModelViewAnimation::GetCurrentRect() const +{ + return m_interpolator.Interpolate(GetT()); +} + +m2::AnyRectD ModelViewAnimation::GetTargetRect() const +{ + return m_interpolator.Interpolate(1.0); +} + +double ModelViewAnimation::GetDuration(m2::AnyRectD const & startRect, m2::AnyRectD const & endRect, + ScreenBase const & convertor) +{ + m2::PointD const pxStartZero(convertor.GtoP(startRect.GlobalZero())); + m2::PointD const pxEndZero(convertor.GtoP(endRect.GlobalZero())); + + m2::RectD const & pixelRect = convertor.PixelRect(); + double moveDuration = GetMoveDuration(pxStartZero, pxEndZero, min(pixelRect.SizeX(), pixelRect.SizeY())); + double rotateDuration = GetRotateDuration(startRect.Angle().val(), endRect.Angle().val()); + double scaleDuration = GetScaleDuration(startRect.GetLocalRect(), endRect.GetLocalRect()); + + return max(scaleDuration, max(moveDuration, rotateDuration)); +} + +} // namespace df diff --git a/drape_frontend/animation/model_view_animation.hpp b/drape_frontend/animation/model_view_animation.hpp new file mode 100644 index 0000000000..a061cd711e --- /dev/null +++ b/drape_frontend/animation/model_view_animation.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include "drape_frontend/animation/base_interpolator.hpp" +#include "drape_frontend/animation/interpolations.hpp" + +#include "geometry/any_rect2d.hpp" +#include "geometry/screenbase.hpp" + +namespace df +{ + +class ModelViewAnimation : public BaseInterpolator +{ +public: + ModelViewAnimation(m2::AnyRectD const & startRect, m2::AnyRectD const & endRect, double duration); + m2::AnyRectD GetCurrentRect() const; + m2::AnyRectD GetTargetRect() const; + + static double GetDuration(m2::AnyRectD const & startRect, m2::AnyRectD const & endRect, ScreenBase const & convertor); + +private: + InterpolateAnyRect m_interpolator; +}; + +} // namespace df diff --git a/drape_frontend/animation/modelview_angle_animation.cpp b/drape_frontend/animation/modelview_angle_animation.cpp deleted file mode 100644 index 2806d88929..0000000000 --- a/drape_frontend/animation/modelview_angle_animation.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "modelview_angle_animation.hpp" - -namespace df -{ - -ModelViewAngleAnimation::ModelViewAngleAnimation(double startAngle, double endAngle) - : BaseModeViewAnimation(GetStandardDuration(startAngle, endAngle)) - , m_angle(startAngle, endAngle) -{ - -} - -ModelViewAngleAnimation::ModelViewAngleAnimation(double startAngle, double endAngle, double duration) - : BaseModeViewAnimation(duration) - , m_angle(startAngle, endAngle) -{ -} - -void ModelViewAngleAnimation::Apply(Navigator & navigator) -{ - double resultAngle = m_angle.Interpolate(GetT()); - m2::AnyRectD r = navigator.Screen().GlobalRect(); - r.SetAngle(resultAngle); - navigator.SetFromRect(r); -} - -double ModelViewAngleAnimation::GetStandardDuration(double startAngle, double endAngle) -{ - return fabs(ang::GetShortestDistance(startAngle, endAngle) / math::twicePi * 2.0); -} - -} diff --git a/drape_frontend/animation/modelview_angle_animation.hpp b/drape_frontend/animation/modelview_angle_animation.hpp deleted file mode 100644 index b128a0f383..0000000000 --- a/drape_frontend/animation/modelview_angle_animation.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "drape_frontend/animation/base_modelview_animation.hpp" -#include "drape_frontend/animation/interpolations.hpp" - -namespace df -{ - -class ModelViewAngleAnimation : public BaseModeViewAnimation -{ -public: - ModelViewAngleAnimation(double startAngle, double endAngle); - ModelViewAngleAnimation(double startAngle, double endAngle, double duration); - void Apply(Navigator & navigator) override; - - static double GetStandardDuration(double startAngle, double endAngle); - -private: - InerpolateAngle m_angle; -}; - -} diff --git a/drape_frontend/animation/modelview_center_animation.cpp b/drape_frontend/animation/modelview_center_animation.cpp deleted file mode 100644 index 9a3d1b49eb..0000000000 --- a/drape_frontend/animation/modelview_center_animation.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "drape_frontend/animation/modelview_center_animation.hpp" -#include "drape_frontend/animation/interpolations.hpp" - -namespace df -{ - -ModelViewCenterAnimation::ModelViewCenterAnimation(m2::PointD const & start, - m2::PointD const & end, - double duration) - : BaseModeViewAnimation(duration) - , m_startPt(start) - , m_endPt(end) -{ -} - -void ModelViewCenterAnimation::Apply(Navigator & navigator) -{ - m2::PointD center = InterpolatePoint(m_startPt, m_endPt, GetT()); - navigator.CenterViewport(center); -} - -} diff --git a/drape_frontend/animation/modelview_center_animation.hpp b/drape_frontend/animation/modelview_center_animation.hpp deleted file mode 100644 index 1e4e4747b1..0000000000 --- a/drape_frontend/animation/modelview_center_animation.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "drape_frontend/animation/base_modelview_animation.hpp" - -namespace df -{ - -class ModelViewCenterAnimation : public BaseModeViewAnimation -{ -public: - ModelViewCenterAnimation(m2::PointD const & start, m2::PointD const & end, double duration); - - void Apply(Navigator & navigator) override; - -private: - m2::PointD m_startPt; - m2::PointD m_endPt; -}; - -} diff --git a/drape_frontend/animation/modelview_complex_animation.cpp b/drape_frontend/animation/modelview_complex_animation.cpp deleted file mode 100644 index b80ea4da83..0000000000 --- a/drape_frontend/animation/modelview_complex_animation.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "modelview_complex_animation.hpp" - -namespace df -{ - -ModelViewComplexAnimation::ModelViewComplexAnimation(m2::AnyRectD const & startRect, m2::AnyRectD const & endRect, double duration) - : BaseModeViewAnimation(duration) - , m_interpolator(startRect, endRect) -{ -} - -void ModelViewComplexAnimation::Apply(df::Navigator & navigator) -{ - navigator.SetFromRect(m_interpolator.Interpolate(GetT())); -} - -} diff --git a/drape_frontend/animation/modelview_complex_animation.hpp b/drape_frontend/animation/modelview_complex_animation.hpp deleted file mode 100644 index c9e07b3225..0000000000 --- a/drape_frontend/animation/modelview_complex_animation.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "drape_frontend/animation/base_modelview_animation.hpp" -#include "drape_frontend/animation/interpolations.hpp" - -namespace df -{ - -class ModelViewComplexAnimation : public BaseModeViewAnimation -{ -public: - ModelViewComplexAnimation(m2::AnyRectD const & startRect, m2::AnyRectD const & endRect, double duration); - void Apply(Navigator & navigator) override; - -private: - InterpolateAnyRect m_interpolator; -}; - -} diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index cc37072280..23c3dd96e0 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -91,24 +91,24 @@ void DrapeEngine::AddTouchEvent(TouchEvent const & event) AddUserEvent(event); } -void DrapeEngine::Scale(double factor, m2::PointD const & pxPoint) +void DrapeEngine::Scale(double factor, m2::PointD const & pxPoint, bool isAnim) { - AddUserEvent(ScaleEvent(factor, pxPoint)); + AddUserEvent(ScaleEvent(factor, pxPoint, isAnim)); } -void DrapeEngine::SetModelViewCenter(m2::PointD const & centerPt, int zoom) +void DrapeEngine::SetModelViewCenter(m2::PointD const & centerPt, int zoom, bool isAnim) { - AddUserEvent(SetCenterEvent(centerPt, zoom)); + AddUserEvent(SetCenterEvent(centerPt, zoom, isAnim)); } -void DrapeEngine::SetModelViewRect(m2::RectD const & rect, bool applyRotation, int zoom) +void DrapeEngine::SetModelViewRect(m2::RectD const & rect, bool applyRotation, int zoom, bool isAnim) { - AddUserEvent(SetRectEvent(rect, applyRotation, zoom)); + AddUserEvent(SetRectEvent(rect, applyRotation, zoom, isAnim)); } -void DrapeEngine::SetModelViewAnyRect(m2::AnyRectD const & rect) +void DrapeEngine::SetModelViewAnyRect(m2::AnyRectD const & rect, bool isAnim) { - AddUserEvent(SetAnyRectEvent(rect)); + AddUserEvent(SetAnyRectEvent(rect, isAnim)); } int DrapeEngine::AddModelViewListener(TModelViewListenerFn const & listener) diff --git a/drape_frontend/drape_engine.hpp b/drape_frontend/drape_engine.hpp index 5c74d64d09..97792fb7d0 100644 --- a/drape_frontend/drape_engine.hpp +++ b/drape_frontend/drape_engine.hpp @@ -58,12 +58,12 @@ public: void Resize(int w, int h); void AddTouchEvent(TouchEvent const & event); - void Scale(double factor, m2::PointD const & pxPoint); + void Scale(double factor, m2::PointD const & pxPoint, bool isAnim); /// if zoom == -1, then current zoom will not change - void SetModelViewCenter(m2::PointD const & centerPt, int zoom); - void SetModelViewRect(m2::RectD const & rect, bool applyRotation, int zoom); - void SetModelViewAnyRect(m2::AnyRectD const & rect); + void SetModelViewCenter(m2::PointD const & centerPt, int zoom, bool isAnim); + void SetModelViewRect(m2::RectD const & rect, bool applyRotation, int zoom, bool isAnim); + void SetModelViewAnyRect(m2::AnyRectD const & rect, bool isAnim); using TModelViewListenerFn = FrontendRenderer::TModelViewChanged; int AddModelViewListener(TModelViewListenerFn const & listener); diff --git a/drape_frontend/drape_frontend.pro b/drape_frontend/drape_frontend.pro index 03b7b1c719..fc36b2c4f4 100755 --- a/drape_frontend/drape_frontend.pro +++ b/drape_frontend/drape_frontend.pro @@ -10,11 +10,9 @@ DEFINES += DRAW_INFO SOURCES += \ animation/base_interpolator.cpp \ - animation/modelview_angle_animation.cpp \ - animation/modelview_center_animation.cpp \ - animation/modelview_complex_animation.cpp \ animation/interpolation_holder.cpp \ animation/interpolations.cpp \ + animation/model_view_animation.cpp \ apply_feature_functors.cpp \ area_shape.cpp \ backend_renderer.cpp \ @@ -54,13 +52,10 @@ SOURCES += \ user_event_stream.cpp \ HEADERS += \ - animation/base_modelview_animation.hpp \ - animation/modelview_angle_animation.hpp \ - animation/modelview_center_animation.hpp \ - animation/modelview_complex_animation.hpp \ + animation/base_interpolator.hpp \ animation/interpolation_holder.hpp \ animation/interpolations.hpp \ - animation/base_interpolator.hpp \ + animation/model_view_animation.hpp \ apply_feature_functors.hpp \ area_shape.hpp \ backend_renderer.hpp \ diff --git a/drape_frontend/drape_frontend_tests/user_event_stream_tests.cpp b/drape_frontend/drape_frontend_tests/user_event_stream_tests.cpp index 2e553f17e7..f922d93b29 100644 --- a/drape_frontend/drape_frontend_tests/user_event_stream_tests.cpp +++ b/drape_frontend/drape_frontend_tests/user_event_stream_tests.cpp @@ -33,7 +33,7 @@ public: void SetRect(m2::RectD const & r) { - m_stream.AddEvent(df::SetRectEvent(r, false, -1)); + m_stream.AddEvent(df::SetRectEvent(r, false, -1, false)); } void AddExpectation(char const * action) diff --git a/drape_frontend/user_event_stream.cpp b/drape_frontend/user_event_stream.cpp index 89dc7d0c9b..56735f4539 100644 --- a/drape_frontend/user_event_stream.cpp +++ b/drape_frontend/user_event_stream.cpp @@ -1,5 +1,3 @@ -#include "drape_frontend/animation/modelview_complex_animation.hpp" -#include "drape_frontend/animation/modelview_angle_animation.hpp" #include "drape_frontend/user_event_stream.hpp" #include "drape_frontend/visual_params.hpp" @@ -65,41 +63,41 @@ ScreenBase const & UserEventStream::ProcessEvents(bool & modelViewChange, bool & } modelViewChange = !events.empty() || m_state != STATE_EMPTY; + bool breakAnim = false; for (UserEvent const & e : events) { switch (e.m_type) { case UserEvent::EVENT_SCALE: - m_navigator.Scale(e.m_scaleEvent.m_pxPoint, e.m_scaleEvent.m_factor); + breakAnim = Scale(e.m_scaleEvent.m_pxPoint, e.m_scaleEvent.m_factor, e.m_scaleEvent.m_isAnim); TouchCancel(m_touches); break; case UserEvent::EVENT_RESIZE: m_navigator.OnSize(e.m_resize.m_width, e.m_resize.m_height); viewportChanged = true; + breakAnim = true; TouchCancel(m_touches); break; case UserEvent::EVENT_SET_ANY_RECT: - SetRect(e.m_anyRect.m_rect); + breakAnim = SetRect(e.m_anyRect.m_rect, e.m_anyRect.m_isAnim); TouchCancel(m_touches); break; case UserEvent::EVENT_SET_RECT: - SetRect(e.m_rectEvent.m_rect, e.m_rectEvent.m_zoom, e.m_rectEvent.m_applyRotation); + breakAnim = SetRect(e.m_rectEvent.m_rect, e.m_rectEvent.m_zoom, e.m_rectEvent.m_applyRotation, e.m_rectEvent.m_isAnim); TouchCancel(m_touches); break; case UserEvent::EVENT_SET_CENTER: - SetCenter(e.m_centerEvent.m_center, e.m_centerEvent.m_zoom); + breakAnim = SetCenter(e.m_centerEvent.m_center, e.m_centerEvent.m_zoom, e.m_centerEvent.m_isAnim); TouchCancel(m_touches); break; case UserEvent::EVENT_TOUCH: - ProcessTouch(e.m_touchEvent); + breakAnim = ProcessTouch(e.m_touchEvent); break; case UserEvent::EVENT_ROTATE: { - m2::AnyRectD rect = m_navigator.Screen().GlobalRect(); - m2::AnyRectD dstRect = rect; + m2::AnyRectD dstRect = GetTargetRect(); dstRect.SetAngle(e.m_rotate.m_targetAzimut); - double duration = ModelViewAngleAnimation::GetStandardDuration(rect.Angle().val(), dstRect.Angle().val()); - m_animation.reset(new ModelViewComplexAnimation(rect, dstRect, duration)); + breakAnim = SetRect(dstRect, true); } break; default: @@ -108,17 +106,16 @@ ScreenBase const & UserEventStream::ProcessEvents(bool & modelViewChange, bool & } } + if (breakAnim) + m_animation.reset(); + if (m_animation != nullptr) { - if (m_state != STATE_EMPTY) + m2::AnyRectD rect = m_animation->GetCurrentRect(); + m_navigator.SetFromRect(rect); + modelViewChange = true; + if (m_animation->IsFinished()) m_animation.reset(); - else - { - m_animation->Apply(m_navigator); - modelViewChange = true; - if (m_animation->IsFinished()) - m_animation.reset(); - } } if (m_state == STATE_TAP_DETECTION && m_validTouchesCount == 1) @@ -133,68 +130,107 @@ void UserEventStream::SetTapListener(TTapDetectedFn const & tapCallback, TSingle m_filterFn = filterFn; } -void UserEventStream::SetCenter(m2::PointD const & center, int zoom) +bool UserEventStream::Scale(m2::PointD const & pxScaleCenter, double factor, bool isAnim) { - m2::RectD rect = df::GetRectForDrawScale(zoom, center); - SetRect(rect, zoom, true); + if (isAnim) + { + m2::PointD glbCenter = m_navigator.PtoG(pxScaleCenter); + m2::AnyRectD rect = GetTargetRect(); + m2::RectD sizeRect = rect.GetLocalRect(); + sizeRect.Scale(1.0 / factor); + return SetRect(m2::AnyRectD(glbCenter, rect.Angle(), sizeRect), true); + } + else + { + m_navigator.Scale(pxScaleCenter, factor); + return true; + } } -void UserEventStream::SetRect(m2::RectD rect, int zoom, bool applyRotation) +bool UserEventStream::SetCenter(m2::PointD const & center, int zoom, bool isAnim) +{ + m2::RectD rect = df::GetRectForDrawScale(zoom, center); + return SetRect(rect, zoom, true, isAnim); +} + +bool UserEventStream::SetRect(m2::RectD rect, int zoom, bool applyRotation, bool isAnim) { CheckMinGlobalRect(rect); CheckMinMaxVisibleScale(m_isCountryLoaded, rect, zoom); - if (applyRotation) - SetRect(ToRotated(m_navigator, rect)); - else - SetRect(m2::AnyRectD(rect)); + m2::AnyRectD targetRect = applyRotation ? ToRotated(m_navigator, rect) : m2::AnyRectD(rect); + return SetRect(targetRect, isAnim); } -void UserEventStream::SetRect(m2::AnyRectD const & rect) +bool UserEventStream::SetRect(m2::AnyRectD const & rect, bool isAnim) { - double const halfSize = df::VisualParams::Instance().GetTileSize() / 2.0; - m2::RectD etalonRect(-halfSize, -halfSize, halfSize, halfSize); - - m2::PointD const pxCenter = m_navigator.Screen().PixelRect().Center(); - etalonRect.Offset(pxCenter); - - m_navigator.SetFromRects(rect, etalonRect); + if (isAnim) + { + m2::AnyRectD startRect = m_navigator.Screen().GlobalRect(); + double const duration = ModelViewAnimation::GetDuration(startRect, rect, m_navigator.Screen()); + m_animation.reset(new ModelViewAnimation(startRect, rect, duration)); + return false; + } + else + { + m_navigator.SetFromRect(rect); + return true; + } } -void UserEventStream::ProcessTouch(TouchEvent const & touch) +m2::AnyRectD UserEventStream::GetCurrentRect() const +{ + return m_navigator.Screen().GlobalRect(); +} + +m2::AnyRectD UserEventStream::GetTargetRect() const +{ + if (m_animation) + return m_animation->GetTargetRect(); + else + return GetCurrentRect(); +} + +bool UserEventStream::ProcessTouch(TouchEvent const & touch) { ASSERT(touch.m_touches[0].m_id != -1, ()); ASSERT(touch.m_touches[1].m_id == -1 || (touch.m_touches[0].m_id < touch.m_touches[1].m_id), ()); + bool isMapTouch = false; switch (touch.m_type) { case TouchEvent::TOUCH_DOWN: - TouchDown(touch.m_touches); + isMapTouch |= TouchDown(touch.m_touches); break; case TouchEvent::TOUCH_MOVE: - TouchMove(touch.m_touches); + isMapTouch |= TouchMove(touch.m_touches); break; case TouchEvent::TOUCH_CANCEL: - TouchCancel(touch.m_touches); + isMapTouch |= TouchCancel(touch.m_touches); break; case TouchEvent::TOUCH_UP: - TouchUp(touch.m_touches); + isMapTouch |= TouchUp(touch.m_touches); break; default: ASSERT(false, ()); break; } + + return isMapTouch; } -void UserEventStream::TouchDown(array const & touches) +bool UserEventStream::TouchDown(array const & touches) { size_t touchCount = GetValidTouchesCount(touches); + bool isMapTouch = true; if (touchCount == 1) { ASSERT(m_state == STATE_EMPTY, ()); if (!TryBeginFilter(touches[0])) BeginTapDetector(); + else + isMapTouch = false; } else if (touchCount == 2) { @@ -220,11 +256,13 @@ void UserEventStream::TouchDown(array const & touches) } UpdateTouches(touches, touchCount); + return isMapTouch; } -void UserEventStream::TouchMove(array const & touches) +bool UserEventStream::TouchMove(array const & touches) { size_t touchCount = GetValidTouchesCount(touches); + bool isMapTouch = true; switch (m_state) { @@ -236,6 +274,7 @@ void UserEventStream::TouchMove(array const & touches) break; case STATE_FILTER: ASSERT(touchCount == 1, ()); + isMapTouch = false; break; case STATE_TAP_DETECTION: ASSERT(touchCount == 1, ()); @@ -254,11 +293,13 @@ void UserEventStream::TouchMove(array const & touches) } UpdateTouches(touches, touchCount); + return isMapTouch; } -void UserEventStream::TouchCancel(array const & touches) +bool UserEventStream::TouchCancel(array const & touches) { size_t touchCount = GetValidTouchesCount(touches); + bool isMapTouch = true; switch (m_state) { case STATE_EMPTY: @@ -270,6 +311,7 @@ void UserEventStream::TouchCancel(array const & touches) case STATE_TAP_DETECTION: ASSERT(touchCount == 1, ()); CancelTapDetector(); + isMapTouch = false; break; case STATE_DRAG: ASSERT(touchCount == 1, ()); @@ -283,11 +325,13 @@ void UserEventStream::TouchCancel(array const & touches) break; } UpdateTouches(touches, touchCount); + return isMapTouch; } -void UserEventStream::TouchUp(array const & touches) +bool UserEventStream::TouchUp(array const & touches) { size_t touchCount = GetValidTouchesCount(touches); + bool isMapTouch = true; switch (m_state) { case STATE_EMPTY: @@ -296,6 +340,7 @@ void UserEventStream::TouchUp(array const & touches) case STATE_FILTER: ASSERT(touchCount == 1, ()); EndFilter(touches[0]); + isMapTouch = false; break; case STATE_TAP_DETECTION: ASSERT(touchCount == 1, ()); @@ -312,7 +357,9 @@ void UserEventStream::TouchUp(array const & touches) default: break; } + UpdateTouches(touches, touchCount); + return isMapTouch; } void UserEventStream::UpdateTouches(array const & touches, size_t validCount) diff --git a/drape_frontend/user_event_stream.hpp b/drape_frontend/user_event_stream.hpp index 5a2b7eb908..a1bec9e4a5 100644 --- a/drape_frontend/user_event_stream.hpp +++ b/drape_frontend/user_event_stream.hpp @@ -1,7 +1,7 @@ #pragma once #include "drape_frontend/navigator.hpp" -#include "drape_frontend/animation/base_modelview_animation.hpp" +#include "drape_frontend/animation/model_view_animation.hpp" #include "geometry/point2d.hpp" #include "geometry/rect2d.hpp" @@ -45,47 +45,57 @@ struct TouchEvent struct ScaleEvent { - ScaleEvent(double factor, m2::PointD const & pxPoint) + ScaleEvent(double factor, m2::PointD const & pxPoint, bool isAnim) : m_factor(factor) , m_pxPoint(pxPoint) + , m_isAnim(isAnim) { } double m_factor; m2::PointD m_pxPoint; + bool m_isAnim; }; struct SetCenterEvent { - SetCenterEvent(m2::PointD const & center, int zoom) + SetCenterEvent(m2::PointD const & center, int zoom, bool isAnim) : m_center(center) , m_zoom(zoom) + , m_isAnim(isAnim) { } m2::PointD m_center; // center point in mercator int m_zoom; // if zoom == -1, then zoom level will'n change + bool m_isAnim; }; struct SetRectEvent { - SetRectEvent(m2::RectD const & rect, bool rotate, int zoom) + SetRectEvent(m2::RectD const & rect, bool rotate, int zoom, bool isAnim) : m_rect(rect) , m_applyRotation(rotate) , m_zoom(zoom) + , m_isAnim(isAnim) { } m2::RectD m_rect; // destination mercator rect 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; }; struct SetAnyRectEvent { - SetAnyRectEvent(m2::AnyRectD const & rect) : m_rect(rect) {} + SetAnyRectEvent(m2::AnyRectD const & rect, bool isAnim) + : m_rect(rect) + , m_isAnim(isAnim) + {} m2::AnyRectD m_rect; // destination mercator rect + bool m_isAnim; }; struct RotateEvent @@ -168,16 +178,20 @@ public: #endif private: - void SetCenter(m2::PointD const & center, int zoom); - void SetRect(m2::RectD rect, int zoom, bool applyRotation); - void SetRect(m2::AnyRectD const & rect); + bool Scale(m2::PointD const & pxScaleCenter, double factor, bool isAnim); + bool SetCenter(m2::PointD const & center, int zoom, bool isAnim); + bool SetRect(m2::RectD rect, int zoom, bool applyRotation, bool isAnim); + bool SetRect(m2::AnyRectD const & rect, bool isAnim); - void ProcessTouch(TouchEvent const & touch); + m2::AnyRectD GetCurrentRect() const; + m2::AnyRectD GetTargetRect() const; - void TouchDown(array const & touches); - void TouchMove(array const & touches); - void TouchCancel(array const & touches); - void TouchUp(array const & touches); + bool ProcessTouch(TouchEvent const & touch); + + bool TouchDown(array const & touches); + bool TouchMove(array const & touches); + bool TouchCancel(array const & touches); + bool TouchUp(array const & touches); void UpdateTouches(array const & touches, size_t validCount); size_t GetValidTouchesCount(array const & touches) const; @@ -220,7 +234,7 @@ private: array m_touches; size_t m_validTouchesCount; - unique_ptr m_animation; + unique_ptr m_animation; #ifdef DEBUG TTestBridge m_testFn; diff --git a/map/framework.cpp b/map/framework.cpp index 7ab3ea3d95..226778b5de 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -645,7 +645,7 @@ void Framework::LoadState() if (Settings::Get("ScreenClipRect", rect) && df::GetWorldRect().IsRectInside(rect.GetGlobalRect())) { - ShowRect(rect); + CallDrapeFunction(bind(&df::DrapeEngine::SetModelViewAnyRect, _1, rect, false)); } else ShowAll(); @@ -653,7 +653,7 @@ void Framework::LoadState() void Framework::ShowAll() { - CallDrapeFunction(bind(&df::DrapeEngine::SetModelViewAnyRect, _1, m2::AnyRectD(m_model.GetWorldRect()))); + CallDrapeFunction(bind(&df::DrapeEngine::SetModelViewAnyRect, _1, m2::AnyRectD(m_model.GetWorldRect()), false)); } m2::PointD Framework::GetPixelCenter() const @@ -668,7 +668,7 @@ m2::PointD const & Framework::GetViewportCenter() const void Framework::SetViewportCenter(m2::PointD const & pt) { - CallDrapeFunction(bind(&df::DrapeEngine::SetModelViewCenter, _1, pt, -1)); + CallDrapeFunction(bind(&df::DrapeEngine::SetModelViewCenter, _1, pt, -1, true)); } m2::RectD Framework::GetCurrentViewport() const @@ -679,17 +679,17 @@ m2::RectD Framework::GetCurrentViewport() const void Framework::ShowRect(double lat, double lon, double zoom) { m2::PointD center(MercatorBounds::FromLatLon(lat, lon)); - CallDrapeFunction(bind(&df::DrapeEngine::SetModelViewCenter, _1, center, zoom)); + CallDrapeFunction(bind(&df::DrapeEngine::SetModelViewCenter, _1, center, zoom, true)); } void Framework::ShowRect(m2::RectD const & rect, int maxScale) { - CallDrapeFunction(bind(&df::DrapeEngine::SetModelViewRect, _1, rect, true, maxScale)); + CallDrapeFunction(bind(&df::DrapeEngine::SetModelViewRect, _1, rect, true, maxScale, true)); } void Framework::ShowRect(m2::AnyRectD const & rect) { - CallDrapeFunction(bind(&df::DrapeEngine::SetModelViewAnyRect, _1, rect)); + CallDrapeFunction(bind(&df::DrapeEngine::SetModelViewAnyRect, _1, rect, true)); } void Framework::GetTouchRect(m2::PointD const & center, uint32_t pxRadius, m2::AnyRectD & rect) @@ -740,17 +740,17 @@ void Framework::Scale(EScaleMode mode) void Framework::Scale(Framework::EScaleMode mode, m2::PointD const & pxPoint) { - Scale(ScaleModeToFactor(mode), pxPoint); + Scale(ScaleModeToFactor(mode), pxPoint, true); } void Framework::Scale(double factor) { - Scale(factor, m_currentMovelView.PixelRect().Center()); + Scale(factor, m_currentMovelView.PixelRect().Center(), true); } -void Framework::Scale(double factor, m2::PointD const & pxPoint) +void Framework::Scale(double factor, m2::PointD const & pxPoint, bool isAnim) { - CallDrapeFunction(bind(&df::DrapeEngine::Scale, _1, factor, pxPoint)); + CallDrapeFunction(bind(&df::DrapeEngine::Scale, _1, factor, pxPoint, isAnim)); } void Framework::TouchEvent(df::TouchEvent const & touch) diff --git a/map/framework.hpp b/map/framework.hpp index b0258c396a..8efebf6649 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -381,7 +381,7 @@ public: void Scale(EScaleMode mode); void Scale(EScaleMode mode, m2::PointD const & pxPoint); void Scale(double factor); - void Scale(double factor, m2::PointD const & pxPoint); + void Scale(double factor, m2::PointD const & pxPoint, bool isAnim); void TouchEvent(df::TouchEvent const & touch); //@} diff --git a/qt/draw_widget.cpp b/qt/draw_widget.cpp index 24aff2c95c..c1e37346b2 100644 --- a/qt/draw_widget.cpp +++ b/qt/draw_widget.cpp @@ -265,7 +265,7 @@ bool IsLocationEmulation(QMouseEvent * e) void DrawWidget::wheelEvent(QWheelEvent * e) { - m_framework->Scale(exp(e->delta() / 360.0), m2::PointD(L2D(e->x()), L2D(e->y()))); + m_framework->Scale(exp(e->delta() / 360.0), m2::PointD(L2D(e->x()), L2D(e->y())), false); } bool DrawWidget::Search(search::SearchParams params)