Event-side size storage in Actor. 56/27956/2
authorKingsley Stephens <k.stephens@partner.samsung.com>
Mon, 22 Sep 2014 12:25:59 +0000 (13:25 +0100)
committerKingsley Stephens <k.stephens@partner.samsung.com>
Tue, 23 Sep 2014 13:13:27 +0000 (14:13 +0100)
Change-Id: Ia43f6cd2768882806c34be1f462c47e1e9f499da

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

index 38dddff..95dc2e6 100644 (file)
@@ -818,6 +818,48 @@ int UtcDaliActorGetNaturalSize(void)
   END_TEST;
 }
 
+int UtcDaliActorGetCurrentSizeImmediate(void)
+{
+  TestApplication application;
+
+  Actor actor = Actor::New();
+  Vector3 vector(100.0f, 100.0f, 20.0f);
+
+  DALI_TEST_CHECK(vector != actor.GetSize());
+  DALI_TEST_CHECK(vector != actor.GetCurrentSize());
+
+  actor.SetSize(vector);
+
+  DALI_TEST_CHECK(vector == actor.GetSize());
+  DALI_TEST_CHECK(vector != actor.GetCurrentSize());
+
+  // flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_CHECK(vector == actor.GetSize());
+  DALI_TEST_CHECK(vector == actor.GetCurrentSize());
+
+  // Animation
+  // Build the animation
+  const float durationSeconds = 2.0f;
+  Animation animation = Animation::New( durationSeconds );
+  const Vector3 targetValue( 10.0f, 20.0f, 30.0f );
+  animation.AnimateTo( Property( actor, Actor::SIZE ), targetValue );
+
+  DALI_TEST_CHECK( actor.GetSize() == targetValue );
+
+  // Start the animation
+  animation.Play();
+
+  application.SendNotification();
+  application.Render( static_cast<unsigned int>( durationSeconds * 1000.0f ) );
+
+  DALI_TEST_CHECK( actor.GetSize() == targetValue );
+
+  END_TEST;
+}
+
 // SetPosition(float x, float y)
 int UtcDaliActorSetPosition01(void)
 {
@@ -1849,6 +1891,11 @@ int UtcDaliActorApplyConstraintAppliedCallback(void)
   ActiveConstraint activeConstraint3 = child3.ApplyConstraint( constraint );
   activeConstraint3.AppliedSignal().Connect( TestConstraintCallback3 );
 
+  // Check event-side size
+  DALI_TEST_EQUALS( child1.GetSize(), Vector3::ZERO, TEST_LOCATION );
+  DALI_TEST_EQUALS( child2.GetSize(), Vector3::ZERO, TEST_LOCATION );
+  DALI_TEST_EQUALS( child3.GetSize(), Vector3::ZERO, TEST_LOCATION );
+
   DALI_TEST_EQUALS( child1.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
   DALI_TEST_EQUALS( child2.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
   DALI_TEST_EQUALS( child3.GetCurrentSize(), Vector3::ZERO, TEST_LOCATION );
@@ -1856,6 +1903,7 @@ int UtcDaliActorApplyConstraintAppliedCallback(void)
   application.SendNotification();
 
   application.Render(static_cast<unsigned int>(1000.0f)); // 1 elapsed second
+
   DALI_TEST_EQUALS( child1.GetCurrentSize(), parentSize*0.20f, TEST_LOCATION ); // 1 /  5 * 100 = 20%
   DALI_TEST_EQUALS( child2.GetCurrentSize(), parentSize*0.10f, TEST_LOCATION ); // 1 / 10 * 100 = 10%
   DALI_TEST_EQUALS( child3.GetCurrentSize(), parentSize*0.00f, TEST_LOCATION ); // 0%
index 52c903a..fcb0680 100644 (file)
@@ -1103,22 +1103,32 @@ void Actor::SetSize(const Vector3& size)
 {
   if( NULL != mNode )
   {
+    mSize = size;
+
     // mNode is being used in a separate thread; queue a message to set the value & base value
-    SceneGraph::NodePropertyMessage<Vector3>::Send( mStage->GetUpdateManager(), mNode, &mNode->mSize, &AnimatableProperty<Vector3>::Bake, size );
+    SceneGraph::NodePropertyMessage<Vector3>::Send( mStage->GetUpdateManager(), mNode, &mNode->mSize, &AnimatableProperty<Vector3>::Bake, mSize );
 
     // Notification for derived classes
-    OnSizeSet(size);
+    OnSizeSet( mSize );
 
     // Emit signal for application developer
 
     if( !mSetSizeSignalV2.Empty() )
     {
       Dali::Actor handle( this );
-      mSetSizeSignalV2.Emit( handle, size );
+      mSetSizeSignalV2.Emit( handle, mSize );
     }
   }
 }
 
+void Actor::NotifySizeAnimation(Animation& animation, const Vector3& targetSize)
+{
+  mSize = targetSize;
+
+  // Notify deriving classes
+  OnSizeAnimation( animation, targetSize );
+}
+
 void Actor::SetWidth( float width )
 {
   if( NULL != mNode )
@@ -1146,6 +1156,11 @@ void Actor::SetDepth( float depth )
   }
 }
 
+const Vector3& Actor::GetSize() const
+{
+  return mSize;
+}
+
 const Vector3& Actor::GetCurrentSize() const
 {
   if( NULL != mNode )
@@ -1986,6 +2001,7 @@ Actor::Actor( DerivedType derivedType )
 #endif
   mGestureData( NULL ),
   mAttachment(),
+  mSize( 0.0f, 0.0f, 0.0f ),
   mName(),
   mId( ++mActorCounter ), // actor ID is initialised to start from 1, and 0 is reserved
   mIsRoot( ROOT_LAYER == derivedType ),
index 7bee28b..7a16a3a 100644 (file)
@@ -295,7 +295,15 @@ public:
   void SetDepth( float depth );
 
   /**
-   * Retrieve the Actor's size.
+   * Retrieve the Actor's size from event side.
+   * This size will be the size set or if animating then the target size.
+   * @return The Actor's size.
+   */
+  const Vector3& GetSize() const;
+
+  /**
+   * Retrieve the Actor's size from update side.
+   * This size will be the size set or animating but will be a frame behind.
    * @return The Actor's size.
    */
   const Vector3& GetCurrentSize() const;
@@ -1008,6 +1016,14 @@ public:
 public:  // For Animation
 
   /**
+   * This should only be called by Animation, when the actor is resized using Animation::Resize().
+   *
+   * @param[in] animation The animation that resized the actor
+   * @param[in] targetSize The new target size of the actor
+   */
+  void NotifySizeAnimation(Animation& animation, const Vector3& targetSize);
+
+  /**
    * For use in derived classes.
    * This should only be called by Animation, when the actor is resized using Animation::Resize().
    */
@@ -1331,6 +1347,8 @@ protected:
   Dali::Actor::OnStageSignalV2           mOnStageSignalV2;
   Dali::Actor::OffStageSignalV2          mOffStageSignalV2;
 
+  Vector3         mSize;      ///< Event-side storage for size (not a pointer as most actors will have a size)
+
   std::string     mName;      ///< Name of the actor
   unsigned int    mId;        ///< A unique ID to identify the actor starting from 1, and 0 is reserved
 
index 3f680a5..972c00f 100644 (file)
@@ -469,7 +469,7 @@ void Animation::AnimateTo(ProxyObject& targetObject, Property::Index targetPrope
         if ( maybeActor )
         {
           // Notify the actor that its size is being animated
-          maybeActor->OnSizeAnimation( *this, destinationValue.Get<Vector3>() );
+          maybeActor->NotifySizeAnimation( *this, destinationValue.Get<Vector3>() );
         }
       }
 
@@ -1138,8 +1138,8 @@ void Animation::Resize(Actor& actor, float width, float height, AlphaFunction al
 
   ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
 
-  // notify the actor impl that its size is being animated
-  actor.OnSizeAnimation( *this, targetSize );
+  // Notify the actor impl that its size is being animated
+  actor.NotifySizeAnimation( *this, targetSize );
 
   AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
                                                          Dali::Actor::SIZE,
@@ -1163,8 +1163,8 @@ void Animation::Resize(Actor& actor, const Vector3& size, AlphaFunction alpha, f
 {
   ExtendDuration( TimePeriod(delaySeconds, durationSeconds) );
 
-  // notify the actor impl that its size is being animated
-  actor.OnSizeAnimation( *this, size );
+  // Notify the actor impl that its size is being animated
+  actor.NotifySizeAnimation( *this, size );
 
   AddAnimatorConnector( AnimatorConnector<Vector3>::New( actor,
                                                          Dali::Actor::SIZE,
index 284e45b..2ffa4ab 100644 (file)
@@ -225,6 +225,11 @@ void Actor::SetSize(const Vector3& size)
   GetImplementation(*this).SetSize(size);
 }
 
+Vector3 Actor::GetSize() const
+{
+  return GetImplementation(*this).GetSize();
+}
+
 Vector3 Actor::GetCurrentSize() const
 {
   return GetImplementation(*this).GetCurrentSize();
index 631b591..438735a 100644 (file)
@@ -615,6 +615,15 @@ public:
    * @brief Retrieve the actor's size.
    *
    * @pre The actor has been initialized.
+   * @note This return is the value that was set using SetSize or the target size of an animation
+   * @return The actor's current size.
+   */
+  Vector3 GetSize() const;
+
+  /**
+   * @brief Retrieve the actor's size.
+   *
+   * @pre The actor has been initialized.
    * @note This property can be animated; the return value may not match the value written with SetSize().
    * @return The actor's current size.
    */