}
- //TODO : remove
if ((__pControl->GetShowState() == false) && ((animationBase.IsAutoReverseEnabled()) || (animationBase.IsHoldEndEnabled() == false)))
{
__pVisualElement->SetShowState(true);
target.ReleasePresentationInstance();
}
+
+const _ControlAnimatorImpl*
+_ControlAnimatorImpl::GetInstance(ControlAnimator& element)
+{
+ return element._pControlAnimatorImpl;
+}
+
+result
+_ControlAnimatorImpl::SetSize(float width, float height, int duration, AnimationInterpolatorType animInterpolator)
+{
+ SysTryReturnResult(NID_UI_ANIM, (IsAnimationTargetAnimating(ANIMATION_TARGET_SIZE) == false), E_INVALID_OPERATION, "Same AnimationTargetType is already being animated.");
+ SysTryReturnResult(NID_UI_ANIM, ((width > 0) && (height > 0)), E_INVALID_ARG, "Invalid argument(s) is used. width = %f, height = %f", width, height);
+
+ result r = E_SUCCESS;
+ Control& controlRef = GetControl();
+ FloatDimension newSize = FloatDimension(width, height);
+ FloatDimension currentSize = controlRef.GetSizeF();
+
+ SysTryReturnResult(NID_UI_ANIM, (controlRef.IsResizable()), E_UNSUPPORTED_OPERATION, "Bounds cannot be modified.");
+
+ //CustomControl s Condition check
+ CustomControlBase* pControlBase = dynamic_cast< CustomControlBase* >(&controlRef);
+
+ if (pControlBase)
+ {
+ FloatDimension dim(width, height);
+ _ControlImpl* pControlImpl = _ControlImpl::GetInstance(GetControl());
+ pControlImpl->OnEvaluateSize(dim);
+ }
+ else
+ {
+ SysTryReturnResult(NID_UI_ANIM, !((width < controlRef.GetMinimumSize().width) ||
+ (height < controlRef.GetMinimumSize().height) ||
+ (width > controlRef.GetMaximumSize().width) ||
+ (height > controlRef.GetMaximumSize().height)), E_UNSUPPORTED_OPERATION, "Bounds cannot be modified.");
+ }
+
+
+ int activeAnimationCount = GetActiveAnimationListCount();
+
+
+ if (currentSize == newSize)
+ {
+ return E_SUCCESS;
+ }
+
+
+ if (IsAnimationSupported() == false)
+ {
+ r = __pControl->SetSize(width, height);
+ if (r != E_SUCCESS)
+ {
+ SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set control property.");
+ r = E_SYSTEM;
+ }
+
+
+ return r;
+ }
+ else
+ {
+ bool disable = false;
+ bool propagation = false;
+
+ result r = DisableImplicitAnimation(disable);
+ SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable implicit animation.");
+
+ r = DisableVisualElementPropagation(propagation);
+ SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable visual element propagation.");
+
+ r = controlRef.SetSize(width, height);
+
+ if (propagation)
+ {
+ DisableVisualElementPropagation(propagation);
+ }
+ if (disable)
+ {
+ DisableImplicitAnimation(disable);
+ }
+
+ SysTryReturnResult(NID_UI_ANIM, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set bounds.");
+ r = SetAnimationF(ANIMATION_TARGET_SIZE, ANIMATION_TRIGGER_SIZE_CHANGE, duration, animInterpolator, currentSize, newSize);
+ SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+ }
+
+ SetAnimationTargetStatus(ANIMATION_TRIGGER_SIZE_CHANGE);
+
+ return r;
+
+CATCH:
+
+ SysTryReturnResult(NID_UI_ANIM, (DestroyAnimation(activeAnimationCount) == E_SUCCESS),
+ E_SYSTEM, "A system error has been occurred. Failed to destroy animation.");
+
+ return r;
+}
+
+result
+_ControlAnimatorImpl::SetPosition(float x, float y, int duration, AnimationInterpolatorType animInterpolator)
+{
+ SysLogException(NID_UI_ANIM, E_SYSTEM, "_ControlAnimatorImpl::SetPosition");
+ SysTryReturnResult(NID_UI_ANIM, (IsAnimationTargetAnimating(ANIMATION_TARGET_POSITION) == false), E_INVALID_OPERATION, "Same AnimationTargetType is already being animated.");
+
+ result r = E_SUCCESS;
+
+ Control& controlRef = GetControl();
+
+ FloatPoint newPosition = FloatPoint(x, y);
+ FloatPoint currentPosition = controlRef.GetPositionF();
+
+ SysTryReturnResult(NID_UI_ANIM, (controlRef.IsMovable()), E_UNSUPPORTED_OPERATION, "Bounds cannot be modified.");
+
+ //CustomControl s Condition check
+ CustomControlBase* pControlBase = dynamic_cast< CustomControlBase* >(&controlRef);
+
+ if (pControlBase)
+ {
+ _ControlImpl* pControlImpl = _ControlImpl::GetInstance(GetControl());
+ pControlImpl->OnBoundsChanging(FloatRectangle(x, y, controlRef.GetWidthF(), controlRef.GetHeightF()));
+ }
+
+ int activeAnimationCount = GetActiveAnimationListCount();
+
+ if (currentPosition == newPosition)
+ {
+ return E_SUCCESS;
+ }
+
+
+ if (!(__pControl->IsMovable()))
+ {
+ SysLogException(NID_UI_ANIM, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. Control is not Movable.");
+ return E_INVALID_ARG;
+ }
+ if (IsAnimationSupported() == false)
+ {
+ r = __pControl->SetPosition(x, y);
+ if (r != E_SUCCESS)
+ {
+ SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set control property.");
+ r = E_SYSTEM;
+ }
+
+
+ return r;
+ }
+ else
+ {
+ bool disable = false;
+ bool propagation = false;
+
+ result r = DisableImplicitAnimation(disable);
+ SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable implicit animation.");
+
+ r = DisableVisualElementPropagation(propagation);
+ SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable visual element propagation.");
+
+ r = controlRef.SetPosition(x, y);
+
+ if (propagation)
+ {
+ DisableVisualElementPropagation(propagation);
+ }
+ if (disable)
+ {
+ DisableImplicitAnimation(disable);
+ }
+
+ SysTryReturnResult(NID_UI_ANIM, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set bounds.");
+ r = SetAnimationF(ANIMATION_TARGET_POSITION, ANIMATION_TRIGGER_POSITION_CHANGE, duration, animInterpolator, currentPosition, newPosition);
+ SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+ }
+
+ SetAnimationTargetStatus(ANIMATION_TRIGGER_POSITION_CHANGE);
+
+ return r;
+
+CATCH:
+ SysTryReturnResult(NID_UI_ANIM, (DestroyAnimation(activeAnimationCount) == E_SUCCESS),
+ E_SYSTEM, "A system error has been occurred. Failed to destroy animation.");
+
+ return r;
+}
+
+result
+_ControlAnimatorImpl::SetBounds(FloatRectangle bounds, int duration, AnimationInterpolatorType animInterpolator)
+{
+ SysLogException(NID_UI_ANIM, E_SYSTEM, "_ControlAnimatorImpl::SetPosition");
+ SysTryReturnResult(NID_UI_ANIM, (IsAnimationTargetAnimating(ANIMATION_TARGET_SIZE) == false), E_INVALID_OPERATION, "Same AnimationTargetType is already being animated.");
+ SysTryReturnResult(NID_UI_ANIM, ((bounds.width > 0) && (bounds.height > 0)), E_INVALID_ARG, "Invalid argument(s) is used. width = %f, height = %f", bounds.width, bounds.height);
+
+ result r = E_SUCCESS;
+
+ Control& controlRef = GetControl();
+ FloatPoint newPosition = FloatPoint(bounds.x, bounds.y);
+ FloatPoint currentPosition = controlRef.GetPositionF();
+
+ FloatDimension newSize = FloatDimension(bounds.width, bounds.height);
+ FloatDimension currentSize = controlRef.GetSizeF();
+
+ SysTryReturnResult(NID_UI_ANIM, (controlRef.IsResizable()), E_UNSUPPORTED_OPERATION, "Bounds cannot be modified.");
+
+ //CustomControl s Condition check
+ CustomControlBase* pControlBase = dynamic_cast< CustomControlBase* >(&controlRef);
+
+ if (pControlBase)
+ {
+ FloatDimension dim(bounds.width, bounds.height);
+ _ControlImpl* pControlImpl = _ControlImpl::GetInstance(GetControl());
+ pControlImpl->OnEvaluateSize(dim);
+ }
+ else
+ {
+ SysTryReturnResult(NID_UI_ANIM, !((bounds.width < controlRef.GetMinimumSize().width) ||
+ (bounds.height < controlRef.GetMinimumSize().height) ||
+ (bounds.width > controlRef.GetMaximumSize().width) ||
+ (bounds.height > controlRef.GetMaximumSize().height)), E_UNSUPPORTED_OPERATION, "Bounds cannot be modified.");
+ }
+
+
+ int activeAnimationCount = GetActiveAnimationListCount();
+
+
+ if (currentSize == newSize)
+ {
+ return E_SUCCESS;
+ }
+
+
+ if (IsAnimationSupported() == false)
+ {
+ r = __pControl->SetSize(bounds.width, bounds.height);
+ if (r != E_SUCCESS)
+ {
+ SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set control property.");
+ r = E_SYSTEM;
+ }
+
+
+ return r;
+ }
+ else
+ {
+ bool disable = false;
+ bool propagation = false;
+
+ result r = DisableImplicitAnimation(disable);
+ SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable implicit animation.");
+
+ r = DisableVisualElementPropagation(propagation);
+ SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable visual element propagation.");
+
+ r = controlRef.SetSize(bounds.width, bounds.height);
+
+ if (propagation)
+ {
+ DisableVisualElementPropagation(propagation);
+ }
+ if (disable)
+ {
+ DisableImplicitAnimation(disable);
+ }
+
+ SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set bounds.");
+ r = SetAnimationF(ANIMATION_TARGET_SIZE, ANIMATION_TRIGGER_SIZE_CHANGE, duration, animInterpolator, currentSize, newSize);
+ SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+ }
+
+ SetAnimationTargetStatus(ANIMATION_TRIGGER_SIZE_CHANGE);
+
+ SysTryReturnResult(NID_UI_ANIM, (IsAnimationTargetAnimating(ANIMATION_TARGET_POSITION) == false), E_INVALID_OPERATION, "Same AnimationTargetType is already being animated.");
+ SysTryReturnResult(NID_UI_ANIM, (controlRef.IsMovable()), E_UNSUPPORTED_OPERATION, "Bounds cannot be modified.");
+
+ if (pControlBase)
+ {
+ _ControlImpl* pControlImpl = _ControlImpl::GetInstance(GetControl());
+ pControlImpl->OnBoundsChanging(FloatRectangle(bounds.x, bounds.y, controlRef.GetWidthF(), controlRef.GetHeightF()));
+ }
+
+ if (currentPosition == newPosition)
+ {
+ return E_SUCCESS;
+ }
+
+ if (!(__pControl->IsMovable()))
+ {
+ SysLogException(NID_UI_ANIM, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. Control is not Movable.");
+ return E_INVALID_ARG;
+ }
+ if (IsAnimationSupported() == false)
+ {
+ r = __pControl->SetPosition(bounds.x, bounds.y);
+ if (r != E_SUCCESS)
+ {
+ SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set control property.");
+ r = E_SYSTEM;
+ }
+
+ return r;
+ }
+ else
+ {
+ bool disable = false;
+ bool propagation = false;
+
+ result r = DisableImplicitAnimation(disable);
+ SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable implicit animation.");
+
+ r = DisableVisualElementPropagation(propagation);
+ SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to disable/enable visual element propagation.");
+
+ r = controlRef.SetPosition(bounds.x, bounds.y);
+
+ if (propagation)
+ {
+ DisableVisualElementPropagation(propagation);
+ }
+ if (disable)
+ {
+ DisableImplicitAnimation(disable);
+ }
+
+ SysTryReturnResult(NID_UI_ANIM, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to set bounds.");
+ r = SetAnimationF(ANIMATION_TARGET_POSITION, ANIMATION_TRIGGER_POSITION_CHANGE, duration, animInterpolator, currentPosition, newPosition);
+ SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+ }
+
+ SetAnimationTargetStatus(ANIMATION_TRIGGER_POSITION_CHANGE);
+ return r;
+
+CATCH:
+ SysTryReturnResult(NID_UI_ANIM, (DestroyAnimation(activeAnimationCount) == E_SUCCESS),
+ E_SYSTEM, "A system error has been occurred. Failed to destroy animation.");
+
+ return r;
+}
+
+result
+_ControlAnimatorImpl::SetAnimationF(AnimationTargetType animTarget, ControlAnimatorTriggerType triggerType, int duration, AnimationInterpolatorType animInterpolator, Variant startValue, Variant endValue)
+{
+ result r = E_SUCCESS;
+ String animIdentifier;
+ const IVisualElementAnimationTimingFunction* pTimingFunction = null;
+ BezierTimingFunction* pBezierTimingFunction = null;
+ AnimationBase* pAnimationBase = null;
+
+ SysTryReturnResult(NID_UI_ANIM, (animTarget > ANIMATION_TARGET_NONE && animTarget < ANIMATION_TARGET_ROTATION), E_INVALID_ARG, "Invalid argument(s) is used. animTarget is invalid.");
+ SysTryReturnResult(NID_UI_ANIM, (!(__isAnimationTargetAnimating[animTarget])), E_INVALID_OPERATION, "Same AnimationTargetType is being animated.");
+
+ switch (animInterpolator)
+ {
+ case ANIMATION_INTERPOLATOR_LINEAR:
+ {
+ pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(INTERPOLATOR_LINEAR);
+ }
+ break;
+
+ case ANIMATION_INTERPOLATOR_EASE_IN:
+ {
+ pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(INTERPOLATOR_EASEIN);
+ }
+ break;
+
+ case ANIMATION_INTERPOLATOR_EASE_OUT:
+ {
+ pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(INTERPOLATOR_EASEOUT);
+ }
+ break;
+
+ case ANIMATION_INTERPOLATOR_EASE_IN_OUT:
+ {
+ pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(INTERPOLATOR_EASEINOUT);
+ }
+ break;
+
+ case ANIMATION_INTERPOLATOR_DISCRETE:
+ {
+ pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(INTERPOLATOR_DISCRETE);
+ }
+ break;
+
+ case ANIMATION_INTERPOLATOR_BEZIER:
+ {
+ float cpTime1 = 0.0;
+ float cpValue1 = 0.0;
+ float cpTime2 = 0.0;
+ float cpValue2 = 0.0;
+
+ PointAnimation dummyAnimation(Point(0,0), Point(0,100), 400, ANIMATION_INTERPOLATOR_LINEAR);
+ r = dummyAnimation.GetBezierControlPoints(cpTime1, cpValue1, cpTime2, cpValue2);
+ SysTryReturnResult(NID_UI_ANIM, (r == E_SUCCESS), E_SYSTEM, "A system error has been occurred. Failed to get bezier points.");
+
+ pBezierTimingFunction = new (std::nothrow) BezierTimingFunction();
+ SysTryReturnResult(NID_UI_ANIM, (pBezierTimingFunction), E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+ pBezierTimingFunction->SetControlPoints(cpTime1, cpValue1, cpTime2, cpValue2);
+ pTimingFunction = pBezierTimingFunction;
+
+ }
+ break;
+ }
+
+ SysTryReturnResult(NID_UI_ANIM, (pTimingFunction != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
+
+ VisualElementPropertyAnimation* pAnimation = null;
+ VisualElementValueAnimation* pBoundsAnimation = null;
+ VisualElementValueAnimation* pBaseAnimation = null;
+
+ if (animTarget == ANIMATION_TARGET_SIZE)
+ {
+ pBoundsAnimation = new (std::nothrow) VisualElementValueAnimation(); //deletion will happen in catch/ in Destroy animation
+ SysTryCatch(NID_UI_ANIM, (pBoundsAnimation), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+ pBoundsAnimation->SetTimingFunction(pTimingFunction);
+ }
+ else
+ {
+ pAnimation = new (std::nothrow) VisualElementPropertyAnimation(); //deletion will happen in catch/ in Destroy animation
+ SysTryCatch(NID_UI_ANIM, (pAnimation), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+ pAnimation->SetTimingFunction(pTimingFunction);
+ }
+
+ switch (animTarget)
+ {
+ case ANIMATION_TARGET_SIZE:
+ {
+ float startWidth = startValue.ToFloatDimension().width;
+ float startHeight = startValue.ToFloatDimension().height;
+ float endWidth = endValue.ToFloatDimension().width;
+ float endHeight = endValue.ToFloatDimension().height;
+
+ FloatRectangle presentationBounds = const_cast<VisualElement*>((__pVisualElement)->AcquirePresentationInstance())->GetBounds();
+ FloatRectangle modelBounds = __pVisualElement->GetBounds();
+
+ __presentationBounds = presentationBounds;
+
+ float startX = presentationBounds.x;
+ float startY = presentationBounds.y;
+
+ float endX = modelBounds.x;
+ float endY = modelBounds.y;
+
+ pBoundsAnimation->SetStartValue(Variant(FloatRectangle(startX, startY, startWidth, startHeight)));
+ pBoundsAnimation->SetEndValue(Variant(FloatRectangle(endX, endY, endWidth, endHeight)));
+ pBoundsAnimation->SetVisualElementAnimationTickEventListener(this);
+ animIdentifier.Append(DIMENSION);
+
+ __pVisualElement->ReleasePresentationInstance();
+ }
+ break;
+
+ case ANIMATION_TARGET_POSITION:
+ {
+ FloatPoint controlPos;
+ float absStartX = 0.0f;
+ float absStartY = 0.0f;
+ float absEndX = 0.0f;
+ float absEndY = 0.0f;
+
+ controlPos = __pControl->GetPositionF();
+
+ FloatPoint parentPosition(0, 0);
+
+ if (__pControlImpl->GetParent())
+ {
+ parentPosition.x = __pControlImpl->GetParent()->GetClientBoundsF().x;
+ parentPosition.y = __pControlImpl->GetParent()->GetClientBoundsF().y;
+ }
+
+ absStartX = parentPosition.x + startValue.ToFloatPoint().x;
+ absStartY = parentPosition.y + startValue.ToFloatPoint().y;
+
+ absEndX = parentPosition.x + endValue.ToFloatPoint().x;
+ absEndY = parentPosition.y + endValue.ToFloatPoint().y;
+
+ pAnimation->SetPropertyName(VeSubPropBoundsPosition);
+
+ Variant startPosition(FloatPoint(absStartX, absStartY));
+ Variant endPosition(FloatPoint(absEndX, absEndY));
+
+ pAnimation->SetStartValue(startPosition);
+ pAnimation->SetEndValue(endPosition);
+ animIdentifier.Append(POSITION);
+ }
+ break;
+
+ case ANIMATION_TARGET_ALPHA:
+ {
+ pAnimation->SetPropertyName(VePrivPropShowOpacity);
+
+ pAnimation->SetStartValue(startValue);
+ pAnimation->SetEndValue(endValue);
+ animIdentifier.Append(ALPHA);
+ }
+ break;
+
+ default:
+ SysAssertf(false, "Animation type is invalid!");
+ break;
+ }
+
+ if (animTarget == ANIMATION_TARGET_SIZE)
+ {
+ pBaseAnimation = pBoundsAnimation;
+ }
+ else
+ {
+ pBaseAnimation = pAnimation;
+ }
+
+ //Set the Animation values and start the Animation
+ pBaseAnimation->SetDuration(duration);
+ pBaseAnimation->SetVisualElementAnimationStatusEventListener(this);
+
+ animIdentifier.Append(__animationId);
+ __animationId++;
+
+ r = __pVisualElement->AddAnimation(animIdentifier, *pBaseAnimation);
+ SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation could not be started.");
+ r = AddActiveAnimation(animTarget, *pAnimationBase, *pBaseAnimation, triggerType, animIdentifier, pBezierTimingFunction);
+ SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Animation could not be added to playlist.");
+
+ delete pAnimation;
+ return r;
+
+CATCH:
+ delete pAnimation;
+ delete pBoundsAnimation;
+ delete pBezierTimingFunction;
+
+ return r;
+}
}}} // Tizen::Ui::Animations