1 #ifndef DALI_INTERNAL_KEY_FRAME_CHANNEL_H
2 #define DALI_INTERNAL_KEY_FRAME_CHANNEL_H
5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
25 #include <dali/internal/event/animation/progress-value.h>
26 #include <dali/public-api/animation/animation.h>
27 #include <dali/public-api/common/vector-wrapper.h>
34 struct KeyFrameChannel
36 using ProgressValues = std::vector<ProgressValue<V>>;
38 bool IsActive(float progress) const
40 if(!mValues.empty() && (progress >= mValues[0].GetProgress()))
47 V GetValue(float progress, Dali::Animation::Interpolation interpolation) const
51 if(progress >= mValues.back().GetProgress())
53 interpolatedV = mValues.back().GetValue();
57 // Find lowest element s.t. progress is greater than progress.
58 // So start->GetProgress() <= progress < end->GetProgress() is satisfied.
59 auto end = std::lower_bound(mValues.begin(), mValues.end(), progress, [](const auto& element, const float& progress) { return element.GetProgress() <= progress; });
62 const bool validInterval = (end != mValues.end()) && (start->GetProgress() <= progress);
66 float frameProgress = (progress - start->GetProgress()) / (end->GetProgress() - start->GetProgress());
67 if(interpolation == Dali::Animation::LINEAR)
69 Interpolate(interpolatedV, start->GetValue(), end->GetValue(), frameProgress);
73 //Calculate prev and next values
75 if(start != mValues.begin())
77 prev = (start - 1)->GetValue();
81 //Project next value through start point
82 prev = start->GetValue() + (start->GetValue() - (start + 1)->GetValue());
86 if(end != mValues.end() - 1)
88 next = (end + 1)->GetValue();
92 //Project prev value through end point
93 next = end->GetValue() + (end->GetValue() - (end - 1)->GetValue());
96 CubicInterpolate(interpolatedV, prev, start->GetValue(), end->GetValue(), next, frameProgress);
100 return interpolatedV;
103 ProgressValues mValues;
106 } // namespace Internal
109 #endif // DALI_INTERNAL_KEY_FRAME_CHANNEL_H