From 4f9b7715ec6ed5ff63d82dae061a759f22094e3d Mon Sep 17 00:00:00 2001 From: jmm Date: Fri, 7 Mar 2025 17:35:12 +0900 Subject: [PATCH] Allow animatable property getter and setter functions Change-Id: I2b314566bb1ecfffad9533bee61d085289604788 Signed-off-by: jmm --- dali/internal/event/common/object-impl.cpp | 23 +++++++++-- dali/internal/event/common/type-info-impl.cpp | 41 +++++++++++++++++-- dali/internal/event/common/type-info-impl.h | 22 +++++++++- .../event/common/type-registry-impl.cpp | 6 +-- .../event/common/type-registry-impl.h | 6 ++- dali/public-api/object/type-registry.cpp | 6 +-- dali/public-api/object/type-registry.h | 13 ++++-- 7 files changed, 98 insertions(+), 19 deletions(-) diff --git a/dali/internal/event/common/object-impl.cpp b/dali/internal/event/common/object-impl.cpp index cef02dfed..1e63f2095 100644 --- a/dali/internal/event/common/object-impl.cpp +++ b/dali/internal/event/common/object-impl.cpp @@ -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 { diff --git a/dali/internal/event/common/type-info-impl.cpp b/dali/internal/event/common/type-info-impl.cpp index 77dd25d61..4a1657c72 100644 --- a/dali/internal/event/common/type-info-impl.cpp +++ b/dali/internal/event/common/type-info-impl.cpp @@ -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(index), RegisteredProperty(type, ConstString(name), Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX)))) + if(DALI_UNLIKELY(!mRegisteredProperties.Register(static_cast(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(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(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(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(index)); + if(iter != mRegisteredProperties.end() && iter->second.getFunc) + { + return iter->second.getFunc(const_cast(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(index)); diff --git a/dali/internal/event/common/type-info-impl.h b/dali/internal/event/common/type-info-impl.h index ad0de51a1..3f40ce7a1 100644 --- a/dali/internal/event/common/type-info-impl.h +++ b/dali/internal/event/common/type-info-impl.h @@ -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. diff --git a/dali/internal/event/common/type-registry-impl.cpp b/dali/internal/event/common/type-registry-impl.cpp index add652041..12cc1ca67 100644 --- a/dali/internal/event/common/type-registry-impl.cpp +++ b/dali/internal/event/common/type-registry-impl.cpp @@ -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; } diff --git a/dali/internal/event/common/type-registry-impl.h b/dali/internal/event/common/type-registry-impl.h index 8437ba077..85488d968 100644 --- a/dali/internal/event/common/type-registry-impl.h +++ b/dali/internal/event/common/type-registry-impl.h @@ -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 diff --git a/dali/public-api/object/type-registry.cpp b/dali/public-api/object/type-registry.cpp index 2b69d9d6a..3b627144e 100644 --- a/dali/public-api/object/type-registry.cpp +++ b/dali/public-api/object/type-registry.cpp @@ -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) diff --git a/dali/public-api/object/type-registry.h b/dali/public-api/object/type-registry.h index 7eddbe209..58265e84b 100644 --- a/dali/public-api/object/type-registry.h +++ b/dali/public-api/object/type-registry.h @@ -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); }; /** -- 2.34.1