Ensure cached values of properties animated using AnimateTo are updated
[platform/core/uifw/dali-core.git] / dali / internal / event / common / object-impl.cpp
index 14a5008..344e72c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -273,6 +273,20 @@ Property::Index Object::GetPropertyIndex( Property::Index key ) const
   return index;
 }
 
+Property::Index Object::GetPropertyIndex( Property::Key key ) const
+{
+  Property::Index index = Property::INVALID_INDEX;
+  if( key.type == Property::Key::INDEX )
+  {
+    index = GetPropertyIndex( key.indexKey );
+  }
+  else
+  {
+    index = GetPropertyIndex( key.stringKey );
+  }
+  return index;
+}
+
 bool Object::IsPropertyWritable( Property::Index index ) const
 {
   DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
@@ -443,6 +457,9 @@ void Object::SetProperty( Property::Index index, const Property::Value& property
     }
     else
     {
+      // update the cached property value
+      animatableProperty->SetPropertyValue( propertyValue );
+
       // set the scene graph property value
       SetSceneGraphProperty( index, *animatableProperty, propertyValue );
     }
@@ -478,12 +495,16 @@ void Object::SetProperty( Property::Index index, const Property::Value& property
     {
       if( custom->IsAnimatable() )
       {
+        // update the cached property value
+        custom->SetPropertyValue( propertyValue );
+
         // set the scene graph property value
         SetSceneGraphProperty( index, *custom, propertyValue );
       }
       else if( custom->IsWritable() )
       {
-        custom->value = propertyValue;
+        // update the cached property value
+        custom->SetPropertyValue( propertyValue );
       }
       else
       {
@@ -538,8 +559,61 @@ Property::Value Object::GetProperty(Property::Index index) const
     }
     else
     {
+      // get the cached animatable property value
+      value = animatableProperty->GetPropertyValue();
+    }
+  }
+  else if(mCustomProperties.Count() > 0)
+  {
+    CustomPropertyMetadata* custom = FindCustomProperty( index );
+    if(custom)
+    {
+      // get the cached custom property value
+      value = custom->GetPropertyValue();
+    }
+    else
+    {
+      DALI_LOG_ERROR("Invalid property index\n");
+    }
+  } // if custom
+
+  return value;
+}
+
+Property::Value Object::GetCurrentProperty( Property::Index index ) const
+{
+  DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index is out of bounds" );
+
+  Property::Value value;
+
+  if ( index < DEFAULT_PROPERTY_MAX_COUNT )
+  {
+    value = GetDefaultPropertyCurrentValue( index );
+  }
+  else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
+  {
+    const TypeInfo* typeInfo( GetTypeInfo() );
+    if ( typeInfo )
+    {
+      value = typeInfo->GetProperty( this, index );
+    }
+    else
+    {
+      DALI_LOG_ERROR("Cannot find property index\n");
+    }
+  }
+  else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
+  {
+    // check whether the animatable property is registered already, if not then register one.
+    AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index );
+    if(!animatableProperty)
+    {
+      DALI_LOG_ERROR("Cannot find property index\n");
+    }
+    else
+    {
       // get the animatable property value
-      value = GetPropertyValue( animatableProperty );
+      value = GetCurrentPropertyValue( animatableProperty );
     }
   }
   else if(mCustomProperties.Count() > 0)
@@ -548,7 +622,7 @@ Property::Value Object::GetProperty(Property::Index index) const
     if(custom)
     {
       // get the custom property value
-      value = GetPropertyValue( custom );
+      value = GetCurrentPropertyValue( custom );
     }
     else
     {
@@ -680,11 +754,11 @@ Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Prop
     {
       DALI_ASSERT_ALWAYS( index <= PROPERTY_CUSTOM_MAX_INDEX && "Too many custom properties have been registered" );
 
-      mCustomProperties.PushBack( new CustomPropertyMetadata( name, key, propertyValue.GetType(), property ) );
+      mCustomProperties.PushBack( new CustomPropertyMetadata( name, key, propertyValue, property ) );
     }
     else
     {
-      mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, Property::INVALID_COMPONENT_INDEX, propertyValue.GetType(), property ) ); // base property
+      mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, propertyValue, property ) );
     }
 
     // queue a message to add the property
@@ -782,7 +856,7 @@ Dali::PropertyNotification Object::AddPropertyNotification(Property::Index index
   {
     if ( index <= PROPERTY_REGISTRATION_MAX_INDEX )
     {
-      DALI_ASSERT_ALWAYS( false && "Property notification added to event side only property." );
+      DALI_ABORT( "Property notification added to event side only property." );
     }
     else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
     {
@@ -850,6 +924,32 @@ void Object::RemovePropertyNotifications()
   }
 }
 
+void Object::NotifyPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value )
+{
+  if ( index < DEFAULT_PROPERTY_MAX_COUNT )
+  {
+    OnNotifyDefaultPropertyAnimation( animation, index, value );
+  }
+  else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
+  {
+    AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index );
+    if( animatableProperty )
+    {
+      // update the cached property value
+      animatableProperty->SetPropertyValue( value );
+    }
+  }
+  else
+  {
+    CustomPropertyMetadata* custom = FindCustomProperty( index );
+    if( custom && custom->IsAnimatable() )
+    {
+      // update the cached property value
+      custom->SetPropertyValue( value );
+    }
+  }
+}
+
 void Object::EnablePropertyNotifications()
 {
   if( mPropertyNotifications )
@@ -925,7 +1025,7 @@ void Object::RemoveUniformMapping( const std::string& uniformName )
   RemoveUniformMapMessage( GetEventThreadServices(), *sceneObject, uniformName);
 }
 
-Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const
+Property::Value Object::GetCurrentPropertyValue( const PropertyMetadata* entry ) const
 {
   Property::Value value;
 
@@ -933,7 +1033,7 @@ Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const
 
   if( !entry->IsAnimatable() )
   {
-    value = entry->value;
+    value = entry->GetPropertyValue();
   }
   else
   {
@@ -1069,8 +1169,7 @@ Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const
 
       default:
       {
-        DALI_ASSERT_ALWAYS( false && "PropertyType enumeration is out of bounds" );
-        break;
+        // unreachable code due to higher level logic
       }
     } // switch(type)
   } // if animatable
@@ -1400,7 +1499,7 @@ AnimatablePropertyMetadata* Object::RegisterAnimatableProperty(Property::Index i
           // If the base property is not registered yet, register the base property first.
           const  std::string& basePropertyName = typeInfo->GetPropertyName(basePropertyIndex);
 
-          if( Property::INVALID_INDEX != RegisterSceneGraphProperty( basePropertyName, Property::INVALID_KEY, basePropertyIndex, Property::Value(typeInfo->GetPropertyType( basePropertyIndex ) ) ) )
+          if( Property::INVALID_INDEX != RegisterSceneGraphProperty( basePropertyName, Property::INVALID_KEY, basePropertyIndex, typeInfo->GetPropertyDefaultValue( basePropertyIndex ) ) )
           {
             animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
             AddUniformMapping( basePropertyIndex, basePropertyName );
@@ -1410,7 +1509,7 @@ AnimatablePropertyMetadata* Object::RegisterAnimatableProperty(Property::Index i
         if(animatableProperty)
         {
           // Create the metadata for the property component.
-          mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, typeInfo->GetComponentIndex(index), animatableProperty->GetType(), animatableProperty->GetSceneGraphProperty() ) );
+          mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, typeInfo->GetComponentIndex(index), animatableProperty->value, animatableProperty->GetSceneGraphProperty() ) );
         }
       }