Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / animations / FUiAnim_RectangleAnimationImpl.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_RectangleAnimationImpl.cpp
20  * @brief       This file contains implementation of _RectangleAnimationImpl class
21  *
22  * This file contains implementation _RectanngleAnimationImpl class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FBaseColHashMapT.h>
27
28 #include <FUiVariant.h>
29
30 #include "FUiAnim_VisualElementAnimationVariantInterpolator.h"
31 #include "FUiAnim_AnimationBaseImpl.h"
32 #include "FUiAnim_RectangleAnimationImpl.h"
33
34
35 using namespace Tizen::Base;
36 using namespace Tizen::Ui::Animations;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Graphics;
39
40
41 namespace Tizen { namespace Ui { namespace Animations
42 {
43
44 _RectangleAnimationImpl::~_RectangleAnimationImpl(void)
45 {
46
47 }
48
49 _RectangleAnimationImpl::_RectangleAnimationImpl(RectangleAnimation* pRectangle)
50         : anchorX(0.0)
51         , anchorY(0.0)
52         , startValue(Rectangle(0, 0, 0, 0))
53         , endValue(Rectangle(0, 0, 0, 0))
54         , __pRectangleAnimation(pRectangle)
55 {
56
57 }
58
59 result
60 _RectangleAnimationImpl::CopyRectangleAnimationValue(const RectangleAnimation& rectangleAnimation)
61 {
62         result r = E_SUCCESS;
63
64         _AnimationBaseImpl* pAnimationBaseImpl = __pRectangleAnimation->_pAnimationBaseImpl;
65
66         // Deleting the contents of existing keyframe
67         r = pAnimationBaseImpl->RemoveAllKeyFrames();
68         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Propagating.");
69
70         // Copying the contents
71         startValue = rectangleAnimation._pRectangleAnimationImpl->startValue;
72         endValue = rectangleAnimation._pRectangleAnimationImpl->endValue;
73
74         if (rectangleAnimation._pAnimationBaseImpl->keyFrameList.GetCount() == 0)
75         {
76                 return E_SUCCESS;
77         }
78
79         IMapEnumeratorT< long, Object* >* pMapEnum = null;
80         MapEntryT< long, Object* > value;
81         Rectangle* pRectObj = null;
82
83         pMapEnum = rectangleAnimation._pAnimationBaseImpl->keyFrameList.GetMapEnumeratorN();
84         r = GetLastResult();
85         SysTryReturnResult(NID_UI_ANIM, (pMapEnum), r, "Failed to get enumerator.");
86
87
88         while (pMapEnum->MoveNext() == E_SUCCESS)
89         {
90                 r = pMapEnum->GetCurrent(value);
91                 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
92
93                 Rectangle* pRectValue = dynamic_cast< Rectangle* >(value.GetValue());
94                 SysTryCatch(NID_UI_ANIM, (pRectValue), r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. KeyFrame value is invalid.");
95
96                 pRectObj = new (std::nothrow) Rectangle(*pRectValue);
97                 SysTryCatch(NID_UI_ANIM, (pRectObj), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
98
99                 r = pAnimationBaseImpl->keyFrameList.Add(value.GetKey(), pRectObj);
100                 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
101         }
102
103         delete pMapEnum;
104
105         return E_SUCCESS;
106
107 CATCH:
108         delete pRectObj;
109         delete pMapEnum;
110
111         return r;
112 }
113
114 result
115 _RectangleAnimationImpl::GetAnimatedValue(float actualProgress, Tizen::Graphics::Rectangle& animatedValue) const
116 {
117         Variant startRect(startValue);
118         Variant endRect(endValue);
119         Variant value(Rectangle(0, 0, 0, 0));
120
121         _VisualElementAnimationVariantInterpolator variantInterpolator;
122         result r = variantInterpolator.Interpolate(actualProgress, startRect, endRect, value);
123
124         animatedValue = value.ToRectangle();
125         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, " A system error has been occurred. Failed to get the animated value.");
126
127         return r;
128 }
129
130
131 }}}             // Tizen::Ui::Animations
132