Implemented the Handle assignment operators properly
[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::SetRemoveTime( TimePeriod timePeriod )
74 {
75   GetImplementation(*this).SetRemoveTime( timePeriod );
76 }
77
78 TimePeriod Constraint::GetRemoveTime() const
79 {
80   return GetImplementation(*this).GetRemoveTime();
81 }
82
83 void Constraint::SetAlphaFunction( AlphaFunction func )
84 {
85   GetImplementation(*this).SetAlphaFunction( func );
86 }
87
88 AlphaFunction Constraint::GetAlphaFunction()
89 {
90   return GetImplementation(*this).GetAlphaFunction();
91 }
92
93 void Constraint::SetRemoveAction(Constraint::RemoveAction action)
94 {
95   GetImplementation(*this).SetRemoveAction(action);
96 }
97
98 Constraint::RemoveAction Constraint::GetRemoveAction() const
99 {
100   return GetImplementation(*this).GetRemoveAction();
101 }
102
103 void Constraint::SetTag( const unsigned int tag )
104 {
105   GetImplementation(*this).SetTag( tag );
106 }
107
108 unsigned int Constraint::GetTag() const
109 {
110   return GetImplementation(*this).GetTag();
111 }
112
113
114
115
116
117 Constraint Constraint::New( Property::Index target,
118                             Property::Type targetType,
119                             AnyFunction func,
120                             AnyFunction interpolator )
121 {
122   Internal::SourceContainer sources; // empty
123
124   return Constraint( new Internal::Constraint( target,
125                                                targetType,
126                                                sources,
127                                                func,
128                                                interpolator ) );
129 }
130
131 Constraint Constraint::New( Property::Index target,
132                             Property::Type targetType,
133                             ConstraintSource source1,
134                             AnyFunction func,
135                             AnyFunction interpolator )
136 {
137   Internal::SourceContainer sources;
138   sources.push_back( Internal::Source( source1 ) );
139
140   return Constraint( new Internal::Constraint( target,
141                                                targetType,
142                                                sources,
143                                                func,
144                                                interpolator ) );
145 }
146
147 Constraint Constraint::New( Property::Index target,
148                             Property::Type targetType,
149                             ConstraintSource source1,
150                             ConstraintSource source2,
151                             AnyFunction func,
152                             AnyFunction interpolator )
153 {
154   Internal::SourceContainer sources;
155   sources.push_back( Internal::Source( source1 ) );
156   sources.push_back( Internal::Source( source2 ) );
157
158   return Constraint( new Internal::Constraint( target,
159                                                targetType,
160                                                sources,
161                                                func,
162                                                interpolator ) );
163 }
164
165 Constraint Constraint::New( Property::Index target,
166                             Property::Type targetType,
167                             ConstraintSource source1,
168                             ConstraintSource source2,
169                             ConstraintSource source3,
170                             AnyFunction func,
171                             AnyFunction interpolator )
172 {
173   Internal::SourceContainer sources;
174   sources.push_back( Internal::Source( source1 ) );
175   sources.push_back( Internal::Source( source2 ) );
176   sources.push_back( Internal::Source( source3 ) );
177
178   return Constraint( new Internal::Constraint( target,
179                                                targetType,
180                                                sources,
181                                                func,
182                                                interpolator ) );
183 }
184
185 Constraint Constraint::New( Property::Index target,
186                             Property::Type targetType,
187                             ConstraintSource source1,
188                             ConstraintSource source2,
189                             ConstraintSource source3,
190                             ConstraintSource source4,
191                             AnyFunction func,
192                             AnyFunction interpolator )
193 {
194   Internal::SourceContainer sources;
195   sources.push_back( Internal::Source( source1 ) );
196   sources.push_back( Internal::Source( source2 ) );
197   sources.push_back( Internal::Source( source3 ) );
198   sources.push_back( Internal::Source( source4 ) );
199
200   return Constraint( new Internal::Constraint( target,
201                                                targetType,
202                                                sources,
203                                                func,
204                                                interpolator ) );
205 }
206
207 Constraint Constraint::New( Property::Index target,
208                             Property::Type targetType,
209                             ConstraintSource source1,
210                             ConstraintSource source2,
211                             ConstraintSource source3,
212                             ConstraintSource source4,
213                             ConstraintSource source5,
214                             AnyFunction func,
215                             AnyFunction interpolator )
216 {
217   Internal::SourceContainer sources;
218   sources.push_back( Internal::Source( source1 ) );
219   sources.push_back( Internal::Source( source2 ) );
220   sources.push_back( Internal::Source( source3 ) );
221   sources.push_back( Internal::Source( source4 ) );
222   sources.push_back( Internal::Source( source5 ) );
223
224   return Constraint( new Internal::Constraint( target,
225                                                targetType,
226                                                sources,
227                                                func,
228                                                interpolator ) );
229 }
230
231 Constraint Constraint::New( Property::Index target,
232                             Property::Type targetType,
233                             ConstraintSource source1,
234                             ConstraintSource source2,
235                             ConstraintSource source3,
236                             ConstraintSource source4,
237                             ConstraintSource source5,
238                             ConstraintSource source6,
239                             AnyFunction func,
240                             AnyFunction interpolator )
241 {
242   Internal::SourceContainer sources;
243   sources.push_back( Internal::Source( source1 ) );
244   sources.push_back( Internal::Source( source2 ) );
245   sources.push_back( Internal::Source( source3 ) );
246   sources.push_back( Internal::Source( source4 ) );
247   sources.push_back( Internal::Source( source5 ) );
248   sources.push_back( Internal::Source( source6 ) );
249
250   return Constraint( new Internal::Constraint( target,
251                                                targetType,
252                                                sources,
253                                                func,
254                                                interpolator ) );
255 }
256
257 Constraint Constraint::DownCast( BaseHandle handle )
258 {
259   return Constraint( dynamic_cast<Dali::Internal::Constraint*>(handle.GetObjectPtr()) );
260 }
261
262 } // namespace Dali