5 * Copyright (c) 2020 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.
23 #include <cstdint> // uint32_t
26 #include <dali/public-api/common/dali-common.h>
27 #include <dali/public-api/object/base-handle.h>
28 #include <dali/public-api/object/property-types.h>
29 #include <dali/public-api/object/property-value.h>
30 #include <dali/public-api/object/property-notification-declarations.h>
31 #include <dali/public-api/object/ref-object.h>
36 * @addtogroup dali_core_object
41 class PropertyNotification;
42 class PropertyCondition;
44 namespace Internal DALI_INTERNAL
50 * @brief Dali::Handle is a handle to an internal property owning Dali object that can have constraints applied to it.
53 class DALI_CORE_API Handle : public BaseHandle
58 * @brief Enumeration for Handle's capabilities that can be queried using Handle::Supports().
64 * @brief Some objects support dynamic property creation at run-time.
66 * New properties are registered by calling RegisterProperty() with an unused property name.
69 DYNAMIC_PROPERTIES = 0x01,
75 * @brief This constructor is used by Dali New() methods.
78 * @param[in] handle A pointer to a newly allocated Dali resource
80 Handle( Dali::Internal::Object* handle );
83 * @brief This constructor provides an uninitialized Dali::Handle.
85 * This should be initialized with a Dali New() method before use.
86 * Methods called on an uninitialized Dali::Handle will assert.
88 * Handle handle; // uninitialized
89 * handle.SomeMethod(); // unsafe! This will assert
91 * handle = SomeClass::New(); // now initialized
92 * handle.SomeMethod(); // safe
99 * @brief Creates a new object.
102 * @return A handle to a newly allocated object
107 * @brief Dali::Handle is intended as a base class.
109 * This is non-virtual since derived Handle types must not contain data or virtual methods.
115 * @brief This copy constructor is required for (smart) pointer semantics.
118 * @param[in] handle A reference to the copied handle
120 Handle( const Handle& handle );
123 * @brief This assignment operator is required for (smart) pointer semantics.
126 * @param[in] rhs A reference to the copied handle
127 * @return A reference to this
129 Handle& operator=( const Handle& rhs );
132 * @brief Move constructor.
135 * @param[in] rhs A reference to the moved handle
137 Handle( Handle&& rhs );
140 * @brief Move assignment operator.
143 * @param[in] rhs A reference to the moved handle
144 * @return A reference to this handle
146 Handle& operator=( Handle&& rhs );
149 * @brief Downcasts to a handle.
151 * If not, the returned handle is left uninitialized.
153 * @param[in] handle to An object
154 * @return handle or an uninitialized handle
156 static Handle DownCast( BaseHandle handle );
159 * @brief Queries whether an handle supports a given capability.
162 * @param[in] capability The queried capability
163 * @return True if the capability is supported
165 bool Supports( Capability capability ) const;
170 * @brief Queries how many properties are provided by an handle.
172 * This may vary between instances of a class, if dynamic properties are supported.
174 * @return The number of properties
176 uint32_t GetPropertyCount() const;
179 * @brief Queries the name of a property.
182 * @param[in] index The index of the property
183 * @return The name of the property
185 std::string GetPropertyName( Property::Index index ) const;
188 * @brief Queries the index of a property.
190 * Returns the first property index that matches the given name exactly.
193 * @param[in] name The name of the property
194 * @return The index of the property, or Property::INVALID_INDEX if no property exists with the given name
196 Property::Index GetPropertyIndex( const std::string& name ) const;
199 * @brief Queries whether a property can be set using SetProperty().
202 * @param[in] index The index of the property
203 * @return True if the property is writable
204 * @pre Property::INVALID_INDEX < index.
206 bool IsPropertyWritable( Property::Index index ) const;
209 * @brief Queries whether a writable property can be the target of an animation or constraint.
212 * @param[in] index The index of the property
213 * @return True if the property is animatable
215 bool IsPropertyAnimatable( Property::Index index ) const;
218 * @brief Queries whether a property can be used as in input to a constraint.
221 * @param[in] index The index of the property
222 * @return True if the property can be used as a constraint input
224 bool IsPropertyAConstraintInput( Property::Index index ) const;
227 * @brief Queries the type of a property.
230 * @param[in] index The index of the property
231 * @return The type of the property
233 Property::Type GetPropertyType( Property::Index index ) const;
236 * @brief Sets the value of an existing property.
238 * Property should be write-able. Setting a read-only property is a no-op.
240 * @param[in] index The index of the property
241 * @param[in] propertyValue The new value of the property
242 * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
244 void SetProperty( Property::Index index, const Property::Value& propertyValue );
247 * @brief Registers a new animatable property.
250 * @param[in] name The name of the property
251 * @param[in] propertyValue The new value of the property
252 * @return The index of the property or Property::INVALID_INDEX if registration failed
253 * @pre The object supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
254 * Property names are expected to be unique, but this is not enforced.
255 * Property indices are unique to each registered custom property in a given object.
256 * returns Property::INVALID_INDEX if registration failed. This can happen if you try to register
257 * animatable property on an object that does not have scene graph object.
258 * @note Only the following types can be animated:
259 * - Property::BOOLEAN
261 * - Property::INTEGER
262 * - Property::VECTOR2
263 * - Property::VECTOR3
264 * - Property::VECTOR4
265 * - Property::MATRIX3
267 * - Property::ROTATION
268 * @note If a property with the desired name already exists, then the value given is just set.
270 Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue );
273 * @brief Registers a new property.
275 * Properties can be set as non animatable using property attributes.
277 * @param[in] name The name of the property
278 * @param[in] propertyValue The new value of the property
279 * @param[in] accessMode The property access mode (writable, animatable etc)
280 * @return The index of the property
281 * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
282 * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
283 * @note Only the following types can be animated:
284 * - Property::BOOLEAN
286 * - Property::INTEGER
287 * - Property::VECTOR2
288 * - Property::VECTOR3
289 * - Property::VECTOR4
290 * - Property::MATRIX3
292 * - Property::ROTATION
293 * @note If a property with the desired name already exists, then the value given is just set.
295 Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );
298 * @brief Retrieves a property value.
301 * @param[in] index The index of the property
302 * @return The property value
304 Property::Value GetProperty( Property::Index index ) const;
307 * @brief Convenience function for obtaining a property of a known type.
310 * @param[in] index The index of the property
311 * @return The property value
312 * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
314 template <typename T>
315 T GetProperty( Property::Index index ) const
317 Property::Value value = GetProperty(index);
319 return T( value.Get<T>() );
323 * @brief Retrieves the latest value of the property from the scene-graph.
326 * @param[in] index The index of the property
327 * @return The property value
329 Property::Value GetCurrentProperty( Property::Index index ) const;
332 * @brief Convenience function for obtaining the current value of a property of a known type.
335 * @param[in] index The index of the property
336 * @return The property value
337 * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
339 template <typename T>
340 T GetCurrentProperty( Property::Index index ) const
342 Property::Value value = GetCurrentProperty( index );
344 return T( value.Get<T>() );
348 * @brief Retrieves all the property indices for this object (including custom properties).
351 * @param[out] indices A container of property indices for this object
352 * @note The added container is cleared.
354 void GetPropertyIndices( Property::IndexContainer& indices ) const;
357 * @brief Adds a property notification to this object.
360 * @param[in] index The index of the property
361 * @param[in] condition The notification will be triggered when this condition is satisfied
362 * @return A handle to the newly created PropertyNotification
364 PropertyNotification AddPropertyNotification( Property::Index index,
365 const PropertyCondition& condition );
368 * @brief Adds a property notification to this object.
371 * @param[in] index The index of the property
372 * @param[in] componentIndex Index to the component of a complex property such as a Vector
373 * @param[in] condition The notification will be triggered when this condition is satisfied
374 * @return A handle to the newly created PropertyNotification
376 PropertyNotification AddPropertyNotification( Property::Index index,
378 const PropertyCondition& condition );
381 * @brief Removes a property notification from this object.
384 * @param[in] propertyNotification The propertyNotification to be removed
386 void RemovePropertyNotification( Dali::PropertyNotification propertyNotification );
389 * @brief Removes all property notifications from this object.
392 void RemovePropertyNotifications();
397 * @brief Removes all constraints from an Object.
400 * @pre The object has been initialized.
402 void RemoveConstraints();
405 * @brief Removes all the constraint from the Object with a matching tag.
408 * @param[in] tag The tag of the constraints which will be removed
409 * @pre The Object has been initialized.
411 void RemoveConstraints( uint32_t tag );
415 * @brief This namespace provides a convenient function to create an object with a custom "weight" property.
418 namespace WeightObject
421 DALI_CORE_API extern const Property::Index WEIGHT; ///< name "weight", type FLOAT
424 * @brief Convenience function to create an object with a custom "weight" property.
427 * @return A handle to a newly allocated object
429 DALI_CORE_API Handle New();
431 } // namespace WeightObject
438 #endif // DALI_HANDLE_H