(Animation) Ensure AnimateBetween updates the cached event-side properties 72/130272/5
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Sat, 20 May 2017 03:08:52 +0000 (04:08 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 26 May 2017 11:25:10 +0000 (12:25 +0100)
Change-Id: I8d83611eebf8e9bdca7dd9390a207924706eeb97

automated-tests/src/dali/utc-Dali-Animation.cpp
dali/internal/event/animation/animation-impl.cpp
dali/internal/event/animation/key-frames-impl.cpp
dali/internal/event/animation/key-frames-impl.h

index e91881e..5b56b88 100644 (file)
@@ -8791,6 +8791,9 @@ int UtcDaliAnimationAnimateBetweenActorColorAlphaP(void)
   // Start the animation
   animation.Play();
 
+  // Final key frame value should be retrievable straight away
+  DALI_TEST_EQUALS( actor.GetProperty< float >( Actor::Property::COLOR_ALPHA ), 0.9f, TEST_LOCATION );
+
   bool signalReceived(false);
   AnimationFinishCheck finishCheck(signalReceived);
   animation.FinishedSignal().Connect(&application, finishCheck);
@@ -9141,6 +9144,9 @@ int UtcDaliAnimationAnimateBetweenActorVisibleP(void)
   // Start the animation
   animation.Play();
 
+  // Final key frame value should be retrievable straight away
+  DALI_TEST_EQUALS( actor.GetProperty< bool >( Actor::Property::VISIBLE ), true, TEST_LOCATION );
+
   bool signalReceived(false);
   AnimationFinishCheck finishCheck(signalReceived);
   animation.FinishedSignal().Connect(&application, finishCheck);
@@ -9228,6 +9234,9 @@ int UtcDaliAnimationAnimateBetweenActorOrientation01P(void)
   // Start the animation
   animation.Play();
 
+  // Final key frame value should be retrievable straight away
+  DALI_TEST_EQUALS( actor.GetProperty< Quaternion >( Actor::Property::ORIENTATION ), Quaternion( Degree( 60 ), Vector3::ZAXIS ), TEST_LOCATION );
+
   bool signalReceived(false);
   AnimationFinishCheck finishCheck(signalReceived);
   animation.FinishedSignal().Connect(&application, finishCheck);
@@ -11122,3 +11131,77 @@ int UtcDaliAnimationTimePeriodOrderSeveralAnimateToCalls(void)
 
   END_TEST;
 }
+
+int UtcDaliAnimationAnimateBetweenIntegerP(void)
+{
+  TestApplication application;
+
+  int startValue(1);
+  Actor actor = Actor::New();
+  const Property::Index index = actor.RegisterProperty("customProperty", startValue );
+  Stage::GetCurrent().Add(actor);
+
+  application.Render();
+  application.SendNotification();
+
+  DALI_TEST_EQUALS( actor.GetProperty< int >( index ), startValue, TEST_LOCATION );
+
+  // Build the animation
+  float durationSeconds(1.0f);
+  Animation animation = Animation::New(durationSeconds);
+
+  KeyFrames keyFrames = KeyFrames::New();
+  keyFrames.Add(0.0f, 10);
+  keyFrames.Add(0.2f, 20);
+  keyFrames.Add(0.4f, 30);
+  keyFrames.Add(0.6f, 40);
+  keyFrames.Add(0.8f, 50);
+  keyFrames.Add(1.0f, 60);
+
+  animation.AnimateBetween( Property(actor, index ), keyFrames );
+
+  // Start the animation
+  animation.Play();
+
+  // Target value should change to the last key-frame's value straight away
+  DALI_TEST_EQUALS( actor.GetProperty< int >( index ), 60, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliAnimationAnimateBetweenVector2P(void)
+{
+  TestApplication application;
+
+  Vector2 startValue( 10.0f, 20.0f );
+  Actor actor = Actor::New();
+  const Property::Index index = actor.RegisterProperty("customProperty", startValue );
+  Stage::GetCurrent().Add(actor);
+
+  application.Render();
+  application.SendNotification();
+
+  DALI_TEST_EQUALS( actor.GetProperty< Vector2 >( index ), startValue, TEST_LOCATION );
+
+  // Build the animation
+  float durationSeconds(1.0f);
+  Animation animation = Animation::New(durationSeconds);
+
+  KeyFrames keyFrames = KeyFrames::New();
+  keyFrames.Add( 0.0f, Vector2( 0.0f, 5.0f ) );
+  keyFrames.Add( 0.2f, Vector2( 30.0f, 25.0f ) );
+  keyFrames.Add( 0.4f, Vector2( 40.0f, 35.0f ) );
+  keyFrames.Add( 0.6f, Vector2( 50.0f, 45.0f ) );
+  keyFrames.Add( 0.8f, Vector2( 60.0f, 55.0f ) );
+  keyFrames.Add( 1.0f, Vector2( 70.0f, 65.0f ) );
+
+  animation.AnimateBetween( Property(actor, index ), keyFrames );
+
+  // Start the animation
+  animation.Play();
+
+  // Target value should change to the last key-frame's value straight away
+  DALI_TEST_EQUALS( actor.GetProperty< Vector2 >( index ), Vector2( 70.0f, 65.0f ), TEST_LOCATION );
+
+  END_TEST;
+}
index bb2b50c..83837ea 100644 (file)
@@ -649,6 +649,14 @@ void Animation::AnimateBetween(Property target, const KeyFrames& keyFrames, Alph
 
   ExtendDuration( period );
 
+  // Store data to later notify the object that its property is being animated
+  ConnectorTargetValues connectorPair;
+  connectorPair.targetValue = keyFrames.GetLastKeyFrameValue();
+  connectorPair.connectorIndex = mConnectors.Count();
+  connectorPair.timePeriod = period;
+  connectorPair.animatorType = BETWEEN;
+  mConnectorTargetValues.push_back( connectorPair );
+
   switch(keyFrames.GetType())
   {
     case Dali::Property::BOOLEAN:
index 031495e..a111c17 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -160,5 +160,18 @@ KeyFrameSpec* KeyFrames::GetKeyFramesBase() const
   return mKeyFrames.Get();
 }
 
+Property::Value KeyFrames::GetLastKeyFrameValue() const
+{
+  Property::Value value;
+
+  unsigned int noOfKeyFrames = mKeyFrames->GetNumberOfKeyFrames();
+  if( noOfKeyFrames )
+  {
+    mKeyFrames->GetKeyFrameAsValue( noOfKeyFrames - 1, value );
+  }
+
+  return value;
+}
+
 } // Internal
 } // Dali
index 433d2bc..7146a2a 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_KEY_FRAMES_H__
 
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -95,6 +95,11 @@ public:
    */
   KeyFrameSpec* GetKeyFramesBase() const;
 
+  /**
+   * Return the value of the last key frame.
+   */
+  Dali::Property::Value GetLastKeyFrameValue() const;
+
 private:
   Dali::Property::Type mType; // Type of the specialization
   IntrusivePtr<KeyFrameSpec> mKeyFrames;   // Pointer to the specialized key frame object
@@ -116,6 +121,13 @@ public:
 
   virtual unsigned int GetNumberOfKeyFrames() const = 0;
 
+  /**
+   * Get the key frame value as a Property::Value.
+   * @param[in] index The index of the key frame to fetch
+   * @param[out] value The value of the given key frame
+   */
+  virtual void GetKeyFrameAsValue( unsigned int index, Property::Value& value ) = 0;
+
 protected:
 
   /**
@@ -227,6 +239,14 @@ public:
   }
 
   /**
+   * @copydoc KeyFrameSpec::GetKeyFrameAsValue()
+   */
+  virtual void GetKeyFrameAsValue( unsigned int index, Property::Value& value )
+  {
+    value = mPVs[index].mValue;
+  }
+
+  /**
    * Return whether the progress is valid for the range of keyframes. (The first
    * keyframe doesn't have to start at 0, and the last doesn't have to end at 1.0)
    * @param[in] progress The progress to test