diff --git a/anim/angle_interpolation.hpp b/anim/angle_interpolation.hpp index 55a2102557..063fee2266 100644 --- a/anim/angle_interpolation.hpp +++ b/anim/angle_interpolation.hpp @@ -1,16 +1,11 @@ #pragma once #include "task.hpp" -#include "../std/function.hpp" namespace anim { class AngleInterpolation : public Task { - public: - - typedef function TCallback; - private: double m_startAngle; diff --git a/anim/anim.pro b/anim/anim.pro index 477a63413a..512015ab9d 100644 --- a/anim/anim.pro +++ b/anim/anim.pro @@ -13,8 +13,10 @@ HEADERS += \ controller.hpp \ task.hpp \ angle_interpolation.hpp \ + segment_interpolation.hpp \ SOURCES += \ controller.cpp \ task.cpp \ angle_interpolation.cpp \ + segment_interpolation.cpp \ diff --git a/anim/segment_interpolation.cpp b/anim/segment_interpolation.cpp new file mode 100644 index 0000000000..ae7fbcb974 --- /dev/null +++ b/anim/segment_interpolation.cpp @@ -0,0 +1,48 @@ +#include "segment_interpolation.hpp" + +namespace anim +{ + SegmentInterpolation::SegmentInterpolation(m2::PointD const & startPt, + m2::PointD const & endPt, + double interval, + m2::PointD & outPt) + : m_startPt(startPt), + m_endPt(endPt), + m_interval(interval), + m_outPt(outPt) + { + m_deltaPt = m_endPt - m_startPt; + } + + void SegmentInterpolation::OnStart(double ts) + { + m_startTime = ts; + m_outPt = m_startPt; + Task::OnStart(ts); + } + + void SegmentInterpolation::OnStep(double ts) + { + if (ts - m_startTime > m_interval) + { + End(); + return; + } + + if (!IsRunning()) + return; + + double elapsedSec = ts - m_startTime; + + m_outPt = m_startPt + m_deltaPt * (elapsedSec / m_interval); + + Task::OnStep(ts); + } + + void SegmentInterpolation::OnEnd(double ts) + { + // ensuring that the final value was reached + m_outPt = m_endPt; + Task::OnEnd(ts); + } +} diff --git a/anim/segment_interpolation.hpp b/anim/segment_interpolation.hpp new file mode 100644 index 0000000000..26f22f4934 --- /dev/null +++ b/anim/segment_interpolation.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include "task.hpp" +#include "../geometry/point2d.hpp" + +namespace anim +{ + class SegmentInterpolation : public Task + { + private: + + m2::PointD m_startPt; + m2::PointD m_endPt; + m2::PointD m_deltaPt; + m2::PointD & m_outPt; + double m_startTime; + double m_interval; + + public: + + SegmentInterpolation(m2::PointD const & startPt, + m2::PointD const & endPt, + double interval, + m2::PointD & outPt); + + void OnStart(double ts); + void OnStep(double ts); + void OnEnd(double ts); + }; +} + diff --git a/map/map.pro b/map/map.pro index dc1cf6b04b..9de0b02079 100644 --- a/map/map.pro +++ b/map/map.pro @@ -52,6 +52,7 @@ HEADERS += \ compass_arrow.hpp \ compass_filter.hpp \ animator.hpp \ + move_screen_task.hpp SOURCES += \ feature_vec_model.cpp \ @@ -95,6 +96,7 @@ SOURCES += \ compass_arrow.cpp \ compass_filter.cpp \ animator.cpp \ + move_screen_task.cpp !iphone*:!bada*:!android* { HEADERS += qgl_render_context.hpp @@ -113,3 +115,5 @@ SOURCES += \ + + diff --git a/map/move_screen_task.cpp b/map/move_screen_task.cpp new file mode 100644 index 0000000000..2a292f1cf3 --- /dev/null +++ b/map/move_screen_task.cpp @@ -0,0 +1,26 @@ +#include "move_screen_task.hpp" + +#include "framework.hpp" + +MoveScreenTask::MoveScreenTask(Framework * framework, + m2::PointD const & startPt, + m2::PointD const & endPt, + double interval) + : anim::SegmentInterpolation(startPt, + endPt, + interval, + m_outPt), + m_framework(framework) +{} + +void MoveScreenTask::OnStep(double ts) +{ + anim::SegmentInterpolation::OnStep(ts); + m_framework->GetNavigator().SetOrg(m_outPt); +} + +void MoveScreenTask::OnEnd(double ts) +{ + anim::SegmentInterpolation::OnEnd(ts); + m_framework->GetNavigator().SetOrg(m_outPt); +} diff --git a/map/move_screen_task.hpp b/map/move_screen_task.hpp new file mode 100644 index 0000000000..7de6bc0c73 --- /dev/null +++ b/map/move_screen_task.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "../anim/segment_interpolation.hpp" + +class Framework; + +class MoveScreenTask : public anim::SegmentInterpolation +{ +private: + + Framework * m_framework; + m2::PointD m_outPt; + +public: + + MoveScreenTask(Framework * framework, + m2::PointD const & startPt, + m2::PointD const & endPt, + double interval); + + void OnStep(double ts); + void OnEnd(double ts); +}; diff --git a/map/navigator.cpp b/map/navigator.cpp index 0a11f55b48..3883f04ddd 100644 --- a/map/navigator.cpp +++ b/map/navigator.cpp @@ -588,6 +588,11 @@ void Navigator::SetAngle(double angle) m_Screen.SetAngle(angle); } +void Navigator::SetOrg(m2::PointD const & org) +{ + m_Screen.SetOrg(org); +} + void Navigator::Move(double azDir, double factor) { m2::RectD const r = m_Screen.ClipRect(); diff --git a/map/navigator.hpp b/map/navigator.hpp index da7882790f..634b2f495e 100644 --- a/map/navigator.hpp +++ b/map/navigator.hpp @@ -48,6 +48,7 @@ public: void Scale(double scale); void Rotate(double angle); void SetAngle(double angle); + void SetOrg(m2::PointD const & org); void Move(double azDir, double factor);