Merge "Added api to check actor's depth in the hierarchy" into devel/master
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 2 Jul 2015 13:55:17 +0000 (06:55 -0700)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Thu, 2 Jul 2015 13:55:17 +0000 (06:55 -0700)
automated-tests/src/dali/utc-Dali-Actor.cpp
automated-tests/src/dali/utc-Dali-CustomActor.cpp
automated-tests/src/dali/utc-Dali-TypeRegistry.cpp
dali/internal/event/actors/actor-impl.cpp
dali/internal/event/actors/actor-impl.h
dali/internal/event/actors/custom-actor-internal.h
dali/public-api/actors/actor.cpp
dali/public-api/actors/actor.h
dali/public-api/actors/custom-actor-impl.h

index 0c79181..599e1c6 100644 (file)
@@ -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;
+}
+
index afc9fcd..aca2c62 100644 (file)
@@ -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()
index 8ffa68e..8280e4a 100644 (file)
@@ -203,7 +203,7 @@ struct MyTestCustomActor : public CustomActorImpl
   }
 
   // From CustomActorImpl
-  virtual void OnStageConnection( unsigned int depth )
+  virtual void OnStageConnection( int depth )
   {
   }
   virtual void OnStageDisconnection()
index 9cd7f41..2dd7f01 100644 (file)
@@ -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
index 759d295..1b0cd11 100644 (file)
@@ -761,6 +761,19 @@ public:
    */
   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
@@ -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
index 2c5eaba..f4bef9f 100644 (file)
@@ -70,7 +70,7 @@ private:
   /**
    * @copydoc Internal::Actor::OnStageConnectionExternal
    */
-  virtual void OnStageConnectionExternal( unsigned int depth )
+  virtual void OnStageConnectionExternal( int depth )
   {
     mImpl->OnStageConnection( depth );
   }
index fe27d7a..f231920 100644 (file)
@@ -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();
index 8500a4d..523dc06 100644 (file)
@@ -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
 
   /**
index b54e57f..d246378 100644 (file)
@@ -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.