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