[dali_1.0.9] Merge branch 'tizen'
[platform/core/uifw/dali-core.git] / dali / public-api / animation / constraint.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/public-api/animation/constraint.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/animation/time-period.h>
23 #include <dali/internal/event/animation/constraint-impl.h>
24 #include <dali/internal/event/animation/constraint-source-impl.h>
25
26 namespace Dali
27 {
28
29 const AlphaFunction            Constraint::DEFAULT_ALPHA_FUNCTION = AlphaFunctions::Linear;
30 const Constraint::RemoveAction Constraint::DEFAULT_REMOVE_ACTION  = Constraint::Bake;
31
32 Constraint::Constraint()
33 {
34 }
35
36 Constraint::Constraint(Internal::Constraint* constraint)
37 : BaseHandle(constraint)
38 {
39 }
40
41 Constraint::~Constraint()
42 {
43 }
44
45 Constraint::Constraint(const Constraint& handle)
46 : BaseHandle(handle)
47 {
48 }
49
50 Constraint& Constraint::operator=(const Constraint& rhs)
51 {
52   BaseHandle::operator=(rhs);
53   return *this;
54 }
55
56 Constraint& Constraint::operator=(BaseHandle::NullType* rhs)
57 {
58   DALI_ASSERT_ALWAYS( (rhs == NULL) && "Can only assign NULL pointer to handle");
59   Reset();
60   return *this;
61 }
62
63 void Constraint::SetApplyTime( TimePeriod timePeriod )
64 {
65   GetImplementation(*this).SetApplyTime( timePeriod );
66 }
67
68 TimePeriod Constraint::GetApplyTime() const
69 {
70   return GetImplementation(*this).GetApplyTime();
71 }
72
73 void Constraint::SetAlphaFunction( AlphaFunction func )
74 {
75   GetImplementation(*this).SetAlphaFunction( func );
76 }
77
78 AlphaFunction Constraint::GetAlphaFunction()
79 {
80   return GetImplementation(*this).GetAlphaFunction();
81 }
82
83 void Constraint::SetRemoveAction(Constraint::RemoveAction action)
84 {
85   GetImplementation(*this).SetRemoveAction(action);
86 }
87
88 Constraint::RemoveAction Constraint::GetRemoveAction() const
89 {
90   return GetImplementation(*this).GetRemoveAction();
91 }
92
93 void Constraint::SetTag( const unsigned int tag )
94 {
95   GetImplementation(*this).SetTag( tag );
96 }
97
98 unsigned int Constraint::GetTag() const
99 {
100   return GetImplementation(*this).GetTag();
101 }
102
103
104
105
106
107 Constraint Constraint::New( Property::Index target,
108                             Property::Type targetType,
109                             AnyFunction func,
110                             AnyFunction interpolator )
111 {
112   Internal::SourceContainer sources; // empty
113
114   return Constraint( new Internal::Constraint( target,
115                                                targetType,
116                                                sources,
117                                                func,
118                                                interpolator ) );
119 }
120
121 Constraint Constraint::New( Property::Index target,
122                             Property::Type targetType,
123                             ConstraintSource source1,
124                             AnyFunction func,
125                             AnyFunction interpolator )
126 {
127   Internal::SourceContainer sources;
128   sources.push_back( Internal::Source( source1 ) );
129
130   return Constraint( new Internal::Constraint( target,
131                                                targetType,
132                                                sources,
133                                                func,
134                                                interpolator ) );
135 }
136
137 Constraint Constraint::New( Property::Index target,
138                             Property::Type targetType,
139                             ConstraintSource source1,
140                             ConstraintSource source2,
141                             AnyFunction func,
142                             AnyFunction interpolator )
143 {
144   Internal::SourceContainer sources;
145   sources.push_back( Internal::Source( source1 ) );
146   sources.push_back( Internal::Source( source2 ) );
147
148   return Constraint( new Internal::Constraint( target,
149                                                targetType,
150                                                sources,
151                                                func,
152                                                interpolator ) );
153 }
154
155 Constraint Constraint::New( Property::Index target,
156                             Property::Type targetType,
157                             ConstraintSource source1,
158                             ConstraintSource source2,
159                             ConstraintSource source3,
160                             AnyFunction func,
161                             AnyFunction interpolator )
162 {
163   Internal::SourceContainer sources;
164   sources.push_back( Internal::Source( source1 ) );
165   sources.push_back( Internal::Source( source2 ) );
166   sources.push_back( Internal::Source( source3 ) );
167
168   return Constraint( new Internal::Constraint( target,
169                                                targetType,
170                                                sources,
171                                                func,
172                                                interpolator ) );
173 }
174
175 Constraint Constraint::New( Property::Index target,
176                             Property::Type targetType,
177                             ConstraintSource source1,
178                             ConstraintSource source2,
179                             ConstraintSource source3,
180                             ConstraintSource source4,
181                             AnyFunction func,
182                             AnyFunction interpolator )
183 {
184   Internal::SourceContainer sources;
185   sources.push_back( Internal::Source( source1 ) );
186   sources.push_back( Internal::Source( source2 ) );
187   sources.push_back( Internal::Source( source3 ) );
188   sources.push_back( Internal::Source( source4 ) );
189
190   return Constraint( new Internal::Constraint( target,
191                                                targetType,
192                                                sources,
193                                                func,
194                                                interpolator ) );
195 }
196
197 Constraint Constraint::New( Property::Index target,
198                             Property::Type targetType,
199                             ConstraintSource source1,
200                             ConstraintSource source2,
201                             ConstraintSource source3,
202                             ConstraintSource source4,
203                             ConstraintSource source5,
204                             AnyFunction func,
205                             AnyFunction interpolator )
206 {
207   Internal::SourceContainer sources;
208   sources.push_back( Internal::Source( source1 ) );
209   sources.push_back( Internal::Source( source2 ) );
210   sources.push_back( Internal::Source( source3 ) );
211   sources.push_back( Internal::Source( source4 ) );
212   sources.push_back( Internal::Source( source5 ) );
213
214   return Constraint( new Internal::Constraint( target,
215                                                targetType,
216                                                sources,
217                                                func,
218                                                interpolator ) );
219 }
220
221 Constraint Constraint::New( Property::Index target,
222                             Property::Type targetType,
223                             ConstraintSource source1,
224                             ConstraintSource source2,
225                             ConstraintSource source3,
226                             ConstraintSource source4,
227                             ConstraintSource source5,
228                             ConstraintSource source6,
229                             AnyFunction func,
230                             AnyFunction interpolator )
231 {
232   Internal::SourceContainer sources;
233   sources.push_back( Internal::Source( source1 ) );
234   sources.push_back( Internal::Source( source2 ) );
235   sources.push_back( Internal::Source( source3 ) );
236   sources.push_back( Internal::Source( source4 ) );
237   sources.push_back( Internal::Source( source5 ) );
238   sources.push_back( Internal::Source( source6 ) );
239
240   return Constraint( new Internal::Constraint( target,
241                                                targetType,
242                                                sources,
243                                                func,
244                                                interpolator ) );
245 }
246
247 Constraint Constraint::DownCast( BaseHandle handle )
248 {
249   return Constraint( dynamic_cast<Dali::Internal::Constraint*>(handle.GetObjectPtr()) );
250 }
251
252 } // namespace Dali