Added test case for SetInheritPosition/IsPositionInherited 24/64224/1
authorFerran Sole <ferran.sole@samsung.com>
Wed, 30 Mar 2016 13:44:20 +0000 (14:44 +0100)
committerFerran Sole <ferran.sole@samsung.com>
Wed, 30 Mar 2016 13:44:20 +0000 (14:44 +0100)
Change-Id: I5fe65e6d6d13ae81366bf5cc7d372dac7805dbbb

automated-tests/src/dali/utc-Dali-Actor.cpp
dali/internal/event/actors/actor-impl.cpp
dali/internal/update/nodes/node.h

index 3062511..67dd53b 100644 (file)
@@ -1111,6 +1111,64 @@ int UtcDaliActorInheritPosition(void)
   END_TEST;
 }
 
+int UtcDaliActorSetInheritPosition(void)
+{
+  tet_infoline("Testing Actor::SetInheritPosition");
+  TestApplication application;
+
+  Actor parent = Actor::New();
+  Vector3 parentPosition( 1.0f, 2.0f, 3.0f );
+  parent.SetPosition( parentPosition );
+  parent.SetParentOrigin( ParentOrigin::CENTER );
+  parent.SetAnchorPoint( AnchorPoint::CENTER );
+  Stage::GetCurrent().Add( parent );
+
+  Actor child = Actor::New();
+  child.SetParentOrigin( ParentOrigin::CENTER );
+  child.SetAnchorPoint( AnchorPoint::CENTER );
+  Vector3 childPosition( 10.0f, 11.0f, 12.0f );
+  child.SetPosition( childPosition );
+  parent.Add( child );
+
+  // The actors should not have a world position yet
+  DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
+  DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
+
+  // first test default, which is to inherit position
+  DALI_TEST_EQUALS( child.IsPositionInherited(), true, TEST_LOCATION );
+  application.SendNotification();
+  application.Render(0); // should only really call Update as Render is not required to update scene
+  DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
+  DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
+  DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
+  DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), parentPosition + childPosition, TEST_LOCATION );
+
+  //Change child position
+  Vector3 childOffset( -1.0f, 1.0f, 0.0f );
+  child.SetPosition( childOffset );
+
+  // Use local position as world postion
+  child.SetInheritPosition( false );
+  DALI_TEST_EQUALS( child.IsPositionInherited(), false, TEST_LOCATION );
+  application.SendNotification();
+  application.Render(0); // should only really call Update as Render is not required to update scene
+  DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
+  DALI_TEST_EQUALS( child.GetCurrentPosition(), childOffset, TEST_LOCATION );
+  DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
+  DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), childOffset, TEST_LOCATION );
+
+  //Change back to inherit position from parent
+  child.SetInheritPosition( true );
+  DALI_TEST_EQUALS( child.IsPositionInherited(), true, TEST_LOCATION );
+  application.SendNotification();
+  application.Render(0); // should only really call Update as Render is not required to update scene
+  DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
+  DALI_TEST_EQUALS( child.GetCurrentPosition(), childOffset, TEST_LOCATION );
+  DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
+  DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), parentPosition + childOffset, TEST_LOCATION );
+  END_TEST;
+}
+
 // SetOrientation(float angleRadians, Vector3 axis)
 int UtcDaliActorSetOrientation01(void)
 {
index 7828b77..40c302f 100644 (file)
@@ -742,7 +742,7 @@ void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
   if( NULL != mNode )
   {
     // mNode is being used in a separate thread; queue a message to set the value
-    SetPositionInheritanceModeMessage( GetEventThreadServices(), *mNode, mode );
+    SetInheritPositionMessage( GetEventThreadServices(), *mNode, mode == INHERIT_PARENT_POSITION );
   }
 }
 
index e12c5ad..534a40a 100644 (file)
@@ -402,19 +402,6 @@ public:
   }
 
   /**
-   * Set the position inheritance mode.
-   * @see Dali::Actor::PositionInheritanceMode
-   * @param[in] mode The new position inheritance mode.
-   */
-  void SetPositionInheritanceMode( PositionInheritanceMode mode )
-  {
-    if( mTransformId != INVALID_TRANSFORM_ID )
-    {
-      mTransformManager->SetInheritPosition(mTransformId, mode == INHERIT_PARENT_POSITION );
-    }
-  }
-
-  /**
    * Retrieve the local orientation of the node, relative to its parent.
    * @param[in] bufferIndex The buffer to read from.
    * @return The local orientation.
@@ -879,17 +866,6 @@ inline void SetAnchorPointMessage( EventThreadServices& eventThreadServices, con
   new (slot) LocalType( &node, &Node::SetAnchorPoint, anchor );
 }
 
-inline void SetPositionInheritanceModeMessage( EventThreadServices& eventThreadServices, const Node& node, PositionInheritanceMode mode )
-{
-  typedef MessageValue1< Node, PositionInheritanceMode > LocalType;
-
-  // Reserve some memory inside the message queue
-  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
-  // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &node, &Node::SetPositionInheritanceMode, mode );
-}
-
 inline void SetInheritPositionMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
 {
   typedef MessageValue1< Node, bool > LocalType;