From 976e145aa7066b74195e82d548340580582433ec Mon Sep 17 00:00:00 2001 From: Ferran Sole Date: Tue, 15 Apr 2014 10:01:28 +0100 Subject: [PATCH] Added tag ( id ) to Constraints so they can be identified ( and removed ) by its tag value [Issue#] N/A [Problem] ItemView is not flexible enough [Cause] ItemView removes all constraints from actors it manages [Solution] Added tag to constraints so ItemView can tag its constraints and remove only those when needed Change-Id: Id2e016f7b9f906bd4fa62d6fe249bd1ad60a1d97 --- automated-tests/src/dali/tct-dali-core.h | 2 + automated-tests/src/dali/utc-Dali-Actor.cpp | 82 ++++++++++++++ capi/dali/public-api/animation/constraint.h | 14 +++ capi/dali/public-api/object/constrainable.h | 8 ++ .../animation/active-constraint-base.cpp | 12 ++ .../event/animation/active-constraint-base.h | 15 +++ .../event/animation/active-constraint-impl.h | 2 + .../event/animation/constraint-impl.cpp | 13 +++ .../event/animation/constraint-impl.h | 13 +++ dali/internal/event/common/proxy-object.cpp | 106 +++++++++++------- dali/internal/event/common/proxy-object.h | 11 ++ dali/public-api/animation/constraint.cpp | 14 +++ dali/public-api/object/constrainable.cpp | 7 ++ 13 files changed, 256 insertions(+), 43 deletions(-) diff --git a/automated-tests/src/dali/tct-dali-core.h b/automated-tests/src/dali/tct-dali-core.h index 6c3544e7f..7a7d126d9 100644 --- a/automated-tests/src/dali/tct-dali-core.h +++ b/automated-tests/src/dali/tct-dali-core.h @@ -205,6 +205,7 @@ extern int UtcDaliActorApplyConstraint(void); extern int UtcDaliActorApplyConstraintAppliedCallback(void); extern int UtcDaliActorRemoveConstraints(void); extern int UtcDaliActorRemoveConstraint(void); +extern int UtcDaliActorRemoveConstraintTag(void); extern int UtcDaliActorTouchedSignal(void); extern int UtcDaliActorSetSizeSignal(void); extern int UtcDaliActorOnOffStageSignal(void); @@ -1413,6 +1414,7 @@ testcase tc_array[] = { {"UtcDaliActorApplyConstraintAppliedCallback", UtcDaliActorApplyConstraintAppliedCallback, utc_dali_actor_startup, utc_dali_actor_cleanup}, {"UtcDaliActorRemoveConstraints", UtcDaliActorRemoveConstraints, utc_dali_actor_startup, utc_dali_actor_cleanup}, {"UtcDaliActorRemoveConstraint", UtcDaliActorRemoveConstraint, utc_dali_actor_startup, utc_dali_actor_cleanup}, + {"UtcDaliActorRemoveConstraintTag", UtcDaliActorRemoveConstraintTag, utc_dali_actor_startup, utc_dali_actor_cleanup}, {"UtcDaliActorTouchedSignal", UtcDaliActorTouchedSignal, utc_dali_actor_startup, utc_dali_actor_cleanup}, {"UtcDaliActorSetSizeSignal", UtcDaliActorSetSizeSignal, utc_dali_actor_startup, utc_dali_actor_cleanup}, {"UtcDaliActorOnOffStageSignal", UtcDaliActorOnOffStageSignal, utc_dali_actor_startup, utc_dali_actor_cleanup}, diff --git a/automated-tests/src/dali/utc-Dali-Actor.cpp b/automated-tests/src/dali/utc-Dali-Actor.cpp index dca5d0a5a..d7038759f 100644 --- a/automated-tests/src/dali/utc-Dali-Actor.cpp +++ b/automated-tests/src/dali/utc-Dali-Actor.cpp @@ -2157,6 +2157,88 @@ int UtcDaliActorRemoveConstraint(void) END_TEST; } +int UtcDaliActorRemoveConstraintTag(void) +{ + tet_infoline(" UtcDaliActorRemoveConstraintTag"); + TestApplication application; + + Actor actor = Actor::New(); + + // 1. Apply Constraint1 and Constraint2, and test... + unsigned int result1 = 0u; + unsigned int result2 = 0u; + + unsigned constraint1Tag = 1u; + Constraint constraint1 = Constraint::New( Actor::COLOR, TestConstraintRef(result1, 1) ); + constraint1.SetTag( constraint1Tag ); + actor.ApplyConstraint( constraint1 ); + + unsigned constraint2Tag = 2u; + Constraint constraint2 = Constraint::New( Actor::COLOR, TestConstraintRef(result2, 2) ); + constraint2.SetTag( constraint2Tag ); + actor.ApplyConstraint( constraint2 ); + + Stage::GetCurrent().Add( actor ); + // flush the queue and render once + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION ); + + // 2. Remove Constraint1 and test... + result1 = 0; + result2 = 0; + actor.RemoveConstraints(constraint1Tag); + // make color property dirty, which will trigger constraints to be reapplied. + actor.SetColor( Color::WHITE ); + // flush the queue and render once + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( result1, 0u, TEST_LOCATION ); ///< constraint 1 should not apply now. + DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION ); + + // 3. Re-Apply Constraint1 and test... + result1 = 0; + result2 = 0; + actor.ApplyConstraint( constraint1 ); + // make color property dirty, which will trigger constraints to be reapplied. + actor.SetColor( Color::WHITE ); + // flush the queue and render once + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( result2, 2u, TEST_LOCATION ); + + // 2. Remove Constraint2 and test... + result1 = 0; + result2 = 0; + actor.RemoveConstraints(constraint2Tag); + // make color property dirty, which will trigger constraints to be reapplied. + actor.SetColor( Color::WHITE ); + // flush the queue and render once + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( result1, 1u, TEST_LOCATION ); + DALI_TEST_EQUALS( result2, 0u, TEST_LOCATION ); ///< constraint 2 should not apply now. + + // 2. Remove Constraint1 as well and test... + result1 = 0; + result2 = 0; + actor.RemoveConstraints(constraint1Tag); + // make color property dirty, which will trigger constraints to be reapplied. + actor.SetColor( Color::WHITE ); + // flush the queue and render once + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( result1, 0u, TEST_LOCATION ); ///< constraint 1 should not apply now. + DALI_TEST_EQUALS( result2, 0u, TEST_LOCATION ); ///< constraint 2 should not apply now. + END_TEST; +} int UtcDaliActorTouchedSignal(void) { diff --git a/capi/dali/public-api/animation/constraint.h b/capi/dali/public-api/animation/constraint.h index b00af1b0e..a07c517f3 100644 --- a/capi/dali/public-api/animation/constraint.h +++ b/capi/dali/public-api/animation/constraint.h @@ -591,6 +591,20 @@ public: */ RemoveAction GetRemoveAction() const; + /** + * @brief Set a tag for the constraint so it can be identified later + * + * @param[in] tag An integer to identify the constraint + */ + void SetTag( const unsigned int tag ); + + /** + * @brief Get the tag + * + * @return The tag + */ + unsigned int GetTag() const; + public: // Not intended for use by Application developers /** diff --git a/capi/dali/public-api/object/constrainable.h b/capi/dali/public-api/object/constrainable.h index b7e670675..7bc68d15e 100644 --- a/capi/dali/public-api/object/constrainable.h +++ b/capi/dali/public-api/object/constrainable.h @@ -118,6 +118,14 @@ public: */ void RemoveConstraints(); + /** + * @brief Remove all the constraint from the Object with a matching tag. + * + * @pre The Object has been intialized. + * @param[in] tag The tag of the constraints which will be removed + */ + void RemoveConstraints( unsigned int tag ); + public: diff --git a/dali/internal/event/animation/active-constraint-base.cpp b/dali/internal/event/animation/active-constraint-base.cpp index 5aa63b4c0..7f2937750 100644 --- a/dali/internal/event/animation/active-constraint-base.cpp +++ b/dali/internal/event/animation/active-constraint-base.cpp @@ -82,6 +82,7 @@ ActiveConstraintBase::ActiveConstraintBase( EventToUpdate& eventToUpdate, Proper mRemoveTime( 0.0f ), mAlphaFunction( Dali::Constraint::DEFAULT_ALPHA_FUNCTION ), mRemoveAction( Dali::Constraint::DEFAULT_REMOVE_ACTION ), + mTag(0), mApplyAnimation(), mRemoveAnimation() { @@ -263,6 +264,17 @@ ActiveConstraintBase::RemoveAction ActiveConstraintBase::GetRemoveAction() const return mRemoveAction; } +void ActiveConstraintBase::SetTag(const unsigned int tag) +{ + mTag = tag; +} + +unsigned int ActiveConstraintBase::GetTag() const +{ + return mTag; +} + + bool ActiveConstraintBase::IsSceneObjectRemovable() const { return true; // The constraint removed when target SceneGraph::PropertyOwner is destroyed diff --git a/dali/internal/event/animation/active-constraint-base.h b/dali/internal/event/animation/active-constraint-base.h index 051ee1987..2f0090e39 100644 --- a/dali/internal/event/animation/active-constraint-base.h +++ b/dali/internal/event/animation/active-constraint-base.h @@ -156,6 +156,18 @@ public: */ RemoveAction GetRemoveAction() const; + /** + * @copydoc Dali::Constraint::SetTag() + */ + void SetTag(const unsigned int tag); + + /** + * @copydoc Dali::Constraint::GetTag() + */ + unsigned int GetTag() const; + + + /** * Connects a callback function with the object's signals. * @param[in] object The object providing the signal. @@ -293,6 +305,7 @@ protected: AlphaFunction mAlphaFunction; RemoveAction mRemoveAction; + unsigned int mTag; private: @@ -300,6 +313,8 @@ private: Dali::Animation mApplyAnimation; ///< Used to automatically animate weight from 0.0f -> 1.0f Dali::Animation mRemoveAnimation; ///< Used to automatically animate weight back to 0.0f + + }; } // namespace Internal diff --git a/dali/internal/event/animation/active-constraint-impl.h b/dali/internal/event/animation/active-constraint-impl.h index 44a6c8d55..7d3c7a515 100644 --- a/dali/internal/event/animation/active-constraint-impl.h +++ b/dali/internal/event/animation/active-constraint-impl.h @@ -106,6 +106,7 @@ public: clone->SetRemoveTime(mRemoveTime); clone->SetAlphaFunction(mAlphaFunction); clone->SetRemoveAction(mRemoveAction); + clone->SetTag( mTag ); return clone; } @@ -484,6 +485,7 @@ public: clone->SetRemoveTime(mRemoveTime); clone->SetAlphaFunction(mAlphaFunction); clone->SetRemoveAction(mRemoveAction); + clone->SetTag( mTag ); return clone; } diff --git a/dali/internal/event/animation/constraint-impl.cpp b/dali/internal/event/animation/constraint-impl.cpp index 4e1e3cecc..6c618af6f 100644 --- a/dali/internal/event/animation/constraint-impl.cpp +++ b/dali/internal/event/animation/constraint-impl.cpp @@ -269,6 +269,19 @@ Dali::Constraint::RemoveAction Constraint::GetRemoveAction() const return GetImplementation( mActiveConstraintTemplate ).GetRemoveAction(); } + +void Constraint::SetTag(unsigned int tag) +{ + GetImplementation( mActiveConstraintTemplate ).SetTag(tag); +} + +unsigned int Constraint::GetTag() const +{ + return GetImplementation( mActiveConstraintTemplate ).GetTag(); +} + + + Constraint::~Constraint() { } diff --git a/dali/internal/event/animation/constraint-impl.h b/dali/internal/event/animation/constraint-impl.h index 7c0b9facb..daa5d4d81 100644 --- a/dali/internal/event/animation/constraint-impl.h +++ b/dali/internal/event/animation/constraint-impl.h @@ -97,6 +97,19 @@ public: */ Dali::Constraint::RemoveAction GetRemoveAction() const; + /** + * @copydoc Dali::Constraint::SetTag() + */ + void SetTag( const unsigned int tag); + + /** + * @copydoc Dali::Constraint::GetTag() + */ + unsigned int GetTag() const; + + + + /** * Create an active constraint. * An active constraint is created each time the constraint is applied to an object. diff --git a/dali/internal/event/common/proxy-object.cpp b/dali/internal/event/common/proxy-object.cpp index 47b4fb574..1f311bd68 100644 --- a/dali/internal/event/common/proxy-object.cpp +++ b/dali/internal/event/common/proxy-object.cpp @@ -894,43 +894,74 @@ TypeInfo* ProxyObject::GetTypeInfo() const return mTypeInfo; } -void ProxyObject::RemoveConstraint( Dali::ActiveConstraint activeConstraint ) +void ProxyObject::RemoveConstraint( ActiveConstraint& constraint, bool isInScenegraph ) { - if( mConstraints ) + if( isInScenegraph ) { - // If we have nothing in the scene-graph, just remove the activeConstraint from container - const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject(); - if ( NULL == propertyOwner ) + ActiveConstraintBase& baseConstraint = GetImplementation( constraint ); + baseConstraint.BeginRemove(); + if ( baseConstraint.IsRemoving() ) { - ActiveConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), activeConstraint ) ); - if( it != mConstraints->end() ) + if( !mRemovedConstraints ) { - mConstraints->erase( it ); + mRemovedConstraints = new ActiveConstraintContainer; } - delete mRemovedConstraints; - mRemovedConstraints = NULL; - return; + // Wait for remove animation before destroying active-constraints + mRemovedConstraints->push_back( constraint ); } + } + else if( mRemovedConstraints ) + { + delete mRemovedConstraints; + mRemovedConstraints = NULL; + } +} - // Discard constraints which are fully removed - DeleteRemovedConstraints(); - ActiveConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), activeConstraint ) ); - if( it != mConstraints->end() ) +void ProxyObject::RemoveConstraint( Dali::ActiveConstraint activeConstraint ) +{ + if( mConstraints ) + { + bool isInSceneGraph( NULL != GetSceneObject() ); + if( isInSceneGraph ) { - ActiveConstraintBase& constraint = GetImplementation( *it ); + DeleteRemovedConstraints(); + } - constraint.BeginRemove(); + ActiveConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), activeConstraint ) ); + if( it != mConstraints->end() ) + { + RemoveConstraint( *it, isInSceneGraph ); mConstraints->erase( it ); + } + } + +} + - if ( constraint.IsRemoving() ) + +void ProxyObject::RemoveConstraints( unsigned int tag ) +{ + if( mConstraints ) + { + bool isInSceneGraph( NULL != GetSceneObject() ); + if( isInSceneGraph ) + { + DeleteRemovedConstraints(); + } + + ActiveConstraintIter iter( mConstraints->begin() ); + while(iter != mConstraints->end() ) + { + ActiveConstraintBase& constraint = GetImplementation( *iter ); + if( constraint.GetTag() == tag ) { - if( !mRemovedConstraints ) - { - mRemovedConstraints = new ActiveConstraintContainer; - } - // Wait for remove animation before destroying active-constraints - mRemovedConstraints->push_back( *it ); + RemoveConstraint( *iter, isInSceneGraph ); + iter = mConstraints->erase( iter ); + } + else + { + ++iter; } } } @@ -944,31 +975,18 @@ void ProxyObject::RemoveConstraints() const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject(); if ( NULL == propertyOwner ) { - delete mConstraints; - mConstraints = NULL; delete mRemovedConstraints; mRemovedConstraints = NULL; - return; } - - // Discard constraints which are fully removed - DeleteRemovedConstraints(); - - const ActiveConstraintConstIter endIter = mConstraints->end(); - for ( ActiveConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter ) + else { - ActiveConstraintBase& constraint = GetImplementation( *iter ); + // Discard constraints which are fully removed + DeleteRemovedConstraints(); - constraint.BeginRemove(); - - if ( constraint.IsRemoving() ) + const ActiveConstraintConstIter endIter = mConstraints->end(); + for ( ActiveConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter ) { - if( !mRemovedConstraints ) - { - mRemovedConstraints = new ActiveConstraintContainer; - } - // Wait for remove animation before destroying active-constraints - mRemovedConstraints->push_back( *iter ); + RemoveConstraint( *iter, true ); } } @@ -977,6 +995,8 @@ void ProxyObject::RemoveConstraints() } } + + ProxyObject::~ProxyObject() { // Notification for observers diff --git a/dali/internal/event/common/proxy-object.h b/dali/internal/event/common/proxy-object.h index 5a932e6cb..056720c0d 100644 --- a/dali/internal/event/common/proxy-object.h +++ b/dali/internal/event/common/proxy-object.h @@ -276,6 +276,11 @@ public: // Constraints */ void RemoveConstraints(); + /** + * Remove all constraints from a ProxyObject with a matching tag + */ + void RemoveConstraints( unsigned int tag ); + protected: /** @@ -312,6 +317,12 @@ private: */ void DeleteRemovedConstraints(); + /** + * Helper to remove active constraints + */ + void RemoveConstraint( ActiveConstraint& constraint, bool isInScenegraph ); + + private: // Default property extensions for derived classes /** diff --git a/dali/public-api/animation/constraint.cpp b/dali/public-api/animation/constraint.cpp index 7e1773aa5..7e1afd322 100644 --- a/dali/public-api/animation/constraint.cpp +++ b/dali/public-api/animation/constraint.cpp @@ -81,6 +81,20 @@ Constraint::RemoveAction Constraint::GetRemoveAction() const return GetImplementation(*this).GetRemoveAction(); } +void Constraint::SetTag( const unsigned int tag ) +{ + GetImplementation(*this).SetTag( tag ); +} + +unsigned int Constraint::GetTag() const +{ + return GetImplementation(*this).GetTag(); +} + + + + + Constraint Constraint::New( Property::Index target, Property::Type targetType, AnyFunction func, diff --git a/dali/public-api/object/constrainable.cpp b/dali/public-api/object/constrainable.cpp index 8ff96d76a..edb0a4599 100644 --- a/dali/public-api/object/constrainable.cpp +++ b/dali/public-api/object/constrainable.cpp @@ -67,4 +67,11 @@ void Constrainable::RemoveConstraints() GetImplementation(*this).RemoveConstraints(); } +void Constrainable::RemoveConstraints( unsigned int tag ) +{ + GetImplementation(*this).RemoveConstraints( tag ); +} + + + } // Dali -- 2.34.1