From ccdb358857ca68add99ee9abd462a6bd7cda3064 Mon Sep 17 00:00:00 2001 From: ExMix Date: Tue, 9 Jun 2015 12:37:50 +0300 Subject: [PATCH] [drape] helper class for create chain of animations --- drape_frontend/animation/value_mapping.hpp | 72 ++++++++++++++++++++++ drape_frontend/drape_frontend.pro | 13 ++-- 2 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 drape_frontend/animation/value_mapping.hpp diff --git a/drape_frontend/animation/value_mapping.hpp b/drape_frontend/animation/value_mapping.hpp new file mode 100644 index 0000000000..5c8cbe2360 --- /dev/null +++ b/drape_frontend/animation/value_mapping.hpp @@ -0,0 +1,72 @@ +#pragma once + +#include "base/buffer_vector.hpp" +#include "base/logging.hpp" + +namespace df +{ + +template +class ValueMapping +{ + /// double = interpolation point [0.0, 1.0] + /// TValue = output value + using TRangePoint = pair; + using TRangeVector = buffer_vector; + using TRangeIter = typename TRangeVector::const_iterator; +public: + ValueMapping() = default; + + void AddRangePoint(double t, TValue const & v) + { +#ifdef DEBUG + if (!m_ranges.empty()) + ASSERT(m_ranges.back().first < t, ()); +#endif + m_ranges.emplace_back(t, v); + } + + TValue GetValue(double t) + { + TRangePoint startPoint, endPoint; + GetRangePoints(t, startPoint, endPoint); + + double normT = t - startPoint.first; + double rangeT = endPoint.first - startPoint.first; + double rangeV = endPoint.second - startPoint.second; + + return startPoint.second + rangeV * normT / rangeT; + } + +private: + void GetRangePoints(double t, TRangePoint & startPoint, TRangePoint & endPoint) + { + ASSERT(t >= 0.0 && t <= 1.0, ()); + ASSERT(m_ranges.size() > 1, ()); + + TRangeIter startIter = m_ranges.begin(); + if (t < startIter->first) + { + startPoint.first = 0.0; + startPoint.second = TValue(); + endPoint = *startIter; + return; + } + + TRangeIter endIter = startIter + 1; + while (t > endIter->first) + { + endIter++; + ASSERT(m_ranges.end() != endIter, ()); + } + + ASSERT(startIter->first <= t && t <= endIter->first, ()); + startPoint = *startIter; + endPoint = *endIter; + } + +private: + TRangeVector m_ranges; +}; + +} diff --git a/drape_frontend/drape_frontend.pro b/drape_frontend/drape_frontend.pro index 7badf3de55..9f3b38c3a1 100755 --- a/drape_frontend/drape_frontend.pro +++ b/drape_frontend/drape_frontend.pro @@ -14,6 +14,7 @@ SOURCES += \ animation/interpolations.cpp \ animation/model_view_animation.cpp \ animation/opacity_animation.cpp \ + animation/show_hide_animation.cpp \ apply_feature_functors.cpp \ area_shape.cpp \ backend_renderer.cpp \ @@ -37,7 +38,9 @@ SOURCES += \ read_manager.cpp \ read_mwm_task.cpp \ render_group.cpp \ + render_node.cpp \ rule_drawer.cpp \ + selection_shape.cpp \ stylist.cpp \ text_layout.cpp \ text_shape.cpp \ @@ -52,9 +55,6 @@ SOURCES += \ user_marks_provider.cpp \ viewport.cpp \ visual_params.cpp \ - selection_shape.cpp \ - animation/show_hide_animation.cpp \ - render_node.cpp HEADERS += \ animation/base_interpolator.hpp \ @@ -62,6 +62,8 @@ HEADERS += \ animation/interpolations.hpp \ animation/model_view_animation.hpp \ animation/opacity_animation.hpp \ + animation/show_hide_animation.hpp \ + animation/value_mapping.hpp \ apply_feature_functors.hpp \ area_shape.hpp \ backend_renderer.hpp \ @@ -89,7 +91,9 @@ HEADERS += \ read_manager.hpp \ read_mwm_task.hpp \ render_group.hpp \ + render_node.hpp \ rule_drawer.hpp \ + selection_shape.hpp \ shape_view_params.hpp \ stylist.hpp \ text_layout.hpp \ @@ -105,6 +109,3 @@ HEADERS += \ user_marks_provider.hpp \ viewport.hpp \ visual_params.hpp \ - selection_shape.hpp \ - animation/show_hide_animation.hpp \ - render_node.hpp