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 FUiAnimRectangleAnimation.cpp
20 * @brief This file contains implementation of RectangleAnimation class
22 * This file contains implementation of RectangleAnimation class.
25 #include <FBaseSysLog.h>
26 #include <FBaseColHashMapT.h>
28 #include <FUiAnimRectangleAnimation.h>
30 #include "FUiAnim_RectangleAnimationImpl.h"
31 #include "FUiAnim_AnimationBaseImpl.h"
34 using namespace Tizen::Base;
35 using namespace Tizen::Ui::Animations;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Graphics;
40 namespace Tizen { namespace Ui { namespace Animations
43 RectangleAnimation::RectangleAnimation(void)
44 : _pRectangleAnimationImpl(null)
48 RectangleAnimation::RectangleAnimation(const Rectangle& startValue, const Rectangle& endValue, long duration, AnimationInterpolatorType interpolator)
49 : AnimationBase(duration, interpolator)
50 , _pRectangleAnimationImpl(null)
52 result r = GetLastResult();
53 SysTryReturnVoidResult(NID_UI_ANIM, (_pAnimationBaseImpl), r, "[%s] Propagating.", GetErrorMessage(r));
55 SysTryReturnVoidResult(NID_UI_ANIM, (startValue.height >= 0 && startValue.width >= 0 && endValue.height >= 0 && endValue.width >= 0),
56 E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. startValue = (%d, %d, %d, %d), endValue = (%d, %d, %d, %d)",
57 startValue.x, startValue.y, startValue.width, startValue.height, endValue.x, endValue.y, endValue.width, endValue.height);
59 _pRectangleAnimationImpl = new (std::nothrow) _RectangleAnimationImpl(this);
60 if (_pRectangleAnimationImpl == null)
62 SysLogException(NID_UI_ANIM, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
64 delete _pAnimationBaseImpl;
65 _pAnimationBaseImpl = null;
70 _pRectangleAnimationImpl->startValue = startValue;
71 _pRectangleAnimationImpl->endValue = endValue;
74 RectangleAnimation::~RectangleAnimation(void)
76 delete _pRectangleAnimationImpl;
77 _pRectangleAnimationImpl = null;
80 RectangleAnimation::RectangleAnimation(const RectangleAnimation& rectangleAnimation)
81 : AnimationBase(rectangleAnimation)
82 , _pRectangleAnimationImpl(null)
84 result r = GetLastResult();
85 SysTryReturnVoidResult(NID_UI_ANIM, (_pAnimationBaseImpl), r, "[%s] Propagating.", GetErrorMessage(r));
87 _pRectangleAnimationImpl = new (std::nothrow) _RectangleAnimationImpl(this);
88 SysTryCatch(NID_UI_ANIM, (_pRectangleAnimationImpl), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
90 rectangleAnimation.GetAnchor(_pRectangleAnimationImpl->anchorX, _pRectangleAnimationImpl->anchorY);
92 r = _pRectangleAnimationImpl->CopyRectangleAnimationValue(rectangleAnimation);
93 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to copy rectangle animation value.");
98 delete _pAnimationBaseImpl;
99 _pAnimationBaseImpl = null;
100 delete _pRectangleAnimationImpl;
101 _pRectangleAnimationImpl = null;
105 RectangleAnimation::operator =(const RectangleAnimation& rhs)
111 result r = E_SUCCESS;
113 AnimationBase::operator =(rhs);
115 rhs.GetAnchor(_pRectangleAnimationImpl->anchorX, _pRectangleAnimationImpl->anchorY);
117 r = _pRectangleAnimationImpl->CopyRectangleAnimationValue(rhs);
118 SysTryReturn(NID_UI_ANIM, (r == E_SUCCESS), *this, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to copy rectangle animation value.");
125 RectangleAnimation::operator ==(const RectangleAnimation& rhs) const
127 result r = E_SUCCESS;
129 if (_pAnimationBaseImpl->keyFrameList.GetCount() != rhs._pAnimationBaseImpl->keyFrameList.GetCount())
134 ArrayListT< long >* pKeyList1 = null;
135 ArrayListT< long >* pKeyList2 = null;
136 ICollectionT< long >* pKeyN = _pAnimationBaseImpl->keyFrameList.GetKeysN();
138 if (_pAnimationBaseImpl->keyFrameList.GetCount() != 0)
140 pKeyList1 = new (std::nothrow) ArrayListT< long >;
141 SysTryCatch(NID_UI_ANIM, (pKeyList1 != null && pKeyN != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
143 r = pKeyList1->Construct(*pKeyN);
144 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] Failed to construct key list.");
146 pKeyList2 = new (std::nothrow) ArrayListT< long >;
147 SysTryCatch(NID_UI_ANIM, (pKeyList2 != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
149 ComparerT< long > comparer;
151 r = pKeyList1->Sort(comparer);
152 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to sort key list.");
154 r = pKeyList2->Sort(comparer);
155 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to sort key list.");
159 Object* pObjValue1 = null;
160 Object* pObjValue2 = null;
162 for (int index = 0; index < _pAnimationBaseImpl->keyFrameList.GetCount(); index++)
164 pKeyList1->GetAt(index, time1);
165 pKeyList2->GetAt(index, time2);
171 _pAnimationBaseImpl->keyFrameList.GetValue(time1, pObjValue1);
172 rhs._pAnimationBaseImpl->keyFrameList.GetValue(time2, pObjValue2);
174 if ((!pObjValue1) && (!pObjValue2))
178 else if ((!pObjValue1) || (!pObjValue2))
183 Rectangle* pRectValue1 = dynamic_cast< Rectangle* >(pObjValue1);
184 if (pRectValue1 == null)
188 Rectangle* pRectValue2 = dynamic_cast< Rectangle* >(pObjValue2);
189 if (pRectValue2 == null)
193 if (!(pRectValue1->Equals(*pRectValue2)))
205 if (!((_pRectangleAnimationImpl->startValue).Equals(rhs._pRectangleAnimationImpl->startValue)) ||
206 !((_pRectangleAnimationImpl->endValue).Equals(rhs._pRectangleAnimationImpl->endValue)))
211 if (((Float::Compare(_pRectangleAnimationImpl->anchorX, rhs._pRectangleAnimationImpl->anchorX)) != 0) &&
212 ((Float::Compare(_pRectangleAnimationImpl->anchorY, rhs._pRectangleAnimationImpl->anchorY)) != 0))
217 return _pAnimationBaseImpl->CompareTimingValues(rhs);
228 RectangleAnimation::operator !=(const RectangleAnimation& rhs) const
230 return !(*this == rhs);
234 RectangleAnimation::Equals(const Object& obj) const
236 const RectangleAnimation* pRectangleAnim = dynamic_cast< const RectangleAnimation* >(&obj);
237 if (pRectangleAnim == null)
242 return (*this == *pRectangleAnim);
246 RectangleAnimation::GetHashCode(void) const
248 return (((int) GetRepeatCount()) + ((int) GetOffset()) + ((int) GetDuration()) + ((int) GetDelay()));
252 RectangleAnimation::SetAnchor(float anchorX, float anchorY)
254 SysTryReturnResult(NID_UI_ANIM, (anchorX >= 0.0 && anchorX <= 1.0 && anchorY >= 0.0 && anchorY <= 1.0), E_INVALID_ARG, "Invalid argument(s) is used. anchorX = %f, anchorY = %f.", anchorX, anchorY);
256 _pRectangleAnimationImpl->anchorX = anchorX;
257 _pRectangleAnimationImpl->anchorY = anchorY;
263 RectangleAnimation::GetAnchor(float& anchorX, float& anchorY) const
265 anchorX = _pRectangleAnimationImpl->anchorX;
266 anchorY = _pRectangleAnimationImpl->anchorY;
270 RectangleAnimation::GetAnimatedValue(long currentTime, Rectangle& animatedValue) const
272 SysTryReturnResult(NID_UI_ANIM, (currentTime >= 0 && currentTime <= GetDuration()), E_INVALID_ARG, "Invalid argument(s) is used. currentTime = %ld", currentTime);
274 float actualProgress = _pAnimationBaseImpl->GetActualProgressValue(currentTime);
275 SysTryReturnResult(NID_UI_ANIM, (actualProgress >= 0.0f && actualProgress <= 1.0f), E_SYSTEM, "System error in calculating progress.");
277 return _pRectangleAnimationImpl->GetAnimatedValue(actualProgress, animatedValue);
281 RectangleAnimation::AddKeyFrame(long time, const Rectangle& value)
283 SysTryReturnResult(NID_UI_ANIM, (time > 0 && time != _pAnimationBaseImpl->duration), E_INVALID_ARG, "Invalid argument(s) is used. time = %ld", time);
285 result r = E_SUCCESS;
286 Rectangle* pRectObj = null;
288 if (time > _pAnimationBaseImpl->duration)
290 pRectObj = new (std::nothrow) Rectangle(_pRectangleAnimationImpl->endValue);
291 SysTryReturnResult(NID_UI_ANIM, (pRectObj != null), E_OUT_OF_MEMORY, "Memory allocation failed");
293 r = _pAnimationBaseImpl->keyFrameList.Add(_pAnimationBaseImpl->duration, dynamic_cast< Object* >(pRectObj));
294 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.");
296 _pAnimationBaseImpl->duration = time;
297 _pRectangleAnimationImpl->endValue = value;
301 pRectObj = new (std::nothrow) Rectangle(value);
302 SysTryReturnResult(NID_UI_ANIM, (pRectObj != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
304 Object* pKeyValue = null;
305 _pAnimationBaseImpl->keyFrameList.GetValue(time, pKeyValue);
306 if (pKeyValue != null)
308 _pAnimationBaseImpl->keyFrameList.Remove(time); // Remove the already existing entry
311 r = _pAnimationBaseImpl->keyFrameList.Add(time, dynamic_cast< Object* >(pRectObj));
312 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.");
323 RectangleAnimation::GetKeyFrameAt(int index, long& time, Rectangle& value) const
325 SysTryReturnResult(NID_UI_ANIM, (index >= 0 && index < _pAnimationBaseImpl->keyFrameList.GetCount()),
326 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Index (%d) is out of range.", index);
328 result r = E_SUCCESS;
329 Object* pObjValue = null;
330 Rectangle* pDimValue = null;
331 ComparerT< long > comparer;
333 ArrayListT< long >* pKeyList = new (std::nothrow) ArrayListT< long >;
334 ICollectionT< long >* pKeyN = _pAnimationBaseImpl->keyFrameList.GetKeysN();
336 SysTryCatch(NID_UI_ANIM, (pKeyList != null && pKeyN != null), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
338 r = pKeyList->Construct(*pKeyN);
339 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to construct key list.");
340 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.");
342 r = pKeyList->Sort(comparer);
343 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.");
345 r = pKeyList->GetAt(index, time);
346 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to get the time from list.");
348 r = _pAnimationBaseImpl->keyFrameList.GetValue(time, pObjValue);
349 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.");
351 pDimValue = dynamic_cast< Rectangle* >(pObjValue);
365 RectangleAnimation::RemoveKeyFrame(long time)
367 return _pAnimationBaseImpl->RemoveKeyFrame(time);
371 RectangleAnimation::RemoveKeyFrameAt(int index)
373 return _pAnimationBaseImpl->RemoveKeyFrameAt(index);
377 RectangleAnimation::RemoveAllKeyFrames(void)
379 result r = E_SUCCESS;
381 IMapEnumeratorT< long, Object* >* pMapEnum = _pAnimationBaseImpl->keyFrameList.GetMapEnumeratorN();
382 SysTryReturnResult(NID_UI_ANIM, (pMapEnum), E_OUT_OF_MEMORY, "Memory allocation failed.");
384 MapEntryT< long, Object* > value;
386 while (pMapEnum->MoveNext() == E_SUCCESS)
388 r = pMapEnum->GetCurrent(value);
389 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to get the current value.");
391 Object* pObj = value.GetValue();
396 _pAnimationBaseImpl->keyFrameList.RemoveAll();
406 RectangleAnimation::SetStartValue(const Rectangle& startValue)
408 SysTryReturnResult(NID_UI_ANIM, (startValue.width >= 0 && startValue.height >= 0), E_INVALID_ARG, "Invalid argument(s) is used. size = (%d, %d)", startValue.width, startValue.height);
410 _pRectangleAnimationImpl->startValue = startValue;
417 RectangleAnimation::SetEndValue(const Rectangle& endValue)
419 SysTryReturnResult(NID_UI_ANIM, (endValue.width >= 0 && endValue.height >= 0), E_INVALID_ARG, "Invalid argument(s) is used. size = (%d, %d)", endValue.width, endValue.height);
421 _pRectangleAnimationImpl->endValue = endValue;
427 RectangleAnimation::GetStartValue(void) const
429 return _pRectangleAnimationImpl->startValue;
433 RectangleAnimation::GetEndValue(void) const
435 return _pRectangleAnimationImpl->endValue;
439 RectangleAnimation::GetType(void) const
441 return ANIMATION_TYPE_RECTANGLE_ANIMATION;
445 }}} // Tizen::Ui::Animations