Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrlAnimation.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  * @file        FUiCtrlAnimation.cpp
19  * @brief       This is the implementation file for Animation class.
20  */
21
22 #include <FUiCtrlAnimation.h>
23 #include <FBaseSysLog.h>
24 #include "FUiCtrl_AnimationImpl.h"
25
26 using namespace Tizen::Graphics;
27 using namespace Tizen::Base::Collection;
28
29 namespace Tizen { namespace Ui { namespace Controls
30 {
31
32 Animation::Animation(void)
33 {
34 }
35
36 Animation::~Animation(void)
37 {
38 }
39
40 result
41 Animation::Construct(const Rectangle& rectangle, const IList& animationFrames)
42 {
43         result r = E_SUCCESS;
44
45         _AnimationImpl* pAnimationImpl = _AnimationImpl::GetInstance(*this);
46
47         SysAssertf((pAnimationImpl == null), "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
48
49         pAnimationImpl = _AnimationImpl::CreateAnimationImplN(this);
50         r = GetLastResult();
51         SysTryReturn(NID_UI_CTRL, pAnimationImpl != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
52
53         _pControlImpl = pAnimationImpl;
54
55         r = Control::SetBounds(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
56         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
57
58         r = pAnimationImpl->SetAnimationFrames(animationFrames);
59         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
60
61         pAnimationImpl->SetImageCount(animationFrames.GetCount());
62
63         return E_SUCCESS;
64
65 CATCH:
66         delete pAnimationImpl;
67         pAnimationImpl = null;
68
69         _pControlImpl = null;
70
71         return r;
72 }
73
74 void
75 Animation::AddAnimationEventListener(IAnimationEventListener& listener)
76 {
77         _AnimationImpl* pAnimationImpl = _AnimationImpl::GetInstance(*this);
78         SysAssertf(pAnimationImpl != null, "Not yet constructed. Construct() should be called before use.");
79
80         result r = pAnimationImpl->AddAnimationEventListener(listener);
81         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
82
83         SetLastResult(E_SUCCESS);
84         return;
85 }
86
87 void
88 Animation::RemoveAnimationEventListener(IAnimationEventListener& listener)
89 {
90         _AnimationImpl* pAnimationImpl = _AnimationImpl::GetInstance(*this);
91         SysAssertf(pAnimationImpl != null, "Not yet constructed. Construct() should be called before use.");
92
93         result r = pAnimationImpl->RemoveAnimationEventListener(listener);
94         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
95
96         SetLastResult(E_SUCCESS);
97         return;
98 }
99
100 void
101 Animation::SetRepeatCount(int count)
102 {
103         _AnimationImpl* pAnimationImpl = _AnimationImpl::GetInstance(*this);
104         SysAssertf(pAnimationImpl != null, "Not yet constructed. Construct() should be called before use.");
105
106         result r = pAnimationImpl->SetRepeatCount(count);
107         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
108
109         SetLastResult(E_SUCCESS);
110         return;
111 }
112
113 int
114 Animation::GetRepeatCount(void) const
115 {
116         const _AnimationImpl* pAnimationImpl = _AnimationImpl::GetInstance(*this);
117         SysAssertf(pAnimationImpl != null, "Not yet constructed. Construct() should be called before use.");
118
119         return pAnimationImpl->GetRepeatCount();
120 }
121
122 int
123 Animation::GetCurrentRepeatedCount(void) const
124 {
125         const _AnimationImpl* pAnimationImpl = _AnimationImpl::GetInstance(*this);
126         SysAssertf(pAnimationImpl != null, "Not yet constructed. Construct() should be called before use.");
127
128         return pAnimationImpl->GetCurrentRepeatedCount();
129 }
130
131 int
132 Animation::GetImageCount(void) const
133 {
134         const _AnimationImpl* pAnimationImpl = _AnimationImpl::GetInstance(*this);
135         SysAssertf(pAnimationImpl != null, "Not yet constructed. Construct() should be called before use.");
136
137         return pAnimationImpl->GetImageCount();
138 }
139
140 void
141 Animation::Play(void)
142 {
143         _AnimationImpl* pAnimationImpl = _AnimationImpl::GetInstance(*this);
144         SysAssertf(pAnimationImpl != null, "Not yet constructed. Construct() should be called before use.");
145
146         result r = pAnimationImpl->Play();
147         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
148
149         SetLastResult(E_SUCCESS);
150         return;
151 }
152
153 void
154 Animation::Stop(void)
155 {
156         _AnimationImpl* pAnimationImpl = _AnimationImpl::GetInstance(*this);
157         SysAssertf(pAnimationImpl != null, "Not yet constructed. Construct() should be called before use.");
158
159         result r = pAnimationImpl->Stop();
160         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
161
162         SetLastResult(E_SUCCESS);
163         return;
164 }
165
166 void
167 Animation::Pause(void)
168 {
169         _AnimationImpl* pAnimationImpl = _AnimationImpl::GetInstance(*this);
170         SysAssertf(pAnimationImpl != null, "Not yet constructed. Construct() should be called before use.");
171
172         result r = pAnimationImpl->Pause();
173         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
174
175         SetLastResult(E_SUCCESS);
176         return;
177 }
178
179 AnimationStatus
180 Animation::GetStatus(void) const
181 {
182         const _AnimationImpl* pAnimationImpl = _AnimationImpl::GetInstance(*this);
183         SysAssertf(pAnimationImpl != null, "Not yet constructed. Construct() should be called before use.");
184
185         return pAnimationImpl->GetStatus();
186 }
187
188 }}} // Tizen::Ui::Controls