1 #ifndef __DALI_CONSTRAINABLE_H__
2 #define __DALI_CONSTRAINABLE_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.
22 #include <dali/public-api/object/handle.h>
23 #include <dali/public-api/animation/active-constraint.h>
24 #include <dali/public-api/animation/constraint.h>
26 namespace Dali DALI_IMPORT_API
29 namespace Internal DALI_INTERNAL
37 * @brief Dali::Constrainable is a handle to an internal property owning Dali object that
38 * can have constraints applied to it.
40 class Constrainable : public Handle
45 * @brief Create a constrainable object.
47 * @return A handle to a newly allocated object.
49 static Constrainable New();
52 * @brief This constructor provides an uninitialized Dali::Constrainable.
54 * This should be initialized with a Dali New() method before use.
55 * Methods called on an uninitialized Dali::Constrainable will assert.
57 * Constrainable handle; // uninitialized
58 * handle.SomeMethod(); // unsafe! This will assert
60 * handle = SomeClass::New(); // now initialized
61 * handle.SomeMethod(); // safe
67 * @brief Downcast a handle to a custom object.
69 * @param[in] handle The handle to cast.
70 * @return A handle to a custom object or an empty handle.
72 static Constrainable DownCast( BaseHandle handle );
75 * @brief Dali::Constrainable is intended as a base class
77 * This is non-virtual since derived Handle types must not contain data or virtual methods.
82 * @brief This copy constructor is required for (smart) pointer semantics.
84 * @param [in] handle A reference to the copied handle
86 Constrainable(const Constrainable& handle);
89 * @brief This assignment operator is required for (smart) pointer semantics.
91 * @param [in] rhs A reference to the copied handle
92 * @return A reference to this
94 Constrainable& operator=(const Constrainable& rhs);
97 * @brief This method is defined to allow assignment of the NULL value,
98 * and will throw an exception if passed any other value.
100 * Assigning to NULL is an alias for Reset().
101 * @param [in] rhs A NULL pointer
102 * @return A reference to this handle
104 Constrainable& operator=(BaseHandle::NullType* rhs);
107 * @brief Constrain one of the properties of an Actor.
109 * @note The constraint will be copied by the Actor. This means that modifying the apply-time etc.
110 * of the constraint, will not affect actors which are already being constrained.
111 * @pre The Actor has been initialized.
112 * @param[in] constraint The constraint to apply.
113 * @return The active-constraint being applied to the actor.
115 ActiveConstraint ApplyConstraint( Constraint constraint );
118 * @brief Constrain one of the properties of an Actor, using a custom weight property.
120 * This overload is intended to allow a single weight property to be shared by many constraints
121 * e.g. call WeightObject::New() once, and pass the return value into every call to ApplyConstraint().
122 * @pre The Actor has been initialized.
123 * @param[in] constraint The constraint to apply.
124 * @param[in] weightObject An object which is expected to have a float property named "weight".
125 * @return The active-constraint being applied to the actor.
127 ActiveConstraint ApplyConstraint( Constraint constraint, Constrainable weightObject );
130 * @brief Remove one constraint from an Object.
132 * @pre The Object has been intialized.
133 * @param[in] activeConstraint The active-constraint to remove.
135 void RemoveConstraint(ActiveConstraint activeConstraint);
138 * @brief Remove all constraints from an Object.
140 * @pre The object has been initialized.
142 void RemoveConstraints();
145 * @brief Remove all the constraint from the Object with a matching tag.
147 * @pre The Object has been intialized.
148 * @param[in] tag The tag of the constraints which will be removed
150 void RemoveConstraints( unsigned int tag );
155 * @brief This constructor is used by Dali New() methods.
157 * @param [in] handle A pointer to a newly allocated Dali resource
159 explicit DALI_INTERNAL Constrainable(Dali::Internal::Object* handle);
162 namespace WeightObject
165 extern const Property::Index WEIGHT; ///< name "weight", type FLOAT
168 * @brief Convenience function to create an object with a custom "weight" property.
170 * @return A handle to a newly allocated object.
174 } // namespace WeightObject
178 #endif // __DALI_CONSTRAINABLE_H__