Renaming of enum values for coding standards compliance.
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / linear-constrainer-impl.cpp
index 8d9d014..c357e41 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
 #include <cstring> // for strcmp
 
 // INTERNAL INCLUDES
-#include <dali/internal/event/common/property-helper.h>
 #include <dali/public-api/animation/constraint.h>
+#include <dali/public-api/object/property-array.h>
+#include <dali/public-api/object/type-registry.h>
+#include <dali/internal/event/common/property-helper.h>
+
 
 namespace Dali
 {
@@ -39,7 +42,14 @@ namespace
 DALI_PROPERTY_TABLE_BEGIN
 DALI_PROPERTY( "value",        ARRAY,     true,    false,       false,        Dali::LinearConstrainer::Property::VALUE )
 DALI_PROPERTY( "progress",     ARRAY,     true,    false,       false,        Dali::LinearConstrainer::Property::PROGRESS )
-DALI_PROPERTY_TABLE_END( DEFAULT_OBJECT_PROPERTY_START_INDEX )
+DALI_PROPERTY_TABLE_END( DEFAULT_OBJECT_PROPERTY_START_INDEX, LinearConstrainerDefaultProperties )
+
+BaseHandle Create()
+{
+  return Dali::LinearConstrainer::New();
+}
+
+TypeRegistration mType( typeid( Dali::LinearConstrainer ), typeid( Dali::Handle ), Create, LinearConstrainerDefaultProperties );
 
 } //Unnamed namespace
 
@@ -57,135 +67,74 @@ LinearConstrainer::~LinearConstrainer()
 {
 }
 
-unsigned int LinearConstrainer::GetDefaultPropertyCount() const
-{
-  return DEFAULT_PROPERTY_COUNT;
-}
-
-void LinearConstrainer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
-{
-  indices.reserve( DEFAULT_PROPERTY_COUNT );
-
-  for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
-  {
-    indices.push_back( i );
-  }
-}
-
-const char* LinearConstrainer::GetDefaultPropertyName(Property::Index index) const
-{
-  if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
-  {
-    return DEFAULT_PROPERTY_DETAILS[index].name;
-  }
-
-  // index out of range
-  return NULL;
-}
-
-Property::Index LinearConstrainer::GetDefaultPropertyIndex(const std::string& name) const
-{
-  Property::Index index = Property::INVALID_INDEX;
-
-  // Look for name in default properties
-  for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
-  {
-    const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[ i ];
-    if( 0 == strcmp( name.c_str(), property->name ) )
-    {
-      index = i;
-      break;
-    }
-  }
-  return index;
-}
-
-Property::Type LinearConstrainer::GetDefaultPropertyType(Property::Index index) const
-{
-  if( index < DEFAULT_PROPERTY_COUNT )
-  {
-    return DEFAULT_PROPERTY_DETAILS[index].type;
-  }
-
-  // index out of range
-  return Property::NONE;
-}
-
 Property::Value LinearConstrainer::GetDefaultProperty( Property::Index index ) const
 {
-  Property::Value value;
   if( index == Dali::LinearConstrainer::Property::VALUE )
   {
-    value = Property::Value(Property::ARRAY);
-    size_t count( mValue.Size() );
-    for( size_t i( 0 ); i != count; ++i )
+    Property::Value value( Property::ARRAY );
+    Property::Array* array = value.GetArray();
+    uint32_t count = static_cast<uint32_t>( mValue.Size() );
+
+    if( array )
     {
-      value.AppendItem( mValue[i] );
+      array->Reserve( count );
+      for( uint32_t i( 0 ); i != count; ++i )
+      {
+        array->PushBack( mValue[i] );
+      }
     }
+    return value;
   }
   else if( index == Dali::LinearConstrainer::Property::PROGRESS )
   {
-    value = Property::Value(Property::ARRAY);
-    size_t count( mValue.Size() );
-    for( size_t i( 0 ); i != count; ++i )
-    {
-      value.AppendItem( mProgress[i] );
-    }
-  }
-
-  return value;
-}
+    Property::Value value( Property::ARRAY );
+    Property::Array* array = value.GetArray();
+    uint32_t count = static_cast<uint32_t>( mProgress.Size() );
 
-void LinearConstrainer::SetDefaultProperty(Property::Index index, const Property::Value& propertyValue)
-{
-  if( index == Dali::LinearConstrainer::Property::VALUE  )
-  {
-    size_t propertyArrayCount = propertyValue.GetSize();
-    mValue.Resize( propertyArrayCount );
-    for( size_t i(0); i != propertyArrayCount; ++i )
+    if( array )
     {
-      propertyValue.GetItem(i).Get( mValue[i] );
+      array->Reserve( count );
+      for( uint32_t i( 0 ); i != count; ++i )
+      {
+        array->PushBack( mProgress[i] );
+      }
     }
-  }
-  else if( index == Dali::LinearConstrainer::Property::PROGRESS  )
-  {
-    size_t propertyArrayCount = propertyValue.GetSize();
-    mProgress.Resize( propertyArrayCount );
-    for( size_t i(0); i != propertyArrayCount; ++i )
-    {
-      propertyValue.GetItem(i).Get( mProgress[i] );
-    }
-  }
-}
-
-bool LinearConstrainer::IsDefaultPropertyWritable(Property::Index index) const
-{
-  if( index < DEFAULT_PROPERTY_COUNT )
-  {
-    return DEFAULT_PROPERTY_DETAILS[index].writable;
+    return value;
   }
 
-  return false;
+  return Property::Value();
 }
 
-bool LinearConstrainer::IsDefaultPropertyAnimatable(Property::Index index) const
+Property::Value LinearConstrainer::GetDefaultPropertyCurrentValue( Property::Index index ) const
 {
-  if( index < DEFAULT_PROPERTY_COUNT )
-  {
-    return DEFAULT_PROPERTY_DETAILS[index].animatable;
-  }
-
-  return false;
+  return GetDefaultProperty( index ); // Event-side only properties
 }
 
-bool LinearConstrainer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
+void LinearConstrainer::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
 {
-  if( index < DEFAULT_PROPERTY_COUNT )
+  const Property::Array* array = propertyValue.GetArray();
+  if( array )
   {
-    return DEFAULT_PROPERTY_DETAILS[index].constraintInput;
+    uint32_t propertyArrayCount = static_cast<uint32_t>( array->Count() );
+    if( index == Dali::LinearConstrainer::Property::VALUE  )
+    {
+      mValue.Clear(); // remove old values
+      mValue.Resize( propertyArrayCount );
+      for( uint32_t i(0); i != propertyArrayCount; ++i )
+      {
+        array->GetElementAt( i ).Get( mValue[ i ] );
+      }
+    }
+    else if( index == Dali::LinearConstrainer::Property::PROGRESS  )
+    {
+      mProgress.Clear(); // remove old values
+      mProgress.Resize( propertyArrayCount );
+      for( uint32_t i(0); i != propertyArrayCount; ++i )
+      {
+        array->GetElementAt( i ).Get( mProgress[ i ] );
+      }
+    }
   }
-
-  return false;
 }
 
 void LinearConstrainer::Apply( Property target, Property source, const Vector2& range, const Vector2& wrap)
@@ -193,11 +142,10 @@ void LinearConstrainer::Apply( Property target, Property source, const Vector2&
   Dali::Constraint constraint = Dali::Constraint::New<float>( target.object, target.propertyIndex, LinearConstraintFunctor( mValue, mProgress, range, wrap ) );
   constraint.AddSource( Dali::Source(source.object, source.propertyIndex ) );
 
-  constraint.SetTag( reinterpret_cast<size_t>( this ) );
-  constraint.SetRemoveAction( Dali::Constraint::Discard );
+  constraint.SetTag( static_cast<uint32_t>( reinterpret_cast<uintptr_t>( this ) ) ); // taking 32bits of this as tag
+  constraint.SetRemoveAction( Dali::Constraint::DISCARD );
   constraint.Apply();
 
-
   //Start observing the object
   Observe( target.object );
 }