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/common/property-metadata.h>
22 #include <dali/public-api/math/quaternion.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali/public-api/math/vector3.h>
25 #include <dali/public-api/math/vector4.h>
26 #include <dali/public-api/object/property.h>
27 #include <dali/public-api/common/extents.h>
28 #include <dali/public-api/math/matrix3.h>
29 #include <dali/public-api/math/matrix.h>
30 #include <dali/public-api/math/rect.h>
31 #include <dali/public-api/object/property-map.h>
32 #include <dali/public-api/object/property-array.h>
43 /// Helper to adjust the property value by an amount specified in another property-value
44 template < typename PropertyType >
45 inline void AdjustProperty( Property::Value& currentPropertyValue, const Property::Value& relativePropertyValue )
47 PropertyType currentValue;
48 PropertyType relativeValue;
49 if( currentPropertyValue.Get( currentValue ) && relativePropertyValue.Get( relativeValue ) )
51 currentPropertyValue = currentValue + relativeValue;
55 } // unnamed namespace
57 void PropertyMetadata::SetPropertyValue( const Property::Value& propertyValue )
67 case Property::RECTANGLE:
69 Rect<int32_t> convertedValue;
70 if( propertyValue.Get( convertedValue ) )
72 value = convertedValue;
77 case Property::STRING:
79 std::string convertedValue;
80 if( propertyValue.Get( convertedValue ) )
82 value = convertedValue;
89 Property::Array* array = propertyValue.GetArray();
99 Property::Map* map = propertyValue.GetMap();
107 case Property::EXTENTS:
109 Extents convertedValue;
110 if( propertyValue.Get( convertedValue ) )
112 value = convertedValue;
117 case Property::BOOLEAN:
120 if( propertyValue.Get( convertedValue ) )
122 value = convertedValue;
127 case Property::INTEGER:
129 int32_t convertedValue;
130 if( propertyValue.Get( convertedValue ) )
132 value = convertedValue;
137 case Property::FLOAT:
139 float convertedValue;
140 if( propertyValue.Get( convertedValue ) )
142 value = convertedValue;
147 case Property::ROTATION:
149 Quaternion convertedValue;
150 if( propertyValue.Get( convertedValue ) )
152 value = convertedValue;
157 case Property::MATRIX:
159 Matrix convertedValue;
160 if( propertyValue.Get( convertedValue ) )
162 value = convertedValue;
167 case Property::MATRIX3:
169 Matrix3 convertedValue;
170 if( propertyValue.Get( convertedValue ) )
172 value = convertedValue;
177 case Property::VECTOR2:
179 Vector2 vector2Value;
180 value.Get( vector2Value );
182 if( componentIndex == 0 )
184 vector2Value.x = propertyValue.Get< float >();
186 else if( componentIndex == 1 )
188 vector2Value.y = propertyValue.Get< float >();
192 propertyValue.Get( vector2Value );
195 value = vector2Value;
199 case Property::VECTOR3:
201 Vector3 vector3Value;
202 value.Get( vector3Value );
204 if( componentIndex == 0 )
206 vector3Value.x = propertyValue.Get< float >();
208 else if( componentIndex == 1 )
210 vector3Value.y = propertyValue.Get< float >();
212 else if( componentIndex == 2 )
214 vector3Value.z = propertyValue.Get< float >();
218 propertyValue.Get( vector3Value );
221 value = vector3Value;
225 case Property::VECTOR4:
227 Vector4 vector4Value;
228 value.Get( vector4Value );
230 if( componentIndex == 0 )
232 vector4Value.x = propertyValue.Get< float >();
234 else if( componentIndex == 1 )
236 vector4Value.y = propertyValue.Get< float >();
238 else if( componentIndex == 2 )
240 vector4Value.z = propertyValue.Get< float >();
242 else if( componentIndex == 3 )
244 vector4Value.w = propertyValue.Get< float >();
248 propertyValue.Get( vector4Value );
251 value = vector4Value;
257 Property::Value PropertyMetadata::GetPropertyValue() const
259 Property::Value propertyValue;
261 if( !IsAnimatable() )
263 propertyValue = value;
270 case Property::RECTANGLE:
271 case Property::STRING:
272 case Property::ARRAY:
274 case Property::EXTENTS:
275 case Property::BOOLEAN:
276 case Property::INTEGER:
277 case Property::FLOAT:
278 case Property::MATRIX:
279 case Property::MATRIX3:
280 case Property::ROTATION:
282 propertyValue = value;
286 case Property::VECTOR2:
288 Vector2 vector2Value;
289 value.Get( vector2Value );
291 if( componentIndex == 0 )
293 propertyValue = vector2Value.x;
295 else if( componentIndex == 1 )
297 propertyValue = vector2Value.y;
301 propertyValue = vector2Value;
306 case Property::VECTOR3:
308 Vector3 vector3Value;
309 value.Get( vector3Value );
311 if( componentIndex == 0 )
313 propertyValue = vector3Value.x;
315 else if( componentIndex == 1 )
317 propertyValue = vector3Value.y;
319 else if( componentIndex == 2 )
321 propertyValue = vector3Value.z;
325 propertyValue = vector3Value;
330 case Property::VECTOR4:
332 Vector4 vector4Value;
333 value.Get( vector4Value );
335 if( componentIndex == 0 )
337 propertyValue = vector4Value.x;
339 else if( componentIndex == 1 )
341 propertyValue = vector4Value.y;
343 else if( componentIndex == 2 )
345 propertyValue = vector4Value.z;
347 else if( componentIndex == 3 )
349 propertyValue = vector4Value.w;
353 propertyValue = vector4Value;
360 return propertyValue;
363 void PropertyMetadata::AdjustPropertyValueBy( const Property::Value& relativePropertyValue )
368 case Property::RECTANGLE:
369 case Property::STRING:
370 case Property::ARRAY:
372 case Property::EXTENTS:
373 case Property::MATRIX:
374 case Property::MATRIX3:
380 case Property::BOOLEAN:
382 bool currentValue = false;
383 bool relativeValue = false;
384 if( value.Get( currentValue ) && relativePropertyValue.Get( relativeValue ) )
386 value = currentValue || relativeValue;
391 case Property::INTEGER:
393 AdjustProperty< int >( value, relativePropertyValue );
397 case Property::FLOAT:
399 AdjustProperty< float >( value, relativePropertyValue );
403 case Property::ROTATION:
405 Quaternion currentValue;
406 Quaternion relativeValue;
407 if( value.Get( currentValue ) && relativePropertyValue.Get( relativeValue ) )
409 value = currentValue * relativeValue;
414 case Property::VECTOR2:
416 if( componentIndex == Property::INVALID_COMPONENT_INDEX )
418 AdjustProperty< Vector2 >( value, relativePropertyValue );
422 Vector2 vector2Value;
423 value.Get( vector2Value );
425 if( componentIndex == 0 )
427 vector2Value.x += relativePropertyValue.Get< float >();
429 else if( componentIndex == 1 )
431 vector2Value.y += relativePropertyValue.Get< float >();
434 value = vector2Value;
440 case Property::VECTOR3:
442 if( componentIndex == Property::INVALID_COMPONENT_INDEX )
444 AdjustProperty< Vector3 >( value, relativePropertyValue );
448 Vector3 vector3Value;
449 value.Get( vector3Value );
451 if( componentIndex == 0 )
453 vector3Value.x += relativePropertyValue.Get< float >();
455 else if( componentIndex == 1 )
457 vector3Value.y += relativePropertyValue.Get< float >();
459 else if( componentIndex == 2 )
461 vector3Value.z += relativePropertyValue.Get< float >();
464 value = vector3Value;
469 case Property::VECTOR4:
471 if( componentIndex == Property::INVALID_COMPONENT_INDEX )
473 AdjustProperty< Vector4 >( value, relativePropertyValue );
477 Vector4 vector4Value;
478 value.Get( vector4Value );
480 if( componentIndex == 0 )
482 vector4Value.x += relativePropertyValue.Get< float >();
484 else if( componentIndex == 1 )
486 vector4Value.y += relativePropertyValue.Get< float >();
488 else if( componentIndex == 2 )
490 vector4Value.z += relativePropertyValue.Get< float >();
492 else if( componentIndex == 3 )
494 vector4Value.w += relativePropertyValue.Get< float >();
497 value = vector4Value;
504 } // namespace Internal