1 #ifndef DALI_INTERNAL_PROPERTY_METADATA_H
2 #define DALI_INTERNAL_PROPERTY_METADATA_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
26 #include <dali/internal/common/const-string.h>
27 #include <dali/public-api/common/constants.h>
28 #include <dali/public-api/object/property-value.h>
29 #include <dali/public-api/object/property.h>
41 * @brief Base class for the Metadata required by custom and registered animatable properties.
43 * The value type field should be queried, before accessing the scene-graph property:
46 * void Example(PropertyEntry entry)
48 * if (entry.value.GetType() == Property::VECTOR3)
50 * SceneGraph::AnimatableProperty<Vector3>* property = dynamic_cast< SceneGraph::AnimatableProperty<Vector3>* >( entry.property );
56 class PropertyMetadata
60 * @brief Virtual Destructor.
62 virtual ~PropertyMetadata() = default;
65 * @brief Returns whether the property is animatable (i.e. if its a scene graph property).
66 * @return True if animatable, false otherwise
68 bool IsAnimatable(void) const
70 return nullptr != mSceneGraphProperty;
74 * @brief Whether the property can be written to.
75 * @return True if the property can be written to, false otherwise
77 bool IsWritable(void) const
83 * @brief Retrieves the scene-graph property.
84 * @return The scene graph property
86 * @note Should only be called if the scene-graph property was passed in originally. Will debug assert if the stored property is NULL.
88 const SceneGraph::PropertyBase* GetSceneGraphProperty() const
90 DALI_ASSERT_DEBUG(mSceneGraphProperty && "Accessing uninitialized SceneGraph property");
91 return mSceneGraphProperty;
95 * @brief Retrieve the type of the property.
96 * @return Type of the held property value
98 inline Property::Type GetType() const
100 return value.GetType();
104 * Set the cached value of the property.
105 * @param[in] value The propertyValue to set.
107 void SetPropertyValue(const Property::Value& propertyValue);
110 * Get the cached value of a the property.
111 * @return The cached value of the property.
113 Property::Value GetPropertyValue() const;
116 * Modifies the stored value by the relativeValue.
117 * @param[in] relativeValue The value to change by.
119 void AdjustPropertyValueBy(const Property::Value& relativeValue);
123 * @brief Constructor to create Metadata for a property.
124 * @param[in] propertyValue The value of the property (this is used by the event thread)
125 * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
126 * @param[in] writable Whether the property is writable
128 PropertyMetadata(Property::Value propertyValue,
129 const SceneGraph::PropertyBase* sceneGraphProperty,
131 : value(mStoredValue),
132 componentIndex(Property::INVALID_COMPONENT_INDEX),
133 mStoredValue(std::move(propertyValue)),
134 mSceneGraphProperty(sceneGraphProperty),
140 * @brief Constructor to create Metadata for a component of another property.
141 * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
142 * @param[in] writable Whether the property is writable
143 * @param[in] baseValueRef A reference to the metadata of the base animatable property
144 * @param[in] propertyComponentIndex The component index of the property
146 PropertyMetadata(const SceneGraph::PropertyBase* sceneGraphProperty, bool writable, Property::Value& baseValueRef, int32_t propertyComponentIndex)
147 : value(baseValueRef),
148 componentIndex(propertyComponentIndex),
150 mSceneGraphProperty(sceneGraphProperty),
157 PropertyMetadata(const PropertyMetadata&);
158 PropertyMetadata& operator=(const PropertyMetadata&);
162 * @brief The value of this property used to read/write by the event thread.
164 * If this PropertyMetadata is for property component, then refers to the value in the PropertyMetadata of the base property
165 * to ensure the components are kept in sync with the overall value on the event thread.
166 * Otherwise, this refers to mStoredValue.
168 Property::Value& value;
171 * @brief The index of the property component.
173 int32_t componentIndex;
176 Property::Value mStoredValue; ///< The cached property value used to read/write by the event thread
177 const SceneGraph::PropertyBase* mSceneGraphProperty; ///< A pointer to a scene-graph property; should not be modified from actor-thread
178 bool mWritable : 1; ///< Whether the property is writable
182 * @brief Metadata for a registered animatable property.
184 class AnimatablePropertyMetadata : public PropertyMetadata
188 * @brief Constructs metadata for a registered animatable property.
189 * @param[in] propertyIndex The index of the animatable property
190 * @param[in] propertyComponentIndex The component index of the animatable property
191 * @param[in] propertyValue The value of the property (this is used by the event thread)
192 * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
194 * @note The base animatable property MUST be created before the component animatable property.
196 AnimatablePropertyMetadata(Property::Index propertyIndex,
197 const Property::Value& propertyValue,
198 const SceneGraph::PropertyBase* sceneGraphProperty)
199 : PropertyMetadata(propertyValue, sceneGraphProperty, true),
202 DALI_ASSERT_DEBUG(sceneGraphProperty && "Uninitialized scene-graph property");
206 * @brief Constructs metadata for a registered animatable component of another property.
207 * @param[in] propertyIndex The index of the animatable property
208 * @param[in] propertyComponentIndex The component index of the animatable property
209 * @param[in] baseValueRef A reference to the metadata of the base animatable property
210 * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
212 * @note The base animatable property MUST be created before the component animatable property.
214 AnimatablePropertyMetadata(Property::Index propertyIndex,
215 int propertyComponentIndex,
216 Property::Value& baseValueRef,
217 const SceneGraph::PropertyBase* sceneGraphProperty)
218 : PropertyMetadata(sceneGraphProperty, true, baseValueRef, propertyComponentIndex),
221 DALI_ASSERT_DEBUG(sceneGraphProperty && "Uninitialized scene-graph property");
227 ~AnimatablePropertyMetadata() override = default;
231 AnimatablePropertyMetadata();
232 AnimatablePropertyMetadata(const AnimatablePropertyMetadata&);
233 AnimatablePropertyMetadata& operator=(const AnimatablePropertyMetadata&);
236 Property::Index index; ///< The index of the property.
239 class CustomPropertyMetadata : public PropertyMetadata
243 * Constructs Metadata for scene-graph-based custom properties, i.e. animatable custom properties.
244 * @param[in] propertyName The name of the custom property
245 * @param[in] propertyKey The key of the custom property
246 * @param[in] propertyValue The value of the property (this is used by the event thread)
247 * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
249 * @note A valid sceneGraphProperty is mandatory otherwise this will debug assert.
251 CustomPropertyMetadata(ConstString propertyName,
252 Property::Index propertyKey,
253 Property::Value propertyValue,
254 const SceneGraph::PropertyBase* sceneGraphProperty)
255 : PropertyMetadata(std::move(propertyValue), sceneGraphProperty, true),
258 childPropertyIndex(Property::INVALID_INDEX)
260 DALI_ASSERT_DEBUG(sceneGraphProperty && "Uninitialized scene-graph property");
264 * Constructs metadata for event side only custom properties.
265 * @param[in] propertyName The name of the custom property
266 * @param[in] propertyValue The value of the property (this is used by the event thread)
267 * @param[in] accessMode The access mode of the custom property (writable, animatable etc)
269 * @note The access mode MUST NOT be animatable otherwise this will debug assert.
271 CustomPropertyMetadata(ConstString propertyName,
272 Property::Value propertyValue,
273 Property::AccessMode accessMode)
274 : PropertyMetadata(std::move(propertyValue), nullptr, (accessMode != Property::READ_ONLY)),
276 key(Property::INVALID_KEY),
277 childPropertyIndex(Property::INVALID_INDEX)
279 DALI_ASSERT_DEBUG(accessMode != Property::ANIMATABLE && "Event side only properties should not be animatable");
285 ~CustomPropertyMetadata() override = default;
289 CustomPropertyMetadata();
290 CustomPropertyMetadata(const CustomPropertyMetadata&);
291 CustomPropertyMetadata& operator=(const CustomPropertyMetadata&);
294 ConstString name; ///< The name of the property.
295 Property::Index key; ///< The key of the property.
296 Property::Index childPropertyIndex; ///< The index as a child property.
299 } // namespace Internal
303 #endif // DALI_INTERNAL_PROPERTY_METADATA_H