2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/public-api/animation/constraint.h>
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>
30 namespace // unnamed namespace
34 Internal::PropertyConstraint< P >* CreatePropertyConstraint( CallbackBase* func )
36 return new Internal::PropertyConstraint< P >( reinterpret_cast< Dali::Constraint::Function< P >* >( func ) );
39 } // unnamed namespace
41 const Constraint::RemoveAction Constraint::DEFAULT_REMOVE_ACTION = Constraint::Bake;
43 Constraint::Constraint()
47 Constraint Constraint::Clone( Handle object )
49 return Constraint( GetImplementation( *this ).Clone( GetImplementation( object ) ) );
52 Constraint::~Constraint()
56 Constraint::Constraint( const Constraint& constraint )
57 : BaseHandle( constraint )
61 Constraint& Constraint::operator=( const Constraint& rhs )
63 BaseHandle::operator=( rhs );
67 Constraint Constraint::DownCast( BaseHandle baseHandle )
69 return Constraint( dynamic_cast< Dali::Internal::ConstraintBase* >( baseHandle.GetObjectPtr() ) );
72 void Constraint::AddSource( ConstraintSource source )
74 GetImplementation( *this ).AddSource( Internal::Source( source ) );
77 void Constraint::Apply()
79 GetImplementation( *this ).Apply();
82 void Constraint::Remove()
84 GetImplementation( *this ).Remove();
87 Handle Constraint::GetTargetObject()
89 return GetImplementation(*this).GetTargetObject();
92 Property::Index Constraint::GetTargetProperty()
94 return GetImplementation(*this).GetTargetProperty();
97 void Constraint::SetRemoveAction(Constraint::RemoveAction action)
99 GetImplementation(*this).SetRemoveAction(action);
102 Constraint::RemoveAction Constraint::GetRemoveAction() const
104 return GetImplementation(*this).GetRemoveAction();
107 void Constraint::SetTag( uint32_t tag )
109 GetImplementation(*this).SetTag( tag );
112 uint32_t Constraint::GetTag() const
114 return GetImplementation(*this).GetTag();
117 Constraint::Constraint( Internal::ConstraintBase* constraint )
118 : BaseHandle( constraint )
122 Constraint Constraint::New( Handle handle, Property::Index targetIndex, Property::Type targetType, CallbackBase* function )
124 Constraint constraint;
125 Internal::SourceContainer sources;
126 Internal::Object& object = GetImplementation( handle );
128 switch ( targetType )
130 case Property::BOOLEAN:
132 Internal::PropertyConstraintPtr< bool >::Type funcPtr( CreatePropertyConstraint< bool >( function ) );
134 constraint = Dali::Constraint( Internal::Constraint< bool >::New( object,
141 case Property::FLOAT:
143 Internal::PropertyConstraintPtr< float >::Type funcPtr( CreatePropertyConstraint< float >( function ) );
145 constraint = Dali::Constraint( Internal::Constraint< float >::New( object,
152 case Property::INTEGER:
154 Internal::PropertyConstraintPtr< int >::Type funcPtr( CreatePropertyConstraint< int >( function ) );
156 constraint = Dali::Constraint( Internal::Constraint< int >::New( object,
163 case Property::VECTOR2:
165 Internal::PropertyConstraintPtr< Vector2 >::Type funcPtr( CreatePropertyConstraint< Vector2 >( function ) );
167 constraint = Dali::Constraint( Internal::Constraint< Vector2 >::New( object,
174 case Property::VECTOR3:
176 Internal::PropertyConstraintPtr< Vector3 >::Type funcPtr( CreatePropertyConstraint< Vector3 >( function ) );
178 constraint = Dali::Constraint( Internal::Constraint< Vector3 >::New( object,
185 case Property::VECTOR4:
187 Internal::PropertyConstraintPtr< Vector4 >::Type funcPtr( CreatePropertyConstraint< Vector4 >( function ) );
189 constraint = Dali::Constraint( Internal::Constraint< Vector4 >::New( object,
196 case Property::ROTATION:
198 Internal::PropertyConstraintPtr< Quaternion >::Type funcPtr( CreatePropertyConstraint< Quaternion >( function ) );
200 constraint = Dali::Constraint( Internal::Constraint< Quaternion >::New( object,
207 case Property::MATRIX:
209 Internal::PropertyConstraintPtr< Matrix >::Type funcPtr( CreatePropertyConstraint< Matrix >( function ) );
211 constraint = Dali::Constraint( Internal::Constraint< Matrix >::New( object,
218 case Property::MATRIX3:
220 Internal::PropertyConstraintPtr<Matrix3>::Type funcPtr( CreatePropertyConstraint<Matrix3>( function ) );
222 constraint = Dali::Constraint( Internal::Constraint< Matrix3 >::New( object,
231 DALI_ABORT( "Property not constrainable" );