Merge "Clean up the code to build successfully on macOS" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / path-constrainer-impl.cpp
index 17dea0f..bcae22e 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,8 +41,15 @@ namespace
 DALI_PROPERTY_TABLE_BEGIN
 DALI_PROPERTY( "forward",       VECTOR3,   true,    false,       false,        Dali::PathConstrainer::Property::FORWARD )
 DALI_PROPERTY( "points",         ARRAY,    true,    false,       false,        Dali::PathConstrainer::Property::POINTS )
-DALI_PROPERTY( "control-points", ARRAY,    true,    false,       false,        Dali::PathConstrainer::Property::CONTROL_POINTS )
-DALI_PROPERTY_TABLE_END( DEFAULT_OBJECT_PROPERTY_START_INDEX )
+DALI_PROPERTY( "controlPoints",  ARRAY,    true,    false,       false,        Dali::PathConstrainer::Property::CONTROL_POINTS )
+DALI_PROPERTY_TABLE_END( DEFAULT_OBJECT_PROPERTY_START_INDEX, PathConstrainerDefaultProperties )
+
+BaseHandle Create()
+{
+  return Dali::PathConstrainer::New();
+}
+
+TypeRegistration mType( typeid( Dali::PathConstrainer ), typeid( Dali::Handle ), Create, PathConstrainerDefaultProperties );
 
 } //Unnamed namespace
 
@@ -55,98 +64,61 @@ PathConstrainer::PathConstrainer()
 {
 }
 
-PathConstrainer::~PathConstrainer()
-{
-}
-
-unsigned int PathConstrainer::GetDefaultPropertyCount() const
-{
-  return DEFAULT_PROPERTY_COUNT;
-}
-
-void PathConstrainer::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* PathConstrainer::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 PathConstrainer::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 ) ) // dont want to convert rhs to string
-    {
-      index = i;
-      break;
-    }
-  }
-  return index;
-}
-
-Property::Type PathConstrainer::GetDefaultPropertyType(Property::Index index) const
-{
-  if( index < DEFAULT_PROPERTY_COUNT )
-  {
-    return DEFAULT_PROPERTY_DETAILS[index].type;
-  }
-
-  // index out of range
-  return Property::NONE;
-}
+PathConstrainer::~PathConstrainer() = default;
 
 Property::Value PathConstrainer::GetDefaultProperty( Property::Index index ) const
 {
-  Property::Value value;
   if( index == Dali::PathConstrainer::Property::FORWARD )
   {
-    value = Property::Value( mForward );
+    return Property::Value( mForward );
   }
-  else if( index == Dali::PathConstrainer::Property::POINTS )
+  else
   {
-    Property::Array propertyArray;
-    value = Property::Value(propertyArray);
-    const Dali::Vector<Vector3>& point = mPath->GetPoints();
-    size_t pointCount( point.Size() );
-    for( size_t i( 0 ); i != pointCount; ++i )
+    if( index == Dali::PathConstrainer::Property::POINTS )
     {
-      value.AppendItem( point[i] );
+      Property::Value value( Property::ARRAY );
+      Property::Array* array = value.GetArray();
+      const Dali::Vector<Vector3>& point = mPath->GetPoints();
+      Property::Array::SizeType pointCount = static_cast<Property::Array::SizeType>( point.Size() );
+
+      if( array )
+      {
+        array->Reserve( pointCount );
+        for( Property::Array::SizeType i = 0; i < pointCount; ++i )
+        {
+          array->PushBack( point[i] );
+        }
+      }
+      return value;
     }
-  }
-  else if( index == Dali::PathConstrainer::Property::CONTROL_POINTS )
-  {
-    Property::Array propertyArray;
-    value = Property::Value(propertyArray);
-    const Dali::Vector<Vector3>& point = mPath->GetControlPoints();
-    size_t pointCount( point.Size() );
-    for( size_t i( 0 ); i != pointCount; ++i )
+    else if( index == Dali::PathConstrainer::Property::CONTROL_POINTS )
     {
-      value.AppendItem( point[i] );
+      Property::Value value( Property::ARRAY );
+      Property::Array* array = value.GetArray();
+      const Dali::Vector<Vector3>& point = mPath->GetControlPoints();
+      Property::Array::SizeType pointCount = static_cast<Property::Array::SizeType>( point.Size() );
+
+      if( array )
+      {
+        array->Reserve( pointCount );
+        for( Property::Array::SizeType i = 0; i < pointCount; ++i )
+        {
+          array->PushBack( point[i] );
+        }
+      }
+      return value;
     }
   }
 
-  return value;
+  return Property::Value();
 }
 
-void PathConstrainer::SetDefaultProperty(Property::Index index, const Property::Value& propertyValue)
+Property::Value PathConstrainer::GetDefaultPropertyCurrentValue( Property::Index index ) const
+{
+  return GetDefaultProperty( index ); // Event-side only properties
+}
+
+void PathConstrainer::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
 {
   if( index == Dali::PathConstrainer::Property::FORWARD )
   {
@@ -154,64 +126,34 @@ void PathConstrainer::SetDefaultProperty(Property::Index index, const Property::
   }
   else if( index == Dali::PathConstrainer::Property::POINTS  )
   {
-    Property::Array propertyArray;
-    propertyValue.Get(propertyArray);
-
-    size_t propertyArrayCount = propertyArray.size();
-    Dali::Vector<Vector3> point;
-    point.Resize( propertyArrayCount );
-    for( size_t i(0); i!=propertyArrayCount; ++i )
+    const Property::Array* array = propertyValue.GetArray();
+    mPath->ClearPoints();
+    if( array )
     {
-      propertyArray[i].Get( point[i]);
+      for( Property::Array::SizeType i = 0, count = array->Count(); i < count; ++i )
+      {
+        Vector3 point;
+        array->GetElementAt( i ).Get( point );
+        mPath->AddPoint( point );
+      }
     }
-    mPath->SetPoints( point );
   }
   else if( index == Dali::PathConstrainer::Property::CONTROL_POINTS )
   {
-    Property::Array propertyArray;
-    propertyValue.Get(propertyArray);
-
-    size_t propertyArrayCount = propertyArray.size();
-    Dali::Vector<Vector3> point;
-    point.Resize( propertyArrayCount );
-    for( size_t i(0); i!=propertyArrayCount; ++i )
+    const Property::Array* array = propertyValue.GetArray();
+    mPath->ClearControlPoints();
+    if( array )
     {
-      propertyArray[i].Get( point[i]);
+      for( Property::Array::SizeType i = 0, count = array->Count(); i < count; ++i )
+      {
+        Vector3 point;
+        array->GetElementAt( i ).Get( point );
+        mPath->AddControlPoint( point );
+      }
     }
-    mPath->SetControlPoints( point );
   }
 }
 
-bool PathConstrainer::IsDefaultPropertyWritable(Property::Index index) const
-{
-  if( index < DEFAULT_PROPERTY_COUNT )
-  {
-    return DEFAULT_PROPERTY_DETAILS[index].writable;
-  }
-
-  return false;
-}
-
-bool PathConstrainer::IsDefaultPropertyAnimatable(Property::Index index) const
-{
-  if( index < DEFAULT_PROPERTY_COUNT )
-  {
-    return DEFAULT_PROPERTY_DETAILS[index].animatable;
-  }
-
-  return false;
-}
-
-bool PathConstrainer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
-{
-  if( index < DEFAULT_PROPERTY_COUNT )
-  {
-    return DEFAULT_PROPERTY_DETAILS[index].constraintInput;
-  }
-
-  return false;
-}
-
 void PathConstrainer::Apply( Property target, Property source, const Vector2& range, const Vector2& wrap)
 {
   Dali::Property::Type propertyType = target.object.GetPropertyType( target.propertyIndex);
@@ -221,8 +163,8 @@ void PathConstrainer::Apply( Property target, Property source, const Vector2& ra
     Dali::Constraint constraint = Dali::Constraint::New<Vector3>( target.object, target.propertyIndex, PathConstraintFunctor( mPath, 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();
   }
   else if( propertyType == Dali::Property::ROTATION )
@@ -231,8 +173,8 @@ void PathConstrainer::Apply( Property target, Property source, const Vector2& ra
     Dali::Constraint constraint = Dali::Constraint::New<Quaternion>( target.object, target.propertyIndex, PathConstraintFunctor( mPath, range, mForward, 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();
   }