1 #ifndef __DALI_INTERNAL_PROPERTY_METADATA_H__
2 #define __DALI_INTERNAL_PROPERTY_METADATA_H__
5 * Copyright (c) 2017 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;
122 * @brief Constructor to create Metadata for a property.
123 * @param[in] propertyValue The value of the property (this is used by the event thread)
124 * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
125 * @param[in] writable Whether the property is writable
127 PropertyMetadata( const Property::Value& propertyValue,
128 const SceneGraph::PropertyBase* sceneGraphProperty,
130 : value( mStoredValue ),
131 componentIndex( Property::INVALID_COMPONENT_INDEX ),
132 mStoredValue( propertyValue ),
133 mSceneGraphProperty( sceneGraphProperty ),
134 mWritable( writable )
139 * @brief Constructor to create Metadata for a component of another property.
140 * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
141 * @param[in] writable Whether the property is writable
142 * @param[in] baseValueRef A reference to the metadata of the base animatable property
143 * @param[in] propertyComponentIndex The component index of the property
145 PropertyMetadata( const SceneGraph::PropertyBase* sceneGraphProperty, bool writable, Property::Value& baseValueRef, int propertyComponentIndex )
146 : value( baseValueRef ),
147 componentIndex( propertyComponentIndex ),
149 mSceneGraphProperty( sceneGraphProperty ),
150 mWritable( writable )
157 PropertyMetadata( const PropertyMetadata& );
158 PropertyMetadata& operator=( const PropertyMetadata& );
163 * @brief The value of this property used to read/write by the event thread.
165 * If a component index, then refers to the value in the PropertyMetatdata of the base property
166 * to ensure the components are kept in sync with the overall value on the event thread.
167 * Otherwise, this just refers to the storedValue.
169 Property::Value& value;
172 * @brief The index of the property component.
178 Property::Value mStoredValue; ///< The stored property value used to read/write by the event thread
179 const SceneGraph::PropertyBase* mSceneGraphProperty; ///< A pointer to a scene-graph property; should not be modified from actor-thread
180 bool mWritable:1; ///< Whether the property is writable
184 * @brief Metadata for a registered animatable property.
186 class AnimatablePropertyMetadata : public PropertyMetadata
191 * @brief Constructs metadata for a registered animatable property.
192 * @param[in] propertyIndex The index of the animatable property
193 * @param[in] propertyComponentIndex The component index of the animatable property
194 * @param[in] propertyValue The value of the property (this is used by the event thread)
195 * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
197 * @note The base animatable property MUST be created before the component animatable property.
199 AnimatablePropertyMetadata( Property::Index propertyIndex,
200 const Property::Value& propertyValue,
201 const SceneGraph::PropertyBase* sceneGraphProperty )
202 : PropertyMetadata( propertyValue, sceneGraphProperty, true ),
203 index( propertyIndex )
205 DALI_ASSERT_DEBUG( sceneGraphProperty && "Uninitialized scene-graph property" );
209 * @brief Constructs metadata for a registered animatable component of another property.
210 * @param[in] propertyIndex The index of the animatable property
211 * @param[in] propertyComponentIndex The component index of the animatable property
212 * @param[in] baseValueRef A reference to the metadata of the base animatable property
213 * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
215 * @note The base animatable property MUST be created before the component animatable property.
217 AnimatablePropertyMetadata( Property::Index propertyIndex,
218 int propertyComponentIndex,
219 Property::Value& baseValueRef,
220 const SceneGraph::PropertyBase* sceneGraphProperty )
221 : PropertyMetadata( sceneGraphProperty, true, baseValueRef, propertyComponentIndex ),
222 index( propertyIndex )
224 DALI_ASSERT_DEBUG( sceneGraphProperty && "Uninitialized scene-graph property" );
230 virtual ~AnimatablePropertyMetadata()
237 AnimatablePropertyMetadata();
238 AnimatablePropertyMetadata( const AnimatablePropertyMetadata& );
239 AnimatablePropertyMetadata& operator=( const AnimatablePropertyMetadata& );
243 Property::Index index; ///< The index of the property.
246 class CustomPropertyMetadata : public PropertyMetadata
251 * Constructs Metadata for scene-graph-based custom properties, i.e. animatable custom properties.
252 * @param[in] propertyName The name of the custom property
253 * @param[in] propertyKey The key of the custom property
254 * @param[in] propertyValue The value of the property (this is used by the event thread)
255 * @param[in] sceneGraphProperty A pointer to the scene-graph owned property
257 * @note A valid sceneGraphProperty is mandatory otherwise this will debug assert.
259 CustomPropertyMetadata( const std::string& propertyName,
260 Property::Index propertyKey,
261 const Property::Value& propertyValue,
262 const SceneGraph::PropertyBase* sceneGraphProperty )
263 : PropertyMetadata( propertyValue, sceneGraphProperty, true ),
264 name( propertyName ),
266 childPropertyIndex( Property::INVALID_INDEX )
268 DALI_ASSERT_DEBUG( sceneGraphProperty && "Uninitialized scene-graph property" );
272 * Constructs metadata for event side only custom properties.
273 * @param[in] propertyName The name of the custom property
274 * @param[in] propertyValue The value of the property (this is used by the event thread)
275 * @param[in] accessMode The access mode of the custom property (writable, animatable etc)
277 * @note The access mode MUST NOT be animatable otherwise this will debug assert.
279 CustomPropertyMetadata( const std::string& propertyName,
280 const Property::Value& propertyValue,
281 Property::AccessMode accessMode )
282 : PropertyMetadata( propertyValue, NULL, ( accessMode != Property::READ_ONLY ) ),
283 name( propertyName ),
284 key( Property::INVALID_KEY ),
285 childPropertyIndex( Property::INVALID_INDEX )
287 DALI_ASSERT_DEBUG( accessMode != Property::ANIMATABLE && "Event side only properties should not be animatable" );
293 virtual ~CustomPropertyMetadata()
300 CustomPropertyMetadata();
301 CustomPropertyMetadata( const CustomPropertyMetadata& );
302 CustomPropertyMetadata& operator=( const CustomPropertyMetadata& );
306 std::string name; ///< The name of the property.
307 Property::Index key; ///< The key of the property.
308 Property::Index childPropertyIndex; ///< The index as a child property.
311 } // namespace Internal
315 #endif // __DALI_INTERNAL_PROPERTY_METADATA_H__