2 * Copyright (c) 2017 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>
37 /// Helper to adjust the property value by an amount specified in another property-value
38 template < typename PropertyType >
39 inline void AdjustProperty( Property::Value& currentPropertyValue, const Property::Value& relativePropertyValue )
41 PropertyType currentValue;
42 PropertyType relativeValue;
43 if( currentPropertyValue.Get( currentValue ) && relativePropertyValue.Get( relativeValue ) )
45 currentPropertyValue = currentValue + relativeValue;
49 } // unnamed namespace
51 void PropertyMetadata::SetPropertyValue( const Property::Value& propertyValue )
56 case Property::RECTANGLE:
57 case Property::STRING:
60 case Property::EXTENTS:
61 case Property::BOOLEAN:
62 case Property::INTEGER:
64 case Property::ROTATION:
65 case Property::MATRIX:
66 case Property::MATRIX3:
68 value = propertyValue;
72 case Property::VECTOR2:
75 value.Get( vector2Value );
77 if( componentIndex == 0 )
79 vector2Value.x = propertyValue.Get< float >();
81 else if( componentIndex == 1 )
83 vector2Value.y = propertyValue.Get< float >();
87 propertyValue.Get( vector2Value );
94 case Property::VECTOR3:
97 value.Get( vector3Value );
99 if( componentIndex == 0 )
101 vector3Value.x = propertyValue.Get< float >();
103 else if( componentIndex == 1 )
105 vector3Value.y = propertyValue.Get< float >();
107 else if( componentIndex == 2 )
109 vector3Value.z = propertyValue.Get< float >();
113 propertyValue.Get( vector3Value );
116 value = vector3Value;
120 case Property::VECTOR4:
122 Vector4 vector4Value;
123 value.Get( vector4Value );
125 if( componentIndex == 0 )
127 vector4Value.x = propertyValue.Get< float >();
129 else if( componentIndex == 1 )
131 vector4Value.y = propertyValue.Get< float >();
133 else if( componentIndex == 2 )
135 vector4Value.z = propertyValue.Get< float >();
137 else if( componentIndex == 3 )
139 vector4Value.w = propertyValue.Get< float >();
143 propertyValue.Get( vector4Value );
146 value = vector4Value;
152 Property::Value PropertyMetadata::GetPropertyValue() const
154 Property::Value propertyValue;
156 if( !IsAnimatable() )
158 propertyValue = value;
165 case Property::RECTANGLE:
166 case Property::STRING:
167 case Property::ARRAY:
169 case Property::EXTENTS:
170 case Property::BOOLEAN:
171 case Property::INTEGER:
172 case Property::FLOAT:
173 case Property::MATRIX:
174 case Property::MATRIX3:
175 case Property::ROTATION:
177 propertyValue = value;
181 case Property::VECTOR2:
183 Vector2 vector2Value;
184 value.Get( vector2Value );
186 if( componentIndex == 0 )
188 propertyValue = vector2Value.x;
190 else if( componentIndex == 1 )
192 propertyValue = vector2Value.y;
196 propertyValue = vector2Value;
201 case Property::VECTOR3:
203 Vector3 vector3Value;
204 value.Get( vector3Value );
206 if( componentIndex == 0 )
208 propertyValue = vector3Value.x;
210 else if( componentIndex == 1 )
212 propertyValue = vector3Value.y;
214 else if( componentIndex == 2 )
216 propertyValue = vector3Value.z;
220 propertyValue = vector3Value;
225 case Property::VECTOR4:
227 Vector4 vector4Value;
228 value.Get( vector4Value );
230 if( componentIndex == 0 )
232 propertyValue = vector4Value.x;
234 else if( componentIndex == 1 )
236 propertyValue = vector4Value.y;
238 else if( componentIndex == 2 )
240 propertyValue = vector4Value.z;
242 else if( componentIndex == 3 )
244 propertyValue = vector4Value.w;
248 propertyValue = vector4Value;
255 return propertyValue;
258 void PropertyMetadata::AdjustPropertyValueBy( const Property::Value& relativePropertyValue )
263 case Property::RECTANGLE:
264 case Property::STRING:
265 case Property::ARRAY:
267 case Property::EXTENTS:
268 case Property::MATRIX:
269 case Property::MATRIX3:
275 case Property::BOOLEAN:
277 bool currentValue = false;
278 bool relativeValue = false;
279 if( value.Get( currentValue ) && relativePropertyValue.Get( relativeValue ) )
281 value = currentValue || relativeValue;
286 case Property::INTEGER:
288 AdjustProperty< int >( value, relativePropertyValue );
292 case Property::FLOAT:
294 AdjustProperty< float >( value, relativePropertyValue );
298 case Property::ROTATION:
300 Quaternion currentValue;
301 Quaternion relativeValue;
302 if( value.Get( currentValue ) && relativePropertyValue.Get( relativeValue ) )
304 value = currentValue * relativeValue;
309 case Property::VECTOR2:
311 if( componentIndex == Property::INVALID_COMPONENT_INDEX )
313 AdjustProperty< Vector2 >( value, relativePropertyValue );
317 Vector2 vector2Value;
318 value.Get( vector2Value );
320 if( componentIndex == 0 )
322 vector2Value.x += relativePropertyValue.Get< float >();
324 else if( componentIndex == 1 )
326 vector2Value.y += relativePropertyValue.Get< float >();
329 value = vector2Value;
335 case Property::VECTOR3:
337 if( componentIndex == Property::INVALID_COMPONENT_INDEX )
339 AdjustProperty< Vector3 >( value, relativePropertyValue );
343 Vector3 vector3Value;
344 value.Get( vector3Value );
346 if( componentIndex == 0 )
348 vector3Value.x += relativePropertyValue.Get< float >();
350 else if( componentIndex == 1 )
352 vector3Value.y += relativePropertyValue.Get< float >();
354 else if( componentIndex == 2 )
356 vector3Value.z += relativePropertyValue.Get< float >();
359 value = vector3Value;
364 case Property::VECTOR4:
366 if( componentIndex == Property::INVALID_COMPONENT_INDEX )
368 AdjustProperty< Vector4 >( value, relativePropertyValue );
372 Vector4 vector4Value;
373 value.Get( vector4Value );
375 if( componentIndex == 0 )
377 vector4Value.x += relativePropertyValue.Get< float >();
379 else if( componentIndex == 1 )
381 vector4Value.y += relativePropertyValue.Get< float >();
383 else if( componentIndex == 2 )
385 vector4Value.z += relativePropertyValue.Get< float >();
387 else if( componentIndex == 3 )
389 vector4Value.w += relativePropertyValue.Get< float >();
392 value = vector4Value;
399 } // namespace Internal