From 11974eb9cab6d1a817fd47ce29b63b2e40798195 Mon Sep 17 00:00:00 2001 From: HyeJin Lee Date: Tue, 9 Apr 2013 23:58:41 +0900 Subject: [PATCH] fix notification sequence with group repeat Change-Id: I6d218659d18009f107d1d1464f2d648fd5eaee73 --- src/ui/animations/FUiAnim_AnimationGroupNode.cpp | 56 +++++++++------ src/ui/animations/FUiAnim_AnimationGroupNode.h | 1 + src/ui/animations/FUiAnim_TransactionNode.cpp | 92 +++++++++++++----------- src/ui/animations/FUiAnim_TransactionNode.h | 41 ++++++++++- 4 files changed, 122 insertions(+), 68 deletions(-) diff --git a/src/ui/animations/FUiAnim_AnimationGroupNode.cpp b/src/ui/animations/FUiAnim_AnimationGroupNode.cpp index 91c1716..71b838b 100644 --- a/src/ui/animations/FUiAnim_AnimationGroupNode.cpp +++ b/src/ui/animations/FUiAnim_AnimationGroupNode.cpp @@ -101,10 +101,8 @@ _AnimationGroupNode::SetBaseTime(unsigned int baseTime) __baseTime = baseTime; __adjustedBaseTime = __baseTime; - if (__status == _STATUS_END) - { - __status = _STATUS_READY; - } + // reset for nested group repeat + __status = _STATUS_READY; } void @@ -121,7 +119,7 @@ _AnimationGroupNode::Commit(void) bool _AnimationGroupNode::IsRemovable(void) const { - return (__pParent->IsRemovable() && __currentRepeatCount == GetRepeatCount()); + return (__pParent->IsRemovable() && __currentRepeatCount == GetRepeatCount() && __status != _STATUS_REPEAT); } void @@ -154,6 +152,10 @@ _AnimationGroupNode::CalculateProgress(unsigned int currentTime) case _STATUS_END: return; + case _STATUS_REPEAT: + SetChildrenBaseTime(__baseTime + __adjustedBaseTime, false); + break; + default: // nothing to do break; @@ -171,9 +173,9 @@ _AnimationGroupNode::CalculateProgress(unsigned int currentTime) return; } - offset = __animation.GetOffset(); - repeatCount = __animation.GetRepeatCount(); - duration = __animation.GetDuration(); + offset = GetOffset(); + repeatCount = GetRepeatCount(); + duration = GetDuration(); if (duration == 0) { duration = 1; @@ -203,19 +205,23 @@ _AnimationGroupNode::CalculateProgress(unsigned int currentTime) { __status = _STATUS_REPEAT; __adjustedBaseTime = delay + duration * (__currentRepeatCount - 1) - offset; - - SetChildrenBaseTime(__baseTime + __adjustedBaseTime, false); } else { __status = _STATUS_RUNNING; } + + // In case of nested group + if (__pParent->GetStatus() == _STATUS_FINISH || __pParent->GetStatus() == _STATUS_REPEAT) + { + __status = _STATUS_FINISH; + } } void _AnimationGroupNode::NotifyTransactionStarted(void) { - if (__isCommitted == false || (__status != _STATUS_START && __status != _STATUS_REPEAT)) + if (__isCommitted == false || __status != _STATUS_START) { return; } @@ -229,19 +235,27 @@ _AnimationGroupNode::NotifyTransactionStarted(void) return; } - switch (__status) + pListener->OnVisualElementAnimationStarted(__animation, __name, pAnimationImpl->GetEventTarget()); +} + +void +_AnimationGroupNode::NotifyTransactionRepeated(void) +{ + if (__isCommitted == false || __status != _STATUS_REPEAT) { - case _STATUS_START: - pListener->OnVisualElementAnimationStarted(__animation, __name, pAnimationImpl->GetEventTarget()); - break; + return; + } - case _STATUS_REPEAT: - pListener->OnVisualElementAnimationRepeated(__animation, __name, pAnimationImpl->GetEventTarget(), __currentRepeatCount); - break; + _VisualElementAnimationImpl* pAnimationImpl = _VisualElementAnimationImpl::GetInstance(__animation); - default: - break; + IVisualElementAnimationStatusEventListener* pListener = pAnimationImpl->GetStatusEventListener(); + + if (pListener == null) + { + return; } + + pListener->OnVisualElementAnimationRepeated(__animation, __name, pAnimationImpl->GetEventTarget(), __currentRepeatCount); } void @@ -252,12 +266,10 @@ _AnimationGroupNode::NotifyTransactionFinished(bool completed) return; } -#if 0 if (__status != _STATUS_FINISH) { __status = _STATUS_FINISH; } -#endif _VisualElementAnimationImpl* pAnimationImpl = _VisualElementAnimationImpl::GetInstance(__animation); diff --git a/src/ui/animations/FUiAnim_AnimationGroupNode.h b/src/ui/animations/FUiAnim_AnimationGroupNode.h index 78c8d5f..d05d03b 100644 --- a/src/ui/animations/FUiAnim_AnimationGroupNode.h +++ b/src/ui/animations/FUiAnim_AnimationGroupNode.h @@ -51,6 +51,7 @@ public: virtual bool IsRemovable(void) const; virtual void NotifyTransactionStarted(void); + virtual void NotifyTransactionRepeated(void); virtual void NotifyTransactionFinished(bool completed); private: diff --git a/src/ui/animations/FUiAnim_TransactionNode.cpp b/src/ui/animations/FUiAnim_TransactionNode.cpp index 690afa9..2e05d92 100644 --- a/src/ui/animations/FUiAnim_TransactionNode.cpp +++ b/src/ui/animations/FUiAnim_TransactionNode.cpp @@ -50,9 +50,6 @@ using namespace Tizen::Base::Collection; namespace Tizen { namespace Ui { namespace Animations { -#define AD_CAST(_AD) static_cast< _AnimationData* >(_AD) -#define AD_CONST_CAST(_AD) static_cast< _AnimationData* >(const_cast< Object* >(_AD)) - unsigned int _AnimationTime::GetTime(bool loopTime) { @@ -136,13 +133,10 @@ _AnimationData::SetBaseTime(unsigned int baseTime) { __baseTime = baseTime; - if (__status == _STATUS_END) - { - // reset for group repeat - __status = _STATUS_READY; - __keyFrameIndex = 0; - __forward = true; - } + // reset for group repeat + __status = _STATUS_READY; + __keyFrameIndex = 0; + __forward = true; return E_SUCCESS; } @@ -590,11 +584,11 @@ _TransactionNode::_TransactionNode(void) result r = __children.Construct(); SysTryReturnVoidResult(NID_UI_ANIM, r == E_SUCCESS, r, "[%s] Failed to construct children list.", GetErrorMessage(r)); - r = __pendingAnimations.Construct(); - SysTryReturnVoidResult(NID_UI_ANIM, r == E_SUCCESS, r, "[%s] Failed to construct pending list.", GetErrorMessage(r)); - r = __animations.Construct(); SysTryReturnVoidResult(NID_UI_ANIM, r == E_SUCCESS, r, "[%s] Failed to construct animations map.", GetErrorMessage(r)); + + r = __pendingAnimations.Construct(); + SysTryReturnVoidResult(NID_UI_ANIM, r == E_SUCCESS, r, "[%s] Failed to construct pending list.", GetErrorMessage(r)); } _TransactionNode::_TransactionNode(const _TransactionNode& node) @@ -616,12 +610,12 @@ _TransactionNode::_TransactionNode(const _TransactionNode& node) result r = __children.Construct(); SysTryReturnVoidResult(NID_UI_ANIM, r == E_SUCCESS, r, "[%s] Failed to construct children list.", GetErrorMessage(r)); - r = __pendingAnimations.Construct(); - SysTryReturnVoidResult(NID_UI_ANIM, r == E_SUCCESS, r, "[%s] Failed to construct pending list.", GetErrorMessage(r)); - r = __animations.Construct(); SysTryReturnVoidResult(NID_UI_ANIM, r == E_SUCCESS, r, "[%s] Failed to construct animations map.", GetErrorMessage(r)); + r = __pendingAnimations.Construct(); + SysTryReturnVoidResult(NID_UI_ANIM, r == E_SUCCESS, r, "[%s] Failed to construct pending list.", GetErrorMessage(r)); + r = CopyAnimationValue(node); SysTryReturnVoidResult(NID_UI_ANIM, r == E_SUCCESS, r, "[%s] Failed to copy the animation value.", GetErrorMessage(r)); } @@ -630,7 +624,7 @@ _TransactionNode::~_TransactionNode(void) { __children.RemoveAllChildren(); - __pendingAnimations.RemoveAll(true); + __pendingAnimations.RemoveAllItems(); RemoveAllAnimations(); } @@ -807,7 +801,7 @@ _TransactionNode::RemoveChild(_TransactionNode& child) void _TransactionNode::RemoveAll(void) { - ReservedRemove(true); + ReservedRemove(); _TransactionNode* pChild = null; @@ -892,13 +886,13 @@ _TransactionNode::RemoveAnimation(VisualElement& target, const String& keyName) for (int index = 0; index < animationCount; index++) { - pAnimationData = AD_CAST(pAnimationList->GetAt(index)); + pAnimationData = static_cast< _AnimationData* >(pAnimationList->GetAt(index)); if (pAnimationData->GetName() == keyName) { if (pAnimationData->IsRemoved() == false) { - r = SetAnimationDataAsPending(*pAnimationData, false); + r = AddAnimationDataInPending(*pAnimationData, false); SysTryReturnResult(NID_UI_ANIM, r == E_SUCCESS, r, "Failed to add to pending list."); } @@ -984,14 +978,14 @@ _TransactionNode::RemoveAnimationByProperty(VisualElement& target, const String& for (int index = 0; index < animationCount; index++) { - pAnimationData = AD_CAST(pAnimationList->GetAt(index)); + pAnimationData = static_cast< _AnimationData* >(pAnimationList->GetAt(index)); pPropertyAnimation = dynamic_cast< VisualElementPropertyAnimation* >(&(pAnimationData->GetAnimation())); if (pPropertyAnimation != null && pPropertyAnimation->GetPropertyName() == property) { if (pAnimationData->IsRemoved() == false) { - r = SetAnimationDataAsPending(*pAnimationData, false); + r = AddAnimationDataInPending(*pAnimationData, false); SysTryReturnVoidResult(NID_UI_ANIM, r == E_SUCCESS, r, "[%s] Failed to add to pending list.", GetErrorMessage(r)); } } @@ -1071,9 +1065,9 @@ _TransactionNode::RemoveAllAnimations(VisualElement& target) for (int index = 0; index < animationCount; index++) { - pAnimationData = AD_CAST(pAnimationList->GetAt(index)); + pAnimationData = static_cast< _AnimationData* >(pAnimationList->GetAt(index)); - r = SetAnimationDataAsPending(*pAnimationData, false); + r = AddAnimationDataInPending(*pAnimationData, false); SysTryReturnVoidResult(NID_UI_ANIM, r == E_SUCCESS, r, "[%s] Failed to add to pending list.", GetErrorMessage(r)); } @@ -1133,7 +1127,7 @@ _TransactionNode::GetAnimation(VisualElement& target, const String& keyName) con for (int index = 0; index < animationCount; index++) { - pAnimationData = AD_CAST(pAnimationList->GetAt(index)); + pAnimationData = static_cast< _AnimationData* >(pAnimationList->GetAt(index)); if (pAnimationData->GetName() == keyName) { @@ -1195,7 +1189,7 @@ _TransactionNode::GetChildrenAnimation(VisualElement& target, const String& keyN } result -_TransactionNode::SetAnimationDataAsPending(_AnimationData& animationData, bool completed) +_TransactionNode::AddAnimationDataInPending(_AnimationData& animationData, bool completed) { result r = E_SUCCESS; @@ -1204,7 +1198,7 @@ _TransactionNode::SetAnimationDataAsPending(_AnimationData& animationData, bool return E_SUCCESS; } - r = __pendingAnimations.Add(animationData); + r = __pendingAnimations.Add(&animationData); animationData.SetPendingMode(_AnimationData::_PENDING_MODE_REMOVING); @@ -1216,6 +1210,16 @@ _TransactionNode::SetAnimationDataAsPending(_AnimationData& animationData, bool } void +_TransactionNode::RemoveAnimationDataInPending(_AnimationData& animationData) +{ + animationData.SetStatus(_AnimationData::_STATUS_END); + + animationData.SetPendingMode(_AnimationData::_PENDING_MODE_NONE); + + __pendingAnimations.Remove(&animationData); +} + +void _TransactionNode::DrawTargets(void) { IMapEnumeratorT* pMapEnum = __animations.GetMapEnumeratorN(); @@ -1283,7 +1287,7 @@ _TransactionNode::SetChildrenBaseTime(unsigned int baseTime, bool self) for (int index = 0; index < animationCount; index++) { - pAnimationData = AD_CAST(pAnimationList->GetAt(index)); + pAnimationData = static_cast< _AnimationData* >(pAnimationList->GetAt(index)); pAnimationData->SetBaseTime(baseTime); } @@ -1439,6 +1443,11 @@ _TransactionNode::NotifyTransactionStarted(void) } void +_TransactionNode::NotifyTransactionRepeated(void) +{ +} + +void _TransactionNode::NotifyTransactionFinished(bool completed) { if (__isCommitted == false) @@ -1489,7 +1498,7 @@ _TransactionNode::RemoveAnimationByDuplicatedProperty(_AnimationData& animationD for (int index = 0; index < animationCount; index++) { - pRemoveAnimationData = AD_CAST(pAnimationList->GetAt(index)); + pRemoveAnimationData = static_cast< _AnimationData* >(pAnimationList->GetAt(index)); if (&animationData == pRemoveAnimationData) { @@ -1500,15 +1509,12 @@ _TransactionNode::RemoveAnimationByDuplicatedProperty(_AnimationData& animationD if (pRemovePropertyAnimation && pRemovePropertyAnimation->GetPropertyName() == pPropertyAnimation->GetPropertyName()) { - result r = SetAnimationDataAsPending(*pRemoveAnimationData, false); + result r = AddAnimationDataInPending(*pRemoveAnimationData, false); SysTryReturn(NID_UI_ANIM, r == E_SUCCESS, r, false, "[%s] Failed to add to pending list.", GetErrorMessage(r)); - //TODO: refactoring for group if (IsRemovable() == false && pRemoveAnimationData->GetStatus() != _AnimationData::_STATUS_READY) { - pRemoveAnimationData->SetStatus(_AnimationData::_STATUS_END); - pRemoveAnimationData->SetPendingMode(_AnimationData::_PENDING_MODE_NONE); - __pendingAnimations.Remove(*pRemoveAnimationData, false); + RemoveAnimationDataInPending(*pRemoveAnimationData); } } } @@ -1550,7 +1556,7 @@ _TransactionNode::ProcessPendingAnimations(void) for (int index = pendingAnimationCount - 1; index >= 0; index--) { - pAnimationData = AD_CAST(__pendingAnimations.GetAt(index)); + pAnimationData = __pendingAnimations.GetItemAt(index); if (pAnimationData->GetPendingMode() == _AnimationData::_PENDING_MODE_REMOVE) { @@ -1568,7 +1574,7 @@ _TransactionNode::ProcessPendingAnimations(void) delete pAnimationList; } - __pendingAnimations.RemoveAt(index, false); + __pendingAnimations.RemoveAt(index); } } } @@ -1614,7 +1620,7 @@ _TransactionNode::ProcessAnimationTick(unsigned int tick) pChild->ProcessAnimationTick(tick); - if (__status == _STATUS_FINISH || pChild->__status == _STATUS_FINISH) + if (__status == _STATUS_REPEAT || __status == _STATUS_FINISH || pChild->__status == _STATUS_FINISH) { pChild->ReservedRemove(); @@ -1631,6 +1637,8 @@ _TransactionNode::ProcessAnimationTick(unsigned int tick) } } } + + NotifyTransactionRepeated(); } void @@ -1664,7 +1672,7 @@ _TransactionNode::OnAnimationTick(unsigned int tick) for (int index = 0; index < animationCount; index++) { - pAnimationData = AD_CAST(pAnimationList->GetAt(index)); + pAnimationData = static_cast< _AnimationData* >(pAnimationList->GetAt(index)); if (pAnimationData->IsRemoved()) { @@ -1684,15 +1692,13 @@ _TransactionNode::OnAnimationTick(unsigned int tick) pAnimationData->OnTickOccurred(*pTarget, currentValue); - if (__status == _STATUS_FINISH || pAnimationData->GetStatus() == _AnimationData::_STATUS_FINISH) + if (__status == _STATUS_REPEAT || __status == _STATUS_FINISH || pAnimationData->GetStatus() == _AnimationData::_STATUS_FINISH) { - SetAnimationDataAsPending(*pAnimationData, true); + AddAnimationDataInPending(*pAnimationData, true); - //TODO: refactoring for group if (IsRemovable() == false) { - pAnimationData->SetPendingMode(_AnimationData::_PENDING_MODE_NONE); - __pendingAnimations.Remove(*pAnimationData, false); + RemoveAnimationDataInPending(*pAnimationData); } } } diff --git a/src/ui/animations/FUiAnim_TransactionNode.h b/src/ui/animations/FUiAnim_TransactionNode.h index 50aefd7..4a02306 100644 --- a/src/ui/animations/FUiAnim_TransactionNode.h +++ b/src/ui/animations/FUiAnim_TransactionNode.h @@ -183,10 +183,13 @@ public: bool IsEmpty(void) const; + _TransactionStatus GetStatus(void) const { return __status; } + bool IsRunning(void) const; virtual bool IsRemovable(void) const; virtual void NotifyTransactionStarted(void); + virtual void NotifyTransactionRepeated(void); virtual void NotifyTransactionFinished(bool completed); void ProcessAnimationTick(unsigned int tick); @@ -201,7 +204,8 @@ private: const VisualElementAnimation* GetAnimation(VisualElement& target, const Tizen::Base::String& property) const; - result SetAnimationDataAsPending(_AnimationData& animationData, bool completed); + result AddAnimationDataInPending(_AnimationData& animationData, bool completed); + void RemoveAnimationDataInPending(_AnimationData& animationData); void ReservedRemove(bool remove = true); bool IsReservedRemove(void) const; @@ -264,9 +268,38 @@ protected: } }; - ChildrenListT __children; + class AnimationDataListT : public Tizen::Base::Collection::ArrayListT<_AnimationData*> + { + public: + _AnimationData* GetItemAt(int index) const + { + _AnimationData* pData = null; + + if (likely(GetAt(index, pData) == E_SUCCESS)) + { + return pData; + } + + return null; + } - Tizen::Base::Collection::ArrayList __pendingAnimations; + void RemoveAllItems(void) + { + _AnimationData* pData = null; + + int itemCount = GetCount(); + + for (int index = 0; index < itemCount; index++) + { + if (likely(GetAt(index, pData) == E_SUCCESS)) + { + delete pData; + } + } + + RemoveAll(); + } + }; class AnimationHashMapT : public Tizen::Base::Collection::HashMapT { @@ -281,7 +314,9 @@ protected: } }; + ChildrenListT __children; AnimationHashMapT __animations; + AnimationDataListT __pendingAnimations; }; // _TransactionNode }}} // Tizen::Ui::Animations -- 2.7.4