Add Property::EXTENTS type
[platform/core/uifw/dali-core.git] / dali / internal / event / common / property-metadata.cpp
index abbe62e..c77a570 100644 (file)
@@ -19,6 +19,7 @@
 #include <dali/internal/event/common/property-metadata.h>
 
 // INTERNAL INCLUDES
+#include <dali/public-api/math/quaternion.h>
 #include <dali/public-api/math/vector2.h>
 #include <dali/public-api/math/vector3.h>
 #include <dali/public-api/math/vector4.h>
@@ -30,6 +31,23 @@ namespace Dali
 namespace Internal
 {
 
+namespace
+{
+
+/// Helper to adjust the property value by an amount specified in another property-value
+template < typename PropertyType >
+inline void AdjustProperty( Property::Value& currentPropertyValue, const Property::Value& relativePropertyValue )
+{
+  PropertyType currentValue;
+  PropertyType relativeValue;
+  if( currentPropertyValue.Get( currentValue ) && relativePropertyValue.Get( relativeValue ) )
+  {
+    currentPropertyValue = currentValue + relativeValue;
+  }
+}
+
+} // unnamed namespace
+
 void PropertyMetadata::SetPropertyValue( const Property::Value& propertyValue )
 {
   switch ( GetType() )
@@ -39,6 +57,7 @@ void PropertyMetadata::SetPropertyValue( const Property::Value& propertyValue )
     case Property::STRING:
     case Property::ARRAY:
     case Property::MAP:
+    case Property::EXTENTS:
     case Property::BOOLEAN:
     case Property::INTEGER:
     case Property::FLOAT:
@@ -147,6 +166,7 @@ Property::Value PropertyMetadata::GetPropertyValue() const
       case Property::STRING:
       case Property::ARRAY:
       case Property::MAP:
+      case Property::EXTENTS:
       case Property::BOOLEAN:
       case Property::INTEGER:
       case Property::FLOAT:
@@ -235,6 +255,147 @@ Property::Value PropertyMetadata::GetPropertyValue() const
   return propertyValue;
 }
 
+void PropertyMetadata::AdjustPropertyValueBy( const Property::Value& relativePropertyValue )
+{
+  switch ( GetType() )
+  {
+    case Property::NONE:
+    case Property::RECTANGLE:
+    case Property::STRING:
+    case Property::ARRAY:
+    case Property::MAP:
+    case Property::EXTENTS:
+    case Property::MATRIX:
+    case Property::MATRIX3:
+    {
+      // Not animated
+      break;
+    }
+
+    case Property::BOOLEAN:
+    {
+      bool currentValue = false;
+      bool relativeValue = false;
+      if( value.Get( currentValue ) && relativePropertyValue.Get( relativeValue ) )
+      {
+        value = currentValue || relativeValue;
+      }
+      break;
+    }
+
+    case Property::INTEGER:
+    {
+      AdjustProperty< int >( value, relativePropertyValue );
+      break;
+    }
+
+    case Property::FLOAT:
+    {
+      AdjustProperty< float >( value, relativePropertyValue );
+      break;
+    }
+
+    case Property::ROTATION:
+    {
+      Quaternion currentValue;
+      Quaternion relativeValue;
+      if( value.Get( currentValue ) && relativePropertyValue.Get( relativeValue ) )
+      {
+        value = currentValue * relativeValue;
+      }
+      break;
+    }
+
+    case Property::VECTOR2:
+    {
+      if( componentIndex == Property::INVALID_COMPONENT_INDEX )
+      {
+        AdjustProperty< Vector2 >( value, relativePropertyValue );
+      }
+      else
+      {
+        Vector2 vector2Value;
+        value.Get( vector2Value );
+
+        if( componentIndex == 0 )
+        {
+          vector2Value.x += relativePropertyValue.Get< float >();
+        }
+        else if( componentIndex == 1 )
+        {
+          vector2Value.y += relativePropertyValue.Get< float >();
+        }
+
+        value = vector2Value;
+      }
+
+      break;
+    }
+
+    case Property::VECTOR3:
+    {
+      if( componentIndex == Property::INVALID_COMPONENT_INDEX )
+      {
+        AdjustProperty< Vector3 >( value, relativePropertyValue );
+      }
+      else
+      {
+        Vector3 vector3Value;
+        value.Get( vector3Value );
+
+        if( componentIndex == 0 )
+        {
+          vector3Value.x += relativePropertyValue.Get< float >();
+        }
+        else if( componentIndex == 1 )
+        {
+          vector3Value.y += relativePropertyValue.Get< float >();
+        }
+        else if( componentIndex == 2 )
+        {
+          vector3Value.z += relativePropertyValue.Get< float >();
+        }
+
+        value = vector3Value;
+      }
+      break;
+    }
+
+    case Property::VECTOR4:
+    {
+      if( componentIndex == Property::INVALID_COMPONENT_INDEX )
+      {
+        AdjustProperty< Vector4 >( value, relativePropertyValue );
+      }
+      else
+      {
+        Vector4 vector4Value;
+        value.Get( vector4Value );
+
+        if( componentIndex == 0 )
+        {
+          vector4Value.x += relativePropertyValue.Get< float >();
+        }
+        else if( componentIndex == 1 )
+        {
+          vector4Value.y += relativePropertyValue.Get< float >();
+        }
+        else if( componentIndex == 2 )
+        {
+          vector4Value.z += relativePropertyValue.Get< float >();
+        }
+        else if( componentIndex == 3 )
+        {
+          vector4Value.w += relativePropertyValue.Get< float >();
+        }
+
+        value = vector4Value;
+      }
+      break;
+    }
+  }
+}
+
 } // namespace Internal
 
 } // namespace Dali