2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiAnim_AnimationBaseImpl.cpp
20 * @brief This file contains implementation of _AnimationBaseImpl class
22 * This file contains implementation _AnimationBaseImpl class.
25 #include <FBaseSysLog.h>
26 #include <FBaseColIMapEnumerator.h>
27 #include <FBaseColIListT.h>
28 #include <FBaseColArrayList.h>
29 #include <FBaseColHashMapT.h>
30 #include <FBaseFloatComparer.h>
31 #include <FBaseComparerT.h>
33 #include <FUiAnimVisualElementAnimation.h>
34 #include <FUiAnimBezierTimingFunction.h>
36 #include "FUiAnim_AnimationBaseImpl.h"
39 using namespace Tizen::Ui::Animations;
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
44 #define INTERPOLATOR_LINEAR L"Linear"
45 #define INTERPOLATOR_EASEIN L"EaseIn"
46 #define INTERPOLATOR_EASEOUT L"EaseOut"
47 #define INTERPOLATOR_EASEINOUT L"EaseInOut"
48 #define INTERPOLATOR_DISCRETE L"Discrete"
49 #define INTERPOLATOR_BEZIER L"Bezier"
52 namespace Tizen { namespace Ui { namespace Animations
55 _AnimationBaseImpl::_AnimationBaseImpl(AnimationBase* pAnimationBase)
56 : controlPointTime1(0.0)
57 , controlPointValue1(0.0)
58 , controlPointTime2(0.0)
59 , controlPointValue2(0.0)
60 , interpolator(ANIMATION_INTERPOLATOR_LINEAR)
69 , __pAnimationBase(pAnimationBase)
74 _AnimationBaseImpl::~_AnimationBaseImpl(void)
76 result r = RemoveAllKeyFrames();
78 SysTryReturnVoidResult(NID_UI_ANIM, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
82 _AnimationBaseImpl::Construct(void)
84 return keyFrameList.Construct();
89 _AnimationBaseImpl::RemoveKeyFrame(long time)
91 SysTryReturnResult(NID_UI_ANIM, (time > 0 && time <= duration), E_INVALID_ARG, "Invalid argument(s) is used. time =%ld", time);
97 r = keyFrameList.GetValue(time, pObj);
98 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_OBJ_NOT_FOUND, "Key frame is not found. time = %ld", time);
102 keyFrameList.Remove(time);
108 _AnimationBaseImpl::RemoveKeyFrameAt(int index)
110 SysTryReturnResult(NID_UI_ANIM, (index >= 0 && index < keyFrameList.GetCount()), E_OUT_OF_RANGE, "Index (%d) is out of range.", index);
112 result r = E_SUCCESS;
114 ComparerT< long > comparer;
119 ArrayListT< long >* pKeyList = new (std::nothrow) ArrayListT< long >;
120 SysTryReturnResult(NID_UI_ANIM, (pKeyList), E_OUT_OF_MEMORY, "Memory allocation failed.");
122 ICollectionT< long >* pKeyN = keyFrameList.GetKeysN();
123 SysTryCatch(NID_UI_ANIM, (pKeyN), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
125 r = pKeyList->Construct(*pKeyN);
126 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to construct key list.");
127 SysTryCatch(NID_UI_ANIM, !(pKeyList->GetCount() <= 0), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Key list count is invalid.");
129 r = pKeyList->Sort(comparer);
130 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to sort key list.");
132 r = pKeyList->GetAt(index, time);
133 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to sort key list.");
135 keyFrameList.GetValue(time, pObj);
138 keyFrameList.Remove(time);
150 _AnimationBaseImpl::RemoveAllKeyFrames(void)
152 if (keyFrameList.GetCount() > 0)
154 IMapEnumeratorT< long, Object* >* pMapEnum = keyFrameList.GetMapEnumeratorN();
155 result r = GetLastResult();
156 SysTryReturnResult(NID_UI_ANIM, (pMapEnum != null), r, "Propagating.");
158 while (pMapEnum->MoveNext() == E_SUCCESS)
160 Object* pValue = null;
161 pMapEnum->GetValue(pValue);
167 keyFrameList.RemoveAll();
174 _AnimationBaseImpl::CompareTimingValues(const AnimationBase& animBase)
176 return ((interpolator == animBase._pAnimationBaseImpl->interpolator)
177 && (animName == animBase._pAnimationBaseImpl->animName)
178 && (duration == animBase._pAnimationBaseImpl->duration)
179 && (offset == animBase._pAnimationBaseImpl->offset)
180 && (delay == animBase._pAnimationBaseImpl->delay)
181 && (repeatCount == animBase._pAnimationBaseImpl->repeatCount)
182 && (autoReverse == animBase._pAnimationBaseImpl->autoReverse)
183 && (!(Float::Compare(scaleRatio, animBase._pAnimationBaseImpl->scaleRatio)))
184 && (holdEnd == animBase._pAnimationBaseImpl->holdEnd)
185 && (!(Float::Compare(controlPointTime1, animBase._pAnimationBaseImpl->controlPointTime1)))
186 && (!(Float::Compare(controlPointValue1, animBase._pAnimationBaseImpl->controlPointValue1)))
187 && (!(Float::Compare(controlPointTime2, animBase._pAnimationBaseImpl->controlPointTime2)))
188 && (!(Float::Compare(controlPointValue2, animBase._pAnimationBaseImpl->controlPointValue2))));
192 _AnimationBaseImpl::GetActualProgressValue(long currentTime)
194 const IVisualElementAnimationTimingFunction* pTimingFunction = null;
196 switch (interpolator)
198 case ANIMATION_INTERPOLATOR_LINEAR:
200 pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(INTERPOLATOR_LINEAR);
204 case ANIMATION_INTERPOLATOR_EASE_IN:
206 pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(INTERPOLATOR_EASEIN);
210 case ANIMATION_INTERPOLATOR_EASE_OUT:
212 pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(INTERPOLATOR_EASEOUT);
216 case ANIMATION_INTERPOLATOR_EASE_IN_OUT:
218 pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(INTERPOLATOR_EASEINOUT);
222 case ANIMATION_INTERPOLATOR_DISCRETE:
224 pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(INTERPOLATOR_DISCRETE);
228 case ANIMATION_INTERPOLATOR_BEZIER:
230 pTimingFunction = new (std::nothrow) BezierTimingFunction();
231 SysTryReturn(NID_UI_ANIM, (pTimingFunction), -1.0f, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
233 ((BezierTimingFunction*) pTimingFunction)->SetControlPoints(controlPointTime1, controlPointValue1, controlPointTime2, controlPointValue2);
239 SysTryReturn(NID_UI_ANIM, pTimingFunction, -1.0f, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Timing function is null.");
241 long duration = __pAnimationBase->GetDuration();
242 float dur = (1.0f / (float) duration) * ((float) currentTime);
243 float actualProgress = pTimingFunction->CalculateProgress( static_cast< float >(dur));
245 return actualProgress;
249 }}} // Tizen::Ui::Animations