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.
18 #include <dali/internal/update/common/property-condition-functions.h>
19 #include <dali/public-api/common/dali-common.h>
20 #include <dali/public-api/math/vector2.h>
21 #include <dali/public-api/math/vector3.h>
22 #include <dali/public-api/math/vector4.h>
23 #include <dali/public-api/object/property-input.h>
31 // LessThan ///////////////////////////////////////////////////////////////////
33 ConditionFunction LessThan::GetFunction(Property::Type valueType)
35 ConditionFunction function = nullptr;
39 case Property::BOOLEAN:
41 function = LessThan::EvalBoolean;
44 case Property::INTEGER:
46 function = LessThan::EvalInteger;
51 function = LessThan::EvalFloat;
54 case Property::VECTOR2:
56 function = LessThan::EvalVector2;
59 case Property::VECTOR3:
61 function = LessThan::EvalVector3;
64 case Property::VECTOR4:
66 function = LessThan::EvalVector4;
71 function = LessThan::EvalDefault;
79 bool LessThan::EvalBoolean(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
81 const float arg0 = arg[0];
82 return (value.GetBoolean() < arg0);
85 bool LessThan::EvalInteger(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
87 const int32_t arg0 = static_cast<int32_t>(arg[0]);
88 return (value.GetInteger() < arg0);
91 bool LessThan::EvalFloat(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
93 const float arg0 = arg[0];
94 return (value.GetFloat() < arg0);
97 bool LessThan::EvalVector2(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
99 const float arg0 = arg[0];
100 return (value.GetVector2().LengthSquared() < arg0 * arg0);
103 bool LessThan::EvalVector3(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
105 const float arg0 = arg[0];
106 return (value.GetVector3().LengthSquared() < arg0 * arg0);
109 bool LessThan::EvalVector4(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
111 const float arg0 = arg[0];
112 return (value.GetVector4().LengthSquared() < arg0 * arg0);
115 bool LessThan::EvalDefault(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
120 // GreaterThan ///////////////////////////////////////////////////////////////////
122 ConditionFunction GreaterThan::GetFunction(Property::Type valueType)
124 ConditionFunction function = nullptr;
128 case Property::BOOLEAN:
130 function = GreaterThan::EvalBoolean;
133 case Property::INTEGER:
135 function = GreaterThan::EvalInteger;
138 case Property::FLOAT:
140 function = GreaterThan::EvalFloat;
143 case Property::VECTOR2:
145 function = GreaterThan::EvalVector2;
148 case Property::VECTOR3:
150 function = GreaterThan::EvalVector3;
153 case Property::VECTOR4:
155 function = GreaterThan::EvalVector4;
160 function = GreaterThan::EvalDefault;
168 bool GreaterThan::EvalBoolean(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
170 const float arg0 = arg[0];
171 return (value.GetBoolean() > arg0);
174 bool GreaterThan::EvalInteger(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
176 const int32_t arg0 = static_cast<int32_t>(arg[0]);
177 return (value.GetInteger() > arg0);
180 bool GreaterThan::EvalFloat(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
182 const float arg0 = arg[0];
183 return (value.GetFloat() > arg0);
186 bool GreaterThan::EvalVector2(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
188 const float arg0 = arg[0];
189 return (value.GetVector2().LengthSquared() > arg0 * arg0);
192 bool GreaterThan::EvalVector3(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
194 const float arg0 = arg[0];
195 return (value.GetVector3().LengthSquared() > arg0 * arg0);
198 bool GreaterThan::EvalVector4(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
200 const float arg0 = arg[0];
201 return (value.GetVector4().LengthSquared() > arg0 * arg0);
204 bool GreaterThan::EvalDefault(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
209 // Inside /////////////////////////////////////////////////////////////////////
211 ConditionFunction Inside::GetFunction(Property::Type valueType)
213 ConditionFunction function = nullptr;
217 case Property::BOOLEAN:
219 function = Inside::EvalBoolean;
222 case Property::INTEGER:
224 function = Inside::EvalInteger;
227 case Property::FLOAT:
229 function = Inside::EvalFloat;
232 case Property::VECTOR2:
234 function = Inside::EvalVector2;
237 case Property::VECTOR3:
239 function = Inside::EvalVector3;
242 case Property::VECTOR4:
244 function = Inside::EvalVector4;
249 function = Inside::EvalDefault;
257 bool Inside::EvalBoolean(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
259 const bool valueBoolean = value.GetBoolean();
260 return ((valueBoolean > arg[0]) && (valueBoolean < arg[1]));
263 bool Inside::EvalInteger(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
265 const int32_t valueInteger = value.GetInteger();
266 return ((valueInteger > static_cast<int32_t>(arg[0])) && (valueInteger < static_cast<int32_t>(arg[1])));
269 bool Inside::EvalFloat(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
271 const float valueFloat = value.GetFloat();
272 return ((valueFloat > arg[0]) && (valueFloat < arg[1]));
275 bool Inside::EvalVector2(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
277 const float length2 = value.GetVector2().LengthSquared();
278 return ((length2 > arg[0] * arg[0]) && (length2 < arg[1] * arg[1]));
281 bool Inside::EvalVector3(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
283 const float length2 = value.GetVector3().LengthSquared();
284 return ((length2 > arg[0] * arg[0]) && (length2 < arg[1] * arg[1]));
287 bool Inside::EvalVector4(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
289 const float length2 = value.GetVector4().LengthSquared();
290 return ((length2 > arg[0] * arg[0]) && (length2 < arg[1] * arg[1]));
293 bool Inside::EvalDefault(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
298 // Outside ////////////////////////////////////////////////////////////////////
300 ConditionFunction Outside::GetFunction(Property::Type valueType)
302 ConditionFunction function = nullptr;
306 case Property::BOOLEAN:
308 function = Outside::EvalBoolean;
311 case Property::INTEGER:
313 function = Outside::EvalInteger;
316 case Property::FLOAT:
318 function = Outside::EvalFloat;
321 case Property::VECTOR2:
323 function = Outside::EvalVector2;
326 case Property::VECTOR3:
328 function = Outside::EvalVector3;
331 case Property::VECTOR4:
333 function = Outside::EvalVector4;
338 function = Outside::EvalDefault;
346 bool Outside::EvalBoolean(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
348 const bool valueBoolean = value.GetBoolean();
349 return ((valueBoolean < arg[0]) || (valueBoolean > arg[1]));
352 bool Outside::EvalInteger(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
354 const int32_t valueInteger = value.GetInteger();
355 return ((valueInteger < static_cast<int32_t>(arg[0])) || (valueInteger > static_cast<int32_t>(arg[0])));
358 bool Outside::EvalFloat(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
360 const float valueFloat = value.GetFloat();
361 return ((valueFloat < arg[0]) || (valueFloat > arg[1]));
364 bool Outside::EvalVector2(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
366 const float length2 = value.GetVector2().LengthSquared();
367 return ((length2 < arg[0] * arg[0]) || (length2 > arg[1] * arg[1]));
370 bool Outside::EvalVector3(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
372 const float length2 = value.GetVector3().LengthSquared();
373 return ((length2 < arg[0] * arg[0]) || (length2 > arg[1] * arg[1]));
376 bool Outside::EvalVector4(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
378 const float length2 = value.GetVector4().LengthSquared();
379 return ((length2 < arg[0] * arg[0]) || (length2 > arg[1] * arg[1]));
382 bool Outside::EvalDefault(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
387 } // namespace SceneGraph
389 } // namespace Internal