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::BOOLEAN:
61 case Property::INTEGER:
63 case Property::ROTATION:
64 case Property::MATRIX:
65 case Property::MATRIX3:
67 value = propertyValue;
71 case Property::VECTOR2:
74 value.Get( vector2Value );
76 if( componentIndex == 0 )
78 vector2Value.x = propertyValue.Get< float >();
80 else if( componentIndex == 1 )
82 vector2Value.y = propertyValue.Get< float >();
86 propertyValue.Get( vector2Value );
93 case Property::VECTOR3:
96 value.Get( vector3Value );
98 if( componentIndex == 0 )
100 vector3Value.x = propertyValue.Get< float >();
102 else if( componentIndex == 1 )
104 vector3Value.y = propertyValue.Get< float >();
106 else if( componentIndex == 2 )
108 vector3Value.z = propertyValue.Get< float >();
112 propertyValue.Get( vector3Value );
115 value = vector3Value;
119 case Property::VECTOR4:
121 Vector4 vector4Value;
122 value.Get( vector4Value );
124 if( componentIndex == 0 )
126 vector4Value.x = propertyValue.Get< float >();
128 else if( componentIndex == 1 )
130 vector4Value.y = propertyValue.Get< float >();
132 else if( componentIndex == 2 )
134 vector4Value.z = propertyValue.Get< float >();
136 else if( componentIndex == 3 )
138 vector4Value.w = propertyValue.Get< float >();
142 propertyValue.Get( vector4Value );
145 value = vector4Value;
151 Property::Value PropertyMetadata::GetPropertyValue() const
153 Property::Value propertyValue;
155 if( !IsAnimatable() )
157 propertyValue = value;
164 case Property::RECTANGLE:
165 case Property::STRING:
166 case Property::ARRAY:
168 case Property::BOOLEAN:
169 case Property::INTEGER:
170 case Property::FLOAT:
171 case Property::MATRIX:
172 case Property::MATRIX3:
173 case Property::ROTATION:
175 propertyValue = value;
179 case Property::VECTOR2:
181 Vector2 vector2Value;
182 value.Get( vector2Value );
184 if( componentIndex == 0 )
186 propertyValue = vector2Value.x;
188 else if( componentIndex == 1 )
190 propertyValue = vector2Value.y;
194 propertyValue = vector2Value;
199 case Property::VECTOR3:
201 Vector3 vector3Value;
202 value.Get( vector3Value );
204 if( componentIndex == 0 )
206 propertyValue = vector3Value.x;
208 else if( componentIndex == 1 )
210 propertyValue = vector3Value.y;
212 else if( componentIndex == 2 )
214 propertyValue = vector3Value.z;
218 propertyValue = vector3Value;
223 case Property::VECTOR4:
225 Vector4 vector4Value;
226 value.Get( vector4Value );
228 if( componentIndex == 0 )
230 propertyValue = vector4Value.x;
232 else if( componentIndex == 1 )
234 propertyValue = vector4Value.y;
236 else if( componentIndex == 2 )
238 propertyValue = vector4Value.z;
240 else if( componentIndex == 3 )
242 propertyValue = vector4Value.w;
246 propertyValue = vector4Value;
253 return propertyValue;
256 void PropertyMetadata::AdjustPropertyValueBy( const Property::Value& relativePropertyValue )
261 case Property::RECTANGLE:
262 case Property::STRING:
263 case Property::ARRAY:
265 case Property::MATRIX:
266 case Property::MATRIX3:
272 case Property::BOOLEAN:
274 bool currentValue = false;
275 bool relativeValue = false;
276 if( value.Get( currentValue ) && relativePropertyValue.Get( relativeValue ) )
278 value = currentValue || relativeValue;
283 case Property::INTEGER:
285 AdjustProperty< int >( value, relativePropertyValue );
289 case Property::FLOAT:
291 AdjustProperty< float >( value, relativePropertyValue );
295 case Property::ROTATION:
297 Quaternion currentValue;
298 Quaternion relativeValue;
299 if( value.Get( currentValue ) && relativePropertyValue.Get( relativeValue ) )
301 value = currentValue * relativeValue;
306 case Property::VECTOR2:
308 if( componentIndex == Property::INVALID_COMPONENT_INDEX )
310 AdjustProperty< Vector2 >( value, relativePropertyValue );
314 Vector2 vector2Value;
315 value.Get( vector2Value );
317 if( componentIndex == 0 )
319 vector2Value.x += relativePropertyValue.Get< float >();
321 else if( componentIndex == 1 )
323 vector2Value.y += relativePropertyValue.Get< float >();
326 value = vector2Value;
332 case Property::VECTOR3:
334 if( componentIndex == Property::INVALID_COMPONENT_INDEX )
336 AdjustProperty< Vector3 >( value, relativePropertyValue );
340 Vector3 vector3Value;
341 value.Get( vector3Value );
343 if( componentIndex == 0 )
345 vector3Value.x += relativePropertyValue.Get< float >();
347 else if( componentIndex == 1 )
349 vector3Value.y += relativePropertyValue.Get< float >();
351 else if( componentIndex == 2 )
353 vector3Value.z += relativePropertyValue.Get< float >();
356 value = vector3Value;
361 case Property::VECTOR4:
363 if( componentIndex == Property::INVALID_COMPONENT_INDEX )
365 AdjustProperty< Vector4 >( value, relativePropertyValue );
369 Vector4 vector4Value;
370 value.Get( vector4Value );
372 if( componentIndex == 0 )
374 vector4Value.x = relativePropertyValue.Get< float >();
376 else if( componentIndex == 1 )
378 vector4Value.y = relativePropertyValue.Get< float >();
380 else if( componentIndex == 2 )
382 vector4Value.z = relativePropertyValue.Get< float >();
384 else if( componentIndex == 3 )
386 vector4Value.w = relativePropertyValue.Get< float >();
389 value = vector4Value;
396 } // namespace Internal