From 17d7f99e97a04ff3578489d351da6f212690257f Mon Sep 17 00:00:00 2001 From: Ferran Sole Date: Wed, 3 Jun 2015 14:46:05 +0100 Subject: [PATCH] Added parameter in OnStageConnection method indicating the depth of the actor in the hierarchy. Change-Id: I68965e1df12840953e416221f1c539d0fa4004c1 --- .../src/dali/utc-Dali-CustomActor.cpp | 78 ++++++++++++++++--- .../src/dali/utc-Dali-TypeRegistry.cpp | 2 +- dali/internal/event/actors/actor-impl.cpp | 14 ++-- dali/internal/event/actors/actor-impl.h | 20 ++++- .../event/actors/custom-actor-internal.h | 4 +- dali/public-api/actors/custom-actor-impl.h | 4 +- 6 files changed, 100 insertions(+), 22 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-CustomActor.cpp b/automated-tests/src/dali/utc-Dali-CustomActor.cpp index 00da4c114..afc9fcdec 100644 --- a/automated-tests/src/dali/utc-Dali-CustomActor.cpp +++ b/automated-tests/src/dali/utc-Dali-CustomActor.cpp @@ -61,7 +61,8 @@ struct TestCustomActor : public CustomActorImpl mDaliProperty( Property::INVALID_INDEX ), mSizeSet( Vector3::ZERO ), mTargetSize( Vector3::ZERO ), - mNego( false ) + mNego( false ), + mDepth(0u) { } @@ -119,9 +120,10 @@ struct TestCustomActor : public CustomActorImpl } // From CustomActorImpl - virtual void OnStageConnection() + virtual void OnStageConnection( unsigned int depth ) { AddToCallStacks("OnStageConnection"); + mDepth = depth; } virtual void OnStageDisconnection() { @@ -253,6 +255,7 @@ struct TestCustomActor : public CustomActorImpl Vector3 mSizeSet; Vector3 mTargetSize; bool mNego; + unsigned int mDepth; }; /** @@ -269,10 +272,10 @@ struct TestCustomActorVariant1 : public TestCustomActor } // From CustomActorImpl - virtual void OnStageConnection() + virtual void OnStageConnection( unsigned int depth ) { // Chain up first - TestCustomActor::OnStageConnection(); + TestCustomActor::OnStageConnection( depth ); // Add the child Self().Add( mChildToAdd ); @@ -294,10 +297,10 @@ struct TestCustomActorVariant2 : public TestCustomActor } // From CustomActorImpl - virtual void OnStageConnection() + virtual void OnStageConnection( unsigned int depth ) { // Chain up first - TestCustomActor::OnStageConnection(); + TestCustomActor::OnStageConnection( depth ); // Remove all the children for( unsigned int i=0, num=Self().GetChildCount(); ibegin(); iter != endIter; ++iter ) { Actor& actor = GetImplementation( *iter ); - actor.RecursiveConnectToStage( connectionList ); + actor.RecursiveConnectToStage( connectionList, depth+1 ); } } } @@ -2467,7 +2469,7 @@ void Actor::NotifyStageConnection() if( OnStage() && !mOnStageSignalled ) { // Notification for external (CustomActor) derived classes - OnStageConnectionExternal(); + OnStageConnectionExternal( mDepth ); if( !mOnStageSignal.Empty() ) { @@ -3843,7 +3845,7 @@ void Actor::SetParent( Actor* parent, int index ) parent->OnStage() ) { // Instruct each actor to create a corresponding node in the scene graph - ConnectToStage( index ); + ConnectToStage( parent->GetDepth(), 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 a81c32eb8..9a45897e2 100644 --- a/dali/internal/event/actors/actor-impl.h +++ b/dali/internal/event/actors/actor-impl.h @@ -1581,17 +1581,19 @@ protected: /** * Called on a child during Add() when the parent actor is connected to the Stage. * @param[in] stage The stage. + * @param[in] parentDepth The depth of the parent in the hierarchy * @param[in] index If set, it is only used for positioning the actor within the parent's child list. */ - void ConnectToStage( int index = -1 ); + void ConnectToStage( unsigned int parentDepth, int index = -1 ); /** * Helper for ConnectToStage, to recursively connect a tree of actors. * This is atomic i.e. not interrupted by user callbacks. * @param[in] index If set, it is only used for positioning the actor within the parent's child list. + * @param[in] depth The depth in the hierarchy of the actor * @param[out] connectionList On return, the list of connected actors which require notification. */ - void RecursiveConnectToStage( ActorContainer& connectionList, int index = -1 ); + void RecursiveConnectToStage( ActorContainer& connectionList, unsigned int depth, int index = -1 ); /** * Connect the Node associated with this Actor to the scene-graph. @@ -1641,6 +1643,17 @@ 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 @@ -1778,7 +1791,7 @@ private: * For use in external (CustomActor) derived classes. * This is called after the atomic ConnectToStage() traversal has been completed. */ - virtual void OnStageConnectionExternal() + virtual void OnStageConnectionExternal( unsigned int depth ) { } @@ -1894,6 +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 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 ade7a2752..2c5eaba49 100644 --- a/dali/internal/event/actors/custom-actor-internal.h +++ b/dali/internal/event/actors/custom-actor-internal.h @@ -70,9 +70,9 @@ private: /** * @copydoc Internal::Actor::OnStageConnectionExternal */ - virtual void OnStageConnectionExternal() + virtual void OnStageConnectionExternal( unsigned int depth ) { - mImpl->OnStageConnection(); + mImpl->OnStageConnection( depth ); } /** diff --git a/dali/public-api/actors/custom-actor-impl.h b/dali/public-api/actors/custom-actor-impl.h index 32cf1b52a..b54e57f8b 100644 --- a/dali/public-api/actors/custom-actor-impl.h +++ b/dali/public-api/actors/custom-actor-impl.h @@ -90,8 +90,10 @@ public: * B C * / \ \ * D E F + * + * @param[in] depth The depth in the hierarchy for the actor */ - virtual void OnStageConnection() = 0; + virtual void OnStageConnection( unsigned int depth ) = 0; /** * @brief Called after the actor has been disconnected from the stage. -- 2.34.1