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 FUiAnimFloatAnimation.cpp
20 * @brief This file contains implementation of FloatAnimation class
22 * This file contains implementation of FloatAnimation class.
27 #include <FBaseColHashMapT.h>
28 #include <FUiAnimFloatAnimation.h>
30 #include <FBaseSysLog.h>
32 #include "FUiAnim_AnimationBaseImpl.h"
33 #include "FUiAnim_FloatAnimationImpl.h"
36 using namespace Tizen::Base;
37 using namespace Tizen::Ui::Animations;
38 using namespace Tizen::Base::Collection;
41 namespace Tizen { namespace Ui { namespace Animations
45 FloatAnimation::FloatAnimation(void)
46 : _pFloatAnimationImpl(null)
50 FloatAnimation::FloatAnimation(float startValue, float endValue, long duration, AnimationInterpolatorType interpolator)
51 : AnimationBase(duration, interpolator)
52 , _pFloatAnimationImpl(null)
54 result r = GetLastResult();
55 SysTryReturnVoidResult(NID_UI_ANIM, (_pAnimationBaseImpl), r, "[%s] Propagating.", GetErrorMessage(r));
57 _pFloatAnimationImpl = new (std::nothrow) _FloatAnimationImpl(this);
58 if (_pFloatAnimationImpl == null)
60 SysLogException(NID_UI_ANIM, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
62 delete _pAnimationBaseImpl;
63 _pAnimationBaseImpl = null;
68 _pFloatAnimationImpl->startValue = startValue;
69 _pFloatAnimationImpl->endValue = endValue;
72 FloatAnimation::~FloatAnimation(void)
74 delete _pFloatAnimationImpl;
75 _pFloatAnimationImpl = null;
78 FloatAnimation::FloatAnimation(const FloatAnimation& floatAnimation)
79 : AnimationBase(floatAnimation)
80 , _pFloatAnimationImpl(null)
82 result r = GetLastResult();
83 SysTryReturnVoidResult(NID_UI_ANIM, (_pAnimationBaseImpl), r, "[%s] Propagating.", GetErrorMessage(r));
85 _pFloatAnimationImpl = new (std::nothrow) _FloatAnimationImpl(this);
86 SysTryCatch(NID_UI_ANIM, (_pFloatAnimationImpl != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
88 r = _pFloatAnimationImpl->CopyFloatAnimationValue(floatAnimation);
89 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to copy float animation value.");
94 delete _pAnimationBaseImpl;
95 _pAnimationBaseImpl = null;
96 delete _pFloatAnimationImpl;
97 _pFloatAnimationImpl = null;
101 FloatAnimation::operator =(const FloatAnimation& floatAnimation)
105 if ((&floatAnimation) != this)
107 result r = E_SUCCESS;
109 AnimationBase::operator =(floatAnimation);
111 r = _pFloatAnimationImpl->CopyFloatAnimationValue(floatAnimation);
112 SysTryReturn(NID_UI_ANIM, (r == E_SUCCESS), *this, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to copy float animation value.");
119 FloatAnimation::operator ==(const FloatAnimation& rhs) const
121 result r = E_SUCCESS;
123 if (_pAnimationBaseImpl->keyFrameList.GetCount() != rhs._pAnimationBaseImpl->keyFrameList.GetCount())
128 ArrayListT< long >* pKeyList1 = null;
129 ArrayListT< long >* pKeyList2 = null;
130 ICollectionT< long >* pKeyN = _pAnimationBaseImpl->keyFrameList.GetKeysN();
131 ICollectionT< long >* pKeyN1 = rhs._pAnimationBaseImpl->keyFrameList.GetKeysN();
133 if (_pAnimationBaseImpl->keyFrameList.GetCount() != 0)
135 pKeyList1 = new (std::nothrow) ArrayListT< long >;
136 SysTryCatch(NID_UI_ANIM, (pKeyList1 && pKeyN), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
138 r = pKeyList1->Construct(*pKeyN);
139 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] Failed to construct key list.");
141 pKeyList2 = new (std::nothrow) ArrayListT< long >;
142 SysTryCatch(NID_UI_ANIM, (pKeyList2 && pKeyN1), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
144 r = pKeyList2->Construct(*pKeyN1);
145 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] Failed to construct key list.");
147 ComparerT< long > comparer;
149 r = pKeyList1->Sort(comparer);
150 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to sort key list.");
152 r = pKeyList2->Sort(comparer);
153 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to sort key list.");
157 Object* pObjValue1 = null;
158 Object* pObjValue2 = null;
160 for (int index = 0; index < _pAnimationBaseImpl->keyFrameList.GetCount(); index++)
162 pKeyList1->GetAt(index, time1);
163 pKeyList2->GetAt(index, time2);
168 _pAnimationBaseImpl->keyFrameList.GetValue(time1, pObjValue1);
169 rhs._pAnimationBaseImpl->keyFrameList.GetValue(time2, pObjValue2);
170 if ((!pObjValue1) && (!pObjValue2))
174 else if ((!pObjValue1) || (!pObjValue2))
179 Float* pFlValue1 = dynamic_cast< Float* >(pObjValue1);
180 if (pFlValue1 == null)
185 Float* pFlValue2 = dynamic_cast< Float* >(pObjValue2);
186 if (pFlValue2 == null)
190 if (!(pFlValue1->Equals(*pFlValue2)))
202 if (!((_pFloatAnimationImpl->startValue).Equals(rhs._pFloatAnimationImpl->startValue))
203 || !((_pFloatAnimationImpl->endValue).Equals(rhs._pFloatAnimationImpl->endValue)))
208 return _pAnimationBaseImpl->CompareTimingValues(rhs);
220 FloatAnimation::operator !=(const FloatAnimation& rhs) const
222 return !(*this == rhs);
226 FloatAnimation::Equals(const Object& obj) const
228 const FloatAnimation* pFloatAnim = dynamic_cast< const FloatAnimation* >(&obj);
230 if (pFloatAnim == null)
235 return (*this == *pFloatAnim);
239 FloatAnimation::GetHashCode(void) const
241 return (((int) GetRepeatCount()) + ((int) GetOffset()) + ((int) GetDuration()) + ((int) GetDelay()));
245 FloatAnimation::GetAnimatedValue(long currentTime, float& animatedValue) const
247 SysTryReturnResult(NID_UI_ANIM, (currentTime >= 0 && currentTime <= GetDuration()), E_INVALID_ARG, "Invalid argument(s) is used. currentTime = %ld", currentTime);
249 float actualProgress = _pAnimationBaseImpl->GetActualProgressValue(currentTime);
250 SysTryReturnResult(NID_UI_ANIM, (actualProgress >= 0.0f && actualProgress <= 1.0f), E_SYSTEM, "A system error has been occurred. Failed to calculate progress.");
252 return _pFloatAnimationImpl->GetAnimatedValue(actualProgress, animatedValue);
256 FloatAnimation::AddKeyFrame(long time, float value)
258 SysTryReturnResult(NID_UI_ANIM, (time > 0 && time != _pAnimationBaseImpl->duration), E_INVALID_ARG, "Invalid argument(s) is used. time = %ld", time);
260 result r = E_SUCCESS;
261 Float* pFloatObj = null;
263 if (time > _pAnimationBaseImpl->duration)
265 pFloatObj = new (std::nothrow) Float(_pFloatAnimationImpl->endValue);
266 SysTryReturnResult(NID_UI_ANIM, (pFloatObj), E_OUT_OF_MEMORY, "Memory allocation failed.");
268 r = _pAnimationBaseImpl->keyFrameList.Add(_pAnimationBaseImpl->duration, dynamic_cast< Object* >(pFloatObj));
269 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add to key frame list.");
271 _pAnimationBaseImpl->duration = time;
272 _pFloatAnimationImpl->endValue = value;
276 pFloatObj = new (std::nothrow) Float(value);
277 SysTryReturnResult(NID_UI_ANIM, (pFloatObj), E_OUT_OF_MEMORY, "Memory allocation failed.");
279 Object* pKeyValue = null;
280 _pAnimationBaseImpl->keyFrameList.GetValue(time, pKeyValue);
283 _pAnimationBaseImpl->keyFrameList.Remove(time);
288 r = _pAnimationBaseImpl->keyFrameList.Add(time, dynamic_cast< Object* >(pFloatObj));
289 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add to key frame list.");
300 FloatAnimation::GetKeyFrameAt(int index, long& time, float& value) const
302 SysTryReturnResult(NID_UI_ANIM, (index >= 0 && index < _pAnimationBaseImpl->keyFrameList.GetCount()),
303 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Index (%d) is out of range.", index);
305 result r = E_SUCCESS;
306 Object* pObjValue = null;
307 ComparerT< long > comparer;
308 Float* pFloatValue = null;
310 ArrayListT< long >* pKeyList = new (std::nothrow) ArrayListT< long >;
311 ICollectionT< long >* pKeyN = _pAnimationBaseImpl->keyFrameList.GetKeysN();
313 SysTryCatch(NID_UI_ANIM, (pKeyList && pKeyN), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
315 r = pKeyList->Construct(*pKeyN);
316 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to construct key list.");
317 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.");
319 r = pKeyList->Sort(comparer);
320 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.");
322 r = pKeyList->GetAt(index, time);
323 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.");
325 r = _pAnimationBaseImpl->keyFrameList.GetValue(time, pObjValue);
326 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to get key value.");
327 SysTryCatch(NID_UI_ANIM, (pObjValue != null), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to get key frame.");
329 pFloatValue = dynamic_cast< Float* >(pObjValue);
332 value = pFloatValue->ToFloat();
344 FloatAnimation::RemoveKeyFrame(long time)
346 return _pAnimationBaseImpl->RemoveKeyFrame(time);
350 FloatAnimation::RemoveKeyFrameAt(int index)
352 return _pAnimationBaseImpl->RemoveKeyFrameAt(index);
356 FloatAnimation::RemoveAllKeyFrames(void)
358 return _pAnimationBaseImpl->RemoveAllKeyFrames();
362 FloatAnimation::SetStartValue(float startValue)
364 _pFloatAnimationImpl->startValue = startValue;
371 FloatAnimation::SetEndValue(float endValue)
373 _pFloatAnimationImpl->endValue = endValue;
379 FloatAnimation::GetStartValue(void) const
381 return _pFloatAnimationImpl->startValue.ToFloat();
385 FloatAnimation::GetEndValue(void) const
387 return _pFloatAnimationImpl->endValue.ToFloat();
391 FloatAnimation::GetType(void) const
393 return ANIMATION_TYPE_FLOAT_ANIMATION;
396 }}} // Tizen::Ui::Animations