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.
51 class DALI_IMPORT_API Handle : public BaseHandle
56 * @brief An Handle's capabilities can be queried using Handle::Supports()
61 * @brief Some objects support dynamic property creation at run-time.
63 * New properties are registered by calling RegisterProperty() with an unused property name.
65 DYNAMIC_PROPERTIES = 0x01,
71 * @brief This constructor is used by Dali New() methods.
73 * @param [in] handle A pointer to a newly allocated Dali resource
75 Handle( Dali::Internal::Object* handle );
78 * @brief This constructor provides an uninitialized Dali::Handle.
80 * This should be initialized with a Dali New() method before use.
81 * Methods called on an uninitialized Dali::Handle will assert.
83 * Handle handle; // uninitialized
84 * handle.SomeMethod(); // unsafe! This will assert
86 * handle = SomeClass::New(); // now initialized
87 * handle.SomeMethod(); // safe
93 * @brief Create a new object.
95 * @return A handle to a newly allocated object.
100 * @brief Dali::Handle is intended as a base class
102 * This is non-virtual since derived Handle types must not contain data or virtual methods.
107 * @brief This copy constructor is required for (smart) pointer semantics.
109 * @param [in] handle A reference to the copied handle
111 Handle( const Handle& handle );
114 * @brief This assignment operator is required for (smart) pointer semantics.
116 * @param [in] rhs A reference to the copied handle
117 * @return A reference to this
119 Handle& operator=( const Handle& rhs );
122 * @brief Downcast to a handle.
124 * If not the returned handle is left uninitialized.
125 * @param[in] handle to An object
126 * @return handle or an uninitialized handle
128 static Handle DownCast( BaseHandle handle );
131 * @brief Query whether an handle supports a given capability.
133 * @param[in] capability The queried capability.
134 * @return True if the capability is supported.
136 bool Supports( Capability capability ) const;
141 * @brief Query how many properties are provided by an handle.
143 * This may vary between instances of a class, if dynamic properties are supported.
144 * @return The number of properties.
146 unsigned int GetPropertyCount() const;
149 * @brief Query the name of a property.
151 * @param [in] index The index of the property.
152 * @return The name of the property.
154 std::string GetPropertyName( Property::Index index ) const;
157 * @brief Query the index of a property.
158 * Returns the first property index that matches the given name exactly.
160 * @param [in] name The name of the property.
161 * @return The index of the property, or Property::INVALID_INDEX if no property exists with the given name.
163 Property::Index GetPropertyIndex( const std::string& name ) const;
166 * @brief Query whether a property can be set using SetProperty().
168 * @pre Property::INVALID_INDEX < index.
169 * @param [in] index The index of the property.
170 * @return True if the property is writable.
172 bool IsPropertyWritable( Property::Index index ) const;
175 * @brief Query whether a writable property can be the target of an animation or constraint.
177 * @param [in] index The index of the property.
178 * @return True if the property is animatable.
180 bool IsPropertyAnimatable( Property::Index index ) const;
183 * @brief Query whether a property can be used as in input to a constraint.
185 * @param [in] index The index of the property.
186 * @return True if the property can be used as a constraint input.
188 bool IsPropertyAConstraintInput( Property::Index index ) const;
191 * @brief Query the type of a property.
193 * @param [in] index The index of the property.
194 * @return The type of the property.
196 Property::Type GetPropertyType( Property::Index index ) const;
199 * @brief Set the value of an existing property.
201 * Property should be write-able. Setting a read-only property is a no-op.
202 * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
203 * @param [in] index The index of the property.
204 * @param [in] propertyValue The new value of the property.
206 void SetProperty( Property::Index index, const Property::Value& propertyValue );
209 * @brief Register a new animatable property.
211 * @pre The object supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
212 * Property names are expected to be unique, but this is not enforced.
213 * Property indices are unique to each registered custom property in a given object.
214 * returns Property::INVALID_INDEX if registration failed. This can happen if you try to register
215 * animatable property on an object that does not have scene graph object.
216 * @note Only the following types can be animated:
217 * - Property::BOOLEAN
219 * - Property::INTEGER
220 * - Property::VECTOR2
221 * - Property::VECTOR3
222 * - Property::VECTOR4
223 * - Property::MATRIX3
225 * - Property::ROTATION
226 * @param [in] name The name of the property.
227 * @param [in] propertyValue The new value of the property.
228 * @return The index of the property or Property::INVALID_INDEX if registration failed
230 Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue );
233 * @brief Register a new property.
235 * Properties can be set as non animatable using property attributes.
236 * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
237 * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
238 * @note Only the following types can be animated:
239 * - Property::BOOLEAN
241 * - Property::INTEGER
242 * - Property::VECTOR2
243 * - Property::VECTOR3
244 * - Property::VECTOR4
245 * - Property::MATRIX3
247 * - Property::ROTATION
248 * @param [in] name The name of the property.
249 * @param [in] propertyValue The new value of the property.
250 * @param [in] accessMode The property access mode (writable, animatable etc).
251 * @return The index of the property
253 Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );
256 * @brief Retrieve a property value.
258 * @param [in] index The index of the property.
259 * @return The property value.
261 Property::Value GetProperty( Property::Index index ) const;
264 * @brief Convenience function for obtaining a property of a known type.
266 * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
267 * @param [in] index The index of the property.
268 * @return The property value.
270 template <typename T>
271 T GetProperty( Property::Index index ) const
273 Property::Value value = GetProperty(index);
275 return T( value.Get<T>() );
279 * @brief Retrieve all the property indices for this object (including custom properties).
281 * @param[out] indices A container of property indices for this object.
282 * @note the added container is cleared
284 void GetPropertyIndices( Property::IndexContainer& indices ) const;
287 * @brief Add a property notification to this object.
289 * @param [in] index The index of the property.
290 * @param [in] condition The notification will be triggered when this condition is satisfied.
292 * @return A handle to the newly created PropertyNotification
294 PropertyNotification AddPropertyNotification( Property::Index index,
295 const PropertyCondition& condition );
298 * @brief Add a property notification to this object.
300 * @param [in] index The index of the property.
301 * @param [in] componentIndex Index to the component of a complex property such as a Vector
302 * @param [in] condition The notification will be triggered when this condition is satisfied.
304 * @return A handle to the newly created PropertyNotification
306 PropertyNotification AddPropertyNotification( Property::Index index,
308 const PropertyCondition& condition );
311 * @brief Remove a property notification from this object.
313 * @param [in] propertyNotification The propertyNotification to be removed.
315 void RemovePropertyNotification( Dali::PropertyNotification propertyNotification );
318 * @brief Remove all property notifications from this object.
320 void RemovePropertyNotifications();
325 * @brief Remove all constraints from an Object.
327 * @pre The object has been initialized.
329 void RemoveConstraints();
332 * @brief Remove all the constraint from the Object with a matching tag.
334 * @pre The Object has been initialized.
335 * @param[in] tag The tag of the constraints which will be removed
337 void RemoveConstraints( unsigned int tag );
341 namespace WeightObject
344 DALI_IMPORT_API extern const Property::Index WEIGHT; ///< name "weight", type FLOAT
347 * @brief Convenience function to create an object with a custom "weight" property.
349 * @return A handle to a newly allocated object.
351 DALI_IMPORT_API Handle New();
353 } // namespace WeightObject
360 #endif // __DALI_HANDLE_H__