Allow animatable property getter and setter functions 93/320793/9
authorjmm <j0064423.lee@samsung.com>
Fri, 7 Mar 2025 08:35:12 +0000 (17:35 +0900)
committerJeongmin Lee <j0064423.lee@samsung.com>
Fri, 28 Mar 2025 08:54:28 +0000 (08:54 +0000)
Change-Id: I2b314566bb1ecfffad9533bee61d085289604788
Signed-off-by: jmm <j0064423.lee@samsung.com>
dali/internal/event/common/object-impl.cpp
dali/internal/event/common/type-info-impl.cpp
dali/internal/event/common/type-info-impl.h
dali/internal/event/common/type-registry-impl.cpp
dali/internal/event/common/type-registry-impl.h
dali/public-api/object/type-registry.cpp
dali/public-api/object/type-registry.h

index cef02dfed796dce3c3772a8230f57962aa07e8c2..1e63f2095f36e1279366f0bb7b55e61bc390e30e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
@@ -363,6 +363,13 @@ void Object::SetProperty(Property::Index index, Property::Value propertyValue)
       // update the cached property value
       animatableProperty->SetPropertyValue(propertyValue);
 
+      const TypeInfo* typeInfo(GetTypeInfo());
+      if(typeInfo)
+      {
+        // will do nothing if additional setter is nullptr
+        typeInfo->SetAnimatableProperty(this, index, propertyValue);
+      }
+
       // set the scene graph property value
       SetSceneGraphProperty(index, *animatableProperty, propertyValue);
     }
@@ -463,8 +470,18 @@ Property::Value Object::GetProperty(Property::Index index) const
     AnimatablePropertyMetadata* animatableProperty = GetSceneAnimatableProperty(index, nullptr);
     if(animatableProperty)
     {
-      // get the cached animatable property value
-      value = animatableProperty->GetPropertyValue();
+      const TypeInfo* typeInfo(GetTypeInfo());
+      if(typeInfo)
+      {
+        // call additional getter if set
+        value = typeInfo->GetAnimatableProperty(this, index);
+      }
+
+      if(value.GetType() == Property::Type::NONE)
+      {
+        // get the cached animatable property value
+        value = animatableProperty->GetPropertyValue();
+      }
     }
     else
     {
index 77dd25d61221691b4e57088c3bd7b3b560edb05c..4a1657c727db4219cd7ff0ade2be6921a29b48d3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
@@ -504,9 +504,9 @@ void TypeInfo::AddProperty(std::string name, Property::Index index, Property::Ty
   }
 }
 
-void TypeInfo::AddAnimatableProperty(std::string name, Property::Index index, Property::Type type)
+void TypeInfo::AddAnimatableProperty(std::string name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc)
 {
-  if(DALI_UNLIKELY(!mRegisteredProperties.Register(static_cast<std::uint32_t>(index), RegisteredProperty(type, ConstString(name), Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX))))
+  if(DALI_UNLIKELY(!mRegisteredProperties.Register(static_cast<std::uint32_t>(index), RegisteredProperty(type, setFunc, getFunc, ConstString(name), Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX))))
   {
     DALI_LOG_ERROR("Property index already added to Type! name:%s, index:%d, type:%d\n", name.c_str(), index, static_cast<int32_t>(type));
     DALI_ASSERT_ALWAYS(!"Property index already added to Type");
@@ -892,6 +892,24 @@ Property::Value TypeInfo::GetPropertyDefaultValue(Property::Index index) const
   return Property::Value(); // return none
 }
 
+void TypeInfo::SetAnimatableProperty(BaseObject* object, Property::Index index, Property::Value value) const
+{
+  const auto& iter = mRegisteredProperties.Get(static_cast<std::uint32_t>(index));
+  if(iter != mRegisteredProperties.end() && iter->second.setFunc)
+  {
+    iter->second.setFunc(object, index, value);
+  }
+  else if(GetBaseType(mBaseType, mTypeRegistry, mBaseTypeName))
+  {
+    // call base type recursively
+    mBaseType->SetAnimatableProperty(object, index, std::move(value));
+  }
+  else
+  {
+    DALI_LOG_ERROR("Property index %d not found\n", index);
+  }
+}
+
 void TypeInfo::SetProperty(BaseObject* object, Property::Index index, Property::Value value) const
 {
   const auto& iter = mRegisteredProperties.Get(static_cast<std::uint32_t>(index));
@@ -967,6 +985,23 @@ void TypeInfo::SetProperty(BaseObject* object, const std::string& name, Property
   }
 }
 
+Property::Value TypeInfo::GetAnimatableProperty(const BaseObject* object, Property::Index index) const
+{
+  const auto& iter = mRegisteredProperties.Get(static_cast<std::uint32_t>(index));
+  if(iter != mRegisteredProperties.end() && iter->second.getFunc)
+  {
+    return iter->second.getFunc(const_cast<BaseObject*>(object), index);
+  }
+  else if(GetBaseType(mBaseType, mTypeRegistry, mBaseTypeName))
+  {
+    // call base type recursively
+    return mBaseType->GetAnimatableProperty(object, index);
+  }
+
+  // not an error, because scene graph might have the value
+  return Property::Value();
+}
+
 Property::Value TypeInfo::GetProperty(const BaseObject* object, Property::Index index) const
 {
   const auto& iter = mRegisteredProperties.Get(static_cast<std::uint32_t>(index));
index ad0de51a15958dc4ae8dbe454e1646b7c50ab5b8..3f40ce7a1bc429789d8c1e1f95035502dd567641 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_TYPE_INFO_H
 
 /*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
@@ -173,8 +173,10 @@ public:
    * @param[in] name The name of the property.
    * @param[in] index The index of the property
    * @param[in] type The Property::Type.
+   * @param[in] setFunc An additional function to call to set the property (Can be nullptr).
+   * @param[in] getFunc An additional function to call to retrieve the value of the property (Can be nullptr).
    */
-  void AddAnimatableProperty(std::string name, Property::Index index, Property::Type type);
+  void AddAnimatableProperty(std::string name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc);
 
   /**
    * Adds an animatable property with the given default value.
@@ -302,6 +304,14 @@ public:
    */
   Property::Value GetPropertyDefaultValue(Property::Index index) const;
 
+  /**
+   * Sets the value of an animatable property at the index specified for the given object.
+   * @param[in] object The object whose property is to be set.
+   * @param[in] index The property index.
+   * @param[in] value The value to set.
+   */
+  void SetAnimatableProperty(BaseObject* object, Property::Index index, Property::Value value) const;
+
   /**
    * Sets the value of a property at the index specified for the given object.
    * @param[in] object The object whose property is to be set.
@@ -318,6 +328,14 @@ public:
    */
   void SetProperty(BaseObject* object, const std::string& name, Property::Value value) const;
 
+  /**
+   * Retrieves the value of an animatable property at the index specified for the given object.
+   * @param[in] object The object whose property is to be queried.
+   * @param[in] index The property index.
+   * @return The current value of the property.
+   */
+  Property::Value GetAnimatableProperty(const BaseObject* object, Property::Index index) const;
+
   /**
    * Retrieves the value of a property at the index specified for the given object.
    * @param[in] object The object whose property is to be queried.
index add652041de7238ab9608be3e4f4f9664b184825..12cc1ca6750dc07a3be31fc65da121612c78fbbe 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
@@ -206,12 +206,12 @@ bool TypeRegistry::RegisterProperty(const std::string& objectName, std::string n
   return false;
 }
 
-bool TypeRegistry::RegisterAnimatableProperty(TypeRegistration& typeRegistration, std::string name, Property::Index index, Property::Type type)
+bool TypeRegistry::RegisterAnimatableProperty(TypeRegistration& typeRegistration, std::string name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc)
 {
   auto iter = mRegistryLut.Get(ConstString(typeRegistration.RegisteredName()));
   if(iter != mRegistryLut.end())
   {
-    iter->second->AddAnimatableProperty(std::move(name), index, type);
+    iter->second->AddAnimatableProperty(std::move(name), index, type, setFunc, getFunc);
     return true;
   }
 
index 8437ba07762c3bd96c925f72eb3798df4739f7ea..85488d9688107f07fbaf224e877e173f331b140e 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_TYPE_REGISTRY_H
 
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
@@ -156,9 +156,11 @@ public:
    * @param [in] name Property name
    * @param [in] index Property index
    * @param [in] type Property type
+   * @param [in] setFunc An additional function to set the property (Can be nullptr).
+   * @param [in] getFunc An additional function to get the value of a property (Can be nullptr).
    * @return true if registered
    */
-  bool RegisterAnimatableProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Type type);
+  bool RegisterAnimatableProperty(TypeRegistration& registered, std::string name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc);
 
   /**
    * Register a scene graph only property with a default value
index 2b69d9d6a35821cf91bf9f7a0607aa7869682eba..3b627144edc8ae8150f7b8c53d96892fd1d19264 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
@@ -122,11 +122,11 @@ PropertyRegistration::PropertyRegistration(TypeRegistration& registered, std::st
   Internal::TypeRegistry::Get()->RegisterProperty(registered, std::move(name), index, type, setFunc, getFunc);
 }
 
-AnimatablePropertyRegistration::AnimatablePropertyRegistration(TypeRegistration& registered, std::string name, Property::Index index, Property::Type type)
+AnimatablePropertyRegistration::AnimatablePropertyRegistration(TypeRegistration& registered, std::string name, Property::Index index, Property::Type type, TypeInfo::SetPropertyFunction setFunc, TypeInfo::GetPropertyFunction getFunc)
 {
   DALI_ASSERT_ALWAYS((index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX) && (index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX));
 
-  Internal::TypeRegistry::Get()->RegisterAnimatableProperty(registered, std::move(name), index, type);
+  Internal::TypeRegistry::Get()->RegisterAnimatableProperty(registered, std::move(name), index, type, setFunc, getFunc);
 }
 
 AnimatablePropertyRegistration::AnimatablePropertyRegistration(TypeRegistration& registered, std::string name, Property::Index index, const Property::Value& value)
index 7eddbe2099d688a8fac6ef69b7138890f6c81b59..58265e84b636d22a840d5c45364918480a733fb4 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TYPE_REGISTRY_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
@@ -358,9 +358,16 @@ public:
    * @param[in] name The name of the property
    * @param[in] index The property index. Must be a value between ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX and ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX inclusive
    * @param[in] type The property value type
+   * @param[in] setFunc An additional function to call when setting the property (Can be nullptr).
+   * @param[in] getFunc An additional function to call to retrieve the current value of the property (Can be nullptr).
    * @pre "registered" must be registered with the TypeRegistry.
    */
-  AnimatablePropertyRegistration(TypeRegistration& registered, std::string name, Property::Index index, Property::Type type);
+  explicit AnimatablePropertyRegistration(TypeRegistration&             registered,
+                                          std::string                   name,
+                                          Property::Index               index,
+                                          Property::Type                type,
+                                          TypeInfo::SetPropertyFunction setFunc = nullptr,
+                                          TypeInfo::GetPropertyFunction getFunc = nullptr);
 
   /**
    * @brief This constructor registers the animatable property with the registered default value.
@@ -376,7 +383,7 @@ public:
    * @param[in] value The property default value
    * @pre "registered" must be registered with the TypeRegistry.
    */
-  AnimatablePropertyRegistration(TypeRegistration& registered, std::string name, Property::Index index, const Property::Value& value);
+  explicit AnimatablePropertyRegistration(TypeRegistration& registered, std::string name, Property::Index index, const Property::Value& value);
 };
 
 /**