Add Property::EXTENTS type
[platform/core/uifw/dali-core.git] / dali / internal / event / common / object-impl.cpp
index 92a889f..2396fd1 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.
@@ -457,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 );
     }
@@ -492,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
       {
@@ -552,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)
@@ -562,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
     {
@@ -676,6 +736,7 @@ Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Prop
     case Property::STRING:
     case Property::ARRAY:
     case Property::MAP:
+    case Property::EXTENTS:
     case Property::NONE:
     {
       DALI_ASSERT_ALWAYS( !"PropertyType is not animatable" );
@@ -694,15 +755,15 @@ 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
-    InstallCustomPropertyMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *scenePropertyOwner, newProperty.Release() ); // Message takes ownership
+    InstallCustomPropertyMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *scenePropertyOwner, newProperty ); // Message takes ownership
 
     // notify the derived class (optional) method in case it needs to do some more work on the new property
     // note! have to use the local pointer as OwnerPointer now points to NULL as it handed over its ownership
@@ -864,6 +925,50 @@ void Object::RemovePropertyNotifications()
   }
 }
 
+void Object::NotifyPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType )
+{
+  if ( index < DEFAULT_PROPERTY_MAX_COUNT )
+  {
+    OnNotifyDefaultPropertyAnimation( animation, index, value, animationType );
+  }
+  else
+  {
+    PropertyMetadata* propertyMetadata = NULL;
+    if( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
+    {
+      propertyMetadata = FindAnimatableProperty( index );
+    }
+    else
+    {
+      CustomPropertyMetadata* custom = FindCustomProperty( index );
+      if( custom && custom->IsAnimatable() )
+      {
+        propertyMetadata = custom;
+      }
+    }
+
+    if( propertyMetadata )
+    {
+      switch( animationType )
+      {
+        case Animation::TO:
+        case Animation::BETWEEN:
+        {
+          // Update the cached property value
+          propertyMetadata->SetPropertyValue( value );
+          break;
+        }
+        case Animation::BY:
+        {
+          // Adjust the cached property value
+          propertyMetadata->AdjustPropertyValueBy( value );
+          break;
+        }
+      }
+    }
+  }
+}
+
 void Object::EnablePropertyNotifications()
 {
   if( mPropertyNotifications )
@@ -922,9 +1027,9 @@ void Object::AddUniformMapping( Property::Index propertyIndex, const std::string
 
     if( sceneObject != NULL )
     {
-      SceneGraph::UniformPropertyMapping* map = new SceneGraph::UniformPropertyMapping( uniformName, propertyPtr );
+      OwnerPointer< SceneGraph::UniformPropertyMapping > map = new SceneGraph::UniformPropertyMapping( uniformName, propertyPtr );
       // Message takes ownership of Uniform map (and will delete it after copy)
-      AddUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *sceneObject, map);
+      AddUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *sceneObject, map );
     }
     else
     {
@@ -939,7 +1044,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;
 
@@ -947,7 +1052,7 @@ Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const
 
   if( !entry->IsAnimatable() )
   {
-    value = entry->value;
+    value = entry->GetPropertyValue();
   }
   else
   {
@@ -1362,7 +1467,7 @@ CustomPropertyMetadata* Object::FindCustomProperty( Property::Index index ) cons
     int arrayIndex = index - PROPERTY_CUSTOM_START_INDEX;
     if( arrayIndex >= 0 )
     {
-      if( arrayIndex < (int)mCustomProperties.Count() ) // we can only access the first 2 billion custom properties
+      if( arrayIndex < static_cast<int>( mCustomProperties.Count() ) ) // we can only access the first 2 billion custom properties
       {
         property = static_cast<CustomPropertyMetadata*>(mCustomProperties[ arrayIndex ]);
       }
@@ -1373,7 +1478,8 @@ CustomPropertyMetadata* Object::FindCustomProperty( Property::Index index ) cons
 
 AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index index ) const
 {
-  for ( int arrayIndex = 0; arrayIndex < (int)mAnimatableProperties.Count(); arrayIndex++ )
+  const PropertyMetadataLookup::SizeType count = mAnimatableProperties.Count();
+  for ( PropertyMetadataLookup::SizeType arrayIndex = 0; arrayIndex < count; ++arrayIndex )
   {
     AnimatablePropertyMetadata* property = static_cast<AnimatablePropertyMetadata*>( mAnimatableProperties[ arrayIndex ] );
     if( property->index == index )
@@ -1413,7 +1519,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 );
@@ -1423,7 +1529,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() ) );
         }
       }
 
@@ -1445,7 +1551,8 @@ void Object::ResolveChildProperties()
     if( parentTypeInfo )
     {
       // Go through each custom property
-      for ( int arrayIndex = 0; arrayIndex < (int)mCustomProperties.Count(); arrayIndex++ )
+      const PropertyMetadataLookup::SizeType count = mCustomProperties.Count();
+      for ( PropertyMetadataLookup::SizeType arrayIndex = 0; arrayIndex < count; ++arrayIndex )
       {
         CustomPropertyMetadata* customProperty = static_cast<CustomPropertyMetadata*>( mCustomProperties[ arrayIndex ] );