1 #ifndef __DALI_HANDLE_H__
2 #define __DALI_HANDLE_H__
5 * Copyright (c) 2015 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_IMPORT_API Handle : public BaseHandle
57 * @brief An Handle's capabilities 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 Create 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 Downcast 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 Query 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 Query 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 Query 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 Query 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 Query the index of a custom property matching the given key.
183 * Returns the first custom property that matches the given integer key. This is
184 * useful for other classes that know the key but not the name. Requires the property
185 * to have been registered with the associated key.
187 * @note This key is not the same as the Property enum found in
188 * objects such as Actor (which is a preset index).
191 * @param [in] key The integer key of the property
192 * @return The index of the property, or Property::INVALID_INDEX if no property exists with the given key.
193 * @note The key is not the same as the returned index, though it has the same type.
195 Property::Index GetPropertyIndex( Property::Index key ) const;
198 * @brief Query whether a property can be set using SetProperty().
201 * @param [in] index The index of the property.
202 * @return True if the property is writable.
203 * @pre Property::INVALID_INDEX < index.
205 bool IsPropertyWritable( Property::Index index ) const;
208 * @brief Query whether a writable property can be the target of an animation or constraint.
211 * @param [in] index The index of the property.
212 * @return True if the property is animatable.
214 bool IsPropertyAnimatable( Property::Index index ) const;
217 * @brief Query whether a property can be used as in input to a constraint.
220 * @param [in] index The index of the property.
221 * @return True if the property can be used as a constraint input.
223 bool IsPropertyAConstraintInput( Property::Index index ) const;
226 * @brief Query the type of a property.
229 * @param [in] index The index of the property.
230 * @return The type of the property.
232 Property::Type GetPropertyType( Property::Index index ) const;
235 * @brief Set the value of an existing property.
237 * Property should be write-able. Setting a read-only property is a no-op.
239 * @param [in] index The index of the property.
240 * @param [in] propertyValue The new value of the property.
241 * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
243 void SetProperty( Property::Index index, const Property::Value& propertyValue );
246 * @brief Register a new animatable property.
249 * @param [in] name The name of the property.
250 * @param [in] propertyValue The new value of the property.
251 * @return The index of the property or Property::INVALID_INDEX if registration failed
252 * @pre The object supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
253 * Property names are expected to be unique, but this is not enforced.
254 * Property indices are unique to each registered custom property in a given object.
255 * returns Property::INVALID_INDEX if registration failed. This can happen if you try to register
256 * animatable property on an object that does not have scene graph object.
257 * @note Only the following types can be animated:
258 * - Property::BOOLEAN
260 * - Property::INTEGER
261 * - Property::VECTOR2
262 * - Property::VECTOR3
263 * - Property::VECTOR4
264 * - Property::MATRIX3
266 * - Property::ROTATION
267 * @note If a property with the desired name already exists, then the value given is just set.
269 Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue );
272 * @brief Register a new animatable property with an integer key.
275 * @param [in] key The integer key of the property.
276 * @param [in] name The text key of the property.
277 * @param [in] propertyValue The new value of the property.
278 * @return The index of the property or Property::INVALID_INDEX if registration failed
279 * @pre The object supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
280 * Property names and keys are expected to be unique, but this is not enforced.
281 * Property indices are unique to each registered custom property in a given object.
282 * @note Returns Property::INVALID_INDEX if registration failed. This can happen if you try to register
283 * animatable property on an object that does not have scene graph object.
284 * @note The returned property index is not the same as the integer key (though it shares a type)
286 * This version of RegisterProperty associates both an integer key
287 * and the text key with the property, allowing for lookup of the
288 * property index by either key or name ( which is useful when other
289 * classes know the key but not the name )
291 * @note Only the following types can be animated:
292 * - Property::BOOLEAN
294 * - Property::INTEGER
295 * - Property::VECTOR2
296 * - Property::VECTOR3
297 * - Property::VECTOR4
298 * - Property::MATRIX3
300 * - Property::ROTATION
301 * @note If a property with the desired name already exists, then the value given is just set.
303 Property::Index RegisterProperty( Property::Index key, const std::string& name, const Property::Value& propertyValue );
306 * @brief Register a new property.
308 * Properties can be set as non animatable using property attributes.
310 * @param [in] name The name of the property.
311 * @param [in] propertyValue The new value of the property.
312 * @param [in] accessMode The property access mode (writable, animatable etc).
313 * @return The index of the property
314 * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
315 * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
316 * @note Only the following types can be animated:
317 * - Property::BOOLEAN
319 * - Property::INTEGER
320 * - Property::VECTOR2
321 * - Property::VECTOR3
322 * - Property::VECTOR4
323 * - Property::MATRIX3
325 * - Property::ROTATION
326 * @note If a property with the desired name already exists, then the value given is just set.
328 Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );
331 * @brief Retrieve a property value.
334 * @param [in] index The index of the property.
335 * @return The property value.
337 Property::Value GetProperty( Property::Index index ) const;
340 * @brief Convenience function for obtaining a property of a known type.
343 * @param [in] index The index of the property.
344 * @return The property value.
345 * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
347 template <typename T>
348 T GetProperty( Property::Index index ) const
350 Property::Value value = GetProperty(index);
352 return T( value.Get<T>() );
356 * @brief Retrieve all the property indices for this object (including custom properties).
359 * @param[out] indices A container of property indices for this object.
360 * @note the added container is cleared
362 void GetPropertyIndices( Property::IndexContainer& indices ) const;
365 * @brief Add a property notification to this object.
368 * @param [in] index The index of the property.
369 * @param [in] condition The notification will be triggered when this condition is satisfied.
371 * @return A handle to the newly created PropertyNotification
373 PropertyNotification AddPropertyNotification( Property::Index index,
374 const PropertyCondition& condition );
377 * @brief Add a property notification to this object.
380 * @param [in] index The index of the property.
381 * @param [in] componentIndex Index to the component of a complex property such as a Vector
382 * @param [in] condition The notification will be triggered when this condition is satisfied.
384 * @return A handle to the newly created PropertyNotification
386 PropertyNotification AddPropertyNotification( Property::Index index,
388 const PropertyCondition& condition );
391 * @brief Remove a property notification from this object.
394 * @param [in] propertyNotification The propertyNotification to be removed.
396 void RemovePropertyNotification( Dali::PropertyNotification propertyNotification );
399 * @brief Remove all property notifications from this object.
402 void RemovePropertyNotifications();
407 * @brief Remove all constraints from an Object.
410 * @pre The object has been initialized.
412 void RemoveConstraints();
415 * @brief Remove all the constraint from the Object with a matching tag.
418 * @param[in] tag The tag of the constraints which will be removed
419 * @pre The Object has been initialized.
421 void RemoveConstraints( unsigned int tag );
425 namespace WeightObject
428 DALI_IMPORT_API extern const Property::Index WEIGHT; ///< name "weight", type FLOAT
431 * @brief Convenience function to create an object with a custom "weight" property.
434 * @return A handle to a newly allocated object.
436 DALI_IMPORT_API Handle New();
438 } // namespace WeightObject
445 #endif // __DALI_HANDLE_H__