1 #ifndef DALI_INTERNAL_PROPERTY_METADATA_H
2 #define DALI_INTERNAL_PROPERTY_METADATA_H
5 * Copyright (c) 2019 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/public-api/common/constants.h>
27 #include <dali/public-api/object/property.h>
28 #include <dali/public-api/object/property-value.h>
42 * @brief Base class for the Metadata required by custom and registered animatable properties.
44 * The value type field should be queried, before accessing the scene-graph property:
47 * void Example(PropertyEntry entry)
49 * if (entry.value.GetType() == Property::VECTOR3)
51 * SceneGraph::AnimatableProperty<Vector3>* property = dynamic_cast< SceneGraph::AnimatableProperty<Vector3>* >( entry.property );
57 class PropertyMetadata
62 * @brief Virtual Destructor.
64 virtual ~PropertyMetadata()
69 * @brief Returns whether the property is animatable (i.e. if its a scene graph property).
70 * @return True if animatable, false otherwise
72 bool IsAnimatable( void ) const
74 return NULL != mSceneGraphProperty;
78 * @brief Whether the property can be written to.
79 * @return True if the property can be written to, false otherwise
81 bool IsWritable( void ) const
87 * @brief Retrieves the scene-graph property.
88 * @return The scene graph property
90 * @note Should only be called if the scene-graph property was passed in originally. Will debug assert if the stored property is NULL.
92 const SceneGraph::PropertyBase* GetSceneGraphProperty() const
94 DALI_ASSERT_DEBUG( mSceneGraphProperty && "Accessing uninitialized SceneGraph property" );
95 return mSceneGraphProperty;
99 * @brief Retrieve the type of the property.
100 * @return Type of the held property value
102 inline Property::Type GetType() const
104 return value.GetType();
108 * Set the cached value of the property.
109 * @param[in] value The propertyValue to set.
111 void SetPropertyValue( const Property::Value& propertyValue );
114 * Get the cached value of a the property.
115 * @return The cached value of the property.
117 Property::Value GetPropertyValue() const;
120 * Modifies the stored value by the relativeValue.
121 * @param[in] relativeValue The value to change by.
123 void AdjustPropertyValueBy( const Property::Value& relativeValue );
128 * @brief Constructor to create Metadata for a property.
129 * @param[in] propertyValue The value of the property (this is used by the event thread)
130 * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
131 * @param[in] writable Whether the property is writable
133 PropertyMetadata( const Property::Value& propertyValue,
134 const SceneGraph::PropertyBase* sceneGraphProperty,
136 : value( mStoredValue ),
137 componentIndex( Property::INVALID_COMPONENT_INDEX ),
138 mStoredValue( propertyValue ),
139 mSceneGraphProperty( sceneGraphProperty ),
140 mWritable( writable )
145 * @brief Constructor to create Metadata for a component of another property.
146 * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
147 * @param[in] writable Whether the property is writable
148 * @param[in] baseValueRef A reference to the metadata of the base animatable property
149 * @param[in] propertyComponentIndex The component index of the property
151 PropertyMetadata( const SceneGraph::PropertyBase* sceneGraphProperty, bool writable, Property::Value& baseValueRef, int32_t propertyComponentIndex )
152 : value( baseValueRef ),
153 componentIndex( propertyComponentIndex ),
155 mSceneGraphProperty( sceneGraphProperty ),
156 mWritable( writable )
163 PropertyMetadata( const PropertyMetadata& );
164 PropertyMetadata& operator=( const PropertyMetadata& );
169 * @brief The value of this property used to read/write by the event thread.
171 * If this PropertyMetadata is for property component, then refers to the value in the PropertyMetadata of the base property
172 * to ensure the components are kept in sync with the overall value on the event thread.
173 * Otherwise, this refers to mStoredValue.
175 Property::Value& value;
178 * @brief The index of the property component.
180 int32_t componentIndex;
184 Property::Value mStoredValue; ///< The cached property value used to read/write by the event thread
185 const SceneGraph::PropertyBase* mSceneGraphProperty; ///< A pointer to a scene-graph property; should not be modified from actor-thread
186 bool mWritable:1; ///< Whether the property is writable
190 * @brief Metadata for a registered animatable property.
192 class AnimatablePropertyMetadata : public PropertyMetadata
197 * @brief Constructs metadata for a registered animatable property.
198 * @param[in] propertyIndex The index of the animatable property
199 * @param[in] propertyComponentIndex The component index of the animatable property
200 * @param[in] propertyValue The value of the property (this is used by the event thread)
201 * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
203 * @note The base animatable property MUST be created before the component animatable property.
205 AnimatablePropertyMetadata( Property::Index propertyIndex,
206 const Property::Value& propertyValue,
207 const SceneGraph::PropertyBase* sceneGraphProperty )
208 : PropertyMetadata( propertyValue, sceneGraphProperty, true ),
209 index( propertyIndex )
211 DALI_ASSERT_DEBUG( sceneGraphProperty && "Uninitialized scene-graph property" );
215 * @brief Constructs metadata for a registered animatable component of another property.
216 * @param[in] propertyIndex The index of the animatable property
217 * @param[in] propertyComponentIndex The component index of the animatable property
218 * @param[in] baseValueRef A reference to the metadata of the base animatable property
219 * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
221 * @note The base animatable property MUST be created before the component animatable property.
223 AnimatablePropertyMetadata( Property::Index propertyIndex,
224 int propertyComponentIndex,
225 Property::Value& baseValueRef,
226 const SceneGraph::PropertyBase* sceneGraphProperty )
227 : PropertyMetadata( sceneGraphProperty, true, baseValueRef, propertyComponentIndex ),
228 index( propertyIndex )
230 DALI_ASSERT_DEBUG( sceneGraphProperty && "Uninitialized scene-graph property" );
236 ~AnimatablePropertyMetadata() override
243 AnimatablePropertyMetadata();
244 AnimatablePropertyMetadata( const AnimatablePropertyMetadata& );
245 AnimatablePropertyMetadata& operator=( const AnimatablePropertyMetadata& );
249 Property::Index index; ///< The index of the property.
252 class CustomPropertyMetadata : public PropertyMetadata
257 * Constructs Metadata for scene-graph-based custom properties, i.e. animatable custom properties.
258 * @param[in] propertyName The name of the custom property
259 * @param[in] propertyKey The key of the custom property
260 * @param[in] propertyValue The value of the property (this is used by the event thread)
261 * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
263 * @note A valid sceneGraphProperty is mandatory otherwise this will debug assert.
265 CustomPropertyMetadata( const std::string& propertyName,
266 Property::Index propertyKey,
267 const Property::Value& propertyValue,
268 const SceneGraph::PropertyBase* sceneGraphProperty )
269 : PropertyMetadata( propertyValue, sceneGraphProperty, true ),
270 name( propertyName ),
272 childPropertyIndex( Property::INVALID_INDEX )
274 DALI_ASSERT_DEBUG( sceneGraphProperty && "Uninitialized scene-graph property" );
278 * Constructs metadata for event side only custom properties.
279 * @param[in] propertyName The name of the custom property
280 * @param[in] propertyValue The value of the property (this is used by the event thread)
281 * @param[in] accessMode The access mode of the custom property (writable, animatable etc)
283 * @note The access mode MUST NOT be animatable otherwise this will debug assert.
285 CustomPropertyMetadata( const std::string& propertyName,
286 const Property::Value& propertyValue,
287 Property::AccessMode accessMode )
288 : PropertyMetadata( propertyValue, NULL, ( accessMode != Property::READ_ONLY ) ),
289 name( propertyName ),
290 key( Property::INVALID_KEY ),
291 childPropertyIndex( Property::INVALID_INDEX )
293 DALI_ASSERT_DEBUG( accessMode != Property::ANIMATABLE && "Event side only properties should not be animatable" );
299 ~CustomPropertyMetadata() override
306 CustomPropertyMetadata();
307 CustomPropertyMetadata( const CustomPropertyMetadata& );
308 CustomPropertyMetadata& operator=( const CustomPropertyMetadata& );
312 std::string name; ///< The name of the property.
313 Property::Index key; ///< The key of the property.
314 Property::Index childPropertyIndex; ///< The index as a child property.
317 } // namespace Internal
321 #endif // DALI_INTERNAL_PROPERTY_METADATA_H