Added tag ( id ) to Constraints so they can be identified ( and removed ) by its...
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / constraint-impl.h
1 #ifndef __DALI_INTERNAL_CONSTRAINT_H__
2 #define __DALI_INTERNAL_CONSTRAINT_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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
10 //
11 //     http://floralicense.org/license/
12 //
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.
18 //
19
20 // INTERNAL INCLUDES
21 #include <dali/public-api/animation/active-constraint.h>
22 #include <dali/public-api/animation/alpha-functions.h>
23 #include <dali/public-api/animation/constraint.h>
24 #include <dali/public-api/animation/time-period.h>
25 #include <dali/public-api/object/base-object.h>
26 #include <dali/internal/event/animation/constraint-source-impl.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 class ActiveConstraintBase;
35 class ProxyObject;
36
37 /**
38  * Constraints are used to constrain a property of an object, after animations have been applied.
39  */
40 class Constraint : public BaseObject
41 {
42 public:
43
44   typedef Any AnyFunction;
45
46   /**
47    * Construct a new constraint which targets a property.
48    * @param [in] target The index of the property to constrain.
49    * @param [in] targetType The type of the constrained property.
50    * @param [in] sources The proxy objects which provide parameters for func.
51    * @param [in] func The constraint function.
52    * @param [in] interpolator A function used to interpolate between the start value, and the value returned by func.
53    */
54   Constraint( Property::Index target,
55               Property::Type targetType,
56               SourceContainer& sources,
57               AnyFunction& func,
58               AnyFunction& interpolator );
59
60   /**
61    * @copydoc Dali::Constraint::SetApplyTime()
62    */
63   void SetApplyTime( TimePeriod timePeriod );
64
65   /**
66    * @copydoc Dali::Constraint::GetApplyTime()
67    */
68   TimePeriod GetApplyTime() const;
69
70   /**
71    * @copydoc Dali::Constraint::SetRemoveTime()
72    */
73   void SetRemoveTime( TimePeriod timePeriod );
74
75   /**
76    * @copydoc Dali::Constraint::GetRemoveTime()
77    */
78   TimePeriod GetRemoveTime() const;
79
80   /**
81    * @copydoc Dali::Constraint::SetAlphaFunction( AlphaFunction func )
82    */
83   void SetAlphaFunction( AlphaFunction func );
84
85   /**
86    * @copydoc Dali::Constraint::GetAlphaFunction()
87    */
88   AlphaFunction GetAlphaFunction() const;
89
90   /**
91    * @copydoc Dali::Constraint::SetRemoveAction()
92    */
93   void SetRemoveAction(Dali::Constraint::RemoveAction action);
94
95   /**
96    * @copydoc Dali::Constraint::GetRemoveAction()
97    */
98   Dali::Constraint::RemoveAction GetRemoveAction() const;
99
100   /**
101    * @copydoc Dali::Constraint::SetTag()
102    */
103   void SetTag( const unsigned int tag);
104
105   /**
106    * @copydoc Dali::Constraint::GetTag()
107    */
108   unsigned int GetTag() const;
109
110
111
112
113   /**
114    * Create an active constraint.
115    * An active constraint is created each time the constraint is applied to an object.
116    * @return A newly allocated active-constraint.
117    */
118   ActiveConstraintBase* CreateActiveConstraint();
119
120 protected:
121
122   /**
123    * A reference counted object may only be deleted by calling Unreference()
124    */
125   virtual ~Constraint();
126
127 private:
128
129   // Undefined
130   Constraint(const Constraint&);
131
132   // Undefined
133   Constraint& operator=(const Constraint& rhs);
134
135 protected:
136
137   Dali::ActiveConstraint mActiveConstraintTemplate; ///< Used to create active constraints
138
139   TimePeriod mApplyTime;
140 };
141
142 } // namespace Internal
143
144 // Helpers for public-api forwarding methods
145
146 inline Internal::Constraint& GetImplementation(Dali::Constraint& constraint)
147 {
148   DALI_ASSERT_ALWAYS( constraint && "Constraint handle is empty" );
149
150   BaseObject& handle = constraint.GetBaseObject();
151
152   return static_cast<Internal::Constraint&>(handle);
153 }
154
155 inline const Internal::Constraint& GetImplementation(const Dali::Constraint& constraint)
156 {
157   DALI_ASSERT_ALWAYS( constraint && "Constraint handle is empty" );
158
159   const BaseObject& handle = constraint.GetBaseObject();
160
161   return static_cast<const Internal::Constraint&>(handle);
162 }
163
164 } // namespace Dali
165
166 #endif // __DALI_INTERNAL_CONSTRAINT_H__