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