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.push_back( 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 Property::Array propertyArray;
120 value = Property::Value(propertyArray);
121 size_t count( mValue.Size() );
122 for( size_t i( 0 ); i != count; ++i )
124 value.AppendItem( mValue[i] );
127 else if( index == Dali::LinearConstrainer::Property::PROGRESS )
129 Property::Array propertyArray;
130 value = Property::Value(propertyArray);
131 size_t count( mValue.Size() );
132 for( size_t i( 0 ); i != count; ++i )
134 value.AppendItem( mProgress[i] );
141 void LinearConstrainer::SetDefaultProperty(Property::Index index, const Property::Value& propertyValue)
143 if( index == Dali::LinearConstrainer::Property::VALUE )
145 Property::Array propertyArray;
146 propertyValue.Get(propertyArray);
148 size_t propertyArrayCount = propertyArray.size();
149 mValue.Resize( propertyArrayCount );
150 for( size_t i(0); i!=propertyArrayCount; ++i )
152 propertyArray[i].Get( mValue[i]);
155 else if( index == Dali::LinearConstrainer::Property::PROGRESS )
157 Property::Array propertyArray;
158 propertyValue.Get(propertyArray);
160 size_t propertyArrayCount = propertyArray.size();
161 mProgress.Resize( propertyArrayCount );
162 for( size_t i(0); i!=propertyArrayCount; ++i )
164 propertyArray[i].Get( mProgress[i]);
169 bool LinearConstrainer::IsDefaultPropertyWritable(Property::Index index) const
171 if( index < DEFAULT_PROPERTY_COUNT )
173 return DEFAULT_PROPERTY_DETAILS[index].writable;
179 bool LinearConstrainer::IsDefaultPropertyAnimatable(Property::Index index) const
181 if( index < DEFAULT_PROPERTY_COUNT )
183 return DEFAULT_PROPERTY_DETAILS[index].animatable;
189 bool LinearConstrainer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
191 if( index < DEFAULT_PROPERTY_COUNT )
193 return DEFAULT_PROPERTY_DETAILS[index].constraintInput;
199 void LinearConstrainer::Apply( Property target, Property source, const Vector2& range, const Vector2& wrap)
201 Dali::Constraint constraint = Dali::Constraint::New<float>( target.object, target.propertyIndex, LinearConstraintFunctor( mValue, mProgress, range, wrap ) );
202 constraint.AddSource( Dali::Source(source.object, source.propertyIndex ) );
204 constraint.SetTag( reinterpret_cast<size_t>( this ) );
205 constraint.SetRemoveAction( Dali::Constraint::Discard );
209 //Start observing the object
210 Observe( target.object );