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;
+}
+
}
// From CustomActorImpl
- virtual void OnStageConnection( unsigned int depth )
+ virtual void OnStageConnection( int depth )
{
AddToCallStacks("OnStageConnection");
mDepth = depth;
}
// From CustomActorImpl
- virtual void OnStageConnection( unsigned int depth )
+ virtual void OnStageConnection( int depth )
{
// Chain up first
TestCustomActor::OnStageConnection( depth );
}
// From CustomActorImpl
- virtual void OnStageConnection( unsigned int depth )
+ virtual void OnStageConnection( int depth )
{
// Chain up first
TestCustomActor::OnStageConnection( depth );
}
// From CustomActorImpl
- virtual void OnStageConnection( unsigned int depth )
+ virtual void OnStageConnection( int depth )
{
// Chain up first
TestCustomActor::OnStageConnection( depth );
}
// From CustomActorImpl
- virtual void OnStageConnection( unsigned int depth )
+ virtual void OnStageConnection( int depth )
{
}
virtual void OnStageDisconnection()
}
// From CustomActorImpl
- virtual void OnStageConnection( unsigned int depth )
+ virtual void OnStageConnection( int depth )
{
}
virtual void OnStageDisconnection()
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 ),
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
*/
const Vector4& GetCurrentWorldColor() const;
+ /**
+ * @copydoc Dali::Actor::GetHierarchyDepth()
+ */
+ int GetHierarchyDepth() const
+ {
+ if( mIsOnStage )
+ {
+ return static_cast<int>(mDepth);
+ }
+
+ return -1;
+ }
+
public:
// Size negotiation virtual functions
*/
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
* 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 )
{
}
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
/**
* @copydoc Internal::Actor::OnStageConnectionExternal
*/
- virtual void OnStageConnectionExternal( unsigned int depth )
+ virtual void OnStageConnectionExternal( int depth )
{
mImpl->OnStageConnection( depth );
}
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();
*/
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
/**
*
* @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.