Dali 3D User Interface Engine
linear-constrainer-impl.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 
18 // CLASS HEADER
20 
21 //EXTRENAL INCLUDES
22 #include <cstring> // for strcmp
23 
24 // INTERNAL INCLUDES
28 
29 
30 namespace Dali
31 {
32 
33 namespace Internal
34 {
35 
36 namespace
37 {
38 
39 // Properties
40 // Name Type writable animatable constraint-input enum for index-checking
42 DALI_PROPERTY( "value", ARRAY, true, false, false, Dali::LinearConstrainer::Property::VALUE )
43 DALI_PROPERTY( "progress", ARRAY, true, false, false, Dali::LinearConstrainer::Property::PROGRESS )
45 
46 } //Unnamed namespace
47 
49 {
50  return new LinearConstrainer();
51 }
52 
54 : Constrainer()
55 {
56 }
57 
59 {
60 }
61 
63 {
64  return DEFAULT_PROPERTY_COUNT;
65 }
66 
68 {
69  indices.Reserve( DEFAULT_PROPERTY_COUNT );
70 
71  for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
72  {
73  indices.PushBack( i );
74  }
75 }
76 
78 {
79  if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
80  {
81  return DEFAULT_PROPERTY_DETAILS[index].name;
82  }
83 
84  // index out of range
85  return NULL;
86 }
87 
89 {
91 
92  // Look for name in default properties
93  for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
94  {
95  const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[ i ];
96  if( 0 == strcmp( name.c_str(), property->name ) )
97  {
98  index = i;
99  break;
100  }
101  }
102  return index;
103 }
104 
106 {
107  if( index < DEFAULT_PROPERTY_COUNT )
108  {
109  return DEFAULT_PROPERTY_DETAILS[index].type;
110  }
111 
112  // index out of range
113  return Property::NONE;
114 }
115 
117 {
119  {
121  Property::Array* array = value.GetArray();
122  size_t count( mValue.Size() );
123 
124  if( array )
125  {
126  array->Reserve( count );
127  for( size_t i( 0 ); i != count; ++i )
128  {
129  array->PushBack( mValue[i] );
130  }
131  }
132  return value;
133  }
135  {
137  Property::Array* array = value.GetArray();
138  size_t count( mValue.Size() );
139 
140  if( array )
141  {
142  array->Reserve( count );
143  for( size_t i( 0 ); i != count; ++i )
144  {
145  array->PushBack( mProgress[i] );
146  }
147  }
148  return value;
149  }
150 
151  return Property::Value();
152 }
153 
155 {
156  const Property::Array* array = propertyValue.GetArray();
157  if( array )
158  {
159  size_t propertyArrayCount = array->Count();
161  {
162  mValue.Clear(); // remove old values
163  mValue.Resize( propertyArrayCount );
164  for( size_t i(0); i != propertyArrayCount; ++i )
165  {
166  array->GetElementAt( i ).Get( mValue[ i ] );
167  }
168  }
170  {
171  mProgress.Clear(); // remove old values
172  mProgress.Resize( propertyArrayCount );
173  for( size_t i(0); i != propertyArrayCount; ++i )
174  {
175  array->GetElementAt( i ).Get( mProgress[ i ] );
176  }
177  }
178  }
179 }
180 
182 {
183  if( index < DEFAULT_PROPERTY_COUNT )
184  {
185  return DEFAULT_PROPERTY_DETAILS[index].writable;
186  }
187 
188  return false;
189 }
190 
192 {
193  if( index < DEFAULT_PROPERTY_COUNT )
194  {
195  return DEFAULT_PROPERTY_DETAILS[index].animatable;
196  }
197 
198  return false;
199 }
200 
202 {
203  if( index < DEFAULT_PROPERTY_COUNT )
204  {
205  return DEFAULT_PROPERTY_DETAILS[index].constraintInput;
206  }
207 
208  return false;
209 }
210 
211 void LinearConstrainer::Apply( Property target, Property source, const Vector2& range, const Vector2& wrap)
212 {
213  Dali::Constraint constraint = Dali::Constraint::New<float>( target.object, target.propertyIndex, LinearConstraintFunctor( mValue, mProgress, range, wrap ) );
214  constraint.AddSource( Dali::Source(source.object, source.propertyIndex ) );
215 
216  constraint.SetTag( reinterpret_cast<size_t>( this ) );
218  constraint.Apply();
219 
220 
221  //Start observing the object
222  Observe( target.object );
223 }
224 
225 } // Internal
226 
227 } // Dali
Dali Docs Home
Read more about Dali