Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / animations / FUiAnim_AnimationGroupImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17
18 /**
19  * @file        FUiAnim_AnimationGroupImpl.cpp
20  * @brief       This file contains implementation of _AnimationGroupImpl class
21  *
22  * This file contains implementation _AnimationGroupImpl class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FBaseColArrayList.h>
27 #include <FBaseColArrayListT.h>
28
29 #include <FUiAnimDimensionAnimation.h>
30 #include <FUiAnimFloatAnimation.h>
31 #include <FUiAnimRectangleAnimation.h>
32 #include <FUiAnimIntegerAnimation.h>
33 #include <FUiAnimPointAnimation.h>
34 #include <FUiAnimRotateAnimation.h>
35
36 #include "FUiAnim_AnimationGroupImpl.h"
37
38
39 using namespace Tizen::Ui::Animations;
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
42 using namespace Tizen::Ui;
43
44
45 namespace Tizen { namespace Ui { namespace Animations
46 {
47
48 _AnimationGroupImpl::_AnimationGroupImpl(AnimationGroup* pAnimationGroup)
49         : __pAnimationGroup(pAnimationGroup)
50 {
51 }
52
53 _AnimationGroupImpl::~_AnimationGroupImpl(void)
54 {
55         result r = Dispose();
56
57         SysTryReturnVoidResult(NID_UI_ANIM, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
58 }
59
60 result
61 _AnimationGroupImpl::Dispose(void)
62 {
63         result r = E_SUCCESS;
64
65         int index = animationList.GetCount();
66
67         while (index > 0)
68         {
69                 _AnimationGroupImpl::AnimationStore animStore;
70
71                 r = animationList.GetAt(index - 1, animStore);
72
73                 delete animStore.pAnimationBase;
74                 animStore.pAnimationBase = null;
75
76                 index--;
77         }
78
79         animationList.RemoveAll();
80
81         return r;
82 }
83
84 AnimationBase*
85 _AnimationGroupImpl::CloneAnimation(AnimationTargetType animTarget, AnimationBase& animation, result& r)
86 {
87         AnimationType animationType = animation.GetType();
88
89         switch (animTarget)
90         {
91         case ANIMATION_TARGET_SIZE:
92         {
93                 switch (animationType)
94                 {
95                 case ANIMATION_TYPE_DIMENSION_ANIMATION:
96                 {
97                         DimensionAnimation* pDimValue = dynamic_cast< DimensionAnimation* >(&animation);
98                         SysTryReturn(NID_UI_ANIM, (pDimValue), null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not DimensionAnimation.");
99
100                         DimensionAnimation* pAnimValue = new (std::nothrow) DimensionAnimation(*pDimValue);
101                         SysTryReturn(NID_UI_ANIM, (pAnimValue), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
102
103                         return pAnimValue;
104                 }
105                 break;
106
107                 case ANIMATION_TYPE_RECTANGLE_ANIMATION:
108                 {
109                         RectangleAnimation* pRectValue = dynamic_cast< RectangleAnimation* >(&animation);
110                         SysTryReturn(NID_UI_ANIM, (pRectValue), null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not RectangleAnimation.");
111
112                         RectangleAnimation* pAnimValue = new (std::nothrow) RectangleAnimation(*pRectValue);
113                         SysTryReturn(NID_UI_ANIM, (pAnimValue), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
114
115                         return pAnimValue;
116                 }
117                 break;
118
119                 default:
120                         r = E_INVALID_ARG;
121                         return null;
122                 }
123         }
124         break;
125
126
127         case ANIMATION_TARGET_POSITION:
128         {
129                 switch (animationType)
130                 {
131                 case ANIMATION_TYPE_POINT_ANIMATION:
132                 {
133                         PointAnimation* pPtValue = dynamic_cast< PointAnimation* >(&animation);
134                         SysTryReturn(NID_UI_ANIM, (pPtValue), null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not PointAnimation.");
135
136                         PointAnimation* pAnimValue = new (std::nothrow) PointAnimation(*pPtValue);
137                         SysTryReturn(NID_UI_ANIM, (pAnimValue), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
138
139                         return pAnimValue;
140                 }
141                 break;
142
143                 case ANIMATION_TYPE_RECTANGLE_ANIMATION:
144                 {
145                         RectangleAnimation* pRectValue = dynamic_cast< RectangleAnimation* >(&animation);
146                         SysTryReturn(NID_UI_ANIM, (pRectValue), null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not RectangleAnimation.");
147
148                         RectangleAnimation* pAnimValue = new (std::nothrow) RectangleAnimation(*pRectValue);
149                         SysTryReturn(NID_UI_ANIM, (pAnimValue), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
150
151                         return pAnimValue;
152                 }
153                 break;
154
155                 default:
156                         r = E_INVALID_ARG;
157                         return null;
158                 }
159         }
160         break;
161
162         case ANIMATION_TARGET_ALPHA:
163         {
164                 switch (animationType)
165                 {
166                 case ANIMATION_TYPE_FLOAT_ANIMATION:
167                 {
168                         FloatAnimation* pFloatValue = dynamic_cast< FloatAnimation* >(&animation);
169                         SysTryReturn(NID_UI_ANIM, (pFloatValue), null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not FloatAnimation.");
170
171                         FloatAnimation* pAnimValue = new (std::nothrow) FloatAnimation(*pFloatValue);
172                         SysTryReturn(NID_UI_ANIM, (pAnimValue), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
173
174                         return pAnimValue;
175                 }
176                 break;
177
178                 case ANIMATION_TYPE_INTEGER_ANIMATION:
179                 {
180                         IntegerAnimation* pIntValue = dynamic_cast< IntegerAnimation* >(&animation);
181                         SysTryReturn(NID_UI_ANIM, (pIntValue), null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not IntegerAnimation.");
182
183                         IntegerAnimation* pAnimValue = new (std::nothrow) IntegerAnimation(*pIntValue);
184                         SysTryReturn(NID_UI_ANIM, (pAnimValue), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
185
186                         return pAnimValue;
187                 }
188                 break;
189
190                 default:
191                         r = E_INVALID_ARG;
192                         return null;
193                 }
194         }
195         break;
196
197         case ANIMATION_TARGET_ROTATION:
198         {
199                 if (animationType == ANIMATION_TYPE_ROTATE_ANIMATION)
200                 {
201                         RotateAnimation* pRotateValue = dynamic_cast< RotateAnimation* >(&animation);
202                         SysTryReturn(NID_UI_ANIM, (pRotateValue), null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not RotateAnimation.");
203
204                         RotateAnimation* pAnimValue = new (std::nothrow) RotateAnimation(*pRotateValue);
205                         SysTryReturn(NID_UI_ANIM, (pAnimValue), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
206
207                         return pAnimValue;
208                 }
209                 else
210                 {
211                         r = E_INVALID_ARG;
212                         return null;
213                 }
214         }
215         break;
216
217         default:
218                 r = E_INVALID_ARG;
219                 return null;
220         }
221 }
222
223 result
224 _AnimationGroupImpl::Construct()
225 {
226         return animationList.Construct();
227 }
228
229 bool
230 _AnimationGroupImpl::AnimationStore::operator ==(const AnimationStore& animStore) const
231 {
232         if (animTarget != animStore.animTarget)
233         {
234                 return false;
235         }
236
237         if ((!pAnimationBase) && (!animStore.pAnimationBase))
238         {
239                 return true;
240         }
241         else if (((pAnimationBase == null) && (animStore.pAnimationBase != null)) ||
242                          ((pAnimationBase != null) && (animStore.pAnimationBase == null)))
243         {
244                 return false;
245         }
246
247         if (pAnimationBase->GetType() != animStore.pAnimationBase->GetType())
248         {
249                 return false;
250         }
251
252         switch (pAnimationBase->GetType())
253         {
254         case ANIMATION_TYPE_FLOAT_ANIMATION:
255         {
256                 FloatAnimation* pFlAnim1 = dynamic_cast< FloatAnimation* >(pAnimationBase);
257                 SysTryReturn(NID_UI_ANIM, (pFlAnim1), false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not FloatAnimation.");
258
259                 FloatAnimation* pFlAnim2 = dynamic_cast< FloatAnimation* >(animStore.pAnimationBase);
260                 SysTryReturn(NID_UI_ANIM, (pFlAnim2), false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not FloatAnimation.");
261
262                 if ((*pFlAnim1) != (*pFlAnim2))
263                 {
264                         return false;
265                 }
266                 break;
267         }
268
269         case ANIMATION_TYPE_INTEGER_ANIMATION:
270         {
271                 IntegerAnimation* pIntAnim1 = dynamic_cast< IntegerAnimation* >(pAnimationBase);
272                 SysTryReturn(NID_UI_ANIM, (pIntAnim1), false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not IntegerAnimation.");
273
274                 IntegerAnimation* pIntAnim2 = dynamic_cast< IntegerAnimation* >(animStore.pAnimationBase);
275                 SysTryReturn(NID_UI_ANIM, (pIntAnim2), false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not IntegerAnimation.");
276
277                 if ((*pIntAnim1) != (*pIntAnim2))
278                 {
279                         return false;
280                 }
281                 break;
282         }
283
284         case ANIMATION_TYPE_DIMENSION_ANIMATION:
285         {
286                 DimensionAnimation* pDimAnim1 = dynamic_cast< DimensionAnimation* >(pAnimationBase);
287                 SysTryReturn(NID_UI_ANIM, (pDimAnim1), false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not DimensionAnimation.");
288
289                 DimensionAnimation* pDimAnim2 = dynamic_cast< DimensionAnimation* >(animStore.pAnimationBase);
290                 SysTryReturn(NID_UI_ANIM, (pDimAnim2), false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not DimensionAnimation.");
291
292                 if ((*pDimAnim1) != (*pDimAnim2))
293                 {
294                         return false;
295                 }
296                 break;
297         }
298
299         case ANIMATION_TYPE_RECTANGLE_ANIMATION:
300         {
301                 RectangleAnimation* pRectAnim1 = dynamic_cast< RectangleAnimation* >(pAnimationBase);
302                 SysTryReturn(NID_UI_ANIM, (pRectAnim1), false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not RectangleAnimation.");
303
304                 RectangleAnimation* pRectAnim2 = dynamic_cast< RectangleAnimation* >(animStore.pAnimationBase);
305                 SysTryReturn(NID_UI_ANIM, (pRectAnim2), false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not RectangleAnimation.");
306
307                 if ((*pRectAnim1) != (*pRectAnim2))
308                 {
309                         return false;
310                 }
311                 break;
312         }
313
314         case ANIMATION_TYPE_POINT_ANIMATION:
315         {
316                 PointAnimation* pPtAnim1 = dynamic_cast< PointAnimation* >(pAnimationBase);
317                 SysTryReturn(NID_UI_ANIM, (pPtAnim1), false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not PointAnimation.");
318
319                 PointAnimation* pPtAnim2 = dynamic_cast< PointAnimation* >(animStore.pAnimationBase);
320                 SysTryReturn(NID_UI_ANIM, (pPtAnim2), false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not PointAnimation.");
321
322                 if ((*pPtAnim1) != (*pPtAnim2))
323                 {
324                         return false;
325                 }
326                 break;
327         }
328
329         case ANIMATION_TYPE_ROTATE_ANIMATION:
330         {
331                 RotateAnimation* pRotAnim1 = dynamic_cast< RotateAnimation* >(pAnimationBase);
332                 SysTryReturn(NID_UI_ANIM, (pRotAnim1), false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not RotateAnimation.");
333
334                 RotateAnimation* pRotAnim2 = dynamic_cast< RotateAnimation* >(animStore.pAnimationBase);
335                 SysTryReturn(NID_UI_ANIM, (pRotAnim2), false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation is not RotateAnimation.");
336
337                 if ((*pRotAnim1) != (*pRotAnim2))
338                 {
339                         return false;
340                 }
341                 break;
342         }
343
344         default:
345                 return false;
346         }
347
348         return true;
349 }
350
351 bool
352 _AnimationGroupImpl::AnimationStore::operator !=(const AnimationStore& animStore) const
353 {
354         return !(*this == animStore);
355 }
356
357 }}} //Tizen::Ui::Animations