Fork for IVI: mesa fixing
[profile/ivi/uifw.git] / src / ui / animations / FUiAnimAnimationTransaction.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        FUiAnimAnimationTransaction.cpp
20  * @brief       This file contains implementation of AnimationTransaction class
21  *
22  * This file contains implementation of AnimationTransaction class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FBaseColStackT.h>
27
28 #include <FUiAnimAnimationTransaction.h>
29
30 #include "FUiAnim_TransactionNode.h"
31 #include "FUiAnim_AnimationManager.h"
32
33
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::Base::Runtime;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Animations;
39
40
41 namespace Tizen { namespace Ui { namespace Animations
42 {
43
44 AnimationTransaction::~AnimationTransaction(void)
45 {
46
47 }
48
49 result
50 AnimationTransaction::Begin(void)
51 {
52         int transactionId = _AnimationManager::GetInstance()->BeginTransaction();
53         SysTryReturnResult(NID_UI_ANIM, (transactionId != -1), E_OUT_OF_MEMORY, "Propagating.");
54
55         return E_SUCCESS;
56 }
57
58 result
59 AnimationTransaction::Begin(int& transactionId)
60 {
61         transactionId = _AnimationManager::GetInstance()->BeginTransaction();
62         SysTryReturnResult(NID_UI_ANIM, (transactionId != -1), E_OUT_OF_MEMORY, "Propagating.");
63
64         return E_SUCCESS;
65 }
66
67 result
68 AnimationTransaction::Commit(void)
69 {
70         result r = _AnimationManager::GetInstance()->CommitTransaction();
71         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Propagating.");
72
73         return r;
74 }
75
76 result
77 AnimationTransaction::Stop(int transactionId)
78 {
79         SysTryReturnResult(NID_UI_ANIM, (transactionId > 0), E_INVALID_ARG, "Invalid argument(s) is used. transactionId = %d", transactionId);
80
81         result r = _AnimationManager::GetInstance()->StopTransaction(transactionId);
82         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Propagating.");
83
84         return r;
85 }
86
87 result
88 AnimationTransaction::Discard(void)
89 {
90         result r = _AnimationManager::GetInstance()->DiscardTransaction();
91         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Propagating.");
92
93         return r;
94 }
95
96 AnimationTransactionStatus
97 AnimationTransaction::GetStatus(int transactionId)
98 {
99         SysTryReturn(NID_UI_ANIM, (transactionId > 0), ANIMATION_TRANSACTION_STATUS_STOPPED, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. transactionId = %d.", transactionId);
100
101         if (_AnimationManager::GetInstance()->IsTransactionRunning(transactionId))
102         {
103                 return ANIMATION_TRANSACTION_STATUS_PLAYING;
104         }
105
106         return ANIMATION_TRANSACTION_STATUS_STOPPED;
107 }
108
109 result
110 AnimationTransaction::SetTransactionEventListener(IAnimationTransactionEventListener* pListener)
111 {
112         _AnimationManager::GetInstance()->SetTransactionEventListener(pListener);
113
114         return E_SUCCESS;
115 }
116
117 result
118 AnimationTransaction::SetCurrentTransactionEventListener(IAnimationTransactionEventListener* pListener)
119 {
120         _TransactionNode* pNode = _AnimationManager::GetInstance()->GetCurrentTransaction();
121         SysTryReturnResult(NID_UI_ANIM, (pNode != null), E_INVALID_OPERATION, "Transaction isn't opened.");
122
123         result r = pNode->SetEventListener(pListener);
124         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Propagating.");
125
126         return r;
127 }
128
129 result
130 AnimationTransaction::SetVisualElementImplicitAnimationEnabled(bool enable)
131 {
132         _TransactionNode* pNode = _AnimationManager::GetInstance()->GetCurrentTransaction();
133         SysTryReturnResult(NID_UI_ANIM, (pNode != null), E_INVALID_OPERATION, "Transaction isn't opened.");
134
135         result r = pNode->SetImplicitAnimationEnabled(enable);
136         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Propagating.");
137
138         return r;
139 }
140
141 result
142 AnimationTransaction::SetVisualElementAnimationStatusEventListener(IVisualElementAnimationStatusEventListener* pListener)
143 {
144         _TransactionNode* pNode = _AnimationManager::GetInstance()->GetCurrentTransaction();
145         SysTryReturnResult(NID_UI_ANIM, (pNode != null), E_INVALID_OPERATION, "Transaction isn't opened.");
146
147         pNode->SetStatusEventListener(pListener);
148
149         return E_SUCCESS;
150 }
151
152 result
153 AnimationTransaction::SetVisualElementAnimationTimingFunction(const IVisualElementAnimationTimingFunction* pTimingFunction)
154 {
155         _TransactionNode* pNode = _AnimationManager::GetInstance()->GetCurrentTransaction();
156         SysTryReturnResult(NID_UI_ANIM, (pNode != null), E_INVALID_OPERATION, "Transaction isn't opened.");
157
158         pNode->SetTimingFunction(pTimingFunction);
159
160         return E_SUCCESS;
161 }
162
163 result
164 AnimationTransaction::SetVisualElementAnimationValueInterpolator(const IVisualElementAnimationValueInterpolator* pValueInterpolator)
165 {
166         _TransactionNode* pNode = _AnimationManager::GetInstance()->GetCurrentTransaction();
167         SysTryReturnResult(NID_UI_ANIM, (pNode != null), E_INVALID_OPERATION, "Transaction isn't opened.");
168
169         pNode->SetValueInterpolator(pValueInterpolator);
170
171         return E_SUCCESS;
172 }
173
174 result
175 AnimationTransaction::SetVisualElementAnimationDuration(long milliseconds)
176 {
177         _TransactionNode* pNode = _AnimationManager::GetInstance()->GetCurrentTransaction();
178         SysTryReturnResult(NID_UI_ANIM, (pNode != null), E_INVALID_OPERATION, "Transaction isn't opened.");
179         SysTryReturnResult(NID_UI_ANIM, (milliseconds >= 0 && milliseconds >= pNode->GetOffset()),
180                                                 E_INVALID_ARG, "Invalid argument(s) is used. milliseconds = %ld", milliseconds);
181
182         pNode->SetDuration(milliseconds);
183
184         return E_SUCCESS;
185 }
186
187 long
188 AnimationTransaction::GetVisualElementAnimationDuration(void)
189 {
190         _TransactionNode* pNode = _AnimationManager::GetInstance()->GetCurrentTransaction();
191         SysTryReturn(NID_UI_ANIM, (pNode != null), -1, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Transaction isn't opened.");
192
193         return pNode->GetDuration();
194 }
195
196 result
197 AnimationTransaction::SetVisualElementAnimationOffset(long milliseconds)
198 {
199         _TransactionNode* pNode = _AnimationManager::GetInstance()->GetCurrentTransaction();
200         SysTryReturnResult(NID_UI_ANIM, (pNode != null), E_INVALID_OPERATION, "Transaction isn't opened.");
201         SysTryReturnResult(NID_UI_ANIM, (milliseconds >= 0 && milliseconds <= pNode->GetDuration()),
202                                            E_INVALID_ARG, "Invalid argument(s) is used. milliseconds = %ld", milliseconds);
203
204         pNode->SetOffset(milliseconds);
205
206         return E_SUCCESS;
207 }
208
209 long
210 AnimationTransaction::GetVisualElementAnimationOffset(void)
211 {
212         _TransactionNode* pNode = _AnimationManager::GetInstance()->GetCurrentTransaction();
213         SysTryReturn(NID_UI_ANIM, (pNode != null), -1, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Transaction isn't opened.");
214
215         return pNode->GetOffset();
216 }
217
218 result
219 AnimationTransaction::SetVisualElementAnimationDelay(long milliseconds)
220 {
221         SysTryReturnResult(NID_UI_ANIM, (milliseconds >= 0), E_INVALID_ARG, "Invalid argument(s) is used. milliseconds = %ld", milliseconds);
222
223         _TransactionNode* pNode = _AnimationManager::GetInstance()->GetCurrentTransaction();
224         SysTryReturnResult(NID_UI_ANIM, (pNode != null), E_INVALID_OPERATION, "Transaction isn't opened.");
225
226         pNode->SetDelay(milliseconds);
227
228         return E_SUCCESS;
229 }
230
231 long
232 AnimationTransaction::GetVisualElementAnimationDelay(void)
233 {
234         _TransactionNode* pNode = _AnimationManager::GetInstance()->GetCurrentTransaction();
235         SysTryReturn(NID_UI_ANIM, (pNode != null), -1, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Transaction isn't opened.");
236
237         return pNode->GetDelay();
238 }
239
240 result
241 AnimationTransaction::SetVisualElementAnimationRepeatCount(long count)
242 {
243         SysTryReturnResult(NID_UI_ANIM, (count >= 0), E_INVALID_ARG, "Invalid argument(s) is used. count = %ld", count);
244
245         _TransactionNode* pNode = _AnimationManager::GetInstance()->GetCurrentTransaction();
246         SysTryReturnResult(NID_UI_ANIM, (pNode != null), E_INVALID_OPERATION, "Transaction isn't opened.");
247
248         pNode->SetRepeatCount(count);
249
250         return E_SUCCESS;
251 }
252
253 long
254 AnimationTransaction::GetVisualElementAnimationRepeatCount(void)
255 {
256         _TransactionNode* pNode = _AnimationManager::GetInstance()->GetCurrentTransaction();
257         SysTryReturn(NID_UI_ANIM, (pNode != null), -1, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Transaction isn't opened.");
258
259         return pNode->GetRepeatCount();
260 }
261
262 result
263 AnimationTransaction::SetVisualElementAnimationAutoReverseEnabled(bool autoReverse)
264 {
265         _TransactionNode* pNode = _AnimationManager::GetInstance()->GetCurrentTransaction();
266         SysTryReturnResult(NID_UI_ANIM, (pNode != null), E_INVALID_OPERATION, "Transaction isn't opened.");
267
268         pNode->SetAutoReverseEnabled(autoReverse);
269
270         return E_SUCCESS;
271 }
272
273 bool
274 AnimationTransaction::IsVisualElementAnimationAutoReverseEnabled(void)
275 {
276         _TransactionNode* pNode = _AnimationManager::GetInstance()->GetCurrentTransaction();
277         SysTryReturn(NID_UI_ANIM, (pNode != null), false, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Transaction isn't opened.");
278
279         bool autoReverse = pNode->IsAutoReverseEnabled();
280
281         result r = GetLastResult();
282         SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Propagating.");
283
284         return autoReverse;
285 }
286
287 result
288 AnimationTransaction::SetVisualElementAnimationScaleRatio(float scaleRatio)
289 {
290         SysTryReturnResult(NID_UI_ANIM, (scaleRatio > 0.f), E_INVALID_ARG, "Invalid argument(s) is used. scaleRatio = %f", scaleRatio);
291
292         _TransactionNode* pNode = _AnimationManager::GetInstance()->GetCurrentTransaction();
293         SysTryReturnResult(NID_UI_ANIM, (pNode != null), E_INVALID_OPERATION, "Transaction isn't opened.");
294
295         pNode->SetScaleRatio(scaleRatio);
296
297         return E_SUCCESS;
298 }
299
300 float
301 AnimationTransaction::GetVisualElementAnimationScaleRatio(void)
302 {
303         _TransactionNode* pNode = _AnimationManager::GetInstance()->GetCurrentTransaction();
304         SysTryReturn(NID_UI_ANIM, (pNode != null), 0.0f, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Transaction isn't opened.");
305
306         return pNode->GetScaleRatio();
307 }
308
309 } } }   // Tizen::Ui::Animations