1 #ifndef __DALI_HANDLE_H__
2 #define __DALI_HANDLE_H__
5 * Copyright (c) 2014 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 class ActiveConstraint;
37 class PropertyNotification;
38 class PropertyCondition;
40 namespace Internal DALI_INTERNAL
46 * @brief Dali::Handle is a handle to an internal property owning Dali object that can have constraints applied to it.
48 class DALI_IMPORT_API Handle : public BaseHandle
53 * @brief An Handle's capabilities can be queried using Handle::Supports()
58 * @brief Some objects support dynamic property creation at run-time.
60 * New properties are registered by calling RegisterProperty() with an unused property name.
62 DYNAMIC_PROPERTIES = 0x01,
68 * @brief This constructor is used by Dali New() methods.
70 * @param [in] handle A pointer to a newly allocated Dali resource
72 Handle( Dali::Internal::Object* handle );
75 * @brief This constructor provides an uninitialized Dali::Handle.
77 * This should be initialized with a Dali New() method before use.
78 * Methods called on an uninitialized Dali::Handle will assert.
80 * Handle handle; // uninitialized
81 * handle.SomeMethod(); // unsafe! This will assert
83 * handle = SomeClass::New(); // now initialized
84 * handle.SomeMethod(); // safe
90 * @brief Create a new object.
92 * @return A handle to a newly allocated object.
97 * @brief Dali::Handle is intended as a base class
99 * This is non-virtual since derived Handle types must not contain data or virtual methods.
104 * @brief This copy constructor is required for (smart) pointer semantics.
106 * @param [in] handle A reference to the copied handle
108 Handle( const Handle& handle );
111 * @brief This assignment operator is required for (smart) pointer semantics.
113 * @param [in] rhs A reference to the copied handle
114 * @return A reference to this
116 Handle& operator=( const Handle& rhs );
119 * @brief Downcast to a handle.
121 * If not the returned handle is left uninitialized.
122 * @param[in] handle to An object
123 * @return handle or an uninitialized handle
125 static Handle DownCast( BaseHandle handle );
128 * @brief Query whether an handle supports a given capability.
130 * @param[in] capability The queried capability.
131 * @return True if the capability is supported.
133 bool Supports( Capability capability ) const;
138 * @brief Query how many properties are provided by an handle.
140 * This may vary between instances of a class, if dynamic properties are supported.
141 * @return The number of properties.
143 unsigned int GetPropertyCount() const;
146 * @brief Query the name of a property.
148 * @param [in] index The index of the property.
149 * @return The name of the property.
151 std::string GetPropertyName( Property::Index index ) const;
154 * @brief Query the index of a property.
155 * Returns the first property index that matches the given name exactly.
157 * @param [in] name The name of the property.
158 * @return The index of the property, or Property::INVALID_INDEX if no property exists with the given name.
160 Property::Index GetPropertyIndex( const std::string& name ) const;
163 * @brief Query whether a property can be set using SetProperty().
165 * @pre Property::INVALID_INDEX < index.
166 * @param [in] index The index of the property.
167 * @return True if the property is writable.
169 bool IsPropertyWritable( Property::Index index ) const;
172 * @brief Query whether a writable property can be the target of an animation or constraint.
174 * @param [in] index The index of the property.
175 * @return True if the property is animatable.
177 bool IsPropertyAnimatable( Property::Index index ) const;
180 * @brief Query whether a property can be used as in input to a constraint.
182 * @param [in] index The index of the property.
183 * @return True if the property can be used as a constraint input.
185 bool IsPropertyAConstraintInput( Property::Index index ) const;
188 * @brief Query the type of a property.
190 * @param [in] index The index of the property.
191 * @return The type of the property.
193 Property::Type GetPropertyType( Property::Index index ) const;
196 * @brief Set the value of an existing property.
198 * Property should be write-able. Setting a read-only property is a no-op.
199 * @pre The property types match i.e. propertyValue.GetType() is equal to GetPropertyType(index).
200 * @param [in] index The index of the property.
201 * @param [in] propertyValue The new value of the property.
203 void SetProperty( Property::Index index, const Property::Value& propertyValue );
206 * @brief Register a new animatable property.
208 * @pre The object supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
209 * Property names are expected to be unique, but this is not enforced.
210 * Property indices are unique to each registered custom property in a given object.
211 * returns Property::INVALID_INDEX if registration failed. This can happen if you try to register
212 * animatable property on an object that does not have scene graph object.
213 * @note Only the following types can be animated:
214 * - Property::BOOLEAN
216 * - Property::INTEGER
217 * - Property::VECTOR2
218 * - Property::VECTOR3
219 * - Property::VECTOR4
220 * - Property::MATRIX3
222 * - Property::ROTATION
223 * @param [in] name The name of the property.
224 * @param [in] propertyValue The new value of the property.
225 * @return The index of the property or Property::INVALID_INDEX if registration failed
227 Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue );
230 * @brief Register a new property.
232 * Properties can be set as non animatable using property attributes.
233 * @pre The handle supports dynamic properties i.e. Supports(Handle::DYNAMIC_PROPERTIES) returns true.
234 * @pre name is unused i.e. GetPropertyIndex(name) returns PropertyIndex::INVALID.
235 * @note Only the following types can be animated:
236 * - Property::BOOLEAN
238 * - Property::INTEGER
239 * - Property::VECTOR2
240 * - Property::VECTOR3
241 * - Property::VECTOR4
242 * - Property::MATRIX3
244 * - Property::ROTATION
245 * @param [in] name The name of the property.
246 * @param [in] propertyValue The new value of the property.
247 * @param [in] accessMode The property access mode (writable, animatable etc).
248 * @return The index of the property
250 Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );
253 * @brief Retrieve a property value.
255 * @param [in] index The index of the property.
256 * @return The property value.
258 Property::Value GetProperty( Property::Index index ) const;
261 * @brief Convenience function for obtaining a property of a known type.
263 * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
264 * @param [in] index The index of the property.
265 * @return The property value.
267 template <typename T>
268 T GetProperty( Property::Index index ) const
270 Property::Value value = GetProperty(index);
272 return T( value.Get<T>() );
276 * @brief Retrieve all the property indices for this object (including custom properties).
278 * @param[out] indices A container of property indices for this object.
279 * @note the added container is cleared
281 void GetPropertyIndices( Property::IndexContainer& indices ) const;
284 * @brief Add a property notification to this object.
286 * @param [in] index The index of the property.
287 * @param [in] condition The notification will be triggered when this condition is satisfied.
289 * @return A handle to the newly created PropertyNotification
291 PropertyNotification AddPropertyNotification( Property::Index index,
292 const PropertyCondition& condition );
295 * @brief Add a property notification to this object.
297 * @param [in] index The index of the property.
298 * @param [in] componentIndex Index to the component of a complex property such as a Vector
299 * @param [in] condition The notification will be triggered when this condition is satisfied.
301 * @return A handle to the newly created PropertyNotification
303 PropertyNotification AddPropertyNotification( Property::Index index,
305 const PropertyCondition& condition );
308 * @brief Remove a property notification from this object.
310 * @param [in] propertyNotification The propertyNotification to be removed.
312 void RemovePropertyNotification( Dali::PropertyNotification propertyNotification );
315 * @brief Remove all property notifications from this object.
317 void RemovePropertyNotifications();
322 * @brief Constrain one of the properties of an Actor.
324 * @note The constraint will be copied by the Actor. This means that modifying the apply-time etc.
325 * of the constraint, will not affect actors which are already being constrained.
326 * @pre The Actor has been initialized.
327 * @param[in] constraint The constraint to apply.
328 * @return The active-constraint being applied to the actor.
330 ActiveConstraint ApplyConstraint( Constraint constraint );
333 * @brief Constrain one of the properties of an Actor, using a custom weight property.
335 * This overload is intended to allow a single weight property to be shared by many constraints
336 * e.g. call WeightObject::New() once, and pass the return value into every call to ApplyConstraint().
337 * @pre The Actor has been initialized.
338 * @param[in] constraint The constraint to apply.
339 * @param[in] weightObject An object which is expected to have a float property named "weight".
340 * @return The active-constraint being applied to the actor.
342 ActiveConstraint ApplyConstraint( Constraint constraint, Handle weightObject );
345 * @brief Remove one constraint from an Object.
347 * @pre The Object has been initialized.
348 * @param[in] activeConstraint The active-constraint to remove.
350 void RemoveConstraint( ActiveConstraint activeConstraint );
353 * @brief Remove all constraints from an Object.
355 * @pre The object has been initialized.
357 void RemoveConstraints();
360 * @brief Remove all the constraint from the Object with a matching tag.
362 * @pre The Object has been intialized.
363 * @param[in] tag The tag of the constraints which will be removed
365 void RemoveConstraints( unsigned int tag );
368 namespace WeightObject
371 DALI_IMPORT_API extern const Property::Index WEIGHT; ///< name "weight", type FLOAT
374 * @brief Convenience function to create an object with a custom "weight" property.
376 * @return A handle to a newly allocated object.
378 DALI_IMPORT_API Handle New();
380 } // namespace WeightObject
384 #endif // __DALI_HANDLE_H__