Share a single weight property between constraints
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / active-constraint-base.cpp
index 65a71aa..ca99221 100644 (file)
@@ -78,10 +78,12 @@ ActiveConstraintBase::ActiveConstraintBase( EventToUpdate& eventToUpdate, Proper
   mTargetPropertyIndex( targetPropertyIndex ),
   mTargetProxy( NULL ),
   mSceneGraphConstraint( NULL ),
+  mCustomWeight( NULL ),
   mOffstageWeight( Dali::ActiveConstraint::DEFAULT_WEIGHT ),
   mRemoveTime( 0.0f ),
   mAlphaFunction( Dali::Constraint::DEFAULT_ALPHA_FUNCTION ),
   mRemoveAction( Dali::Constraint::DEFAULT_REMOVE_ACTION ),
+  mTag(0),
   mApplyAnimation(),
   mRemoveAnimation()
 {
@@ -102,7 +104,20 @@ ActiveConstraintBase::~ActiveConstraintBase()
   }
 }
 
-void ActiveConstraintBase::FirstApply( ProxyObject& parent, TimePeriod applyTime, ActiveConstraintCallbackType* callback )
+void ActiveConstraintBase::SetCustomWeightObject( ProxyObject& weightObject, Property::Index weightIndex )
+{
+  const SceneGraph::PropertyBase* base = weightObject.GetSceneObjectAnimatableProperty( weightIndex );
+  const SceneGraph::AnimatableProperty<float>* sceneProperty = dynamic_cast< const SceneGraph::AnimatableProperty<float>* >( base );
+
+  if( sceneProperty )
+  {
+    mCustomWeight = sceneProperty;
+
+    OnCustomWeightSet( weightObject );
+  }
+}
+
+void ActiveConstraintBase::FirstApply( ProxyObject& parent, TimePeriod applyTime )
 {
   // Notify derived classes
   OnFirstApply( parent );
@@ -263,6 +278,17 @@ ActiveConstraintBase::RemoveAction ActiveConstraintBase::GetRemoveAction() const
   return mRemoveAction;
 }
 
+void ActiveConstraintBase::SetTag(const unsigned int tag)
+{
+  mTag = tag;
+}
+
+unsigned int ActiveConstraintBase::GetTag() const
+{
+  return mTag;
+}
+
+
 bool ActiveConstraintBase::IsSceneObjectRemovable() const
 {
   return true; // The constraint removed when target SceneGraph::PropertyOwner is destroyed
@@ -273,10 +299,28 @@ unsigned int ActiveConstraintBase::GetDefaultPropertyCount() const
   return DEFAULT_PROPERTY_COUNT;
 }
 
+void ActiveConstraintBase::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
+{
+  indices.reserve( DEFAULT_PROPERTY_COUNT );
+
+  for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
+  {
+    indices.push_back( i );
+  }
+}
+
 const std::string& ActiveConstraintBase::GetDefaultPropertyName( Property::Index index ) const
 {
-  // ProxyObject guarantees that index is within range
-  return DEFAULT_PROPERTY_NAMES[index];
+  if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
+  {
+    return DEFAULT_PROPERTY_NAMES[index];
+  }
+  else
+  {
+    // index out of range..return empty string
+    static const std::string INVALID_PROPERTY_NAME;
+    return INVALID_PROPERTY_NAME;
+  }
 }
 
 Property::Index ActiveConstraintBase::GetDefaultPropertyIndex( const std::string& name ) const
@@ -302,15 +346,26 @@ bool ActiveConstraintBase::IsDefaultPropertyAnimatable( Property::Index index )
   return true; // All default properties are currently animatable
 }
 
+bool ActiveConstraintBase::IsDefaultPropertyAConstraintInput( Property::Index index ) const
+{
+  return true; // All default properties can currently be used as a constraint input
+}
+
 Property::Type ActiveConstraintBase::GetDefaultPropertyType( Property::Index index ) const
 {
-  // ProxyObject guarantees that index is within range
-  return DEFAULT_PROPERTY_TYPES[index];
+  if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
+  {
+    return DEFAULT_PROPERTY_TYPES[index];
+  }
+  else
+  {
+    // Index out-of-range
+    return Property::NONE;
+  }
 }
 
 void ActiveConstraintBase::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
 {
-  // ProxyObject guarantees the property is writable and index is in range
   switch ( index )
   {
     case Dali::ActiveConstraint::WEIGHT:
@@ -336,7 +391,6 @@ Property::Value ActiveConstraintBase::GetDefaultProperty( Property::Index index
 {
   Property::Value value;
 
-  // ProxyObject guarantees that index is within range
   switch ( index )
   {
     case Dali::ActiveConstraint::WEIGHT: