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()
70 Property::Value LinearConstrainer::GetDefaultProperty( Property::Index index ) const
72 if( index == Dali::LinearConstrainer::Property::VALUE )
74 Property::Value value( Property::ARRAY );
75 Property::Array* array = value.GetArray();
76 size_t count( mValue.Size() );
80 array->Reserve( count );
81 for( size_t i( 0 ); i != count; ++i )
83 array->PushBack( mValue[i] );
88 else if( index == Dali::LinearConstrainer::Property::PROGRESS )
90 Property::Value value( Property::ARRAY );
91 Property::Array* array = value.GetArray();
92 size_t count( mProgress.Size() );
96 array->Reserve( count );
97 for( size_t i( 0 ); i != count; ++i )
99 array->PushBack( mProgress[i] );
105 return Property::Value();
108 Property::Value LinearConstrainer::GetDefaultPropertyCurrentValue( Property::Index index ) const
110 return GetDefaultProperty( index ); // Event-side only properties
113 void LinearConstrainer::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
115 const Property::Array* array = propertyValue.GetArray();
118 size_t propertyArrayCount = array->Count();
119 if( index == Dali::LinearConstrainer::Property::VALUE )
121 mValue.Clear(); // remove old values
122 mValue.Resize( propertyArrayCount );
123 for( size_t i(0); i != propertyArrayCount; ++i )
125 array->GetElementAt( i ).Get( mValue[ i ] );
128 else if( index == Dali::LinearConstrainer::Property::PROGRESS )
130 mProgress.Clear(); // remove old values
131 mProgress.Resize( propertyArrayCount );
132 for( size_t i(0); i != propertyArrayCount; ++i )
134 array->GetElementAt( i ).Get( mProgress[ i ] );
140 void LinearConstrainer::Apply( Property target, Property source, const Vector2& range, const Vector2& wrap)
142 Dali::Constraint constraint = Dali::Constraint::New<float>( target.object, target.propertyIndex, LinearConstraintFunctor( mValue, mProgress, range, wrap ) );
143 constraint.AddSource( Dali::Source(source.object, source.propertyIndex ) );
145 constraint.SetTag( static_cast<uint32_t>( reinterpret_cast<uintptr_t>( this ) ) ); // taking 32bits of this as tag
146 constraint.SetRemoveAction( Dali::Constraint::Discard );
149 //Start observing the object
150 Observe( target.object );