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