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