-#ifndef __DALI_INTERNAL_PROPERTY_METADATA_H__
-#define __DALI_INTERNAL_PROPERTY_METADATA_H__
+#ifndef DALI_INTERNAL_PROPERTY_METADATA_H
+#define DALI_INTERNAL_PROPERTY_METADATA_H
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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 <utility>
// INTERNAL INCLUDES
+#include <dali/internal/common/const-string.h>
#include <dali/public-api/common/constants.h>
+#include <dali/public-api/object/property-value.h>
#include <dali/public-api/object/property.h>
namespace Dali
{
-
namespace Internal
{
-
namespace SceneGraph
{
class PropertyBase;
}
/**
- * An entry in a property metadata lookup.
- * The type field should be queried, before accessing the scene-graph property:
+ * @brief Base class for the Metadata required by custom and registered animatable properties.
+ *
+ * The value type field should be queried, before accessing the scene-graph property:
*
* @code
* void Example(PropertyEntry entry)
* {
- * if (entry.type == Property::VECTOR3)
+ * if (entry.value.GetType() == Property::VECTOR3)
* {
* SceneGraph::AnimatableProperty<Vector3>* property = dynamic_cast< SceneGraph::AnimatableProperty<Vector3>* >( entry.property );
* ...
class PropertyMetadata
{
public:
+ /**
+ * @brief Virtual Destructor.
+ */
+ virtual ~PropertyMetadata() = default;
/**
- * Constructor for an uninitalized property metadata
+ * @brief Returns whether the property is animatable (i.e. if its a scene graph property).
+ * @return True if animatable, false otherwise
*/
- PropertyMetadata()
- : type(Property::NONE),
- value(),
- componentIndex(Property::INVALID_COMPONENT_INDEX),
- mProperty(NULL)
+ bool IsAnimatable(void) const
{
+ return nullptr != mSceneGraphProperty;
}
/**
- * Constructor for property metadata
- * @param [in] newProperty A pointer to the property metadata.
+ * @brief Whether the property can be written to.
+ * @return True if the property can be written to, false otherwise
*/
- PropertyMetadata(const SceneGraph::PropertyBase* newProperty)
- : type(Property::NONE),
- value(), // value is held by newProperty
- componentIndex(Property::INVALID_COMPONENT_INDEX),
- mProperty(newProperty)
+ bool IsWritable(void) const
{
- DALI_ASSERT_DEBUG(mProperty && "Uninitialized scenegraph property") ;
+ return mWritable;
}
/**
- * Constructor for property metadata
- * @param [in] newValue The value of the scene-graph owned property.
+ * @brief Retrieves the scene-graph property.
+ * @return The scene graph property
+ *
+ * @note Should only be called if the scene-graph property was passed in originally. Will debug assert if the stored property is NULL.
*/
- PropertyMetadata(Property::Value newValue)
- : type(newValue.GetType()),
- value(newValue),
- componentIndex(Property::INVALID_COMPONENT_INDEX),
- mProperty(NULL)
+ const SceneGraph::PropertyBase* GetSceneGraphProperty() const
{
+ DALI_ASSERT_DEBUG(mSceneGraphProperty && "Accessing uninitialized SceneGraph property");
+ return mSceneGraphProperty;
}
/**
- * Destructor for property metadata
+ * @brief Retrieve the type of the property.
+ * @return Type of the held property value
*/
- virtual ~PropertyMetadata()
+ inline Property::Type GetType() const
{
+ return value.GetType();
}
/**
- * @return true if the property is animatable (i.e. if its a scene graph property)
+ * Set the cached value of the property.
+ * @param[in] value The propertyValue to set.
*/
- bool IsAnimatable(void) const
- {
- return NULL != mProperty;
- }
+ void SetPropertyValue(const Property::Value& propertyValue);
/**
- * @return true if the property can be written to
+ * Get the cached value of a the property.
+ * @return The cached value of the property.
*/
- virtual bool IsWritable(void) const = 0;
+ Property::Value GetPropertyValue() const;
/**
- * @return the scene graph property
+ * Modifies the stored value by the relativeValue.
+ * @param[in] relativeValue The value to change by.
*/
- const SceneGraph::PropertyBase* GetSceneGraphProperty() const
+ void AdjustPropertyValueBy(const Property::Value& relativeValue);
+
+protected:
+ /**
+ * @brief Constructor to create Metadata for a property.
+ * @param[in] propertyValue The value of the property (this is used by the event thread)
+ * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
+ * @param[in] writable Whether the property is writable
+ */
+ PropertyMetadata(Property::Value propertyValue,
+ const SceneGraph::PropertyBase* sceneGraphProperty,
+ bool writable)
+ : value(mStoredValue),
+ componentIndex(Property::INVALID_COMPONENT_INDEX),
+ mStoredValue(std::move(propertyValue)),
+ mSceneGraphProperty(sceneGraphProperty),
+ mWritable(writable)
{
- DALI_ASSERT_DEBUG(mProperty && "Accessing uninitialized SceneGraph property") ;
- return mProperty;
}
- Property::Type type; ///< The type of the property
- Property::Value value; ///< The property value for a non animatable and custom property
- int componentIndex; ///< The index of the property component
-
-protected:
+ /**
+ * @brief Constructor to create Metadata for a component of another property.
+ * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
+ * @param[in] writable Whether the property is writable
+ * @param[in] baseValueRef A reference to the metadata of the base animatable property
+ * @param[in] propertyComponentIndex The component index of the property
+ */
+ PropertyMetadata(const SceneGraph::PropertyBase* sceneGraphProperty, bool writable, Property::Value& baseValueRef, int32_t propertyComponentIndex)
+ : value(baseValueRef),
+ componentIndex(propertyComponentIndex),
+ mStoredValue(),
+ mSceneGraphProperty(sceneGraphProperty),
+ mWritable(writable)
+ {
+ }
+private:
// Not implemented
- PropertyMetadata( const PropertyMetadata& );
- PropertyMetadata& operator=( const PropertyMetadata& );
+ PropertyMetadata(const PropertyMetadata&);
+ PropertyMetadata& operator=(const PropertyMetadata&);
- const SceneGraph::PropertyBase* mProperty; ///< A pointer to a scene-graph property; should not be modified from actor-thread.
-};
+public: // Data
+ /**
+ * @brief The value of this property used to read/write by the event thread.
+ *
+ * If this PropertyMetadata is for property component, then refers to the value in the PropertyMetadata of the base property
+ * to ensure the components are kept in sync with the overall value on the event thread.
+ * Otherwise, this refers to mStoredValue.
+ */
+ Property::Value& value;
+ /**
+ * @brief The index of the property component.
+ */
+ int32_t componentIndex;
+
+private:
+ Property::Value mStoredValue; ///< The cached property value used to read/write by the event thread
+ const SceneGraph::PropertyBase* mSceneGraphProperty; ///< A pointer to a scene-graph property; should not be modified from actor-thread
+ bool mWritable : 1; ///< Whether the property is writable
+};
/**
- * An entry in an animatable property metadata lookup.
- * The type field should be queried, before accessing the animatable property:
+ * @brief Metadata for a registered animatable property.
*/
class AnimatablePropertyMetadata : public PropertyMetadata
{
public:
-
/**
- * Constructor for metadata of animatable property
- * @param [in] newIndex The index of the animatable property.
- * @param [in] newType The type ID of the animatable property.
- * @param [in] newProperty A pointer to the scene-graph owned property.
+ * @brief Constructs metadata for a registered animatable property.
+ * @param[in] propertyIndex The index of the animatable property
+ * @param[in] propertyComponentIndex The component index of the animatable property
+ * @param[in] propertyValue The value of the property (this is used by the event thread)
+ * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
+ *
+ * @note The base animatable property MUST be created before the component animatable property.
*/
- AnimatablePropertyMetadata( Property::Index newIndex,
- int newComponentIndex,
- Property::Type newType,
- const SceneGraph::PropertyBase* newProperty )
- : index(newIndex)
+ AnimatablePropertyMetadata(Property::Index propertyIndex,
+ Property::Value propertyValue,
+ const SceneGraph::PropertyBase* sceneGraphProperty)
+ : PropertyMetadata(std::move(propertyValue), sceneGraphProperty, true),
+ index(propertyIndex)
{
- componentIndex = newComponentIndex;
- type = newType;
- mProperty = newProperty;
- DALI_ASSERT_DEBUG(mProperty && "Uninitialized scenegraph property") ;
+ DALI_ASSERT_DEBUG(sceneGraphProperty && "Uninitialized scene-graph property");
}
/**
- * Constructor for metadata of animatable property
- * @param [in] newIndex The index of the animatable property.
- * @param [in] newValue The value of the scene-graph owned property.
+ * @brief Constructs metadata for a registered animatable component of another property.
+ * @param[in] propertyIndex The index of the animatable property
+ * @param[in] propertyComponentIndex The component index of the animatable property
+ * @param[in] baseValueRef A reference to the metadata of the base animatable property
+ * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
+ *
+ * @note The base animatable property MUST be created before the component animatable property.
*/
- AnimatablePropertyMetadata( Property::Index newIndex,
- int newComponentIndex,
- Property::Value newValue )
- : index(newIndex)
+ AnimatablePropertyMetadata(Property::Index propertyIndex,
+ int propertyComponentIndex,
+ Property::Value& baseValueRef,
+ const SceneGraph::PropertyBase* sceneGraphProperty)
+ : PropertyMetadata(sceneGraphProperty, true, baseValueRef, propertyComponentIndex),
+ index(propertyIndex)
{
- componentIndex = newComponentIndex;
- type = newValue.GetType();
- value = newValue;
+ DALI_ASSERT_DEBUG(sceneGraphProperty && "Uninitialized scene-graph property");
}
/**
- * @return true if the property can be written to
+ * @brief Destructor.
*/
- virtual bool IsWritable(void) const
- {
- return true ;
- }
-
- Property::Index index; ///< The index of the property
+ ~AnimatablePropertyMetadata() override = default;
private:
-
// Not implemented
AnimatablePropertyMetadata();
- AnimatablePropertyMetadata( const AnimatablePropertyMetadata& );
- AnimatablePropertyMetadata& operator=( const AnimatablePropertyMetadata& );
+ AnimatablePropertyMetadata(const AnimatablePropertyMetadata&);
+ AnimatablePropertyMetadata& operator=(const AnimatablePropertyMetadata&);
+
+public: // Data
+ Property::Index index; ///< The index of the property.
};
class CustomPropertyMetadata : public PropertyMetadata
{
public:
-
/**
- * Constructor for metadata of scene graph based properties
- * @param [in] newName The name of the custom property.
- * @param [in] newType The type ID of the custom property.
- * @param [in] newProperty A pointer to the scene-graph owned property.
+ * Constructs Metadata for scene-graph-based custom properties, i.e. animatable custom properties.
+ * @param[in] propertyName The name of the custom property
+ * @param[in] propertyKey The key of the custom property
+ * @param[in] propertyValue The value of the property (this is used by the event thread)
+ * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
+ *
+ * @note A valid sceneGraphProperty is mandatory otherwise this will debug assert.
*/
- CustomPropertyMetadata( const std::string& newName,
- Property::Type newType,
- const SceneGraph::PropertyBase* newProperty)
- : name(newName),
- mAccessMode(Property::ANIMATABLE)
+ CustomPropertyMetadata(ConstString propertyName,
+ Property::Index propertyKey,
+ Property::Value propertyValue,
+ const SceneGraph::PropertyBase* sceneGraphProperty)
+ : PropertyMetadata(std::move(propertyValue), sceneGraphProperty, true),
+ name(propertyName),
+ key(propertyKey),
+ childPropertyIndex(Property::INVALID_INDEX)
{
- type = newType;
- mProperty = newProperty;
- DALI_ASSERT_DEBUG(mProperty && "Uninitialized scenegraph property") ;
+ DALI_ASSERT_DEBUG(sceneGraphProperty && "Uninitialized scene-graph property");
}
/**
- * Constructor for metadata of event side only properties
- * @param [in] newName The name of the custom property.
- * @param [in] newValue The value of the custom property.
- * @param [in] accessMode The access mode of the custom property (writable, animatable etc).
+ * Constructs metadata for event side only custom properties.
+ * @param[in] propertyName The name of the custom property
+ * @param[in] propertyValue The value of the property (this is used by the event thread)
+ * @param[in] accessMode The access mode of the custom property (writable, animatable etc)
+ *
+ * @note The access mode MUST NOT be animatable otherwise this will debug assert.
*/
- CustomPropertyMetadata( const std::string& newName,
- Property::Value newValue,
- Property::AccessMode accessMode )
- : name(newName),
- mAccessMode(accessMode)
+ CustomPropertyMetadata(ConstString propertyName,
+ Property::Value propertyValue,
+ Property::AccessMode accessMode)
+ : PropertyMetadata(std::move(propertyValue), nullptr, (accessMode != Property::READ_ONLY)),
+ name(propertyName),
+ key(Property::INVALID_KEY),
+ childPropertyIndex(Property::INVALID_INDEX)
{
- type = newValue.GetType();
- value = newValue;
- DALI_ASSERT_DEBUG(accessMode != Property::ANIMATABLE && "Animatable must have scenegraph property") ;
+ DALI_ASSERT_DEBUG(accessMode != Property::ANIMATABLE && "Event side only properties should not be animatable");
}
/**
- * @return true if the property can be written to
+ * @brief Destructor.
*/
- virtual bool IsWritable(void) const
- {
- return (mAccessMode == Property::ANIMATABLE) || (mAccessMode == Property::READ_WRITE) ;
- }
-
- std::string name; ///< The name of the property
+ ~CustomPropertyMetadata() override = default;
private:
-
// Not implemented
CustomPropertyMetadata();
- CustomPropertyMetadata( const CustomPropertyMetadata& );
- CustomPropertyMetadata& operator=( const CustomPropertyMetadata& );
+ CustomPropertyMetadata(const CustomPropertyMetadata&);
+ CustomPropertyMetadata& operator=(const CustomPropertyMetadata&);
-private:
- Property::AccessMode mAccessMode; ///< The mode of the property
+public: // Data
+ ConstString name; ///< The name of the property.
+ Property::Index key; ///< The key of the property.
+ Property::Index childPropertyIndex; ///< The index as a child property.
};
} // namespace Internal
} // namespace Dali
-#endif // __DALI_INTERNAL_PROPERTY_METADATA_H__
+#endif // DALI_INTERNAL_PROPERTY_METADATA_H