Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / animations / FUiAnimRotateAnimation.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                FUiAnimRotateAnimation.cpp
20  * @brief               This file contains implementation of RotateAnimation class
21  *
22  * This file contains implementation of RotateAnimation class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FBaseColHashMapT.h>
27
28 #include <FUiAnimRotateAnimation.h>
29
30 #include "FUiAnim_RotateAnimationImpl.h"
31 #include "FUiAnim_AnimationBaseImpl.h"
32 #include "FUiAnim_FloatAnimationImpl.h"
33
34
35 using namespace Tizen::Base;
36 using namespace Tizen::Ui::Animations;
37 using namespace Tizen::Base::Collection;
38
39
40 namespace Tizen { namespace Ui { namespace Animations
41 {
42
43 RotateAnimation::RotateAnimation(void)
44         : _pRotateAnimationImpl(null)
45 {
46 }
47
48 RotateAnimation::RotateAnimation(float startValue, float endValue, long duration, AnimationInterpolatorType interpolator)
49         : FloatAnimation(startValue, endValue, duration, interpolator)
50         , _pRotateAnimationImpl(null)
51 {
52         result r = GetLastResult();
53         SysTryReturnVoidResult(NID_UI_ANIM, (_pAnimationBaseImpl), r, "[%s] Propagating.", GetErrorMessage(r));
54
55         _pRotateAnimationImpl = new (std::nothrow) _RotateAnimationImpl(this);
56         if (_pRotateAnimationImpl == null)
57         {
58                 SysLogException(NID_UI_ANIM, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
59
60                 delete _pFloatAnimationImpl;
61                 _pFloatAnimationImpl = null;
62
63                 delete _pAnimationBaseImpl;
64                 _pAnimationBaseImpl = null;
65
66                 return;
67         }
68
69         return;
70 }
71
72 RotateAnimation::~RotateAnimation(void)
73 {
74         delete _pRotateAnimationImpl;
75         _pRotateAnimationImpl = null;
76 }
77
78 RotateAnimation::RotateAnimation(const RotateAnimation& rotateAnimation)
79         : FloatAnimation(rotateAnimation)
80         , _pRotateAnimationImpl(null)
81 {
82         result r = GetLastResult();
83         SysTryReturnVoidResult(NID_UI_ANIM, (_pAnimationBaseImpl), r, "[%s] Propagating.", GetErrorMessage(r));
84
85         _pRotateAnimationImpl = new (std::nothrow) _RotateAnimationImpl(this);
86         SysTryCatch(NID_UI_ANIM, (_pRotateAnimationImpl != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
87
88         rotateAnimation.GetAnchor(_pRotateAnimationImpl->anchorX, _pRotateAnimationImpl->anchorY);
89
90         return;
91
92 CATCH:
93         delete _pAnimationBaseImpl;
94         _pAnimationBaseImpl = null;
95         delete _pFloatAnimationImpl;
96         _pFloatAnimationImpl = null;
97 }
98
99 RotateAnimation&
100 RotateAnimation::operator =(const RotateAnimation& rhs)
101 {
102         ClearLastResult();
103
104         if ((&rhs) != this)
105         {
106                 FloatAnimation::operator =(rhs);
107
108                 rhs.GetAnchor(_pRotateAnimationImpl->anchorX, _pRotateAnimationImpl->anchorY);
109         }
110
111         return *this;
112 }
113
114 bool
115 RotateAnimation::operator ==(const RotateAnimation& rhs) const
116 {
117         if (!(FloatAnimation::operator ==(rhs)))
118         {
119                 return false;
120         }
121
122         if (Float::Compare(_pRotateAnimationImpl->anchorX, rhs._pRotateAnimationImpl->anchorX) != 0 ||
123                 Float::Compare(_pRotateAnimationImpl->anchorY, rhs._pRotateAnimationImpl->anchorY) != 0)
124         {
125                 return false;
126         }
127
128         return true;
129 }
130
131 bool
132 RotateAnimation::operator !=(const RotateAnimation& rhs) const
133 {
134         return !(*this == rhs);
135 }
136
137 bool
138 RotateAnimation::Equals(const Tizen::Base::Object& rhs) const
139 {
140         const RotateAnimation* pRotateAnim = dynamic_cast< const RotateAnimation* >(&rhs);
141         if (pRotateAnim == null)
142         {
143                 return false;
144         }
145
146         return (*this == *pRotateAnim);
147 }
148
149 int
150 RotateAnimation::GetHashCode(void) const
151 {
152         return (((int) GetRepeatCount()) + ((int) GetOffset()) + ((int) GetDuration()) + ((int) GetDelay()));
153 }
154
155 result
156 RotateAnimation::SetAnchor(float anchorX, float anchorY)
157 {
158         SysTryReturnResult(NID_UI_ANIM, (anchorX >= 0.0 && anchorX <= 1.0 && anchorY >= 0.0 && anchorY <= 1.0), E_INVALID_ARG, "Invalid argument(s) is used. anchorX = %f, anchorX= %f.", anchorX, anchorY);
159
160         _pRotateAnimationImpl->anchorX = anchorX;
161         _pRotateAnimationImpl->anchorY = anchorY;
162
163         return E_SUCCESS;
164 }
165
166 void
167 RotateAnimation::GetAnchor(float& anchorX, float& anchorY) const
168 {
169         anchorX = _pRotateAnimationImpl->anchorX;
170         anchorY = _pRotateAnimationImpl->anchorY;
171
172         return;
173 }
174
175 AnimationType
176 RotateAnimation::GetType(void) const
177 {
178         return ANIMATION_TYPE_ROTATE_ANIMATION;
179 }
180
181 }}}   // Tizen::Ui::Animations