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/internal/event/animation/linear-constrainer-impl.h>
22 #include <cstring> // for strcmp
25 #include <dali/public-api/animation/constraint.h>
26 #include <dali/public-api/object/property-array.h>
27 #include <dali/public-api/object/type-registry.h>
28 #include <dali/internal/event/common/property-helper.h>
41 // Name Type writable animatable constraint-input enum for index-checking
42 DALI_PROPERTY_TABLE_BEGIN
43 DALI_PROPERTY( "value", ARRAY, true, false, false, Dali::LinearConstrainer::Property::VALUE )
44 DALI_PROPERTY( "progress", ARRAY, true, false, false, Dali::LinearConstrainer::Property::PROGRESS )
45 DALI_PROPERTY_TABLE_END( DEFAULT_OBJECT_PROPERTY_START_INDEX, LinearConstrainerDefaultProperties )
49 return Dali::LinearConstrainer::New();
52 TypeRegistration mType( typeid( Dali::LinearConstrainer ), typeid( Dali::Handle ), Create, LinearConstrainerDefaultProperties );
56 LinearConstrainer* LinearConstrainer::New()
58 return new LinearConstrainer();
61 LinearConstrainer::LinearConstrainer()
66 LinearConstrainer::~LinearConstrainer() = default;
68 Property::Value LinearConstrainer::GetDefaultProperty( Property::Index index ) const
70 if( index == Dali::LinearConstrainer::Property::VALUE )
72 Property::Value value( Property::ARRAY );
73 Property::Array* array = value.GetArray();
74 uint32_t count = static_cast<uint32_t>( mValue.Size() );
78 array->Reserve( count );
79 for( uint32_t i( 0 ); i != count; ++i )
81 array->PushBack( mValue[i] );
86 else if( index == Dali::LinearConstrainer::Property::PROGRESS )
88 Property::Value value( Property::ARRAY );
89 Property::Array* array = value.GetArray();
90 uint32_t count = static_cast<uint32_t>( mProgress.Size() );
94 array->Reserve( count );
95 for( uint32_t i( 0 ); i != count; ++i )
97 array->PushBack( mProgress[i] );
103 return Property::Value();
106 Property::Value LinearConstrainer::GetDefaultPropertyCurrentValue( Property::Index index ) const
108 return GetDefaultProperty( index ); // Event-side only properties
111 void LinearConstrainer::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
113 const Property::Array* array = propertyValue.GetArray();
116 uint32_t propertyArrayCount = static_cast<uint32_t>( array->Count() );
117 if( index == Dali::LinearConstrainer::Property::VALUE )
119 mValue.Clear(); // remove old values
120 mValue.Resize( propertyArrayCount );
121 for( uint32_t i(0); i != propertyArrayCount; ++i )
123 array->GetElementAt( i ).Get( mValue[ i ] );
126 else if( index == Dali::LinearConstrainer::Property::PROGRESS )
128 mProgress.Clear(); // remove old values
129 mProgress.Resize( propertyArrayCount );
130 for( uint32_t i(0); i != propertyArrayCount; ++i )
132 array->GetElementAt( i ).Get( mProgress[ i ] );
138 void LinearConstrainer::Apply( Property target, Property source, const Vector2& range, const Vector2& wrap)
140 Dali::Constraint constraint = Dali::Constraint::New<float>( target.object, target.propertyIndex, LinearConstraintFunctor( mValue, mProgress, range, wrap ) );
141 constraint.AddSource( Dali::Source(source.object, source.propertyIndex ) );
143 constraint.SetTag( static_cast<uint32_t>( reinterpret_cast<uintptr_t>( this ) ) ); // taking 32bits of this as tag
144 constraint.SetRemoveAction( Dali::Constraint::DISCARD );
147 //Start observing the object
148 Observe( target.object );