Ensure cached values of properties animated using AnimateTo are updated
[platform/core/uifw/dali-core.git] / dali / internal / event / common / object-impl.h
index 8b96696..035e7ee 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_OBJECT_H__
 
 /*
- * 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.
  */
 
 // INTERNAL INCLUDES
-#include <dali/public-api/animation/active-constraint.h>
 #include <dali/public-api/animation/constraint.h>
 #include <dali/public-api/common/dali-vector.h>
 #include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/object/base-object.h>
 #include <dali/public-api/object/handle.h>
 #include <dali/public-api/object/property.h>
+#include <dali/public-api/object/property-index-ranges.h>
 #include <dali/public-api/object/property-input.h>
 #include <dali/public-api/object/property-notification.h>
-#include <dali/internal/common/owner-container.h>
+#include <dali/devel-api/common/owner-container.h>
 #include <dali/internal/event/common/event-thread-services.h>
 #include <dali/internal/event/common/property-input-impl.h>
 #include <dali/internal/event/common/property-metadata.h>
@@ -41,7 +41,8 @@ class PropertyNotification;
 
 namespace Internal
 {
-class Constraint;
+class Animation;
+class ConstraintBase;
 class EventThreadServices;
 class Handle;
 class PropertyCondition;
@@ -55,9 +56,9 @@ class PropertyBase;
 class PropertyOwner;
 }
 
-typedef std::vector< Dali::ActiveConstraint >     ActiveConstraintContainer;
-typedef ActiveConstraintContainer::iterator       ActiveConstraintIter;
-typedef ActiveConstraintContainer::const_iterator ActiveConstraintConstIter;
+typedef std::vector< Dali::Constraint >     ConstraintContainer;
+typedef ConstraintContainer::iterator       ConstraintIter;
+typedef ConstraintContainer::const_iterator ConstraintConstIter;
 
 
 /**
@@ -151,6 +152,16 @@ public:
   virtual Property::Index GetPropertyIndex( const std::string& name ) const;
 
   /**
+   * @copydoc Dali::Handle::GetPropertyIndex()
+   */
+  virtual Property::Index GetPropertyIndex( Property::Index key ) const;
+
+  /**
+   * @copydoc Dali::Handle::GetPropertyIndex()
+   */
+  virtual Property::Index GetPropertyIndex( Property::Key key ) const;
+
+  /**
    * @copydoc Dali::Handle::IsPropertyWritable()
    */
   virtual bool IsPropertyWritable( Property::Index index ) const;
@@ -181,6 +192,13 @@ public:
   virtual Property::Value GetProperty( Property::Index index ) const;
 
   /**
+   * @brief Retrieves the latest value of the property on the scene-graph.
+   * @param[in]  index  The index of the property required.
+   * @return The latest value of the property on the scene-graph.
+   */
+  virtual Property::Value GetCurrentProperty( Property::Index index ) const;
+
+  /**
    * @copydoc Dali::Handle::GetPropertyIndices()
    */
   virtual void GetPropertyIndices( Property::IndexContainer& indices ) const;
@@ -191,11 +209,21 @@ public:
   virtual Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue );
 
   /**
+   * @copydoc Dali::Handle::RegisterProperty()
+   */
+  virtual Property::Index RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue );
+
+  /**
    * @copydoc Dali::Handle::RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode)
    */
   virtual Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );
 
   /**
+   * @brief Implementing method for this override
+   */
+  virtual Property::Index RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue, Property::AccessMode accessMode );
+
+  /**
    * @copydoc Dali::Handle::AddPropertyNotification()
    */
   virtual Dali::PropertyNotification AddPropertyNotification( Property::Index index,
@@ -212,12 +240,20 @@ public:
    */
   virtual void RemovePropertyNotifications();
 
+  /**
+   * Notifies that a property is being animated.
+   * @param[in] animation The animation animating the property.
+   * @param[in] index The index of the property.
+   * @param[in] value The value of the property after the animation.
+   */
+  void NotifyPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value );
+
   /******************************** Uniform Mappings ********************************/
 
   /**
    * @copydoc Dali::Handle::AddUniformMapping()
    */
-  void AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName );
+  void AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const;
 
   /**
    * @copydoc Dali::Handle::RemoveUniformMapping( )
@@ -227,23 +263,16 @@ public:
   /******************************** Constraints ********************************/
 
   /**
-   * Apply a constraint to a Object.
+   * Apply a constraint to an Object.
    * @param[in] constraint The constraint to apply.
    */
-  Dali::ActiveConstraint ApplyConstraint( Constraint& constraint );
+  void ApplyConstraint( ConstraintBase& constraint );
 
   /**
-   * Apply a constraint to a Object.
-   * @param[in] constraint The constraint to apply.
-   * @param[in] weightObject An object with a "weight" float property.
+   * Remove one constraint from an Object.
+   * @param[in] constraint The constraint to remove.
    */
-  Dali::ActiveConstraint ApplyConstraint( Constraint& constraint, Dali::Handle weightObject );
-
-  /**
-   * Remove one constraint from a Object.
-   * @param[in] activeConstraint The active constraint to remove.
-   */
-  void RemoveConstraint( Dali::ActiveConstraint activeConstraint );
+  void RemoveConstraint( ConstraintBase& constraint );
 
   /**
    * Remove all constraints from a Object.
@@ -319,8 +348,17 @@ protected:
   void OnSceneObjectRemove();
 
   /**
+   * For overriding by derived classes to return the parent of this object.
+   */
+  virtual Object* GetParentObject() const
+  {
+    // By default the Object does not have a parent
+    return NULL;
+  };
+
+  /**
    * For use in derived classes.
-   * This is called after a non animatable custom property is set.
+   * This is called after a property is set.
    * @param [in] index The index of the property.
    * @param [in] propertyValue The value of the property.
    */
@@ -347,6 +385,28 @@ protected:
    */
   AnimatablePropertyMetadata* FindAnimatableProperty( Property::Index index ) const;
 
+  /**
+   * Helper to register a scene-graph property
+   * @param [in] name The name of the property.
+   * @param [in] key The key of the property
+   * @param [in] index The index of the property
+   * @param [in] value The value of the property.
+   * @return The index of the registered property or Property::INVALID_INDEX if registration failed.
+   */
+  Property::Index RegisterSceneGraphProperty(const std::string& name, Property::Index key, Property::Index index, const Property::Value& propertyValue) const;
+
+  /**
+   * Check whether the animatable property is registered already, if not then register one.
+   * @param [in] index The index of the property
+   * @return pointer to the property.
+   */
+  AnimatablePropertyMetadata* RegisterAnimatableProperty(Property::Index index) const;
+
+  /**
+   * Resolve the index and name of child properties if any.
+   */
+  void ResolveChildProperties();
+
 private: // Default property extensions for derived classes
 
   /**
@@ -421,6 +481,22 @@ private: // Default property extensions for derived classes
   virtual Property::Value GetDefaultProperty( Property::Index index ) const = 0;
 
   /**
+   * Retrieve the latest scene-graph value of a default property.
+   * @param[in] index The index of the property.
+   * @return The latest scene-graph value of a default property.
+   */
+  virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const = 0;
+
+  /**
+   * Notifies that a default property is being animated so the deriving class should update the cached value.
+   * @param[in] animation The animation animating the property.
+   * @param[in] index The index of the property.
+   * @param[in] value The value of the property after the animation.
+   */
+  virtual void OnNotifyDefaultPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value )
+  { }
+
+  /**
    * @todo this is virtual so that for now actor can override it,
    * it needs to be removed and only have GetSceneObject but that requires changing actor and constraint logic
    * Retrieve the scene-graph object added by this object.
@@ -460,24 +536,11 @@ private:
   void DisablePropertyNotifications();
 
   /**
-   * Helper for ApplyConstraint overloads.
-   * @param[in] constraint The constraint to apply.
-   * @param[in] weightObject An object with a "weight" float property, or an empty handle.
-   * @return The new active-constraint which is owned by Object.
-   */
-  ActiveConstraintBase* DoApplyConstraint( Constraint& constraint, Dali::Handle weightObject );
-
-  /**
-   * Helper to remove active constraints
-   */
-  void RemoveConstraint( ActiveConstraint& constraint, bool isInScenegraph );
-
-  /**
-   * Get the value of the property.
-   * @param [in] entry An entry from the property lookup container.
-   * @return The new value of the property.
+   * Get the latest value of the property on the scene-graph.
+   * @param[in] entry An entry from the property lookup container.
+   * @return The latest value of the property.
    */
-  Property::Value GetPropertyValue( const PropertyMetadata* entry ) const;
+  Property::Value GetCurrentPropertyValue( const PropertyMetadata* entry ) const;
 
   /**
    * Set the value of scene graph property.
@@ -487,15 +550,6 @@ private:
    */
   virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
 
-  /**
-   * Helper to register a scene-graph property
-   * @param [in] name The name of the property.
-   * @param [in] index The index of the property
-   * @param [in] value The value of the property.
-   * @return The index of the registered property or Property::INVALID_INDEX if registration failed.
-   */
-  Property::Index RegisterSceneGraphProperty(const std::string& name, Property::Index index, const Property::Value& propertyValue) const;
-
 protected:
   /**
    * Get the event thread services object - used for sending messages to the scene graph
@@ -535,7 +589,7 @@ private:
 
   Dali::Vector<Observer*> mObservers;
 
-  ActiveConstraintContainer* mConstraints;               ///< Container of owned active-constraints.
+  ConstraintContainer* mConstraints;               ///< Container of owned -constraints.
 
   typedef std::vector< Dali::PropertyNotification >     PropertyNotificationContainer;
   typedef PropertyNotificationContainer::iterator       PropertyNotificationContainerIter;