From b80e67cb48104646dc91a546cb0733b2c22700e0 Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Thu, 24 Mar 2022 15:56:08 +0900 Subject: [PATCH] Use update object size in CalculateActorScreenPosition Change-Id: I475166706a0eb4defd1761ce56d185da7fe753a1 --- automated-tests/src/dali/utc-Dali-Actor.cpp | 51 +++++++++++++++++++++++++++-- dali/internal/event/actors/actor-coords.cpp | 3 +- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-Actor.cpp b/automated-tests/src/dali/utc-Dali-Actor.cpp index 9873aa7..5ea0d22 100644 --- a/automated-tests/src/dali/utc-Dali-Actor.cpp +++ b/automated-tests/src/dali/utc-Dali-Actor.cpp @@ -50,9 +50,9 @@ void utc_dali_actor_cleanup(void) namespace { -bool gTouchCallBackCalled = false; -bool gTouchCallBackCalled2 = false; -bool gTouchCallBackCalled3 = false; +bool gTouchCallBackCalled = false; +bool gTouchCallBackCalled2 = false; +bool gTouchCallBackCalled3 = false; bool gHitTestTouchCallBackCalled = false; bool gHoverCallBackCalled = false; @@ -7043,6 +7043,51 @@ int UtcDaliActorGetScreenPositionPositionUsesAnchorPointFalse(void) END_TEST; } +int UtcDaliActorGetScreenPositionResizeScene(void) +{ + tet_infoline("UtcDaliActorGetScreenPositionResizeScene Check screen position after resizing the scene size"); + + TestApplication application; + Integration::Scene scene = application.GetScene(); + + Actor actorA = Actor::New(); + actorA.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + actorA.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + actorA.SetProperty(Actor::Property::SIZE, Vector2(10.0f, 10.0f)); + + scene.Add(actorA); + + application.SendNotification(); + application.Render(); + + Vector2 sceneSize = scene.GetSize(); + Vector2 actorScreenPosition = actorA.GetProperty(Actor::Property::SCREEN_POSITION).Get(); + + DALI_TEST_EQUALS(actorScreenPosition, sceneSize / 2, TEST_LOCATION); + + // Resize the scene + Vector2 newSize(1000.0f, 2000.0f); + DALI_TEST_CHECK(scene.GetSize() != newSize); + + scene.SurfaceResized(newSize.width, newSize.height); + + actorScreenPosition = actorA.GetProperty(Actor::Property::SCREEN_POSITION).Get(); + + // The screen position should not be updated yet + DALI_TEST_EQUALS(actorScreenPosition, sceneSize / 2, TEST_LOCATION); + + application.SendNotification(); + application.Render(); + + actorScreenPosition = actorA.GetProperty(Actor::Property::SCREEN_POSITION).Get(); + + // The screen position should be updated + sceneSize = scene.GetSize(); + DALI_TEST_EQUALS(actorScreenPosition, sceneSize / 2, TEST_LOCATION); + + END_TEST; +} + int utcDaliActorPositionUsesAnchorPoint(void) { TestApplication application; diff --git a/dali/internal/event/actors/actor-coords.cpp b/dali/internal/event/actors/actor-coords.cpp index 7a7275a..9d1010e 100644 --- a/dali/internal/event/actors/actor-coords.cpp +++ b/dali/internal/event/actors/actor-coords.cpp @@ -136,7 +136,8 @@ const Vector2 CalculateActorScreenPosition(const Actor& actor, BufferIndex buffe worldPosition -= cameraPosition; Vector3 actorSize = node.GetSize(bufferIndex) * node.GetWorldScale(bufferIndex); - Vector2 halfSceneSize(scene.GetSize() * 0.5f); // World position origin is center of scene + auto sceneSize = scene.GetCurrentSurfaceRect(); // Use the update object's size + Vector2 halfSceneSize(sceneSize.width * 0.5f, sceneSize.height * 0.5f); // World position origin is center of scene Vector3 halfActorSize(actorSize * 0.5f); Vector3 anchorPointOffSet = halfActorSize - actorSize * actor.GetAnchorPointForPosition(); return Vector2(halfSceneSize.width + worldPosition.x - anchorPointOffSet.x, -- 2.7.4