2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
19 * @file FUiAnim_FrameAnimatorImpl.cpp
20 * @brief This file contains implementation of _FrameAnimatorImpl class
22 * This file contains implementation of _FrameAnimatorImpl class.
25 #include <FBaseSysLog.h>
26 #include <FBaseTypes.h>
28 #include <FUiControl.h>
29 #include <FUiCtrlFrame.h>
30 #include <FUiCtrlForm.h>
31 #include <FUiAnimDimensionAnimation.h>
32 #include <FUiAnimPointAnimation.h>
33 #include <FUiAnimRectangleAnimation.h>
34 #include <FUiAnimIntegerAnimation.h>
35 #include <FUiAnimFloatAnimation.h>
36 #include <FUiAnimRotateAnimation.h>
37 #include <FUiAnimAnimationTransaction.h>
38 #include <FUiAnimVisualElement.h>
39 #include <FUiAnimBezierTimingFunction.h>
41 #include "FUi_ControlImpl.h"
42 #include "FUi_Matrix3Df.h"
43 #include "FUiAnim_FrameAnimatorImpl.h"
44 #include "FUiAnim_VisualElementAnimationImpl.h"
46 #include "FUiAnim_VisualElementImpl.h"
47 #include "FUiAnim_ControlVisualElement.h"
48 #include "FUiAnim_MatrixUtil.h"
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::Graphics;
54 using namespace Tizen::Ui;
55 using namespace Tizen::Ui::Controls;
58 namespace Tizen { namespace Ui { namespace Animations
62 _FrameAnimatorImpl::_FrameAnimatorImpl(FrameAnimator* pFrameAnimator)
64 , __pFrameAnimator(pFrameAnimator)
66 , __frameAnimatorStatus(ANIMATOR_STATUS_STOPPED)
67 , __pCurrentForm(null)
69 , __pCurrentFormVisualElement(null)
70 , __pNextFormVisualElement(null)
71 , __animationEffectType(FRAME_ANIMATOR_FORM_TRANSITION_ANIMATION_FADE_IN_OUT)
72 , __animInterpolatorType(ANIMATION_INTERPOLATOR_LINEAR)
74 , __firstBezierControlPointsTime(0.0f)
75 , __firstBezierControlPointsValue(0.0f)
76 , __secondBezierControlPointsTime(0.0f)
77 , __secondBezierControlPointsValue(0.0f)
79 , __veDefaultBounds(0, 0, 0, 0)
80 , __veDefaultOpacity(0)
82 , __pCurrentCaptureVisualElement(null)
83 , __pNextCaptureVisualElement(null)
84 , __pDummySurface(null)
89 _FrameAnimatorImpl::Construct(const Frame& source)
91 SysAssertf((__pFrame == null), "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class.");
95 __pFrame = const_cast< Frame* >(&source);
97 r = __frameActiveAnimationList.Construct();
98 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , r,"[%s] Failed to construct FrameActiveAnimationList.", GetErrorMessage(r));
100 __pBgElement = new (std::nothrow) _ControlVisualElement();
101 SysTryCatch(NID_UI_ANIM, (__pBgElement != null), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
103 r = __pBgElement->ConstructControlVisualElement();
104 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , r, "[%s] Failed to construct ControlVisualElement.", GetErrorMessage(r));
106 __pBgElement->SetName("FrameAnimatorBG");
107 __pBgElement->SetShowState(true);
108 __pBgElement->SetImplicitAnimationEnabled(false);
110 __pCurrentCaptureVisualElement = new (std::nothrow) _VisualElement();
111 SysTryCatch(NID_UI_ANIM, (__pCurrentCaptureVisualElement != null), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
113 r = __pCurrentCaptureVisualElement->Construct();
114 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , r, "[%s] Failed to construct VisualElement.", GetErrorMessage(r));
116 __pCurrentCaptureVisualElement->SetName("FrameAnimatorCurrentCapture");
117 __pCurrentCaptureVisualElement->SetShowState(false);
118 __pCurrentCaptureVisualElement->SetImplicitAnimationEnabled(false);
120 __pNextCaptureVisualElement = new (std::nothrow) _VisualElement();
121 SysTryCatch(NID_UI_ANIM, (__pNextCaptureVisualElement != null), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
123 r = __pNextCaptureVisualElement->Construct();
124 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , r, "[%s] Failed to construct VisualElement.", GetErrorMessage(r));
126 __pNextCaptureVisualElement->SetName("FrameAnimatorNextCapture");
127 __pNextCaptureVisualElement->SetShowState(false);
128 __pNextCaptureVisualElement->SetImplicitAnimationEnabled(false);
130 __pBgElement->AttachChild(*__pCurrentCaptureVisualElement);
131 __pBgElement->AttachChild(*__pNextCaptureVisualElement);
133 __pDummySurface = new (std::nothrow) VisualElementSurface();
134 SysTryCatch(NID_UI_ANIM, (__pDummySurface != null), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
136 r = __pDummySurface->Construct(*__pFrame->GetDisplayContext(), Dimension(1,1));
137 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), , r, "[%s] Failed to construct VisualElementSurface.", GetErrorMessage(r));
147 _FrameAnimatorImpl::~_FrameAnimatorImpl(void)
153 _FrameAnimatorImpl::Dispose(void)
157 AnimationTransaction::Stop(__transactionId);
158 __transactionId = -1;
163 delete __pDummySurface;
164 __pDummySurface = null;
167 // delete with children
170 __pBgElement->Destroy();
174 __frameActiveAnimationList.RemoveAll();
175 __frameAnimStatusEventListener.RemoveAll();
181 _FrameAnimatorImpl::FrameActiveAnimation::operator ==(const FrameActiveAnimation& frameActiveAnim) const
183 if ((formTransitionAnimationType == frameActiveAnim.formTransitionAnimationType) && (pPropertyAnimation == frameActiveAnim.pPropertyAnimation))
192 _FrameAnimatorImpl::FrameActiveAnimation::operator !=(const FrameActiveAnimation& frameActiveAnim) const
194 if ((formTransitionAnimationType != frameActiveAnim.formTransitionAnimationType) || (pPropertyAnimation != frameActiveAnim.pPropertyAnimation))
203 _FrameAnimatorImpl::AddFrameAnimatorEventListener(IFrameAnimatorEventListener& listener)
205 IFrameAnimatorEventListener* pStatusListener = &listener;
207 if (__frameAnimStatusEventListener.Contains(pStatusListener) == true)
209 return E_OBJ_ALREADY_EXIST;
212 result r = __frameAnimStatusEventListener.Add(pStatusListener);
213 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "A system error has been occurred. Failed to add frame animator event listener.");
219 _FrameAnimatorImpl::RemoveFrameAnimatorEventListener(IFrameAnimatorEventListener& listener)
221 IFrameAnimatorEventListener* pStatusListener = &listener;
223 result r = __frameAnimStatusEventListener.Remove(pStatusListener);
224 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_OBJ_NOT_FOUND, "Propagating.");
230 _FrameAnimatorImpl::StopAllAnimations(void)
232 if (__transactionId != -1)
234 result r = AnimationTransaction::Stop(__transactionId);
235 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Propagating.");
242 _FrameAnimatorImpl::AddControl(const Control& control)
244 Form* pCurrentForm = __pFrame->GetCurrentForm();
246 Form* pNextForm = dynamic_cast< Form* >(const_cast< Control* >(&control));
247 SysTryReturnResult(NID_UI_ANIM, (pNextForm), E_INVALID_ARG, "Invalid argument(s) is used. Control is not Form.");
248 SysTryReturnResult(NID_UI_ANIM, (pCurrentForm != pNextForm), E_SUCCESS, "Current form is same as the new form.");
250 result r = __pFrame->AddControl(control);
251 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Propagating.");
253 r = ChangeCurrentForm(pCurrentForm, *pNextForm);
254 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Propagating.");
260 _FrameAnimatorImpl::SetCurrentForm(const Form& form)
262 Form* pCurrentForm = __pFrame->GetCurrentForm();
264 Form* pNextForm = const_cast< Form* >(&form);
265 SysTryReturnResult(NID_UI_ANIM, (pCurrentForm != pNextForm), E_SUCCESS, "Current form is same as the new form.");
267 result r = ChangeCurrentForm(pCurrentForm, *pNextForm);
268 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Propagating.");
274 _FrameAnimatorImpl::ChangeCurrentForm(Form* pCurrentForm, Form& nextForm)
276 SysTryReturnResult(NID_UI_ANIM, __transactionId == -1, E_INVALID_OPERATION, "Last frame animation was not completed.");
278 result r = E_SUCCESS;
280 if (IsAnimationSupported() == false || pCurrentForm == null)
282 r = __pFrame->SetCurrentForm(nextForm);
283 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Propagating.");
290 __pCurrentForm = pCurrentForm;
291 __pNextForm = &nextForm;
293 _ControlImpl* pControlImpl = null;
295 pControlImpl = _ControlImpl::GetInstance(*__pCurrentForm);
296 __pCurrentFormVisualElement = pControlImpl->GetCore().GetVisualElement();
298 r = __pFrame->SetCurrentForm(*__pNextForm);
299 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Propagating.");
301 pControlImpl = _ControlImpl::GetInstance(*__pNextForm);
302 __pNextFormVisualElement = pControlImpl->GetCore().GetVisualElement();
305 pControlImpl->SetBoundsAndUpdateLayout(pControlImpl->GetBounds());
307 __veDefaultMatrix = __pCurrentFormVisualElement->GetTransformMatrix();
308 __veDefaultBounds = _VisualElementImpl::GetInstance(*__pCurrentFormVisualElement)->GetBoundingBox();
309 __veDefaultOpacity = 1.0f; //TODO: check__pCurrentFormVisualElement->GetOpacity();
310 __pCurrentFormVisualElement->SetShowState(true);
312 // prepare background
313 FloatRectangle bgBounds = __pCurrentFormVisualElement->GetBounds();
315 if (__animationEffectType == FRAME_ANIMATOR_FORM_TRANSITION_ANIMATION_TRANSLATE_LEFT
316 || __animationEffectType == FRAME_ANIMATOR_FORM_TRANSITION_ANIMATION_TRANSLATE_RIGHT)
318 if (bgBounds.width <= bgBounds.height)
320 bgBounds.width = bgBounds.height;
324 bgBounds.height = bgBounds.width;
328 __pBgElement->SetBounds(bgBounds);
330 Color bgColor = pCurrentForm->GetBackgroundColor();
331 __pBgElement->SetBackgroundColor(_Colorf((float)bgColor.GetRed() / 255, (float)bgColor.GetGreen() / 255, (float)bgColor.GetBlue() / 255, (float)bgColor.GetAlpha() / 255));
333 VisualElement* pParentVisualElement = __pCurrentFormVisualElement->GetParent();
334 SysTryReturnResult(NID_UI_ANIM, (pParentVisualElement), E_SYSTEM, "A system error has been occurred. Failed to get visual element's parent.");
336 pParentVisualElement->InsertChild(*__pBgElement, __pCurrentFormVisualElement, false);
338 AnimationTransaction::Begin(__transactionId);
339 AnimationTransaction::SetCurrentTransactionEventListener(this);
345 AnimationTransaction::Discard();
346 RemoveAllAnimations(true);
351 r = AnimationTransaction::Commit();
352 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to commit transaction.");
354 __frameAnimatorStatus = ANIMATOR_STATUS_PLAYING;
359 _FrameAnimatorImpl::SetAnimations(void)
361 result r = E_SUCCESS;
364 transId.Append(__transactionId);
366 switch (__animationEffectType)
368 case FRAME_ANIMATOR_FORM_TRANSITION_ANIMATION_TRANSLATE_LEFT:
370 Dimension currentSize = __pCurrentForm->GetSize();
371 Dimension nextSize = __pNextForm->GetSize();
373 Point currFormStartPoint = Point(0, 0);
374 Point currFormEndPoint = Point((-1 * (currentSize.width)), 0);
376 Point nextFormStartPoint = Point((currentSize.width), 0);
377 Point nextFormEndPoint = Point(0, 0);
379 if (currentSize.width > nextSize.width)
381 currFormStartPoint = Point((-1 * (currentSize.width - nextSize.width)), 0);
382 nextFormStartPoint = Point((nextSize.width), 0);
385 r = StartLayerAnimation(__pCurrentFormVisualElement, ANIMATION_TARGET_POSITION, Variant(currFormStartPoint), Variant(currFormEndPoint), transId + (L"CurrentFormLeftTranslatePosition"));
386 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
388 r = StartLayerAnimation(__pNextFormVisualElement, ANIMATION_TARGET_POSITION, Variant(nextFormStartPoint), Variant(nextFormEndPoint), transId + (L"NextFormLeftTranslatePosition"));
389 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
393 case FRAME_ANIMATOR_FORM_TRANSITION_ANIMATION_TRANSLATE_RIGHT:
395 Dimension currentSize = __pCurrentForm->GetSize();
396 Dimension nextSize = __pNextForm->GetSize();
398 Point currFormStartPoint = Point(0, 0);
399 Point currFormEndPoint = Point((nextSize.width), 0);
401 Point nextFormStartPoint = Point((-1 * (nextSize.width)), 0);
402 Point nextFormEndPoint = Point(0, 0);
404 if (currentSize.width < nextSize.width)
406 currFormStartPoint = Point((nextSize.width - currentSize.width), 0);
407 nextFormStartPoint = Point((-1 * (currentSize.width)), 0);
410 r = StartLayerAnimation(__pCurrentFormVisualElement, ANIMATION_TARGET_POSITION, Variant(currFormStartPoint), Variant(currFormEndPoint), transId + (L"CurrentFormRightTranslatePosition"));
411 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list");
413 r = StartLayerAnimation(__pNextFormVisualElement, ANIMATION_TARGET_POSITION, Variant(nextFormStartPoint), Variant(nextFormEndPoint), transId + (L"NextFormRightTranslatePosition"));
414 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list");
418 case FRAME_ANIMATOR_FORM_TRANSITION_ANIMATION_FADE_IN_OUT:
420 r = PrepareCapture();
421 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to capture.");
423 // r = StartLayerAnimation(__pCurrentCaptureVisualElement, ANIMATION_TARGET_ALPHA, Variant(1.0f), Variant(0.0f), transId + (L"CurrentFormFadeOutAlpha"));
424 // SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
426 r = StartLayerAnimation(__pNextCaptureVisualElement, ANIMATION_TARGET_ALPHA, Variant(0.0f), Variant(1.0f), transId + (L"NextFormFadeInAlpha"));
427 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
431 case FRAME_ANIMATOR_FORM_TRANSITION_ANIMATION_ZOOM_IN:
433 Dimension currentSize = __pCurrentForm->GetSize();
435 Dimension startSize = Dimension((currentSize.width * 80) / 100, (currentSize.height * 80) / 100);
436 Dimension endSize = currentSize;
438 r = StartLayerAnimation(__pCurrentFormVisualElement, ANIMATION_TARGET_ALPHA, Variant(1.0f), Variant(0.0f), transId + (L"CurrentFormZoomInAlpha"));
439 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
441 r = StartLayerAnimation(__pNextFormVisualElement, ANIMATION_TARGET_ALPHA, Variant(0.0f), Variant(1.0f), transId + (L"NextFormZoomInAlpha"));
442 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
444 r = StartLayerAnimation(__pNextFormVisualElement, ANIMATION_TARGET_SIZE, Variant(startSize), Variant(endSize), transId + (L"NextFormZoomInSize"));
445 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
449 case FRAME_ANIMATOR_FORM_TRANSITION_ANIMATION_ZOOM_OUT:
451 r = PrepareCapture();
452 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to capture.");
454 Dimension currentSize = __pCurrentForm->GetSize();
456 Dimension startSize = currentSize;
457 Dimension endSize = Dimension((currentSize.width * 80) / 100, (currentSize.height * 80) / 100);
459 r = StartLayerAnimation(__pCurrentCaptureVisualElement, ANIMATION_TARGET_SIZE, Variant(startSize), Variant(endSize), transId + (L"CurrentFormZoomOutSize"));
460 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
462 r = StartLayerAnimation(__pCurrentCaptureVisualElement, ANIMATION_TARGET_ALPHA, Variant(1.0f), Variant(0.0f), transId + (L"CurrentFormZoomOutAlpha"));
463 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
465 r = StartLayerAnimation(__pNextCaptureVisualElement, ANIMATION_TARGET_ALPHA, Variant(0.0f), Variant(1.0f), transId + (L"NextFormZoomOutAlpha"));
466 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
471 case FRAME_ANIMATOR_FORM_TRANSITION_ANIMATION_DEPTH_IN:
473 r = PrepareCapture();
474 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to capture.");
476 Dimension currentSize = __pCurrentForm->GetSize();
478 Dimension currFormStartSize = currentSize;
479 Dimension currFormEndSize = Dimension((currentSize.width * 80) / 100, (currentSize.height * 80) / 100);
480 Dimension nextFormStartSize = Dimension((currentSize.width * 120) / 100, (currentSize.height * 120) / 100);
481 Dimension nextFormEndSize = currentSize;
483 r = StartLayerAnimation(__pCurrentCaptureVisualElement, ANIMATION_TARGET_ALPHA, Variant(1.0f), Variant(0.0f), transId + (L"CurrentFormDepthInAplha"));
484 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
486 r = StartLayerAnimation(__pCurrentCaptureVisualElement, ANIMATION_TARGET_SIZE, Variant(currFormStartSize), Variant(currFormEndSize), transId + (L"CurrentFormDepthInSize"));
487 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
489 r = StartLayerAnimation(__pNextCaptureVisualElement, ANIMATION_TARGET_ALPHA, Variant(0.0f), Variant(1.0f), transId + (L"NextFormDepthInAplha"));
490 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
492 r = StartLayerAnimation(__pNextCaptureVisualElement, ANIMATION_TARGET_SIZE, Variant(nextFormStartSize), Variant(nextFormEndSize), transId + (L"NextFormDepthInSize"));
493 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
497 case FRAME_ANIMATOR_FORM_TRANSITION_ANIMATION_DEPTH_OUT:
499 Dimension currentSize = __pCurrentForm->GetSize();
501 Dimension currFormStartSize = currentSize;
502 Dimension currFormEndSize = Dimension((currentSize.width * 120) / 100, (currentSize.height * 120) / 100);
503 Dimension nextFormStartSize = Dimension((currentSize.width * 80) / 100, (currentSize.height * 80) / 100);
504 Dimension nextFormEndSize = currentSize;
506 r = StartLayerAnimation(__pCurrentFormVisualElement, ANIMATION_TARGET_ALPHA, Variant(1.0f), Variant(0.0f), transId + (L"CurrentFormDepthOutAlpha"));
507 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
509 r = StartLayerAnimation(__pNextFormVisualElement, ANIMATION_TARGET_ALPHA, Variant(0.0f), Variant(1.0f), transId + (L"NextFormDepthOutAlpha"));
510 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
512 r = StartLayerAnimation(__pCurrentFormVisualElement, ANIMATION_TARGET_SIZE, Variant(currFormStartSize), Variant(currFormEndSize), transId + (L"CurrentFormDepthOutSize"));
513 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
515 r = StartLayerAnimation(__pNextFormVisualElement, ANIMATION_TARGET_SIZE, Variant(nextFormStartSize), Variant(nextFormEndSize), transId + (L"NextFormDepthOutSize"));
516 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to add animation to play list.");
521 SysLogException(NID_UI_ANIM, E_SYSTEM, "A system error has been occurred. FrameAnimatorFormTransitionAnimation is invalid.");
529 _FrameAnimatorImpl::PrepareCapture(void)
531 VisualElement* pParentVisualElement = __pNextFormVisualElement->GetParent();
532 SysTryReturnResult(NID_UI_ANIM, (pParentVisualElement), E_SYSTEM, "A system error has been occurred. Failed to get visual element's parent.");
534 pParentVisualElement->InsertChild(*__pBgElement, __pNextFormVisualElement, true);
536 // remove dummy surface
537 __pCurrentCaptureVisualElement->SetSurface(null);
538 __pNextCaptureVisualElement->SetSurface(null);
541 __pCurrentCaptureVisualElement->SetOpacity(1.0f);
542 __pNextCaptureVisualElement->SetOpacity(1.0f);
544 __pCurrentCaptureVisualElement->SetTransformMatrix(__pCurrentFormVisualElement->GetTransformMatrix());
545 __pNextCaptureVisualElement->SetTransformMatrix(__pNextFormVisualElement->GetTransformMatrix());
547 __pCurrentCaptureVisualElement->SetShowState(true);
548 __pNextCaptureVisualElement->SetShowState(true);
550 FloatRectangle currentBounds = __pCurrentFormVisualElement->GetBounds();
551 __pCurrentCaptureVisualElement->SetBounds(currentBounds);
553 FloatRectangle nextBounds = __pNextFormVisualElement->GetBounds();
554 __pNextCaptureVisualElement->SetBounds(nextBounds);
557 __pCurrentFormVisualElement->Draw();
558 __pNextFormVisualElement->Draw();
560 Canvas* pCanvas = null;
562 pCanvas = __pCurrentCaptureVisualElement->GetCanvasN();
563 SysTryReturnResult(NID_UI_ANIM, (pCanvas), E_SYSTEM, "A system error has been occurred. Failed to get canvas.");
565 currentBounds.SetPosition(0, 0);
566 _VisualElementImpl::GetInstance(*__pCurrentFormVisualElement)->Capture(*pCanvas, currentBounds, true);
569 pCanvas = __pNextCaptureVisualElement->GetCanvasN();
570 SysTryReturnResult(NID_UI_ANIM, (pCanvas), E_SYSTEM, "A system error has been occurred. Failed to get canvas.");
572 nextBounds.SetPosition(0, 0);
573 _VisualElementImpl::GetInstance(*__pNextFormVisualElement)->Capture(*pCanvas, nextBounds, true);
581 _FrameAnimatorImpl::StartLayerAnimation(VisualElement* pLayer, AnimationTargetType animTarget, Variant startValue, Variant endValue, String animName)
583 result r = E_SUCCESS;
585 Dimension startSize, endSize;
586 Point startPoint, endPoint;
588 VisualElementPropertyAnimation* propAnimation = null;
589 propAnimation = new (std::nothrow) VisualElementPropertyAnimation();
590 SysTryReturnResult(NID_UI_ANIM, (propAnimation), E_OUT_OF_MEMORY, "Memory allocation failed.");
592 propAnimation->SetDuration(__duration);
594 const IVisualElementAnimationTimingFunction* pTimingFunction = null;
595 const wchar_t* pVePropType = null;
596 Rectangle rect = __pCurrentForm->GetBounds();
598 switch (__animInterpolatorType)
600 case ANIMATION_INTERPOLATOR_LINEAR:
601 pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(L"Linear"); //INTERPOLATION_LINEAR
604 case ANIMATION_INTERPOLATOR_EASE_IN:
605 pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(L"EaseIn"); //INTERPOLATION_EASE_IN
608 case ANIMATION_INTERPOLATOR_EASE_OUT:
609 pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(L"EaseOut"); //INTERPOLATION_EASE_OUT
612 case ANIMATION_INTERPOLATOR_EASE_IN_OUT:
613 pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(L"EaseInOut"); //INTERPOLATION_EASE_INOUT
616 case ANIMATION_INTERPOLATOR_DISCRETE:
617 pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(L"Discrete"); //INTERPOLATION_DISCRETE
620 case ANIMATION_INTERPOLATOR_BEZIER:
622 pTimingFunction = new (std::nothrow) BezierTimingFunction();
623 SysTryCatch(NID_UI_ANIM, (pTimingFunction), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to get TimingFunction.");
625 ((BezierTimingFunction*) pTimingFunction)->SetControlPoints(__firstBezierControlPointsTime, __firstBezierControlPointsValue, __secondBezierControlPointsTime, __secondBezierControlPointsValue);
630 SysTryCatch(NID_UI_ANIM, false, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation interpolator is invalid. ");
634 SysTryCatch(NID_UI_ANIM, (pTimingFunction), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to get TimingFunction.");
635 propAnimation->SetTimingFunction(pTimingFunction);
637 switch(startValue.GetType())
639 case VARIANT_TYPE_POINT:
640 startPoint = startValue.ToPoint();
641 endPoint = endValue.ToPoint();
643 case VARIANT_TYPE_DIMENSION:
644 startSize = startValue.ToDimension();
645 endSize = endValue.ToDimension();
652 case ANIMATION_TARGET_SIZE:
654 float anchorX = 0.0f;
655 float anchorY = 0.0f;
656 float anchorZ = 0.0f;
662 pVePropType = VePropTransform;
664 anchorX = (float) rect.width * anchorX;
665 anchorY = (float) rect.height * anchorY;
667 scaleX = (float) startSize.width / (float) rect.width;
668 scaleY = (float) startSize.height / (float) rect.height;
670 Tizen::Graphics::FloatMatrix4 startMatrix = Tizen::Graphics::FloatMatrix4();
671 //startMatrix.SetAsIdentity(); // default value is identity matrix
672 _MatrixUtilScale(startMatrix, scaleX, scaleY, scaleZ);
673 _MatrixUtilAtAnchor(startMatrix, anchorX, anchorY, anchorZ);
675 scaleX = (float) endSize.width / (float) rect.width;
676 scaleY = (float) endSize.height / (float) rect.height;
678 Tizen::Graphics::FloatMatrix4 endMatrix = Tizen::Graphics::FloatMatrix4();
679 //endMatrix.SetAsIdentity(); // default value is identity matrix
680 _MatrixUtilScale(endMatrix, scaleX, scaleY, scaleZ);
681 _MatrixUtilAtAnchor(endMatrix, anchorX, anchorY, anchorZ);
683 propAnimation->SetStartValue(Variant(startMatrix));
684 propAnimation->SetEndValue(Variant(endMatrix));
688 case ANIMATION_TARGET_POSITION:
690 pVePropType = VePropBounds;
694 rect = pLayer->GetBounds();
695 rect.x = startPoint.x;
696 rect.y = startPoint.y;
697 propAnimation->SetStartValue(Variant(rect));
701 propAnimation->SetEndValue(Variant(rect));
705 case ANIMATION_TARGET_ALPHA:
707 pVePropType = VePropOpacity;
708 propAnimation->SetStartValue(startValue);
709 propAnimation->SetEndValue(endValue);
713 case ANIMATION_TARGET_ROTATION:
715 float anchorX = 0.0f;
716 float anchorY = 0.0f;
718 pVePropType = VeSubPropTransformRotationZ;
719 _VisualElementImpl::GetInstance(*pLayer)->SetAnchor(FloatPoint(anchorX, anchorY));
721 propAnimation->SetStartValue(startValue);
722 propAnimation->SetEndValue(endValue);
728 SysTryCatch(NID_UI_ANIM, false, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] animTarget is invalid.");
733 SysTryCatch(NID_UI_ANIM, (pVePropType), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Animation property type is invalid.");
734 propAnimation->SetPropertyName(pVePropType);
736 r = pLayer->AddAnimation(animName, *propAnimation);
737 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, r, "[E_SYSTEM] A system error has been occurred. Failed to add animation to visual element.");
739 r = AddFrameActiveAnimation(pLayer, __animationEffectType, propAnimation, const_cast < IVisualElementAnimationTimingFunction* >(pTimingFunction), animName);
740 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, r, "[E_SYSTEM] A system error has been occurred. Failed to add frame active animation to the playing list.");
745 delete propAnimation;
747 SysLogException(NID_UI_ANIM, E_SYSTEM, "A system error has been occurred. Failed to start frame animation.");
752 _FrameAnimatorImpl::AddFrameActiveAnimation(VisualElement* _pVisualElement, FrameAnimatorFormTransitionAnimation _formAnimation,
753 VisualElementPropertyAnimation* _pPropertyAnimation, IVisualElementAnimationTimingFunction* _pTimingFunction,
756 SysTryReturnResult(NID_UI_ANIM
757 , (_formAnimation >= FRAME_ANIMATOR_FORM_TRANSITION_ANIMATION_TRANSLATE_LEFT
758 && _formAnimation < FRAME_ANIMATOR_FORM_TRANSITION_ANIMATION_MAX)
759 , E_INVALID_ARG, "Invalid argument(s) is used. FormTransitionType argument is invalid.");
761 result r = E_SUCCESS;
762 FrameActiveAnimation frameActiveAnim;
764 frameActiveAnim.pVisualElement = _pVisualElement;
765 frameActiveAnim.formTransitionAnimationType = _formAnimation;
766 frameActiveAnim.pPropertyAnimation = _pPropertyAnimation;
767 frameActiveAnim.pTimingFunction = _pTimingFunction;
768 frameActiveAnim.animName = _animName;
770 r = __frameActiveAnimationList.Add(frameActiveAnim);
771 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Propagating.");
776 Tizen::Ui::Animations::VisualElementPropertyAnimation*
777 _FrameAnimatorImpl::GetFrameActiveAnimationAt(int index)
779 SysTryReturn(NID_UI_ANIM, (index < __frameActiveAnimationList.GetCount() && (index >= 0)),
780 null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. Index (%d) is out of range.");
782 FrameActiveAnimation frameActiveAnim;
783 result r = __frameActiveAnimationList.GetAt(index, frameActiveAnim);
785 SysTryReturn(NID_UI_ANIM, (r == E_SUCCESS), null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to retrieve FrameActiveAnimation.");
786 return frameActiveAnim.pPropertyAnimation;
790 _FrameAnimatorImpl::RemoveAnimationAt(int index)
792 result r = E_SUCCESS;
793 SysTryReturnResult(NID_UI_ANIM, (index >= 0 && index < __frameActiveAnimationList.GetCount()), E_OUT_OF_RANGE, "Index (%d) is out of range.", index);
795 FrameActiveAnimation frameActiveAnim;
797 r = __frameActiveAnimationList.GetAt(index, frameActiveAnim);
798 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "A system error has been occurred. Failed to retrieve FrameActiveAnimation.");
800 r = __frameActiveAnimationList.RemoveAt(index);
801 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "A system error has been occurred. Failed to remove animation from play list.");
803 if (__animInterpolatorType == ANIMATION_INTERPOLATOR_BEZIER)
805 frameActiveAnim.pPropertyAnimation->SetTimingFunction(null);
806 delete frameActiveAnim.pTimingFunction;
807 frameActiveAnim.pTimingFunction = null;
810 delete frameActiveAnim.pPropertyAnimation;
811 frameActiveAnim.pPropertyAnimation = null;
817 _FrameAnimatorImpl::RemoveAllAnimations(bool deleteAnimation)
819 VisualElement* pParentVisualElement = __pBgElement->GetParent();
820 if (pParentVisualElement)
822 pParentVisualElement->DetachChild(*__pBgElement);
824 __pCurrentCaptureVisualElement->SetShowState(false);
825 __pNextCaptureVisualElement->SetShowState(false);
827 __pCurrentCaptureVisualElement->SetSurface(__pDummySurface);
828 __pNextCaptureVisualElement->SetSurface(__pDummySurface);
833 __pNextFormVisualElement->RemoveAllAnimations();
834 __pCurrentFormVisualElement->RemoveAllAnimations();
837 __transactionId = -1;
839 result r = E_SUCCESS;
841 for (int index = __frameActiveAnimationList.GetCount() - 1; index >= 0; index--)
843 r = RemoveAnimationAt(index);
844 SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), r, "Propagating.");
851 _FrameAnimatorImpl::IsAnimationSupported(void) const
853 return _VisualElementAnimationImpl::IsAnimationSupported();
857 _FrameAnimatorImpl::IsFormPresent(Tizen::Ui::Controls::Form& pPrevForm) const
859 LinkedList* pLinkedList = null;
861 pLinkedList = dynamic_cast< LinkedList* >(__pFrame->GetControls());
862 SysTryReturn(NID_UI_ANIM, (pLinkedList), false, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to get control list.");
864 bool isPresent = pLinkedList->Contains(pPrevForm);
877 _FrameAnimatorImpl::OnAnimationTransactionStarted(int transactionId)
879 OnFrameAnimationStarted();
884 _FrameAnimatorImpl::OnAnimationTransactionStopped(int transactionId)
886 OnFrameAnimationStopped(false);
890 _FrameAnimatorImpl::OnAnimationTransactionFinished(int transactionId)
892 OnFrameAnimationStopped(true);
896 _FrameAnimatorImpl::OnFrameAnimationStarted(void)
898 result r = E_SUCCESS;
900 for (int index = __frameAnimStatusEventListener.GetCount() - 1; index >= 0; index--)
902 IFrameAnimatorEventListener* pStatusListener = null;
904 r = __frameAnimStatusEventListener.GetAt(index, pStatusListener);
905 SysTryReturnVoidResult(NID_UI_ANIM, (r == E_SUCCESS), E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Index (%d) is out of range.", index);
907 pStatusListener->OnFormTransitionAnimationStarted(*__pFrameAnimator, *__pFrame, *__pCurrentForm, *__pNextForm);
912 _FrameAnimatorImpl::OnFrameAnimationStopped(bool completed)
914 result r = E_SUCCESS;
916 if (IsFormPresent(*__pCurrentForm))
918 __pCurrentFormVisualElement->SetTransformMatrix(__veDefaultMatrix);
919 __pCurrentFormVisualElement->SetBounds(__veDefaultBounds);
920 __pCurrentFormVisualElement->SetOpacity(__veDefaultOpacity);
921 __pCurrentFormVisualElement->SetShowState(false);
924 RemoveAllAnimations(false);
926 for (int index = __frameAnimStatusEventListener.GetCount() - 1; index >= 0; index--)
928 IFrameAnimatorEventListener* pStatusListener = null;
930 r = __frameAnimStatusEventListener.GetAt(index, pStatusListener);
931 SysTryReturnVoidResult(NID_UI_ANIM, (r == E_SUCCESS), E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Index (%d) is out of range.", index);
935 pStatusListener->OnFormTransitionAnimationStopped(*__pFrameAnimator, *__pFrame, *__pCurrentForm, *__pNextForm);
939 pStatusListener->OnFormTransitionAnimationFinished(*__pFrameAnimator, *__pFrame, *__pCurrentForm, *__pNextForm);
943 __frameAnimatorStatus = ANIMATOR_STATUS_STOPPED;
947 _FrameAnimatorImpl::GetInstance(FrameAnimator& frameAnimator)
949 return frameAnimator._pFrameAnimatorImpl;
952 const _FrameAnimatorImpl*
953 _FrameAnimatorImpl::GetInstance(const FrameAnimator& frameAnimator)
955 return frameAnimator._pFrameAnimatorImpl;
958 }}} // Tizen::Ui::Animations