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