Clean up the code to build successfully on macOS
[platform/core/uifw/dali-core.git] / dali / public-api / animation / constraint.cpp
1 /*
2  * Copyright (c) 2020 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/internal/event/animation/constraint-impl.h>
23 #include <dali/internal/event/animation/constraint-source-impl.h>
24 #include <dali/internal/event/animation/property-constraint-ptr.h>
25 #include <dali/internal/event/animation/property-constraint.h>
26
27 namespace Dali
28 {
29 namespace // unnamed namespace
30 {
31 template<class P>
32 Internal::PropertyConstraint<P>* CreatePropertyConstraint(CallbackBase* func)
33 {
34   return new Internal::PropertyConstraint<P>(reinterpret_cast<Dali::Constraint::Function<P>*>(func));
35 }
36
37 } // unnamed namespace
38
39 const Constraint::RemoveAction Constraint::DEFAULT_REMOVE_ACTION = Constraint::BAKE;
40
41 Constraint::Constraint()
42 {
43 }
44
45 Constraint Constraint::Clone(Handle object)
46 {
47   return Constraint(GetImplementation(*this).Clone(GetImplementation(object)));
48 }
49
50 Constraint::~Constraint()
51 {
52 }
53
54 Constraint::Constraint(const Constraint& constraint) = default;
55
56 Constraint& Constraint::operator=(const Constraint& rhs) = default;
57
58 Constraint::Constraint(Constraint&& rhs) = default;
59
60 Constraint& Constraint::operator=(Constraint&& rhs) = default;
61
62 Constraint Constraint::DownCast(BaseHandle baseHandle)
63 {
64   return Constraint(dynamic_cast<Dali::Internal::ConstraintBase*>(baseHandle.GetObjectPtr()));
65 }
66
67 void Constraint::AddSource(ConstraintSource source)
68 {
69   GetImplementation(*this).AddSource(Internal::Source(source));
70 }
71
72 void Constraint::Apply()
73 {
74   GetImplementation(*this).Apply();
75 }
76
77 void Constraint::Remove()
78 {
79   GetImplementation(*this).Remove();
80 }
81
82 Handle Constraint::GetTargetObject()
83 {
84   return GetImplementation(*this).GetTargetObject();
85 }
86
87 Property::Index Constraint::GetTargetProperty()
88 {
89   return GetImplementation(*this).GetTargetProperty();
90 }
91
92 void Constraint::SetRemoveAction(Constraint::RemoveAction action)
93 {
94   GetImplementation(*this).SetRemoveAction(action);
95 }
96
97 Constraint::RemoveAction Constraint::GetRemoveAction() const
98 {
99   return GetImplementation(*this).GetRemoveAction();
100 }
101
102 void Constraint::SetTag(const uint32_t tag)
103 {
104   GetImplementation(*this).SetTag(tag);
105 }
106
107 uint32_t Constraint::GetTag() const
108 {
109   return GetImplementation(*this).GetTag();
110 }
111
112 Constraint::Constraint(Internal::ConstraintBase* constraint)
113 : BaseHandle(constraint)
114 {
115 }
116
117 Constraint Constraint::New(Handle handle, Property::Index targetIndex, Property::Type targetType, CallbackBase* function)
118 {
119   Constraint                constraint;
120   Internal::SourceContainer sources;
121   Internal::Object&         object = GetImplementation(handle);
122
123   switch(targetType)
124   {
125     case Property::BOOLEAN:
126     {
127       Internal::PropertyConstraintPtr<bool>::Type funcPtr(CreatePropertyConstraint<bool>(function));
128
129       constraint = Dali::Constraint(Internal::Constraint<bool>::New(object,
130                                                                     targetIndex,
131                                                                     sources,
132                                                                     funcPtr));
133       break;
134     }
135
136     case Property::FLOAT:
137     {
138       Internal::PropertyConstraintPtr<float>::Type funcPtr(CreatePropertyConstraint<float>(function));
139
140       constraint = Dali::Constraint(Internal::Constraint<float>::New(object,
141                                                                      targetIndex,
142                                                                      sources,
143                                                                      funcPtr));
144       break;
145     }
146
147     case Property::INTEGER:
148     {
149       Internal::PropertyConstraintPtr<int>::Type funcPtr(CreatePropertyConstraint<int>(function));
150
151       constraint = Dali::Constraint(Internal::Constraint<int>::New(object,
152                                                                    targetIndex,
153                                                                    sources,
154                                                                    funcPtr));
155       break;
156     }
157
158     case Property::VECTOR2:
159     {
160       Internal::PropertyConstraintPtr<Vector2>::Type funcPtr(CreatePropertyConstraint<Vector2>(function));
161
162       constraint = Dali::Constraint(Internal::Constraint<Vector2>::New(object,
163                                                                        targetIndex,
164                                                                        sources,
165                                                                        funcPtr));
166       break;
167     }
168
169     case Property::VECTOR3:
170     {
171       Internal::PropertyConstraintPtr<Vector3>::Type funcPtr(CreatePropertyConstraint<Vector3>(function));
172
173       constraint = Dali::Constraint(Internal::Constraint<Vector3>::New(object,
174                                                                        targetIndex,
175                                                                        sources,
176                                                                        funcPtr));
177       break;
178     }
179
180     case Property::VECTOR4:
181     {
182       Internal::PropertyConstraintPtr<Vector4>::Type funcPtr(CreatePropertyConstraint<Vector4>(function));
183
184       constraint = Dali::Constraint(Internal::Constraint<Vector4>::New(object,
185                                                                        targetIndex,
186                                                                        sources,
187                                                                        funcPtr));
188       break;
189     }
190
191     case Property::ROTATION:
192     {
193       Internal::PropertyConstraintPtr<Quaternion>::Type funcPtr(CreatePropertyConstraint<Quaternion>(function));
194
195       constraint = Dali::Constraint(Internal::Constraint<Quaternion>::New(object,
196                                                                           targetIndex,
197                                                                           sources,
198                                                                           funcPtr));
199       break;
200     }
201
202     case Property::MATRIX:
203     {
204       Internal::PropertyConstraintPtr<Matrix>::Type funcPtr(CreatePropertyConstraint<Matrix>(function));
205
206       constraint = Dali::Constraint(Internal::Constraint<Matrix>::New(object,
207                                                                       targetIndex,
208                                                                       sources,
209                                                                       funcPtr));
210       break;
211     }
212
213     case Property::MATRIX3:
214     {
215       Internal::PropertyConstraintPtr<Matrix3>::Type funcPtr(CreatePropertyConstraint<Matrix3>(function));
216
217       constraint = Dali::Constraint(Internal::Constraint<Matrix3>::New(object,
218                                                                        targetIndex,
219                                                                        sources,
220                                                                        funcPtr));
221       break;
222     }
223
224     default:
225     {
226       DALI_ABORT("Property not constrainable");
227       break;
228     }
229   }
230
231   return constraint;
232 }
233
234 } // namespace Dali