From 9b761f53598f3d4d45ea06d56d6daee16c3e38f6 Mon Sep 17 00:00:00 2001 From: Kingsley Stephens Date: Mon, 22 Sep 2014 13:25:59 +0100 Subject: [PATCH] Event-side size storage in Actor. Change-Id: Ia43f6cd2768882806c34be1f462c47e1e9f499da --- automated-tests/src/dali/utc-Dali-Actor.cpp | 48 ++++++++++++++++++++++++ dali/internal/event/actors/actor-impl.cpp | 22 +++++++++-- dali/internal/event/actors/actor-impl.h | 20 +++++++++- dali/internal/event/animation/animation-impl.cpp | 10 ++--- dali/public-api/actors/actor.cpp | 5 +++ dali/public-api/actors/actor.h | 9 +++++ 6 files changed, 105 insertions(+), 9 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-Actor.cpp b/automated-tests/src/dali/utc-Dali-Actor.cpp index 38dddff..95dc2e6 100644 --- a/automated-tests/src/dali/utc-Dali-Actor.cpp +++ b/automated-tests/src/dali/utc-Dali-Actor.cpp @@ -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( 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(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% diff --git a/dali/internal/event/actors/actor-impl.cpp b/dali/internal/event/actors/actor-impl.cpp index 52c903a..fcb0680 100644 --- a/dali/internal/event/actors/actor-impl.cpp +++ b/dali/internal/event/actors/actor-impl.cpp @@ -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::Send( mStage->GetUpdateManager(), mNode, &mNode->mSize, &AnimatableProperty::Bake, size ); + SceneGraph::NodePropertyMessage::Send( mStage->GetUpdateManager(), mNode, &mNode->mSize, &AnimatableProperty::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 ), diff --git a/dali/internal/event/actors/actor-impl.h b/dali/internal/event/actors/actor-impl.h index 7bee28b..7a16a3a 100644 --- a/dali/internal/event/actors/actor-impl.h +++ b/dali/internal/event/actors/actor-impl.h @@ -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 diff --git a/dali/internal/event/animation/animation-impl.cpp b/dali/internal/event/animation/animation-impl.cpp index 3f680a5..972c00f 100644 --- a/dali/internal/event/animation/animation-impl.cpp +++ b/dali/internal/event/animation/animation-impl.cpp @@ -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() ); + maybeActor->NotifySizeAnimation( *this, destinationValue.Get() ); } } @@ -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::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::New( actor, Dali::Actor::SIZE, diff --git a/dali/public-api/actors/actor.cpp b/dali/public-api/actors/actor.cpp index 284e45b..2ffa4ab 100644 --- a/dali/public-api/actors/actor.cpp +++ b/dali/public-api/actors/actor.cpp @@ -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(); diff --git a/dali/public-api/actors/actor.h b/dali/public-api/actors/actor.h index 631b591..438735a 100644 --- a/dali/public-api/actors/actor.h +++ b/dali/public-api/actors/actor.h @@ -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. */ -- 2.7.4