From b85fd5868202486969d88ac155f5d49d9c982d00 Mon Sep 17 00:00:00 2001 From: Ferran Sole Date: Mon, 29 Jun 2015 17:27:15 +0100 Subject: [PATCH] Added api to check actor's depth in the hierarchy Change-Id: Iafa09ddf3fb0c1507693330714a3675d9c9f6f61 --- automated-tests/src/dali/utc-Dali-Actor.cpp | 75 ++++++++++++++++++++++ automated-tests/src/dali/utc-Dali-CustomActor.cpp | 10 +-- automated-tests/src/dali/utc-Dali-TypeRegistry.cpp | 2 +- dali/internal/event/actors/actor-impl.cpp | 4 +- dali/internal/event/actors/actor-impl.h | 28 ++++---- dali/internal/event/actors/custom-actor-internal.h | 2 +- dali/public-api/actors/actor.cpp | 5 ++ dali/public-api/actors/actor.h | 7 ++ dali/public-api/actors/custom-actor-impl.h | 2 +- 9 files changed, 112 insertions(+), 23 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-Actor.cpp b/automated-tests/src/dali/utc-Dali-Actor.cpp index 0c79181..599e1c6 100644 --- a/automated-tests/src/dali/utc-Dali-Actor.cpp +++ b/automated-tests/src/dali/utc-Dali-Actor.cpp @@ -2868,3 +2868,78 @@ int UtcDaliActorOnRelayoutSignal(void) END_TEST; } + +int UtcDaliActorGetHierachyDepth(void) +{ + TestApplication application; + tet_infoline("Testing Dali::Actor::GetHierarchyDepth()"); + + + /* Build tree of actors: + * + * Depth + * + * A (parent) 1 + * / \ + * B C 2` + * / \ \ + * D E F 3 + * + * GetHierarchyDepth should return 1 for A, 2 for B and C, and 3 for D, E and F. + */ + Stage stage( Stage::GetCurrent() ); + + Actor actorA = Actor::New(); + Actor actorB = Actor::New(); + Actor actorC = Actor::New(); + Actor actorD = Actor::New(); + Actor actorE = Actor::New(); + Actor actorF = Actor::New(); + + //Test that root actor has depth equal 0 + DALI_TEST_EQUALS( 0, stage.GetRootLayer().GetHierarchyDepth(), TEST_LOCATION ); + + //Test actors return depth -1 when not connected to the tree + DALI_TEST_EQUALS( -1, actorA.GetHierarchyDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( -1, actorB.GetHierarchyDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( -1, actorC.GetHierarchyDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( -1, actorD.GetHierarchyDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( -1, actorE.GetHierarchyDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( -1, actorF.GetHierarchyDepth(), TEST_LOCATION ); + + //Create the hierarchy + stage.Add( actorA ); + actorA.Add( actorB ); + actorA.Add( actorC ); + actorB.Add( actorD ); + actorB.Add( actorE ); + actorC.Add( actorF ); + + //Test actors return correct depth + DALI_TEST_EQUALS( 1, actorA.GetHierarchyDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( 2, actorB.GetHierarchyDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( 2, actorC.GetHierarchyDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( 3, actorD.GetHierarchyDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( 3, actorE.GetHierarchyDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( 3, actorF.GetHierarchyDepth(), TEST_LOCATION ); + + //Removing actorB from the hierarchy. actorB, actorD and actorE should now have depth equal -1 + actorA.Remove( actorB ); + + DALI_TEST_EQUALS( -1, actorB.GetHierarchyDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( -1, actorD.GetHierarchyDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( -1, actorE.GetHierarchyDepth(), TEST_LOCATION ); + + //Removing actorA from the stage. All actors should have depth equal -1 + stage.Remove( actorA ); + + DALI_TEST_EQUALS( -1, actorA.GetHierarchyDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( -1, actorB.GetHierarchyDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( -1, actorC.GetHierarchyDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( -1, actorD.GetHierarchyDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( -1, actorE.GetHierarchyDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( -1, actorF.GetHierarchyDepth(), TEST_LOCATION ); + + END_TEST; +} + diff --git a/automated-tests/src/dali/utc-Dali-CustomActor.cpp b/automated-tests/src/dali/utc-Dali-CustomActor.cpp index afc9fcd..aca2c62 100644 --- a/automated-tests/src/dali/utc-Dali-CustomActor.cpp +++ b/automated-tests/src/dali/utc-Dali-CustomActor.cpp @@ -120,7 +120,7 @@ struct TestCustomActor : public CustomActorImpl } // From CustomActorImpl - virtual void OnStageConnection( unsigned int depth ) + virtual void OnStageConnection( int depth ) { AddToCallStacks("OnStageConnection"); mDepth = depth; @@ -272,7 +272,7 @@ struct TestCustomActorVariant1 : public TestCustomActor } // From CustomActorImpl - virtual void OnStageConnection( unsigned int depth ) + virtual void OnStageConnection( int depth ) { // Chain up first TestCustomActor::OnStageConnection( depth ); @@ -297,7 +297,7 @@ struct TestCustomActorVariant2 : public TestCustomActor } // From CustomActorImpl - virtual void OnStageConnection( unsigned int depth ) + virtual void OnStageConnection( int depth ) { // Chain up first TestCustomActor::OnStageConnection( depth ); @@ -375,7 +375,7 @@ struct TestCustomActorVariant5 : public TestCustomActor } // From CustomActorImpl - virtual void OnStageConnection( unsigned int depth ) + virtual void OnStageConnection( int depth ) { // Chain up first TestCustomActor::OnStageConnection( depth ); @@ -500,7 +500,7 @@ public: } // From CustomActorImpl - virtual void OnStageConnection( unsigned int depth ) + virtual void OnStageConnection( int depth ) { } virtual void OnStageDisconnection() diff --git a/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp b/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp index 8ffa68e..8280e4a 100644 --- a/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp +++ b/automated-tests/src/dali/utc-Dali-TypeRegistry.cpp @@ -203,7 +203,7 @@ struct MyTestCustomActor : public CustomActorImpl } // From CustomActorImpl - virtual void OnStageConnection( unsigned int depth ) + virtual void OnStageConnection( int depth ) { } virtual void OnStageDisconnection() diff --git a/dali/internal/event/actors/actor-impl.cpp b/dali/internal/event/actors/actor-impl.cpp index 9cd7f41..2dd7f01 100644 --- a/dali/internal/event/actors/actor-impl.cpp +++ b/dali/internal/event/actors/actor-impl.cpp @@ -2323,7 +2323,7 @@ Actor::Actor( DerivedType derivedType ) mTargetSize( 0.0f, 0.0f, 0.0f ), mName(), mId( ++mActorCounter ), // actor ID is initialised to start from 1, and 0 is reserved - mDepth( 0 ), + mDepth( 0u ), mIsRoot( ROOT_LAYER == derivedType ), mIsRenderable( RENDERABLE == derivedType ), mIsLayer( LAYER == derivedType || ROOT_LAYER == derivedType ), @@ -3879,7 +3879,7 @@ void Actor::SetParent( Actor* parent, int index ) parent->OnStage() ) { // Instruct each actor to create a corresponding node in the scene graph - ConnectToStage( parent->GetDepth(), index ); + ConnectToStage( parent->GetHierarchyDepth(), index ); } } else // parent being set to NULL diff --git a/dali/internal/event/actors/actor-impl.h b/dali/internal/event/actors/actor-impl.h index 759d295..1b0cd11 100644 --- a/dali/internal/event/actors/actor-impl.h +++ b/dali/internal/event/actors/actor-impl.h @@ -761,6 +761,19 @@ public: */ const Vector4& GetCurrentWorldColor() const; + /** + * @copydoc Dali::Actor::GetHierarchyDepth() + */ + int GetHierarchyDepth() const + { + if( mIsOnStage ) + { + return static_cast(mDepth); + } + + return -1; + } + public: // Size negotiation virtual functions @@ -1642,17 +1655,6 @@ protected: */ float CalculateSizeZ( const Vector2& size ) const; - /** - * Return the depth in the hierarchy of the actor. - * The value returned is only valid if the actor is on the stage. - * - * @return Depth of the actor in the hierarchy - */ - unsigned int GetDepth() const - { - return mDepth; - } - public: // Default property extensions from Object @@ -1790,7 +1792,7 @@ private: * For use in external (CustomActor) derived classes. * This is called after the atomic ConnectToStage() traversal has been completed. */ - virtual void OnStageConnectionExternal( unsigned int depth ) + virtual void OnStageConnectionExternal( int depth ) { } @@ -1905,7 +1907,7 @@ protected: std::string mName; ///< Name of the actor unsigned int mId; ///< A unique ID to identify the actor starting from 1, and 0 is reserved - unsigned int mDepth :12; ///< The depth in the hierarchy of the actor. Only 4096 levels of depth are supported + unsigned short mDepth :12; ///< The depth in the hierarchy of the actor. Only 4096 levels of depth are supported const bool mIsRoot : 1; ///< Flag to identify the root actor const bool mIsRenderable : 1; ///< Flag to identify that this is a renderable actor const bool mIsLayer : 1; ///< Flag to identify that this is a layer diff --git a/dali/internal/event/actors/custom-actor-internal.h b/dali/internal/event/actors/custom-actor-internal.h index 2c5eaba..f4bef9f 100644 --- a/dali/internal/event/actors/custom-actor-internal.h +++ b/dali/internal/event/actors/custom-actor-internal.h @@ -70,7 +70,7 @@ private: /** * @copydoc Internal::Actor::OnStageConnectionExternal */ - virtual void OnStageConnectionExternal( unsigned int depth ) + virtual void OnStageConnectionExternal( int depth ) { mImpl->OnStageConnection( depth ); } diff --git a/dali/public-api/actors/actor.cpp b/dali/public-api/actors/actor.cpp index fe27d7a..f231920 100644 --- a/dali/public-api/actors/actor.cpp +++ b/dali/public-api/actors/actor.cpp @@ -535,6 +535,11 @@ Vector2 Actor::GetMaximumSize() return Vector2( impl.GetMaximumSize( Dimension::WIDTH ), impl.GetMaximumSize( Dimension::HEIGHT ) ); } +int Actor::GetHierarchyDepth() +{ + return GetImplementation(*this).GetHierarchyDepth(); +} + Actor::TouchSignalType& Actor::TouchedSignal() { return GetImplementation(*this).TouchedSignal(); diff --git a/dali/public-api/actors/actor.h b/dali/public-api/actors/actor.h index 8500a4d..523dc06 100644 --- a/dali/public-api/actors/actor.h +++ b/dali/public-api/actors/actor.h @@ -1260,6 +1260,13 @@ public: */ Vector2 GetMaximumSize(); + /** + * @brief Get depth in the hierarchy for the actor + * + * @return The current depth in the hierarchy of the actor, or -1 if actor is not in the hierarchy + */ + int GetHierarchyDepth(); + public: // Signals /** diff --git a/dali/public-api/actors/custom-actor-impl.h b/dali/public-api/actors/custom-actor-impl.h index b54e57f..d246378 100644 --- a/dali/public-api/actors/custom-actor-impl.h +++ b/dali/public-api/actors/custom-actor-impl.h @@ -93,7 +93,7 @@ public: * * @param[in] depth The depth in the hierarchy for the actor */ - virtual void OnStageConnection( unsigned int depth ) = 0; + virtual void OnStageConnection( int depth ) = 0; /** * @brief Called after the actor has been disconnected from the stage. -- 2.7.4