Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / animations / FUiAnim_DimensionAnimationImpl.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_DimensionAnimationImpl.cpp
20  * @brief       This file contains implementation of _DimensionAnimationImpl class
21  *
22  * This file contains implementation _DimensionAnimationImpl 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_DimensionAnimationImpl.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 _DimensionAnimationImpl::~_DimensionAnimationImpl(void)
45 {
46 }
47
48 _DimensionAnimationImpl::_DimensionAnimationImpl(DimensionAnimation* pDimensionAnimation)
49         : anchorX(0.0f)
50         , anchorY(0.0f)
51         , startValue(Dimension(0, 0))
52         , endValue(Dimension(0, 0))
53         , __pDimensionAnimation(pDimensionAnimation)
54 {
55 }
56
57 result
58 _DimensionAnimationImpl::CopyDimensionAnimationValue(const DimensionAnimation& dimensionAnimation)
59 {
60         result r = E_SUCCESS;
61
62         _AnimationBaseImpl* pAnimationBaseImpl = __pDimensionAnimation->_pAnimationBaseImpl;
63
64         // Deleting the contents of existing keyframe
65         r = pAnimationBaseImpl->RemoveAllKeyFrames();
66         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Propagating.");
67
68         // Copying the contents
69         startValue = dimensionAnimation._pDimensionAnimationImpl->startValue;
70         endValue = dimensionAnimation._pDimensionAnimationImpl->endValue;
71
72         if (dimensionAnimation._pAnimationBaseImpl->keyFrameList.GetCount() == 0)
73         {
74                 return E_SUCCESS;
75         }
76
77         IMapEnumeratorT< long, Object* >* pMapEnum = null;
78         MapEntryT< long, Object* > value;
79         Dimension* pDimensionObj = null;
80
81         pMapEnum = dimensionAnimation._pAnimationBaseImpl->keyFrameList.GetMapEnumeratorN();
82         r = GetLastResult();
83         SysTryReturnResult(NID_UI_ANIM, (pMapEnum), r, "Failed to GetMapEnumeratorN()");
84
85         while (pMapEnum->MoveNext() == E_SUCCESS)
86         {
87                 r = pMapEnum->GetCurrent(value);
88                 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
89
90                 Dimension* pDimValue = dynamic_cast< Dimension* >(value.GetValue());
91                 SysTryCatch(NID_UI_ANIM, (pDimValue), r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. KeyFrame value is invalid.");
92
93                 pDimensionObj = new (std::nothrow) Dimension(*pDimValue);
94                 SysTryCatch(NID_UI_ANIM, (pDimensionObj), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
95
96                 r = pAnimationBaseImpl->keyFrameList.Add(value.GetKey(), pDimensionObj);
97                 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
98         }
99
100         delete pMapEnum;
101
102         return E_SUCCESS;
103
104 CATCH:
105         delete pDimensionObj;
106         delete pMapEnum;
107
108         return r;
109 }
110
111 result
112 _DimensionAnimationImpl::GetAnimatedValue(float actualProgress, Tizen::Graphics::Dimension& animatedValue) const
113 {
114         Variant startDimension(startValue);
115         Variant endDimension(endValue);
116         Variant value(Dimension(0, 0));
117
118         _VisualElementAnimationVariantInterpolator variantInterpolator;
119         result r = variantInterpolator.Interpolate(actualProgress, startDimension, endDimension, value);
120
121         animatedValue = value.ToDimension();
122         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "A system error has been occurred. Failed to get the animated value.");
123
124         return r;
125 }
126
127
128 }}}             // Tizen::Ui::Animations
129