1 #ifndef __DALI_HANDLE_H__
2 #define __DALI_HANDLE_H__
5 * Copyright (c) 2018 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.
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/object/base-handle.h>
27 #include <dali/public-api/object/property-types.h>
28 #include <dali/public-api/object/property-value.h>
29 #include <dali/public-api/object/property-notification-declarations.h>
30 #include <dali/public-api/object/ref-object.h>
35 * @addtogroup dali_core_object
40 class PropertyNotification;
41 class PropertyCondition;
43 namespace Internal DALI_INTERNAL
49 * @brief Dali::Handle is a handle to an internal property owning Dali object that can have constraints applied to it.
52 class DALI_CORE_API Handle : public BaseHandle
57 * @brief Enumeration for Handle's capabilities that can be queried using Handle::Supports().
63 * @brief Some objects support dynamic property creation at run-time.
65 * New properties are registered by calling RegisterProperty() with an unused property name.
68 DYNAMIC_PROPERTIES = 0x01,
74 * @brief This constructor is used by Dali New() methods.
77 * @param[in] handle A pointer to a newly allocated Dali resource
79 Handle( Dali::Internal::Object* handle );
82 * @brief This constructor provides an uninitialized Dali::Handle.
84 * This should be initialized with a Dali New() method before use.
85 * Methods called on an uninitialized Dali::Handle will assert.
87 * Handle handle; // uninitialized
88 * handle.SomeMethod(); // unsafe! This will assert
90 * handle = SomeClass::New(); // now initialized
91 * handle.SomeMethod(); // safe
98 * @brief Creates a new object.
101 * @return A handle to a newly allocated object
106 * @brief Dali::Handle is intended as a base class.
108 * This is non-virtual since derived Handle types must not contain data or virtual methods.
114 * @brief This copy constructor is required for (smart) pointer semantics.
117 * @param[in] handle A reference to the copied handle
119 Handle( const Handle& handle );
122 * @brief This assignment operator is required for (smart) pointer semantics.
125 * @param[in] rhs A reference to the copied handle
126 * @return A reference to this
128 Handle& operator=( const Handle& rhs );
131 * @brief Downcasts to a handle.
133 * If not, the returned handle is left uninitialized.
135 * @param[in] handle to An object
136 * @return handle or an uninitialized handle
138 static Handle DownCast( BaseHandle handle );
141 * @brief Queries whether an handle supports a given capability.
144 * @param[in] capability The queried capability
145 * @return True if the capability is supported
147 bool Supports( Capability capability ) const;
152 * @brief Queries how many properties are provided by an handle.
154 * This may vary between instances of a class, if dynamic properties are supported.
156 * @return The number of properties
158 unsigned int GetPropertyCount() const;
161 * @brief Queries the name of a property.
164 * @param[in] index The index of the property
165 * @return The name of the property
167 std::string GetPropertyName( Property::Index index ) const;
170 * @brief Queries the index of a property.
172 * Returns the first property index that matches the given name exactly.
175 * @param[in] name The name of the property
176 * @return The index of the property, or Property::INVALID_INDEX if no property exists with the given name
178 Property::Index GetPropertyIndex( const std::string& name ) const;
181 * @brief Queries whether a property can be set using SetProperty().
184 * @param[in] index The index of the property
185 * @return True if the property is writable
186 * @pre Property::INVALID_INDEX < index.
188 bool IsPropertyWritable( Property::Index index ) const;
191 * @brief Queries whether a writable property can be the target of an animation or constraint.
194 * @param[in] index The index of the property
195 * @return True if the property is animatable
197 bool IsPropertyAnimatable( Property::Index index ) const;
200 * @brief Queries whether a property can be used as in input to a constraint.
203 * @param[in] index The index of the property
204 * @return True if the property can be used as a constraint input
206 bool IsPropertyAConstraintInput( Property::Index index ) const;
209 * @brief Queries the type of a property.
212 * @param[in] index The index of the property
213 * @return The type of the property
215 Property::Type GetPropertyType( Property::Index index ) const;
218 * @brief Sets the value of an existing property.
220 * Property should be write-able. Setting a read-only property is a no-op.
222 * @param[in] index The index of the property
223 * @param[in] propertyValue The new value of the property
224 * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
226 void SetProperty( Property::Index index, const Property::Value& propertyValue );
229 * @brief Registers a new animatable property.
232 * @param[in] name The name of the property
233 * @param[in] propertyValue The new value of the property
234 * @return The index of the property or Property::INVALID_INDEX if registration failed
235 * @pre The object supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
236 * Property names are expected to be unique, but this is not enforced.
237 * Property indices are unique to each registered custom property in a given object.
238 * returns Property::INVALID_INDEX if registration failed. This can happen if you try to register
239 * animatable property on an object that does not have scene graph object.
240 * @note Only the following types can be animated:
241 * - Property::BOOLEAN
243 * - Property::INTEGER
244 * - Property::VECTOR2
245 * - Property::VECTOR3
246 * - Property::VECTOR4
247 * - Property::MATRIX3
249 * - Property::ROTATION
250 * @note If a property with the desired name already exists, then the value given is just set.
252 Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue );
255 * @brief Registers a new property.
257 * Properties can be set as non animatable using property attributes.
259 * @param[in] name The name of the property
260 * @param[in] propertyValue The new value of the property
261 * @param[in] accessMode The property access mode (writable, animatable etc)
262 * @return The index of the property
263 * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
264 * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
265 * @note Only the following types can be animated:
266 * - Property::BOOLEAN
268 * - Property::INTEGER
269 * - Property::VECTOR2
270 * - Property::VECTOR3
271 * - Property::VECTOR4
272 * - Property::MATRIX3
274 * - Property::ROTATION
275 * @note If a property with the desired name already exists, then the value given is just set.
277 Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );
280 * @brief Retrieves a property value.
283 * @param[in] index The index of the property
284 * @return The property value
286 Property::Value GetProperty( Property::Index index ) const;
289 * @brief Convenience function for obtaining a property of a known type.
292 * @param[in] index The index of the property
293 * @return The property value
294 * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
296 template <typename T>
297 T GetProperty( Property::Index index ) const
299 Property::Value value = GetProperty(index);
301 return T( value.Get<T>() );
305 * @brief Retrieves the latest value of the property from the scene-graph.
308 * @param[in] index The index of the property
309 * @return The property value
311 Property::Value GetCurrentProperty( Property::Index index ) const;
314 * @brief Convenience function for obtaining the current value of a property of a known type.
317 * @param[in] index The index of the property
318 * @return The property value
319 * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
321 template <typename T>
322 T GetCurrentProperty( Property::Index index ) const
324 Property::Value value = GetCurrentProperty( index );
326 return T( value.Get<T>() );
330 * @brief Retrieves all the property indices for this object (including custom properties).
333 * @param[out] indices A container of property indices for this object
334 * @note The added container is cleared.
336 void GetPropertyIndices( Property::IndexContainer& indices ) const;
339 * @brief Adds a property notification to this object.
342 * @param[in] index The index of the property
343 * @param[in] condition The notification will be triggered when this condition is satisfied
344 * @return A handle to the newly created PropertyNotification
346 PropertyNotification AddPropertyNotification( Property::Index index,
347 const PropertyCondition& condition );
350 * @brief Adds a property notification to this object.
353 * @param[in] index The index of the property
354 * @param[in] componentIndex Index to the component of a complex property such as a Vector
355 * @param[in] condition The notification will be triggered when this condition is satisfied
356 * @return A handle to the newly created PropertyNotification
358 PropertyNotification AddPropertyNotification( Property::Index index,
360 const PropertyCondition& condition );
363 * @brief Removes a property notification from this object.
366 * @param[in] propertyNotification The propertyNotification to be removed
368 void RemovePropertyNotification( Dali::PropertyNotification propertyNotification );
371 * @brief Removes all property notifications from this object.
374 void RemovePropertyNotifications();
379 * @brief Removes all constraints from an Object.
382 * @pre The object has been initialized.
384 void RemoveConstraints();
387 * @brief Removes all the constraint from the Object with a matching tag.
390 * @param[in] tag The tag of the constraints which will be removed
391 * @pre The Object has been initialized.
393 void RemoveConstraints( unsigned int tag );
397 * @brief This namespace provides a convenient function to create an object with a custom "weight" property.
400 namespace WeightObject
403 DALI_CORE_API extern const Property::Index WEIGHT; ///< name "weight", type FLOAT
406 * @brief Convenience function to create an object with a custom "weight" property.
409 * @return A handle to a newly allocated object
411 DALI_CORE_API Handle New();
413 } // namespace WeightObject
420 #endif // __DALI_HANDLE_H__