Make mTargetSizeDirtyFlag true when Animation changes Actor's Size 22/289022/3
authorseungho baek <sbsh.baek@samsung.com>
Mon, 27 Feb 2023 09:25:14 +0000 (18:25 +0900)
committerseungho baek <sbsh.baek@samsung.com>
Mon, 27 Feb 2023 10:14:25 +0000 (19:14 +0900)
Change-Id: Ied85413cd3bf8f8fc7d19c831e35f700e225c9f4
Signed-off-by: seungho baek <sbsh.baek@samsung.com>
automated-tests/src/dali/utc-Dali-Actor.cpp
dali/internal/event/actors/actor-sizer.cpp

index 4413115..000fbda 100644 (file)
@@ -8578,6 +8578,83 @@ int utcDaliActorGetSizeAfterAnimation(void)
   END_TEST;
 }
 
+int utcDaliActorGetSizeAfterAnimation2(void)
+{
+  TestApplication application;
+  tet_infoline("Check the actor size before / after an animation is finished if before size is equal to animation target size");
+
+  Vector3 actorSize(100.0f, 100.0f, 0.0f);
+
+  Actor actor = Actor::New();
+  actor.SetProperty(Actor::Property::SIZE, actorSize);
+  actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
+  application.GetScene().Add(actor);
+
+  // Size should be updated without rendering.
+  Vector3 size = actor.GetProperty(Actor::Property::SIZE).Get<Vector3>();
+  DALI_TEST_EQUALS(size, actorSize, Math::MACHINE_EPSILON_0, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  // Size and current size should be updated.
+  size = actor.GetProperty(Actor::Property::SIZE).Get<Vector3>();
+  DALI_TEST_EQUALS(size, actorSize, Math::MACHINE_EPSILON_0, TEST_LOCATION);
+  DALI_TEST_EQUALS(actorSize.width, actor.GetProperty<float>(Actor::Property::SIZE_WIDTH), TEST_LOCATION);
+  DALI_TEST_EQUALS(actorSize.height, actor.GetProperty<float>(Actor::Property::SIZE_HEIGHT), TEST_LOCATION);
+  DALI_TEST_EQUALS(actorSize.depth, actor.GetProperty<float>(Actor::Property::SIZE_DEPTH), TEST_LOCATION);
+
+  Vector3 currentSize = actor.GetCurrentProperty(Actor::Property::SIZE).Get<Vector3>();
+  DALI_TEST_EQUALS(currentSize, actorSize, Math::MACHINE_EPSILON_0, TEST_LOCATION);
+  DALI_TEST_EQUALS(actorSize.width, actor.GetCurrentProperty<float>(Actor::Property::SIZE_WIDTH), TEST_LOCATION);
+  DALI_TEST_EQUALS(actorSize.height, actor.GetCurrentProperty<float>(Actor::Property::SIZE_HEIGHT), TEST_LOCATION);
+  DALI_TEST_EQUALS(actorSize.depth, actor.GetCurrentProperty<float>(Actor::Property::SIZE_DEPTH), TEST_LOCATION);
+
+  // Set size again
+  actorSize = Vector3(200.0f, 200.0f, 0.0f);
+  actor.SetProperty(Actor::Property::SIZE, actorSize);
+
+  size = actor.GetProperty(Actor::Property::SIZE).Get<Vector3>();
+  DALI_TEST_EQUALS(size, actorSize, Math::MACHINE_EPSILON_0, TEST_LOCATION);
+
+  Vector3 targetValue(actorSize);
+
+  Animation animation = Animation::New(1.0f);
+  animation.AnimateTo(Property(actor, Actor::Property::SIZE), targetValue);
+  animation.Play();
+
+  // Size should be updated without rendering.
+  size = actor.GetProperty(Actor::Property::SIZE).Get<Vector3>();
+  DALI_TEST_EQUALS(size, targetValue, Math::MACHINE_EPSILON_0, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render(100); // During the animation
+
+  size = actor.GetProperty(Actor::Property::SIZE).Get<Vector3>();
+  DALI_TEST_EQUALS(size, targetValue, Math::MACHINE_EPSILON_0, TEST_LOCATION);
+  DALI_TEST_EQUALS(targetValue.width, actor.GetProperty<float>(Actor::Property::SIZE_WIDTH), TEST_LOCATION);
+  DALI_TEST_EQUALS(targetValue.height, actor.GetProperty<float>(Actor::Property::SIZE_HEIGHT), TEST_LOCATION);
+  DALI_TEST_EQUALS(targetValue.depth, actor.GetProperty<float>(Actor::Property::SIZE_DEPTH), TEST_LOCATION);
+
+  // We should get target value because targetValue is equal to current actor size.
+  currentSize = actor.GetCurrentProperty(Actor::Property::SIZE).Get<Vector3>();
+  DALI_TEST_EQUALS(currentSize, targetValue, Math::MACHINE_EPSILON_0, TEST_LOCATION);
+  DALI_TEST_EQUALS(targetValue.width, actor.GetCurrentProperty<float>(Actor::Property::SIZE_WIDTH), TEST_LOCATION);
+  DALI_TEST_EQUALS(targetValue.height, actor.GetCurrentProperty<float>(Actor::Property::SIZE_HEIGHT), TEST_LOCATION);
+  DALI_TEST_EQUALS(targetValue.depth, actor.GetCurrentProperty<float>(Actor::Property::SIZE_DEPTH), TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render(1000); // After animation finished
+
+  size = actor.GetProperty(Actor::Property::SIZE).Get<Vector3>();
+  DALI_TEST_EQUALS(size, actorSize, Math::MACHINE_EPSILON_0, TEST_LOCATION);
+
+  currentSize = actor.GetCurrentProperty(Actor::Property::SIZE).Get<Vector3>();
+  DALI_TEST_EQUALS(currentSize, actorSize, Math::MACHINE_EPSILON_0, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int utcDaliActorRelayoutAndAnimation(void)
 {
   TestApplication application;
index d3bbfa4..62c4b34 100644 (file)
@@ -685,7 +685,13 @@ float ActorSizer::GetMaximumSize(Dimension::Type dimension) const
 
 void ActorSizer::OnAnimateSize(Animation& animation, Vector3 targetSize, bool relative)
 {
+  Vector3 originalTargetSize = mTargetSize;
   mTargetSize      = targetSize + mTargetSize * float(relative);
+  if(originalTargetSize != mTargetSize)
+  {
+    mTargetSizeDirtyFlag = true;
+  }
+
   mAnimatedSize    = mTargetSize;
   mUseAnimatedSize = AnimatedSizeFlag::WIDTH | AnimatedSizeFlag::HEIGHT | AnimatedSizeFlag::DEPTH;
 
@@ -701,7 +707,12 @@ void ActorSizer::OnAnimateSize(Animation& animation, Vector3 targetSize, bool re
 
 void ActorSizer::OnAnimateWidth(Animation& animation, float width, bool relative)
 {
+  const float originalWidth = mTargetSize.width;
   mTargetSize.width   = width + float(relative) * mTargetSize.width;
+  if(!Equals(originalWidth,mTargetSize.width))
+  {
+    mTargetSizeDirtyFlag = true;
+  }
   mAnimatedSize.width = mTargetSize.width;
   mUseAnimatedSize |= AnimatedSizeFlag::WIDTH;
 
@@ -716,7 +727,12 @@ void ActorSizer::OnAnimateWidth(Animation& animation, float width, bool relative
 
 void ActorSizer::OnAnimateHeight(Animation& animation, float height, bool relative)
 {
+  const float originalHeight = mTargetSize.height;
   mTargetSize.height   = height + float(relative) * mTargetSize.height;
+  if(!Equals(originalHeight, mTargetSize.height))
+  {
+    mTargetSizeDirtyFlag = true;
+  }
   mAnimatedSize.height = mTargetSize.height;
   mUseAnimatedSize |= AnimatedSizeFlag::HEIGHT;
 
@@ -731,7 +747,12 @@ void ActorSizer::OnAnimateHeight(Animation& animation, float height, bool relati
 
 void ActorSizer::OnAnimateDepth(Animation& animation, float depth, bool relative)
 {
+  const float originalDepth = mTargetSize.depth;
   mTargetSize.depth   = depth + float(relative) * mTargetSize.depth;
+  if(!Equals(originalDepth, mTargetSize.depth))
+  {
+    mTargetSizeDirtyFlag = true;
+  }
   mAnimatedSize.depth = mTargetSize.depth;
   mUseAnimatedSize |= AnimatedSizeFlag::DEPTH;