diff options
author | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2016-05-25 18:15:24 +0300 |
---|---|---|
committer | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2016-05-25 19:29:11 +0300 |
commit | f6a3cae058e954d663ff7e75288a92fd63a65d7d (patch) | |
tree | 96e18f595d7eb0263cc88cd0f7980bd824d4d90c /drape_frontend/animation | |
parent | 0930015d6ca1eee7f96853afb94cdec3ad395f05 (diff) |
Calculate target rect inside the animation system.
Diffstat (limited to 'drape_frontend/animation')
-rw-r--r-- | drape_frontend/animation/animation.cpp | 5 | ||||
-rw-r--r-- | drape_frontend/animation/animation.hpp | 2 | ||||
-rw-r--r-- | drape_frontend/animation/arrow_animation.cpp | 14 | ||||
-rw-r--r-- | drape_frontend/animation/arrow_animation.hpp | 3 | ||||
-rw-r--r-- | drape_frontend/animation/follow_animation.cpp | 26 | ||||
-rw-r--r-- | drape_frontend/animation/follow_animation.hpp | 2 | ||||
-rw-r--r-- | drape_frontend/animation/interpolators.hpp | 3 | ||||
-rw-r--r-- | drape_frontend/animation/linear_animation.cpp | 16 | ||||
-rw-r--r-- | drape_frontend/animation/linear_animation.hpp | 3 | ||||
-rw-r--r-- | drape_frontend/animation/perspective_animation.cpp | 19 | ||||
-rw-r--r-- | drape_frontend/animation/perspective_animation.hpp | 2 | ||||
-rw-r--r-- | drape_frontend/animation/scale_animation.cpp | 18 | ||||
-rw-r--r-- | drape_frontend/animation/scale_animation.hpp | 3 | ||||
-rw-r--r-- | drape_frontend/animation/sequence_animation.cpp | 25 | ||||
-rw-r--r-- | drape_frontend/animation/sequence_animation.hpp | 2 |
15 files changed, 131 insertions, 12 deletions
diff --git a/drape_frontend/animation/animation.cpp b/drape_frontend/animation/animation.cpp index 5bf4d09cff..6949e249d7 100644 --- a/drape_frontend/animation/animation.cpp +++ b/drape_frontend/animation/animation.cpp @@ -20,4 +20,9 @@ bool Animation::CouldBeBlendedWith(Animation const & animation) const m_couldBeBlended && animation.m_couldBeBlended); } +bool Animation::HasTargetProperty(TObject object, TProperty property) const +{ + return HasProperty(object, property); +} + } // namespace df diff --git a/drape_frontend/animation/animation.hpp b/drape_frontend/animation/animation.hpp index 79646de28b..0d62e3e037 100644 --- a/drape_frontend/animation/animation.hpp +++ b/drape_frontend/animation/animation.hpp @@ -118,6 +118,7 @@ public: virtual bool HasObject(TObject object) const = 0; virtual TObjectProperties const & GetProperties(TObject object) const = 0; virtual bool HasProperty(TObject object, TProperty property) const = 0; + virtual bool HasTargetProperty(TObject object, TProperty property) const; virtual void SetMaxDuration(double maxDuration) = 0; virtual double GetDuration() const = 0; @@ -127,6 +128,7 @@ public: virtual void Finish() { OnFinish(); } virtual bool GetProperty(TObject object, TProperty property, PropertyValue & value) const = 0; + virtual bool GetTargetProperty(TObject object, TProperty property, PropertyValue & value) const = 0; void SetOnStartAction(TAction const & action) { m_onStartAction = action; } void SetOnFinishAction(TAction const & action) { m_onFinishAction = action; } diff --git a/drape_frontend/animation/arrow_animation.cpp b/drape_frontend/animation/arrow_animation.cpp index 8116b18861..27c61409eb 100644 --- a/drape_frontend/animation/arrow_animation.cpp +++ b/drape_frontend/animation/arrow_animation.cpp @@ -80,6 +80,16 @@ bool ArrowAnimation::IsFinished() const bool ArrowAnimation::GetProperty(TObject object, TProperty property, PropertyValue & value) const { + return GetProperty(object, property, false /* targetValue */, value); +} + +bool ArrowAnimation::GetTargetProperty(TObject object, TProperty property, PropertyValue & value) const +{ + return GetProperty(object, property, true /* targetValue */, value); +} + +bool ArrowAnimation::GetProperty(TObject object, TProperty property, bool targetValue, PropertyValue & value) const +{ ASSERT_EQUAL(object, Animation::MyPositionArrow, ()); switch (property) @@ -87,14 +97,14 @@ bool ArrowAnimation::GetProperty(TObject object, TProperty property, PropertyVal case Animation::Position: if (m_positionInterpolator.IsActive()) { - value = PropertyValue(m_positionInterpolator.GetPosition()); + value = PropertyValue(targetValue ? m_positionInterpolator.GetTargetPosition() : m_positionInterpolator.GetPosition()); return true; } return false; case Animation::Angle: if (m_angleInterpolator.IsActive()) { - value = PropertyValue(m_angleInterpolator.GetAngle()); + value = PropertyValue(targetValue ? m_angleInterpolator.GetTargetAngle() : m_angleInterpolator.GetAngle()); return true; } return false; diff --git a/drape_frontend/animation/arrow_animation.hpp b/drape_frontend/animation/arrow_animation.hpp index ef550a4faf..5d20d85ace 100644 --- a/drape_frontend/animation/arrow_animation.hpp +++ b/drape_frontend/animation/arrow_animation.hpp @@ -27,8 +27,11 @@ public: void Finish() override; bool GetProperty(TObject object, TProperty property, PropertyValue & value) const override; + bool GetTargetProperty(TObject object, TProperty property, PropertyValue & value) const override; private: + bool GetProperty(TObject object, TProperty property, bool targetValue, PropertyValue & value) const; + TAnimObjects m_objects; TObjectProperties m_properties; PositionInterpolator m_positionInterpolator; diff --git a/drape_frontend/animation/follow_animation.cpp b/drape_frontend/animation/follow_animation.cpp index 055db50f41..a268b286b5 100644 --- a/drape_frontend/animation/follow_animation.cpp +++ b/drape_frontend/animation/follow_animation.cpp @@ -114,21 +114,39 @@ m2::PointD MapFollowAnimation::CalculateCenter(double scale, m2::RectD const & p bool MapFollowAnimation::GetProperty(TObject object, TProperty property, PropertyValue & value) const { + return GetProperty(object, property, false /* targetValue */, value); +} + +bool MapFollowAnimation::GetTargetProperty(TObject object, TProperty property, PropertyValue & value) const +{ + return GetProperty(object, property, true /* targetValue */, value); +} + +bool MapFollowAnimation::GetProperty(TObject object, TProperty property, bool targetValue, PropertyValue & value) const +{ if (property == Animation::Position) { m2::RectD const pixelRect = AnimationSystem::Instance().GetLastScreen().PixelRect(); - value = PropertyValue(CalculateCenter(m_scaleInterpolator.GetScale(), pixelRect, m_globalPosition, - m_pixelPosInterpolator.GetPosition(), m_angleInterpolator.GetAngle())); + if (targetValue) + { + value = PropertyValue(CalculateCenter(m_scaleInterpolator.GetTargetScale(), pixelRect, m_globalPosition, + m_pixelPosInterpolator.GetTargetPosition(), m_angleInterpolator.GetTargetAngle())); + } + else + { + value = PropertyValue(CalculateCenter(m_scaleInterpolator.GetScale(), pixelRect, m_globalPosition, + m_pixelPosInterpolator.GetPosition(), m_angleInterpolator.GetAngle())); + } return true; } if (property == Animation::Angle) { - value = PropertyValue(m_angleInterpolator.GetAngle()); + value = PropertyValue(targetValue ? m_angleInterpolator.GetTargetAngle() : m_angleInterpolator.GetAngle()); return true; } if (property == Animation::Scale) { - value = PropertyValue(m_scaleInterpolator.GetScale()); + value = PropertyValue(targetValue ? m_scaleInterpolator.GetTargetScale() : m_scaleInterpolator.GetScale()); return true; } ASSERT(false, ("Wrong property:", property)); diff --git a/drape_frontend/animation/follow_animation.hpp b/drape_frontend/animation/follow_animation.hpp index bf83492139..fdfd38634b 100644 --- a/drape_frontend/animation/follow_animation.hpp +++ b/drape_frontend/animation/follow_animation.hpp @@ -45,11 +45,13 @@ public: bool IsFinished() const override; bool GetProperty(TObject object, TProperty property, PropertyValue & value) const override; + bool GetTargetProperty(TObject object, TProperty property, PropertyValue & value) const override; bool HasScale() const; bool HasPixelOffset() const; private: + bool GetProperty(TObject object, TProperty property, bool targetValue, PropertyValue & value) const; double CalculateDuration() const; ScaleInterpolator m_scaleInterpolator; diff --git a/drape_frontend/animation/interpolators.hpp b/drape_frontend/animation/interpolators.hpp index 387190c36f..ffffd25b27 100644 --- a/drape_frontend/animation/interpolators.hpp +++ b/drape_frontend/animation/interpolators.hpp @@ -65,6 +65,7 @@ public: void Finish() override; m2::PointD GetPosition() const { return m_position; } + m2::PointD GetTargetPosition() const { return m_endPosition; } private: m2::PointD m_startPosition; @@ -88,6 +89,7 @@ public: void Finish() override; double GetScale() const { return m_scale; } + double GetTargetScale() const { return m_endScale; } private: double m_startScale; @@ -112,6 +114,7 @@ public: void Finish() override; double GetAngle() const { return m_angle; } + double GetTargetAngle() const { return m_endAngle; } private: double m_startAngle; diff --git a/drape_frontend/animation/linear_animation.cpp b/drape_frontend/animation/linear_animation.cpp index d45aff0f5c..7ff23dcdb0 100644 --- a/drape_frontend/animation/linear_animation.cpp +++ b/drape_frontend/animation/linear_animation.cpp @@ -127,6 +127,16 @@ bool MapLinearAnimation::IsFinished() const bool MapLinearAnimation::GetProperty(TObject object, TProperty property, PropertyValue & value) const { + return GetProperty(object, property, false /* targetValue */, value); +} + +bool MapLinearAnimation::GetTargetProperty(TObject object, TProperty property, PropertyValue & value) const +{ + return GetProperty(object, property, true /* targetValue */, value); +} + +bool MapLinearAnimation::GetProperty(TObject object, TProperty property, bool targetValue, PropertyValue & value) const +{ ASSERT_EQUAL(object, Animation::MapPlane, ()); switch (property) @@ -134,21 +144,21 @@ bool MapLinearAnimation::GetProperty(TObject object, TProperty property, Propert case Animation::Position: if (m_positionInterpolator.IsActive()) { - value = PropertyValue(m_positionInterpolator.GetPosition()); + value = PropertyValue(targetValue ? m_positionInterpolator.GetTargetPosition() : m_positionInterpolator.GetPosition()); return true; } return false; case Animation::Scale: if (m_scaleInterpolator.IsActive()) { - value = PropertyValue(m_scaleInterpolator.GetScale()); + value = PropertyValue(targetValue ? m_scaleInterpolator.GetTargetScale() : m_scaleInterpolator.GetScale()); return true; } return false; case Animation::Angle: if (m_angleInterpolator.IsActive()) { - value = PropertyValue(m_angleInterpolator.GetAngle()); + value = PropertyValue(targetValue ? m_angleInterpolator.GetTargetAngle() : m_angleInterpolator.GetAngle()); return true; } return false; diff --git a/drape_frontend/animation/linear_animation.hpp b/drape_frontend/animation/linear_animation.hpp index fec452d9e3..2fadc13e9c 100644 --- a/drape_frontend/animation/linear_animation.hpp +++ b/drape_frontend/animation/linear_animation.hpp @@ -41,10 +41,13 @@ public: bool IsFinished() const override; bool GetProperty(TObject object, TProperty property, PropertyValue & value) const override; + bool GetTargetProperty(TObject object, TProperty property, PropertyValue & value) const override; void SetMaxScaleDuration(double maxDuration); private: + bool GetProperty(TObject object, TProperty property, bool targetValue, PropertyValue & value) const; + AngleInterpolator m_angleInterpolator; PositionInterpolator m_positionInterpolator; ScaleInterpolator m_scaleInterpolator; diff --git a/drape_frontend/animation/perspective_animation.cpp b/drape_frontend/animation/perspective_animation.cpp index 7b75be0e5e..73feabbaba 100644 --- a/drape_frontend/animation/perspective_animation.cpp +++ b/drape_frontend/animation/perspective_animation.cpp @@ -35,6 +35,11 @@ bool PerspectiveSwitchAnimation::HasProperty(TObject object, TProperty property) return HasObject(object) && m_properties.find(property) != m_properties.end(); } +bool PerspectiveSwitchAnimation::HasTargetProperty(TObject object, TProperty property) const +{ + return HasObject(object) && property == Animation::SwitchPerspective; +} + void PerspectiveSwitchAnimation::Advance(double elapsedSeconds) { m_angleInterpolator.Advance(elapsedSeconds); @@ -75,6 +80,20 @@ bool PerspectiveSwitchAnimation::IsFinished() const return m_angleInterpolator.IsFinished(); } +bool PerspectiveSwitchAnimation::GetTargetProperty(TObject object, TProperty property, PropertyValue & value) const +{ + ASSERT_EQUAL(object, Animation::MapPlane, ()); + + if (property == Animation::SwitchPerspective) + { + value = PropertyValue(SwitchPerspectiveParams(m_isEnablePerspectiveAnim, m_endAngle, m_endAngle, m_angleFOV)); + return true; + } + + ASSERT(false, ("Wrong property:", property)); + return false; +} + bool PerspectiveSwitchAnimation::GetProperty(TObject object, TProperty property, PropertyValue & value) const { ASSERT_EQUAL(object, Animation::MapPlane, ()); diff --git a/drape_frontend/animation/perspective_animation.hpp b/drape_frontend/animation/perspective_animation.hpp index 93939dc6b7..00671a450d 100644 --- a/drape_frontend/animation/perspective_animation.hpp +++ b/drape_frontend/animation/perspective_animation.hpp @@ -27,6 +27,7 @@ public: TObjectProperties const & GetProperties(TObject object) const override; bool HasProperty(TObject object, TProperty property) const override; + bool HasTargetProperty(TObject object, TProperty property) const override; void Advance(double elapsedSeconds) override; void Finish() override; @@ -39,6 +40,7 @@ public: bool IsFinished() const override; bool GetProperty(TObject object, TProperty property, PropertyValue & value) const override; + bool GetTargetProperty(TObject object, TProperty property, PropertyValue & value) const override; private: AngleInterpolator m_angleInterpolator; diff --git a/drape_frontend/animation/scale_animation.cpp b/drape_frontend/animation/scale_animation.cpp index 5d998273c3..92f814df1d 100644 --- a/drape_frontend/animation/scale_animation.cpp +++ b/drape_frontend/animation/scale_animation.cpp @@ -56,22 +56,34 @@ bool MapScaleAnimation::IsFinished() const return m_scaleInterpolator.IsFinished(); } -bool MapScaleAnimation::GetProperty(TObject object, TProperty property, PropertyValue & value) const +bool MapScaleAnimation::GetProperty(TObject object, TProperty property, bool targetValue, PropertyValue & value) const { + ASSERT_EQUAL(object, Animation::MapPlane, ()); + if (property == Animation::Position) { ScreenBase screen = AnimationSystem::Instance().GetLastScreen(); - screen.SetScale(m_scaleInterpolator.GetScale()); + screen.SetScale(targetValue ? m_scaleInterpolator.GetTargetScale() : m_scaleInterpolator.GetScale()); value = PropertyValue(screen.PtoG(screen.GtoP(m_globalScaleCenter) + m_pixelCenterOffset)); return true; } if (property == Animation::Scale) { - value = PropertyValue(m_scaleInterpolator.GetScale()); + value = PropertyValue(targetValue ? m_scaleInterpolator.GetTargetScale() : m_scaleInterpolator.GetScale()); return true; } ASSERT(false, ("Wrong property:", property)); return false; } +bool MapScaleAnimation::GetTargetProperty(TObject object, TProperty property, PropertyValue & value) const +{ + return GetProperty(object, property, true /* targetValue */, value); +} + +bool MapScaleAnimation::GetProperty(TObject object, TProperty property, PropertyValue & value) const +{ + return GetProperty(object, property, false /* targetValue */, value); +} + } // namespace df diff --git a/drape_frontend/animation/scale_animation.hpp b/drape_frontend/animation/scale_animation.hpp index dc6a73f7af..07706c604a 100644 --- a/drape_frontend/animation/scale_animation.hpp +++ b/drape_frontend/animation/scale_animation.hpp @@ -35,8 +35,11 @@ public: bool IsFinished() const override; bool GetProperty(TObject object, TProperty property, PropertyValue & value) const override; + bool GetTargetProperty(TObject object, TProperty property, PropertyValue & value) const override; private: + bool GetProperty(TObject object, TProperty property, bool targetValue, PropertyValue & value) const; + ScaleInterpolator m_scaleInterpolator; m2::PointD const m_pixelCenterOffset; m2::PointD const m_globalScaleCenter; diff --git a/drape_frontend/animation/sequence_animation.cpp b/drape_frontend/animation/sequence_animation.cpp index 2ccbb96560..3185e5bcfb 100644 --- a/drape_frontend/animation/sequence_animation.cpp +++ b/drape_frontend/animation/sequence_animation.cpp @@ -45,6 +45,17 @@ bool SequenceAnimation::HasProperty(TObject object, TProperty property) const return m_animations.front()->HasProperty(object, property); } +bool SequenceAnimation::HasTargetProperty(TObject object, TProperty property) const +{ + ASSERT(!m_animations.empty(), ()); + for (auto const & anim : m_animations) + { + if (anim->HasTargetProperty(object, property)) + return true; + } + return false; +} + void SequenceAnimation::SetMaxDuration(double maxDuration) { ASSERT(false, ("Not implemented")); @@ -69,6 +80,20 @@ bool SequenceAnimation::GetProperty(TObject object, TProperty property, Property return m_animations.front()->GetProperty(object, property, value); } +bool SequenceAnimation::GetTargetProperty(TObject object, TProperty property, PropertyValue & value) const +{ + ASSERT(!m_animations.empty(), ()); + + for (auto it = m_animations.rbegin(); it != m_animations.rend(); ++it) + { + auto const & anim = *it; + if (anim->HasTargetProperty(object, property)) + return anim->GetTargetProperty(object, property, value); + } + + return false; +} + void SequenceAnimation::AddAnimation(drape_ptr<Animation> animation) { m_animations.push_back(move(animation)); diff --git a/drape_frontend/animation/sequence_animation.hpp b/drape_frontend/animation/sequence_animation.hpp index fe1c85d0fc..2fa353cce6 100644 --- a/drape_frontend/animation/sequence_animation.hpp +++ b/drape_frontend/animation/sequence_animation.hpp @@ -18,6 +18,7 @@ public: bool HasObject(TObject object) const override; TObjectProperties const & GetProperties(TObject object) const override; bool HasProperty(TObject object, TProperty property) const override; + bool HasTargetProperty(TObject object, TProperty property) const override; string const & GetCustomType() const; void SetCustomType(string const & type); @@ -27,6 +28,7 @@ public: bool IsFinished() const override; bool GetProperty(TObject object, TProperty property, PropertyValue &value) const override; + bool GetTargetProperty(TObject object, TProperty property, PropertyValue &value) const override; void AddAnimation(drape_ptr<Animation> animation); |