Added Get Screen Position functionality to Actor 99/117599/7
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Mon, 6 Mar 2017 19:18:05 +0000 (19:18 +0000)
committerAgnelo Vaz <agnelo.vaz@samsung.com>
Wed, 8 Mar 2017 13:39:42 +0000 (13:39 +0000)
Screen coordinates TOP_LEFT is 0,0
This property will return the position of the Actor relative to the TOP_LEFT
The returned position is the position of the actor's Anchor point.
Actor Scaling is supported.
Actor Rotation is not supported.

Change-Id: I8519f2b82ab9f9ac8eec197e783a66dcf5ba949c

automated-tests/src/dali/utc-Dali-Actor.cpp
dali/devel-api/actors/actor-devel.h
dali/internal/event/actors/actor-impl.cpp
dali/internal/event/actors/actor-impl.h

index 5bfa46a..f4d48e0 100644 (file)
@@ -5169,13 +5169,13 @@ int UtcDaliActorRaiseAboveActorAndTargetTheSameN(void)
 
   ResetTouchCallbacks();
 
-  tet_printf( "Raise actor A Above Actor A which is the same actor!!\n" );
+  tet_infoline( "Raise actor A Above Actor A which is the same actor!!\n" );
 
   DevelActor::RaiseAbove( actorA, actorA );
 
   application.ProcessEvent( event );
 
-  tet_printf( "No target is source Actor so RaiseAbove should show no effect\n" );
+  tet_infoline( "No target is source Actor so RaiseAbove should show no effect\n" );
 
   DALI_TEST_EQUALS( gTouchCallBackCalled,  false, TEST_LOCATION );
   DALI_TEST_EQUALS( gTouchCallBackCalled2,  false, TEST_LOCATION );
@@ -5186,7 +5186,7 @@ int UtcDaliActorRaiseAboveActorAndTargetTheSameN(void)
   DevelActor::RaiseAbove( actorA, actorC );
   application.ProcessEvent( event );
 
-  tet_printf( "Raise actor A Above Actor C which will now be successful \n" );
+  tet_infoline( "Raise actor A Above Actor C which will now be successful \n" );
   DALI_TEST_EQUALS( gTouchCallBackCalled,  true, TEST_LOCATION );
   DALI_TEST_EQUALS( gTouchCallBackCalled2,  false, TEST_LOCATION );
   DALI_TEST_EQUALS( gTouchCallBackCalled3,  false , TEST_LOCATION );
@@ -5194,3 +5194,329 @@ int UtcDaliActorRaiseAboveActorAndTargetTheSameN(void)
   END_TEST;
 }
 
+int UtcDaliActorGetScreenPosition(void)
+{
+  tet_infoline( "UtcDaliActorGetScreenPosition Get screen coordinates of Actor \n" );
+
+  TestApplication application;
+
+  Stage stage( Stage::GetCurrent() );
+
+  Actor actorA = Actor::New();
+  actorA.SetAnchorPoint( AnchorPoint::CENTER );
+
+  Vector2 size2( 10.0f, 20.0f );
+  actorA.SetSize( size2 );
+
+  actorA.SetPosition( 0.f, 0.f );
+
+  tet_infoline( "UtcDaliActorGetScreenPosition Center Anchor Point and 0,0 position \n" );
+
+  stage.Add( actorA );
+
+  application.SendNotification();
+  application.Render();
+
+  Vector3 actorWorldPosition = actorA.GetProperty( Actor::Property::WORLD_POSITION ).Get< Vector3 >();
+  Vector2 actorScreenPosition = actorA.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >();
+
+  tet_printf( "Actor World Position ( %f %f ) AnchorPoint::CENTER \n",  actorWorldPosition.x, actorWorldPosition.y  );
+  tet_printf( "Actor Screen Position %f %f \n", actorScreenPosition.x, actorScreenPosition.y );
+
+  DALI_TEST_EQUALS( actorScreenPosition.x,  0lu , TEST_LOCATION );
+  DALI_TEST_EQUALS( actorScreenPosition.y,  0lu , TEST_LOCATION );
+
+  tet_infoline( "UtcDaliActorGetScreenPosition Top Left Anchor Point and 0,0 position \n" );
+
+  actorA.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+
+  application.SendNotification();
+  application.Render();
+
+  actorWorldPosition = actorA.GetProperty( Actor::Property::WORLD_POSITION ).Get< Vector3 >();
+  actorScreenPosition = actorA.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >();
+
+  tet_printf( "Actor World Position  ( %f %f ) AnchorPoint::TOP_LEFT  \n",  actorWorldPosition.x, actorWorldPosition.y );
+  tet_printf( "Actor Screen Position  ( %f %f ) AnchorPoint::TOP_LEFT \n", actorScreenPosition.x, actorScreenPosition.y );
+
+  DALI_TEST_EQUALS( actorScreenPosition.x,  0lu , TEST_LOCATION );
+  DALI_TEST_EQUALS( actorScreenPosition.y,  0lu , TEST_LOCATION );
+
+  tet_infoline( "UtcDaliActorGetScreenPosition Bottom right Anchor Point and 0,0 position \n" );
+
+  actorA.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT );
+
+  application.SendNotification();
+  application.Render();
+
+  actorWorldPosition = actorA.GetProperty( Actor::Property::WORLD_POSITION ).Get< Vector3 >();
+  actorScreenPosition = actorA.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >();
+
+  tet_printf( "Actor World Position ( %f %f ) AnchorPoint::BOTTOM_RIGHT   \n",  actorWorldPosition.x, actorWorldPosition.y );
+  tet_printf( "Actor Screen Position ( %f %f ) AnchorPoint::BOTTOM_RIGHT  \n", actorScreenPosition.x, actorScreenPosition.y );
+
+  DALI_TEST_EQUALS( actorScreenPosition.x,  0lu , TEST_LOCATION );
+  DALI_TEST_EQUALS( actorScreenPosition.y,  0lu , TEST_LOCATION );
+
+  tet_infoline( "UtcDaliActorGetScreenPosition Bottom right Anchor Point and 30,0 position \n" );
+
+  actorA.SetPosition( 30.0, 0.0 );
+
+  application.SendNotification();
+  application.Render();
+
+  actorWorldPosition = actorA.GetProperty( Actor::Property::WORLD_POSITION ).Get< Vector3 >();
+  actorScreenPosition = actorA.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >();
+
+  tet_printf( "Actor World Position ( %f %f ) AnchorPoint::BOTTOM_RIGHT Position x=30 y = 0.0 \n",  actorWorldPosition.x, actorWorldPosition.y );
+  tet_printf( "Actor Screen Position ( %f %f ) AnchorPoint::BOTTOM_RIGHT Position x=30 y = 0.0   \n", actorScreenPosition.x, actorScreenPosition.y );
+
+  DALI_TEST_EQUALS( actorScreenPosition.x,  30lu , TEST_LOCATION );
+  DALI_TEST_EQUALS( actorScreenPosition.y,  0lu , TEST_LOCATION );
+
+  tet_infoline( "UtcDaliActorGetScreenPosition Bottom right Anchor Point and 30,420 position \n" );
+
+  actorA.SetPosition( 30.0, 420.0 );
+
+  application.SendNotification();
+  application.Render();
+
+  actorWorldPosition = actorA.GetProperty( Actor::Property::WORLD_POSITION ).Get< Vector3 >();
+  actorScreenPosition = actorA.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >();
+
+  DALI_TEST_EQUALS( actorScreenPosition.x,  30lu , TEST_LOCATION );
+  DALI_TEST_EQUALS( actorScreenPosition.y,  420lu , TEST_LOCATION );
+
+  tet_printf( "Actor World Position ( %f %f ) AnchorPoint::BOTTOM_RIGHT Position x=30 y = 420.0\n",  actorWorldPosition.x, actorWorldPosition.y );
+  tet_printf( "Actor Screen Position( %f %f ) AnchorPoint::BOTTOM_RIGHT Position x=30 y = 420.0 \n", actorScreenPosition.x, actorScreenPosition.y );
+
+
+  END_TEST;
+}
+
+int UtcDaliActorGetScreenPositionAfterScaling(void)
+{
+  tet_infoline( "UtcDaliActorGetScreenPositionAfterScaling Get screen coordinates of Actor \n" );
+
+  TestApplication application;
+
+  Stage stage( Stage::GetCurrent() );
+
+  Actor actorA = Actor::New();
+  actorA.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+
+  Vector2 size2( 10.0f, 20.0f );
+  actorA.SetSize( size2 );
+  actorA.SetScale( 1.5f );
+  actorA.SetPosition( 0.f, 0.f );
+
+  tet_infoline( "UtcDaliActorGetScreenPositionAfterScaling TopRight Anchor Point, scale 1.5f and 0,0 position \n" );
+
+  stage.Add( actorA );
+
+  application.SendNotification();
+  application.Render();
+
+  Vector3 actorWorldPosition = actorA.GetProperty( Actor::Property::WORLD_POSITION ).Get< Vector3 >();
+  Vector2 actorScreenPosition = actorA.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >();
+
+  tet_printf( "Actor World Position ( %f %f ) AnchorPoint::TOP_LEFT \n",  actorWorldPosition.x, actorWorldPosition.y  );
+  tet_printf( "Actor Screen Position ( %f %f ) \n", actorScreenPosition.x, actorScreenPosition.y );
+
+  DALI_TEST_EQUALS( actorScreenPosition.x,  0lu , TEST_LOCATION );
+  DALI_TEST_EQUALS( actorScreenPosition.y,  0lu , TEST_LOCATION );
+
+  tet_infoline( "UtcDaliActorGetScreenPositionAfterScaling BOTTOM_RIGHT Anchor Point, scale 1.5f and 0,0 position \n" );
+
+  actorA.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT );
+
+  application.SendNotification();
+  application.Render();
+
+  actorWorldPosition = actorA.GetProperty( Actor::Property::WORLD_POSITION ).Get< Vector3 >();
+  actorScreenPosition = actorA.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >();
+
+  tet_printf( "Actor World Position ( %f %f ) AnchorPoint::BOTTOM_RIGHT \n",  actorWorldPosition.x, actorWorldPosition.y  );
+  tet_printf( "Actor Screen Position ( %f %f ) \n", actorScreenPosition.x, actorScreenPosition.y );
+
+  DALI_TEST_EQUALS( actorScreenPosition.x , 0.0f  , TEST_LOCATION );
+  DALI_TEST_EQUALS( actorScreenPosition.y,  0.0f , TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliActorGetScreenPositionWithDifferentParentOrigin(void)
+{
+  tet_infoline( "UtcDaliActorGetScreenPositionWithDifferentParentOrigin Changes parent origin which should not effect result \n" );
+
+  TestApplication application;
+
+  Stage stage( Stage::GetCurrent() );
+
+  Actor actorA = Actor::New();
+  actorA.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  actorA.SetParentOrigin( ParentOrigin::CENTER );
+  Vector2 size2( 10.0f, 20.0f );
+  actorA.SetSize( size2 );
+  actorA.SetPosition( 0.f, 0.f );
+
+  tet_infoline( " TOP_LEFT Anchor Point, ParentOrigin::CENTER and 0,0 position \n" );
+
+  stage.Add( actorA );
+
+  application.SendNotification();
+  application.Render();
+
+  Vector3 actorWorldPosition = actorA.GetProperty( Actor::Property::WORLD_POSITION ).Get< Vector3 >();
+  Vector2 actorScreenPosition = actorA.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >();
+
+  tet_printf( "Actor World Position ( %f %f ) AnchorPoint::TOP_LEFT ParentOrigin::CENTER  \n",  actorWorldPosition.x, actorWorldPosition.y  );
+  tet_printf( "Actor Screen Position ( %f %f ) \n", actorScreenPosition.x, actorScreenPosition.y );
+
+  DALI_TEST_EQUALS( actorScreenPosition.x,  240.0f , TEST_LOCATION );
+  DALI_TEST_EQUALS( actorScreenPosition.y,  400.0f , TEST_LOCATION );
+
+  tet_infoline( " BOTTOM_RIGHT Anchor Point, ParentOrigin::TOP_RIGHT and 0,0 position \n" );
+
+  actorA.SetParentOrigin( ParentOrigin::TOP_RIGHT );
+  actorA.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT );
+
+  application.SendNotification();
+  application.Render();
+
+  actorWorldPosition = actorA.GetProperty( Actor::Property::WORLD_POSITION ).Get< Vector3 >();
+  actorScreenPosition = actorA.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >();
+
+  tet_printf( "Actor World Position ( %f %f ) AnchorPoint::BOTTOM_RIGHT ParentOrigin::TOP_RIGHT \n",  actorWorldPosition.x, actorWorldPosition.y  );
+  tet_printf( "Actor Screen Position ( %f %f ) \n", actorScreenPosition.x, actorScreenPosition.y );
+
+  DALI_TEST_EQUALS( actorScreenPosition.x , 480.0f , TEST_LOCATION );
+  DALI_TEST_EQUALS( actorScreenPosition.y,  0.0f , TEST_LOCATION );
+
+  END_TEST;
+  END_TEST;
+}
+
+int UtcDaliActorGetScreenPositionWithChildActors(void)
+{
+  tet_infoline( "UtcDaliActorGetScreenPositionWithChildActors Check screen position with a tree of actors \n" );
+
+  TestApplication application;
+
+  Stage stage( Stage::GetCurrent() );
+
+  tet_infoline( "Create Child Actor 1 TOP_LEFT Anchor Point, ParentOrigin::CENTER and 0,0 position \n" );
+
+  Actor actorA = Actor::New();
+  actorA.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  actorA.SetParentOrigin( ParentOrigin::CENTER );
+  Vector2 size1( 10.0f, 20.0f );
+  actorA.SetSize( size1 );
+  actorA.SetPosition( 0.f, 0.f );
+
+  tet_infoline( "Create Parent Actor 1 TOP_LEFT Anchor Point, ParentOrigin::CENTER and 0,0 position \n" );
+
+  Actor parentActorA = Actor::New();
+  parentActorA.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  parentActorA.SetParentOrigin( ParentOrigin::CENTER );
+  Vector2 size2( 30.0f, 60.0f );
+  parentActorA.SetSize( size2 );
+  parentActorA.SetPosition( 0.f, 0.f );
+
+  tet_infoline( "Add child 1 to Parent 1 and check screen position \n" );
+
+  stage.Add( parentActorA );
+  parentActorA.Add ( actorA );
+
+  application.SendNotification();
+  application.Render();
+
+  Vector3 actorWorldPosition = actorA.GetProperty( Actor::Property::WORLD_POSITION ).Get< Vector3 >();
+  Vector2 actorScreenPosition = actorA.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >();
+
+  tet_printf( "Actor World Position ( %f %f ) AnchorPoint::TOP_LEFT ParentOrigin::CENTER  \n",  actorWorldPosition.x, actorWorldPosition.y  );
+  tet_printf( "Actor Screen Position ( %f %f ) \n", actorScreenPosition.x, actorScreenPosition.y );
+
+  DALI_TEST_EQUALS( actorScreenPosition.x,  255.0f , TEST_LOCATION );
+  DALI_TEST_EQUALS( actorScreenPosition.y,  430.0f , TEST_LOCATION );
+
+  tet_infoline( "Test 2\n");
+
+  tet_infoline( "change parent anchor point and parent origin then check screen position \n" );
+
+  parentActorA.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT );
+  parentActorA.SetParentOrigin( ParentOrigin::TOP_LEFT );
+
+  application.SendNotification();
+  application.Render();
+
+  actorWorldPosition = actorA.GetProperty( Actor::Property::WORLD_POSITION ).Get< Vector3 >();
+  actorScreenPosition = actorA.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >();
+
+  tet_printf( "Actor World Position ( %f %f ) AnchorPoint::BOTTOM_LEFT ParentOrigin::TOP_LEFT  \n",  actorWorldPosition.x, actorWorldPosition.y  );
+  tet_printf( "Actor Screen Position ( %f %f ) \n", actorScreenPosition.x, actorScreenPosition.y );
+
+  DALI_TEST_EQUALS( actorScreenPosition.x,  15.0f , TEST_LOCATION );
+  DALI_TEST_EQUALS( actorScreenPosition.y,  -30.0f , TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliActorGetScreenPositionWithChildActors02(void)
+{
+  tet_infoline( "UtcDaliActorGetScreenPositionWithChildActors02 Check screen position with a tree of actors \n" );
+
+  TestApplication application;
+
+  Stage stage( Stage::GetCurrent() );
+
+  tet_infoline( "Create Child Actor 1 TOP_LEFT Anchor Point, ParentOrigin::CENTER and 0,0 position \n" );
+
+  Actor actorA = Actor::New();
+  actorA.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  actorA.SetParentOrigin( ParentOrigin::CENTER );
+  Vector2 size1( 10.0f, 20.0f );
+  actorA.SetSize( size1 );
+  actorA.SetPosition( 0.f, 0.f );
+
+  tet_infoline( "Create Parent Actor 1 TOP_LEFT Anchor Point, ParentOrigin::CENTER and 0,0 position \n" );
+
+  Actor parentActorA = Actor::New();
+  parentActorA.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  parentActorA.SetParentOrigin( ParentOrigin::CENTER );
+  Vector2 size2( 30.0f, 60.0f );
+  parentActorA.SetSize( size2 );
+  parentActorA.SetPosition( 0.f, 0.f );
+
+  tet_infoline( "Create Grand Parent Actor 1 TOP_RIGHT Anchor Point, ParentOrigin::CENTER and 0,0 position \n" );
+
+  Actor grandParentActorA = Actor::New();
+  grandParentActorA.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT );
+  grandParentActorA.SetParentOrigin( ParentOrigin::BOTTOM_LEFT );
+  Vector2 size3( 60.0f, 120.0f );
+  grandParentActorA.SetSize( size3 );
+  grandParentActorA.SetPosition( 0.f, 0.f );
+
+  tet_infoline( "Add Parent 1 to Grand Parent 1 \n" );
+
+  stage.Add( grandParentActorA );
+  grandParentActorA.Add ( parentActorA );
+
+  tet_infoline( "Add child 1 to Parent 1 and check screen position \n" );
+
+  parentActorA.Add ( actorA );
+
+  application.SendNotification();
+  application.Render();
+
+  Vector3 actorWorldPosition = actorA.GetProperty( Actor::Property::WORLD_POSITION ).Get< Vector3 >();
+  Vector2 actorScreenPosition = actorA.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >();
+
+  tet_printf( "Actor World Position ( %f %f ) AnchorPoint::TOP_LEFT ParentOrigin::CENTER  \n",  actorWorldPosition.x, actorWorldPosition.y  );
+  tet_printf( "Actor Screen Position ( %f %f ) \n", actorScreenPosition.x, actorScreenPosition.y );
+
+  DALI_TEST_EQUALS( actorScreenPosition.x,  45.0f , TEST_LOCATION );
+  DALI_TEST_EQUALS( actorScreenPosition.y,  770.0f , TEST_LOCATION );
+
+  END_TEST;
+}
index 3cc533d..4d4ad78 100644 (file)
@@ -103,6 +103,13 @@ enum Type
    * @SINCE_1_2.28
    */
   OPACITY              = CLIPPING_MODE + 2,
+
+  /**
+   * @brief Returns the screen position of the Actor
+   * @details Name "screenPosition", type Property::VECTOR2. Read-only
+   * @note This assumes default camera and default render-task and the Z position is ZERO.
+   */
+  SCREEN_POSITION      = CLIPPING_MODE + 3,
 };
 
 } // namespace Property
index d1bfa59..e5ed2fc 100644 (file)
@@ -228,6 +228,7 @@ DALI_PROPERTY( "inheritPosition",     BOOLEAN,  true,  false, false, Dali::Actor
 DALI_PROPERTY( "clippingMode",        STRING,   true,  false, false, Dali::Actor::Property::CLIPPING_MODE )
 DALI_PROPERTY( "siblingOrder",        INTEGER,  true,  false, false, Dali::DevelActor::Property::SIBLING_ORDER )
 DALI_PROPERTY( "opacity",             FLOAT,    true,  true,  true,  Dali::DevelActor::Property::OPACITY )
+DALI_PROPERTY( "screenPosition",      VECTOR2,  false, false, false, Dali::DevelActor::Property::SCREEN_POSITION )
 DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
 
 // Signals
@@ -803,6 +804,25 @@ const Vector3& Actor::GetCurrentWorldPosition() const
   return Vector3::ZERO;
 }
 
+const Vector2 Actor::GetCurrentScreenPosition() const
+{
+  if( OnStage() && NULL != mNode )
+  {
+    StagePtr stage = Stage::GetCurrent();
+    Vector3 worldPosition =  mNode->GetWorldPosition( GetEventThreadServices().GetEventBufferIndex() );
+    Vector3 actorSize = GetCurrentSize() * GetCurrentScale();
+    Vector2 halfStageSize( stage->GetSize() * 0.5f ); // World position origin is center of stage
+    Vector3 halfActorSize( actorSize * 0.5f );
+    // Anchor point offset first set to TOP_LEFT (0,0.5) then moved to required anchor point.
+    Vector3 anchorPointOffSet = halfActorSize - actorSize * GetCurrentAnchorPoint();
+
+    return Vector2( halfStageSize.width + worldPosition.x - anchorPointOffSet.x,
+                    halfStageSize.height + worldPosition.y - anchorPointOffSet.y );
+  }
+
+  return Vector2::ZERO;
+}
+
 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
 {
   // this flag is not animatable so keep the value
@@ -3281,6 +3301,12 @@ Property::Value Actor::GetDefaultProperty( Property::Index index ) const
       value = mClippingMode;
       break;
     }
+
+    case Dali::DevelActor::Property::SCREEN_POSITION:
+    {
+      value = GetCurrentScreenPosition();
+      break;
+    }
   }
 
   return value;
index 0867eef..b73371b 100644 (file)
@@ -1847,6 +1847,13 @@ private:
   bool ShiftSiblingsLevels( ActorContainer& siblings, int targetLevelToShiftFrom );
 
 
+  /**
+   * @brief Get the current position of the actor in screen coordinates.
+   *
+   * @return Returns the screen position of actor
+   */
+  const Vector2 GetCurrentScreenPosition() const;
+
 protected:
 
   Actor* mParent;                 ///< Each actor (except the root) can have one parent