2 * Copyright (c) 2021 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/common/extents.h>
23 #include <dali/public-api/math/matrix.h>
24 #include <dali/public-api/math/matrix3.h>
25 #include <dali/public-api/math/quaternion.h>
26 #include <dali/public-api/math/rect.h>
27 #include <dali/public-api/math/vector2.h>
28 #include <dali/public-api/math/vector3.h>
29 #include <dali/public-api/math/vector4.h>
30 #include <dali/public-api/object/property-array.h>
31 #include <dali/public-api/object/property-map.h>
32 #include <dali/public-api/object/property.h>
40 /// Helper to adjust the property value by an amount specified in another property-value
41 template<typename PropertyType>
42 inline void AdjustProperty(Property::Value& currentPropertyValue, const Property::Value& relativePropertyValue)
44 PropertyType currentValue;
45 PropertyType relativeValue;
46 if(currentPropertyValue.Get(currentValue) && relativePropertyValue.Get(relativeValue))
48 currentPropertyValue = currentValue + relativeValue;
52 } // unnamed namespace
54 void PropertyMetadata::SetPropertyValue(const Property::Value& propertyValue)
64 case Property::RECTANGLE:
66 Rect<int32_t> convertedValue;
67 if(propertyValue.Get(convertedValue))
69 value = convertedValue;
74 case Property::STRING:
76 std::string convertedValue;
77 if(propertyValue.Get(convertedValue))
79 value = convertedValue;
86 const Property::Array* array = propertyValue.GetArray();
96 const Property::Map* map = propertyValue.GetMap();
104 case Property::EXTENTS:
106 Extents convertedValue;
107 if(propertyValue.Get(convertedValue))
109 value = convertedValue;
114 case Property::BOOLEAN:
117 if(propertyValue.Get(convertedValue))
119 value = convertedValue;
124 case Property::INTEGER:
126 int32_t convertedValue;
127 if(propertyValue.Get(convertedValue))
129 value = convertedValue;
134 case Property::FLOAT:
136 float convertedValue;
137 if(propertyValue.Get(convertedValue))
139 value = convertedValue;
144 case Property::ROTATION:
146 Quaternion convertedValue;
147 if(propertyValue.Get(convertedValue))
149 value = convertedValue;
154 case Property::MATRIX:
156 Matrix convertedValue;
157 if(propertyValue.Get(convertedValue))
159 value = convertedValue;
164 case Property::MATRIX3:
166 Matrix3 convertedValue;
167 if(propertyValue.Get(convertedValue))
169 value = convertedValue;
174 case Property::VECTOR2:
176 Vector2 vector2Value;
177 value.Get(vector2Value);
179 if(componentIndex == 0)
181 vector2Value.x = propertyValue.Get<float>();
183 else if(componentIndex == 1)
185 vector2Value.y = propertyValue.Get<float>();
189 propertyValue.Get(vector2Value);
192 value = vector2Value;
196 case Property::VECTOR3:
198 Vector3 vector3Value;
199 value.Get(vector3Value);
201 if(componentIndex == 0)
203 vector3Value.x = propertyValue.Get<float>();
205 else if(componentIndex == 1)
207 vector3Value.y = propertyValue.Get<float>();
209 else if(componentIndex == 2)
211 vector3Value.z = propertyValue.Get<float>();
215 propertyValue.Get(vector3Value);
218 value = vector3Value;
222 case Property::VECTOR4:
224 Vector4 vector4Value;
225 value.Get(vector4Value);
227 if(componentIndex == 0)
229 vector4Value.x = propertyValue.Get<float>();
231 else if(componentIndex == 1)
233 vector4Value.y = propertyValue.Get<float>();
235 else if(componentIndex == 2)
237 vector4Value.z = propertyValue.Get<float>();
239 else if(componentIndex == 3)
241 vector4Value.w = propertyValue.Get<float>();
245 propertyValue.Get(vector4Value);
248 value = vector4Value;
254 Property::Value PropertyMetadata::GetPropertyValue() const
256 Property::Value propertyValue;
260 propertyValue = value;
267 case Property::RECTANGLE:
268 case Property::STRING:
269 case Property::ARRAY:
271 case Property::EXTENTS:
272 case Property::BOOLEAN:
273 case Property::INTEGER:
274 case Property::FLOAT:
275 case Property::MATRIX:
276 case Property::MATRIX3:
277 case Property::ROTATION:
279 propertyValue = value;
283 case Property::VECTOR2:
285 Vector2 vector2Value;
286 value.Get(vector2Value);
288 if(componentIndex == 0)
290 propertyValue = vector2Value.x;
292 else if(componentIndex == 1)
294 propertyValue = vector2Value.y;
298 propertyValue = vector2Value;
303 case Property::VECTOR3:
305 Vector3 vector3Value;
306 value.Get(vector3Value);
308 if(componentIndex == 0)
310 propertyValue = vector3Value.x;
312 else if(componentIndex == 1)
314 propertyValue = vector3Value.y;
316 else if(componentIndex == 2)
318 propertyValue = vector3Value.z;
322 propertyValue = vector3Value;
327 case Property::VECTOR4:
329 Vector4 vector4Value;
330 value.Get(vector4Value);
332 if(componentIndex == 0)
334 propertyValue = vector4Value.x;
336 else if(componentIndex == 1)
338 propertyValue = vector4Value.y;
340 else if(componentIndex == 2)
342 propertyValue = vector4Value.z;
344 else if(componentIndex == 3)
346 propertyValue = vector4Value.w;
350 propertyValue = vector4Value;
357 return propertyValue;
360 void PropertyMetadata::AdjustPropertyValueBy(const Property::Value& relativePropertyValue)
365 case Property::RECTANGLE:
366 case Property::STRING:
367 case Property::ARRAY:
369 case Property::EXTENTS:
370 case Property::MATRIX:
371 case Property::MATRIX3:
377 case Property::BOOLEAN:
379 bool currentValue = false;
380 bool relativeValue = false;
381 if(value.Get(currentValue) && relativePropertyValue.Get(relativeValue))
383 value = currentValue || relativeValue;
388 case Property::INTEGER:
390 AdjustProperty<int>(value, relativePropertyValue);
394 case Property::FLOAT:
396 AdjustProperty<float>(value, relativePropertyValue);
400 case Property::ROTATION:
402 Quaternion currentValue;
403 Quaternion relativeValue;
404 if(value.Get(currentValue) && relativePropertyValue.Get(relativeValue))
406 value = currentValue * relativeValue;
411 case Property::VECTOR2:
413 if(componentIndex == Property::INVALID_COMPONENT_INDEX)
415 AdjustProperty<Vector2>(value, relativePropertyValue);
419 Vector2 vector2Value;
420 value.Get(vector2Value);
422 if(componentIndex == 0)
424 vector2Value.x += relativePropertyValue.Get<float>();
426 else if(componentIndex == 1)
428 vector2Value.y += relativePropertyValue.Get<float>();
431 value = vector2Value;
437 case Property::VECTOR3:
439 if(componentIndex == Property::INVALID_COMPONENT_INDEX)
441 AdjustProperty<Vector3>(value, relativePropertyValue);
445 Vector3 vector3Value;
446 value.Get(vector3Value);
448 if(componentIndex == 0)
450 vector3Value.x += relativePropertyValue.Get<float>();
452 else if(componentIndex == 1)
454 vector3Value.y += relativePropertyValue.Get<float>();
456 else if(componentIndex == 2)
458 vector3Value.z += relativePropertyValue.Get<float>();
461 value = vector3Value;
466 case Property::VECTOR4:
468 if(componentIndex == Property::INVALID_COMPONENT_INDEX)
470 AdjustProperty<Vector4>(value, relativePropertyValue);
474 Vector4 vector4Value;
475 value.Get(vector4Value);
477 if(componentIndex == 0)
479 vector4Value.x += relativePropertyValue.Get<float>();
481 else if(componentIndex == 1)
483 vector4Value.y += relativePropertyValue.Get<float>();
485 else if(componentIndex == 2)
487 vector4Value.z += relativePropertyValue.Get<float>();
489 else if(componentIndex == 3)
491 vector4Value.w += relativePropertyValue.Get<float>();
494 value = vector4Value;
501 } // namespace Internal