From 4927f80c89dde2e049dbdb455dfebf259e5a191e Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Mon, 3 Apr 2017 17:13:41 +0100 Subject: [PATCH] Ensure SCREEN_POSITION value takes POSITION_USES_ANCHOR_POINT property into account Change-Id: I685f336c8ff28e6af4f88d3f5ac7ded804207c23 --- automated-tests/src/dali/utc-Dali-Actor.cpp | 66 ++++++++++++++++++++++++++++- dali/internal/event/actors/actor-impl.cpp | 3 +- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-Actor.cpp b/automated-tests/src/dali/utc-Dali-Actor.cpp index 9599c0c..0009ca7 100644 --- a/automated-tests/src/dali/utc-Dali-Actor.cpp +++ b/automated-tests/src/dali/utc-Dali-Actor.cpp @@ -5519,7 +5519,7 @@ int UtcDaliActorGetScreenPositionWithChildActors02(void) 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" ); + tet_infoline( "Create Grand Parent Actor 1 BOTTOM_LEFT Anchor Point, ParentOrigin::BOTTOM_LEFT and 0,0 position \n" ); Actor grandParentActorA = Actor::New(); grandParentActorA.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT ); @@ -5552,6 +5552,70 @@ int UtcDaliActorGetScreenPositionWithChildActors02(void) END_TEST; } +int UtcDaliActorGetScreenPositionPositionUsesAnchorPointFalse(void) +{ + tet_infoline( "UtcDaliActorGetScreenPositionPositionUsesAnchorPointFalse Check screen position where the position does not use the anchor point" ); + + TestApplication application; + + Stage stage( Stage::GetCurrent() ); + + tet_infoline( "Create an actor with AnchorPoint::TOP_LEFT, ParentOrigin::CENTER and 0,0 position, POSITION_USES_ANCHOR false" ); + + Actor actorA = Actor::New(); + actorA.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + actorA.SetParentOrigin( ParentOrigin::CENTER ); + actorA.SetProperty( DevelActor::Property::POSITION_USES_ANCHOR_POINT, false ); + actorA.SetSize( 10.0f, 20.0f ); + stage.Add( actorA ); + + tet_infoline( "Create an Actor with AnchorPoint::BOTTOM_RIGHT, ParentOrigin::CENTER and 0,0 position, POSITION_USES_ANCHOR false" ); + + Actor actorB = Actor::New(); + actorB.SetAnchorPoint( AnchorPoint::BOTTOM_RIGHT ); + actorB.SetParentOrigin( ParentOrigin::CENTER ); + actorB.SetProperty( DevelActor::Property::POSITION_USES_ANCHOR_POINT, false ); + Vector2 actorBSize( 30.0f, 60.0f ); + actorB.SetSize( actorBSize ); + stage.Add( actorB ); + + tet_infoline( "Create an actor with AnchorPoint::CENTER, ParentOrigin::CENTER and 0,0 position, POSITION_USES_ANCHOR false" ); + + Actor actorC = Actor::New(); + actorC.SetAnchorPoint( AnchorPoint::CENTER ); + actorC.SetParentOrigin( ParentOrigin::CENTER ); + actorC.SetProperty( DevelActor::Property::POSITION_USES_ANCHOR_POINT, false ); + Vector2 actorCSize( 60.0f, 120.0f ); + actorC.SetSize( actorCSize ); + stage.Add( actorC ); + + application.SendNotification(); + application.Render(); + + tet_infoline( "Despite differing sizes and anchor-points, the screen position for all actors is the same"); + + Vector2 center( stage.GetSize() * 0.5f ); + + DALI_TEST_EQUALS( actorA.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >(), center, TEST_LOCATION ); + DALI_TEST_EQUALS( actorB.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >(), center, TEST_LOCATION ); + DALI_TEST_EQUALS( actorC.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >(), center, TEST_LOCATION ); + + tet_infoline( "Add scale to all actors" ); + + actorA.SetScale( 2.0f ); + actorB.SetScale( 2.0f ); + actorC.SetScale( 2.0f ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( actorA.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >(), center /* TOP_LEFT Anchor */, TEST_LOCATION ); + DALI_TEST_EQUALS( actorB.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >(), center - actorBSize /* BOTTOM_RIGHT Anchor */, TEST_LOCATION ); + DALI_TEST_EQUALS( actorC.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >(), center - actorCSize * 0.5f /* CENTER Anchor*/, TEST_LOCATION ); + + END_TEST; +} + int utcDaliActorPositionUsesAnchorPoint(void) { TestApplication application; diff --git a/dali/internal/event/actors/actor-impl.cpp b/dali/internal/event/actors/actor-impl.cpp index 9a3d3d7..e24b229 100644 --- a/dali/internal/event/actors/actor-impl.cpp +++ b/dali/internal/event/actors/actor-impl.cpp @@ -814,8 +814,7 @@ const Vector2 Actor::GetCurrentScreenPosition() const 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(); + Vector3 anchorPointOffSet = halfActorSize - actorSize * ( mPositionUsesAnchorPoint ? GetCurrentAnchorPoint() : AnchorPoint::TOP_LEFT ); return Vector2( halfStageSize.width + worldPosition.x - anchorPointOffSet.x, halfStageSize.height + worldPosition.y - anchorPointOffSet.y ); -- 2.7.4