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.
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 Downcasts to a handle.
134 * If not, the returned handle is left uninitialized.
136 * @param[in] handle to An object
137 * @return handle or an uninitialized handle
139 static Handle DownCast( BaseHandle handle );
142 * @brief Queries whether an handle supports a given capability.
145 * @param[in] capability The queried capability
146 * @return True if the capability is supported
148 bool Supports( Capability capability ) const;
153 * @brief Queries how many properties are provided by an handle.
155 * This may vary between instances of a class, if dynamic properties are supported.
157 * @return The number of properties
159 uint32_t GetPropertyCount() const;
162 * @brief Queries the name of a property.
165 * @param[in] index The index of the property
166 * @return The name of the property
168 std::string GetPropertyName( Property::Index index ) const;
171 * @brief Queries the index of a property.
173 * Returns the first property index that matches the given name exactly.
176 * @param[in] name The name of the property
177 * @return The index of the property, or Property::INVALID_INDEX if no property exists with the given name
179 Property::Index GetPropertyIndex( const std::string& name ) const;
182 * @brief Queries whether a property can be set using SetProperty().
185 * @param[in] index The index of the property
186 * @return True if the property is writable
187 * @pre Property::INVALID_INDEX < index.
189 bool IsPropertyWritable( Property::Index index ) const;
192 * @brief Queries whether a writable property can be the target of an animation or constraint.
195 * @param[in] index The index of the property
196 * @return True if the property is animatable
198 bool IsPropertyAnimatable( Property::Index index ) const;
201 * @brief Queries whether a property can be used as in input to a constraint.
204 * @param[in] index The index of the property
205 * @return True if the property can be used as a constraint input
207 bool IsPropertyAConstraintInput( Property::Index index ) const;
210 * @brief Queries the type of a property.
213 * @param[in] index The index of the property
214 * @return The type of the property
216 Property::Type GetPropertyType( Property::Index index ) const;
219 * @brief Sets the value of an existing property.
221 * Property should be write-able. Setting a read-only property is a no-op.
223 * @param[in] index The index of the property
224 * @param[in] propertyValue The new value of the property
225 * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
227 void SetProperty( Property::Index index, const Property::Value& propertyValue );
230 * @brief Registers a new animatable property.
233 * @param[in] name The name of the property
234 * @param[in] propertyValue The new value of the property
235 * @return The index of the property or Property::INVALID_INDEX if registration failed
236 * @pre The object supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
237 * Property names are expected to be unique, but this is not enforced.
238 * Property indices are unique to each registered custom property in a given object.
239 * returns Property::INVALID_INDEX if registration failed. This can happen if you try to register
240 * animatable property on an object that does not have scene graph object.
241 * @note Only the following types can be animated:
242 * - Property::BOOLEAN
244 * - Property::INTEGER
245 * - Property::VECTOR2
246 * - Property::VECTOR3
247 * - Property::VECTOR4
248 * - Property::MATRIX3
250 * - Property::ROTATION
251 * @note If a property with the desired name already exists, then the value given is just set.
253 Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue );
256 * @brief Registers a new property.
258 * Properties can be set as non animatable using property attributes.
260 * @param[in] name The name of the property
261 * @param[in] propertyValue The new value of the property
262 * @param[in] accessMode The property access mode (writable, animatable etc)
263 * @return The index of the property
264 * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
265 * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
266 * @note Only the following types can be animated:
267 * - Property::BOOLEAN
269 * - Property::INTEGER
270 * - Property::VECTOR2
271 * - Property::VECTOR3
272 * - Property::VECTOR4
273 * - Property::MATRIX3
275 * - Property::ROTATION
276 * @note If a property with the desired name already exists, then the value given is just set.
278 Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );
281 * @brief Retrieves a property value.
284 * @param[in] index The index of the property
285 * @return The property value
287 Property::Value GetProperty( Property::Index index ) const;
290 * @brief Convenience function for obtaining a property of a known type.
293 * @param[in] index The index of the property
294 * @return The property value
295 * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
297 template <typename T>
298 T GetProperty( Property::Index index ) const
300 Property::Value value = GetProperty(index);
302 return T( value.Get<T>() );
306 * @brief Retrieves the latest value of the property from the scene-graph.
309 * @param[in] index The index of the property
310 * @return The property value
312 Property::Value GetCurrentProperty( Property::Index index ) const;
315 * @brief Convenience function for obtaining the current value of a property of a known type.
318 * @param[in] index The index of the property
319 * @return The property value
320 * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
322 template <typename T>
323 T GetCurrentProperty( Property::Index index ) const
325 Property::Value value = GetCurrentProperty( index );
327 return T( value.Get<T>() );
331 * @brief Retrieves all the property indices for this object (including custom properties).
334 * @param[out] indices A container of property indices for this object
335 * @note The added container is cleared.
337 void GetPropertyIndices( Property::IndexContainer& indices ) const;
340 * @brief Adds a property notification to this object.
343 * @param[in] index The index of the property
344 * @param[in] condition The notification will be triggered when this condition is satisfied
345 * @return A handle to the newly created PropertyNotification
347 PropertyNotification AddPropertyNotification( Property::Index index,
348 const PropertyCondition& condition );
351 * @brief Adds a property notification to this object.
354 * @param[in] index The index of the property
355 * @param[in] componentIndex Index to the component of a complex property such as a Vector
356 * @param[in] condition The notification will be triggered when this condition is satisfied
357 * @return A handle to the newly created PropertyNotification
359 PropertyNotification AddPropertyNotification( Property::Index index,
361 const PropertyCondition& condition );
364 * @brief Removes a property notification from this object.
367 * @param[in] propertyNotification The propertyNotification to be removed
369 void RemovePropertyNotification( Dali::PropertyNotification propertyNotification );
372 * @brief Removes all property notifications from this object.
375 void RemovePropertyNotifications();
380 * @brief Removes all constraints from an Object.
383 * @pre The object has been initialized.
385 void RemoveConstraints();
388 * @brief Removes all the constraint from the Object with a matching tag.
391 * @param[in] tag The tag of the constraints which will be removed
392 * @pre The Object has been initialized.
394 void RemoveConstraints( uint32_t tag );
398 * @brief This namespace provides a convenient function to create an object with a custom "weight" property.
401 namespace WeightObject
404 DALI_CORE_API extern const Property::Index WEIGHT; ///< name "weight", type FLOAT
407 * @brief Convenience function to create an object with a custom "weight" property.
410 * @return A handle to a newly allocated object
412 DALI_CORE_API Handle New();
414 } // namespace WeightObject
421 #endif // __DALI_HANDLE_H__