2 * Copyright (c) 2015 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/internal/event/common/property-helper.h>
26 #include <dali/public-api/animation/constraint.h>
38 // Name Type writable animatable constraint-input enum for index-checking
39 DALI_PROPERTY_TABLE_BEGIN
40 DALI_PROPERTY( "value", ARRAY, true, false, false, Dali::LinearConstrainer::Property::VALUE )
41 DALI_PROPERTY( "progress", ARRAY, true, false, false, Dali::LinearConstrainer::Property::PROGRESS )
42 DALI_PROPERTY_TABLE_END( DEFAULT_OBJECT_PROPERTY_START_INDEX )
46 LinearConstrainer* LinearConstrainer::New()
48 return new LinearConstrainer();
51 LinearConstrainer::LinearConstrainer()
56 LinearConstrainer::~LinearConstrainer()
60 unsigned int LinearConstrainer::GetDefaultPropertyCount() const
62 return DEFAULT_PROPERTY_COUNT;
65 void LinearConstrainer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
67 indices.Reserve( DEFAULT_PROPERTY_COUNT );
69 for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
71 indices.PushBack( i );
75 const char* LinearConstrainer::GetDefaultPropertyName(Property::Index index) const
77 if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
79 return DEFAULT_PROPERTY_DETAILS[index].name;
86 Property::Index LinearConstrainer::GetDefaultPropertyIndex(const std::string& name) const
88 Property::Index index = Property::INVALID_INDEX;
90 // Look for name in default properties
91 for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
93 const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[ i ];
94 if( 0 == strcmp( name.c_str(), property->name ) )
103 Property::Type LinearConstrainer::GetDefaultPropertyType(Property::Index index) const
105 if( index < DEFAULT_PROPERTY_COUNT )
107 return DEFAULT_PROPERTY_DETAILS[index].type;
110 // index out of range
111 return Property::NONE;
114 Property::Value LinearConstrainer::GetDefaultProperty( Property::Index index ) const
116 Property::Value value;
117 if( index == Dali::LinearConstrainer::Property::VALUE )
119 value = Property::Value(Property::ARRAY);
120 size_t count( mValue.Size() );
121 for( size_t i( 0 ); i != count; ++i )
123 value.AppendItem( mValue[i] );
126 else if( index == Dali::LinearConstrainer::Property::PROGRESS )
128 value = Property::Value(Property::ARRAY);
129 size_t count( mValue.Size() );
130 for( size_t i( 0 ); i != count; ++i )
132 value.AppendItem( mProgress[i] );
139 void LinearConstrainer::SetDefaultProperty(Property::Index index, const Property::Value& propertyValue)
141 if( index == Dali::LinearConstrainer::Property::VALUE )
143 size_t propertyArrayCount = propertyValue.GetSize();
144 mValue.Resize( propertyArrayCount );
145 for( size_t i(0); i != propertyArrayCount; ++i )
147 propertyValue.GetItem(i).Get( mValue[i] );
150 else if( index == Dali::LinearConstrainer::Property::PROGRESS )
152 size_t propertyArrayCount = propertyValue.GetSize();
153 mProgress.Resize( propertyArrayCount );
154 for( size_t i(0); i != propertyArrayCount; ++i )
156 propertyValue.GetItem(i).Get( mProgress[i] );
161 bool LinearConstrainer::IsDefaultPropertyWritable(Property::Index index) const
163 if( index < DEFAULT_PROPERTY_COUNT )
165 return DEFAULT_PROPERTY_DETAILS[index].writable;
171 bool LinearConstrainer::IsDefaultPropertyAnimatable(Property::Index index) const
173 if( index < DEFAULT_PROPERTY_COUNT )
175 return DEFAULT_PROPERTY_DETAILS[index].animatable;
181 bool LinearConstrainer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
183 if( index < DEFAULT_PROPERTY_COUNT )
185 return DEFAULT_PROPERTY_DETAILS[index].constraintInput;
191 void LinearConstrainer::Apply( Property target, Property source, const Vector2& range, const Vector2& wrap)
193 Dali::Constraint constraint = Dali::Constraint::New<float>( target.object, target.propertyIndex, LinearConstraintFunctor( mValue, mProgress, range, wrap ) );
194 constraint.AddSource( Dali::Source(source.object, source.propertyIndex ) );
196 constraint.SetTag( reinterpret_cast<size_t>( this ) );
197 constraint.SetRemoveAction( Dali::Constraint::Discard );
201 //Start observing the object
202 Observe( target.object );