use modern construct 'override' in the derive class.
[platform/core/uifw/dali-core.git] / dali / internal / update / animation / scene-graph-constraint.h
index 4866d6a..ef32672 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H__
+#ifndef DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H
+#define DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
  *
  */
 
-// EXTERNAL INCLUDES
-#include <boost/function.hpp>
-
 // INTERNAL INCLUDES
-#include <dali/public-api/animation/active-constraint.h>
-#include <dali/public-api/animation/alpha-functions.h>
 #include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/signals/callback.h>
 #include <dali/internal/event/animation/property-constraint-ptr.h>
 #include <dali/internal/update/common/animatable-property.h>
 #include <dali/internal/update/common/property-owner.h>
@@ -49,23 +45,20 @@ class Constraint : public ConstraintBase
 {
 public:
 
-  typedef typename PropertyConstraintPtr< PropertyType >::Type ConstraintFunctionPtr;
-  typedef boost::function< PropertyType (const PropertyType&, const PropertyType&, float progress) > InterpolatorFunc;
+  using ConstraintFunctionPtr = typename PropertyConstraintPtr< PropertyType >::Type;
 
   /**
    * Create a new scene-graph constraint.
    * @param[in] targetProperty The target property.
    * @param[in] ownerSet A set of property owners; func is connected to the properties provided by these objects.
    * @param[in] func The function to calculate the final constrained value.
-   * @param[in] interpolator The function to interpolate between start & final value.
-   * @param[in] customWeight A custom weight property, or NULL if the constraint is using its own.
+   * @param[in] removeAction Remove action to perform when constraint is removed
    * @return A smart-pointer to a newly allocated constraint.
    */
   static ConstraintBase* New( const PropertyBase& targetProperty,
                               PropertyOwnerContainer& ownerContainer,
                               ConstraintFunctionPtr func,
-                              InterpolatorFunc interpolator,
-                              const AnimatableProperty<float>* customWeight )
+                              RemoveAction removeAction )
   {
     // Scene-graph thread can edit these objects
     PropertyBase& property = const_cast< PropertyBase& >( targetProperty );
@@ -73,83 +66,44 @@ public:
     return new Constraint< PropertyType, PropertyAccessorType >( property,
                                                                  ownerContainer,
                                                                  func,
-                                                                 interpolator,
-                                                                 customWeight );
+                                                                 removeAction );
   }
 
   /**
    * Virtual destructor.
    */
-  virtual ~Constraint()
-  {
-  }
-
-  /**
-   * Query whether the constraint needs to be applied. If a constraint depends on a set of properties,
-   * then it should be applied when any of those properties have changed.
-   */
-  bool ApplyNeeded()
+  ~Constraint() override
   {
-    if ( mFirstApply )
-    {
-      mFirstApply = false;
-      return true;
-    }
-
-    if ( ! mTargetProperty.IsClean() ||
-           mFunc->InputsChanged()    ||
-         ! mWeightInput->IsClean() )
-    {
-      return true;
-    }
-
-    // We don't need to reapply constraint if none of the properties changed
-    return false;
   }
 
   /**
    * @copydoc Dali::Internal::SceneGraph::ConstraintBase::Apply()
    */
-  virtual void Apply( BufferIndex updateBufferIndex )
+  void Apply( BufferIndex updateBufferIndex ) override
   {
-    if ( mDisconnected )
-    {
-      return; // Early-out when property owners have been disconnected
-    }
-
-    bool firstApply( mFirstApply );
-
-    if ( mFunc->InputsInitialized() &&
-         ApplyNeeded() )
+    if ( !mDisconnected )
     {
-      const PropertyType& current = mTargetProperty.Get( updateBufferIndex );
-
-      // FINAL_WEIGHT means the constraint is fully-applied, unless weight is still being animated
-      if ( ( ! firstApply && ! mWeightInput->IsClean() ) || // We should not rely on the flag state of weight-input on first apply
-           ! Equals( Dali::ActiveConstraint::FINAL_WEIGHT, (*mWeightInput)[updateBufferIndex] ) )
-      {
-        // Constraint is not fully-applied; interpolation between start & final values
-        mTargetProperty.Set( updateBufferIndex,
-                             mInterpolator( current, mFunc->Apply( updateBufferIndex, current ), (*mWeightInput)[updateBufferIndex] ) );
-      }
-      else
+      if ( mFunc->InputsInitialized() )
       {
-        // Constraint is fully-applied; optionally bake the final value
-        if ( Dali::Constraint::Bake == mRemoveAction )
+        PropertyType current = mTargetProperty.Get( updateBufferIndex );
+        mFunc->Apply( updateBufferIndex, current );
+
+        // Optionally bake the final value
+        if ( Dali::Constraint::BAKE == mRemoveAction )
         {
-          mTargetProperty.Bake( updateBufferIndex, mFunc->Apply( updateBufferIndex, current ) );
+          mTargetProperty.Bake( updateBufferIndex, current );
         }
         else
         {
-          mTargetProperty.Set( updateBufferIndex, mFunc->Apply( updateBufferIndex, current ) );
+          mTargetProperty.Set( updateBufferIndex, current );
         }
-      }
 
-      INCREASE_COUNTER(PerformanceMonitor::CONSTRAINTS_APPLIED);
-    }
-    else
-    {
-      INCREASE_COUNTER(PerformanceMonitor::CONSTRAINTS_SKIPPED);
+        INCREASE_COUNTER(PerformanceMonitor::CONSTRAINTS_APPLIED);
+      }
+      else
+      {
+        INCREASE_COUNTER(PerformanceMonitor::CONSTRAINTS_SKIPPED);
+      }
     }
   }
 
@@ -161,30 +115,26 @@ private:
   Constraint( PropertyBase& targetProperty,
               PropertyOwnerContainer& ownerContainer,
               ConstraintFunctionPtr func,
-              InterpolatorFunc interpolator,
-              const AnimatableProperty<float>* customWeight )
-  : ConstraintBase( ownerContainer ),
+              RemoveAction removeAction )
+  : ConstraintBase( ownerContainer, removeAction ),
     mTargetProperty( &targetProperty ),
-    mFunc( func ),
-    mInterpolator( interpolator ),
-    mWeightInput( customWeight ? customWeight : &mWeight)
+    mFunc( func )
   {
   }
 
   // Undefined
-  Constraint( const Constraint& constraint );
-
-  // Undefined
-  Constraint& operator=( const Constraint& rhs );
+  Constraint() = delete;
+  Constraint( const Constraint& constraint ) = delete;
+  Constraint& operator=( const Constraint& rhs ) = delete;
 
   /**
    * @copydoc Dali::Internal::SceneGraph::ConstraintBase::OnDisconnect()
    */
-  virtual void OnDisconnect()
+  void OnDisconnect() override
   {
     // Discard target object/property pointers
     mTargetProperty.Reset();
-    mFunc = NULL;
+    mFunc = nullptr;
   }
 
 protected:
@@ -193,9 +143,6 @@ protected:
 
   ConstraintFunctionPtr mFunc;
 
-  InterpolatorFunc mInterpolator;
-
-  const AnimatableProperty<float>* mWeightInput;
 };
 
 } // namespace SceneGraph
@@ -204,4 +151,4 @@ protected:
 
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H__
+#endif // DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H