Revert "[Tizen] Implement partial update"
[platform/core/uifw/dali-core.git] / dali / internal / update / common / property-condition-functions.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <dali/public-api/common/dali-common.h>
19 #include <dali/public-api/math/vector2.h>
20 #include <dali/public-api/math/vector3.h>
21 #include <dali/public-api/math/vector4.h>
22 #include <dali/public-api/object/property-input.h>
23 #include <dali/internal/update/common/property-condition-functions.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 namespace SceneGraph
32 {
33
34 // LessThan ///////////////////////////////////////////////////////////////////
35
36 ConditionFunction LessThan::GetFunction(Property::Type valueType)
37 {
38   ConditionFunction function = NULL;
39
40   switch(valueType)
41   {
42     case Property::BOOLEAN:
43     {
44       function = LessThan::EvalBoolean;
45       break;
46     }
47     case Property::INTEGER:
48     {
49       function = LessThan::EvalInteger;
50       break;
51     }
52     case Property::FLOAT:
53     {
54       function = LessThan::EvalFloat;
55       break;
56     }
57     case Property::VECTOR2:
58     {
59       function = LessThan::EvalVector2;
60       break;
61     }
62     case Property::VECTOR3:
63     {
64       function = LessThan::EvalVector3;
65       break;
66     }
67     case Property::VECTOR4:
68     {
69       function = LessThan::EvalVector4;
70       break;
71     }
72     default:
73     {
74       function = LessThan::EvalDefault;
75       break;
76     }
77   } // end switch
78
79   return function;
80 }
81
82 bool LessThan::EvalBoolean( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
83 {
84   const float arg0 = arg[0];
85   return (value.GetBoolean() < arg0);
86 }
87
88 bool LessThan::EvalInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
89 {
90   const int32_t arg0 = static_cast<int32_t>( arg[0] );
91   return (value.GetInteger() < arg0);
92 }
93
94 bool LessThan::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
95 {
96   const float arg0 = arg[0];
97   return (value.GetFloat() < arg0);
98 }
99
100 bool LessThan::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
101 {
102   const float arg0 = arg[0];
103   return (value.GetVector2().LengthSquared() < arg0 * arg0);
104 }
105
106 bool LessThan::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
107 {
108   const float arg0 = arg[0];
109   return (value.GetVector3().LengthSquared() < arg0 * arg0);
110 }
111
112 bool LessThan::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
113 {
114   const float arg0 = arg[0];
115   return (value.GetVector4().LengthSquared() < arg0 * arg0);
116 }
117
118 bool LessThan::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
119 {
120   return false;
121 }
122
123 // GreaterThan ///////////////////////////////////////////////////////////////////
124
125 ConditionFunction GreaterThan::GetFunction(Property::Type valueType)
126 {
127   ConditionFunction function = NULL;
128
129   switch(valueType)
130   {
131     case Property::BOOLEAN:
132     {
133       function = GreaterThan::EvalBoolean;
134       break;
135     }
136     case Property::INTEGER:
137     {
138       function = GreaterThan::EvalInteger;
139       break;
140     }
141     case Property::FLOAT:
142     {
143       function = GreaterThan::EvalFloat;
144       break;
145     }
146     case Property::VECTOR2:
147     {
148       function = GreaterThan::EvalVector2;
149       break;
150     }
151     case Property::VECTOR3:
152     {
153       function = GreaterThan::EvalVector3;
154       break;
155     }
156     case Property::VECTOR4:
157     {
158       function = GreaterThan::EvalVector4;
159       break;
160     }
161     default:
162     {
163       function = GreaterThan::EvalDefault;
164       break;
165     }
166   } // end switch
167
168   return function;
169 }
170
171 bool GreaterThan::EvalBoolean( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
172 {
173   const float arg0 = arg[0];
174   return (value.GetBoolean() > arg0);
175 }
176
177 bool GreaterThan::EvalInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
178 {
179   const int32_t arg0 = static_cast<int32_t>( arg[0] );
180   return (value.GetInteger() > arg0);
181 }
182
183 bool GreaterThan::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
184 {
185   const float arg0 = arg[0];
186   return (value.GetFloat() > arg0);
187 }
188
189 bool GreaterThan::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
190 {
191   const float arg0 = arg[0];
192   return (value.GetVector2().LengthSquared() > arg0 * arg0);
193 }
194
195 bool GreaterThan::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
196 {
197   const float arg0 = arg[0];
198   return (value.GetVector3().LengthSquared() > arg0 * arg0);
199 }
200
201 bool GreaterThan::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
202 {
203   const float arg0 = arg[0];
204   return (value.GetVector4().LengthSquared() > arg0 * arg0);
205 }
206
207 bool GreaterThan::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
208 {
209   return false;
210 }
211
212 // Inside /////////////////////////////////////////////////////////////////////
213
214 ConditionFunction Inside::GetFunction(Property::Type valueType)
215 {
216   ConditionFunction function = NULL;
217
218   switch(valueType)
219   {
220     case Property::BOOLEAN:
221     {
222       function = Inside::EvalBoolean;
223       break;
224     }
225     case Property::INTEGER:
226     {
227       function = Inside::EvalInteger;
228       break;
229     }
230     case Property::FLOAT:
231     {
232       function = Inside::EvalFloat;
233       break;
234     }
235     case Property::VECTOR2:
236     {
237       function = Inside::EvalVector2;
238       break;
239     }
240     case Property::VECTOR3:
241     {
242       function = Inside::EvalVector3;
243       break;
244     }
245     case Property::VECTOR4:
246     {
247       function = Inside::EvalVector4;
248       break;
249     }
250     default:
251     {
252       function = Inside::EvalDefault;
253       break;
254     }
255   } // end switch
256
257   return function;
258 }
259
260 bool Inside::EvalBoolean( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
261 {
262   const bool valueBoolean = value.GetBoolean();
263   return ( (valueBoolean > arg[0]) && (valueBoolean < arg[1]) );
264 }
265
266 bool Inside::EvalInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
267 {
268   const int32_t valueInteger = value.GetInteger();
269   return ( ( valueInteger > static_cast<int32_t>( arg[0] ) ) && ( valueInteger < static_cast<int32_t>( arg[1] ) ) );
270 }
271
272 bool Inside::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
273 {
274   const float valueFloat = value.GetFloat();
275   return ( (valueFloat > arg[0]) && (valueFloat < arg[1]) );
276 }
277
278 bool Inside::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
279 {
280   const float length2 = value.GetVector2().LengthSquared();
281   return ( (length2 > arg[0]*arg[0]) && (length2 < arg[1]*arg[1]) );
282 }
283
284 bool Inside::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
285 {
286   const float length2 = value.GetVector3().LengthSquared();
287   return ( (length2 > arg[0]*arg[0]) && (length2 < arg[1]*arg[1]) );
288 }
289
290 bool Inside::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
291 {
292   const float length2 = value.GetVector4().LengthSquared();
293   return ( (length2 > arg[0]*arg[0]) && (length2 < arg[1]*arg[1]) );
294 }
295
296 bool Inside::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
297 {
298   return false;
299 }
300
301 // Outside ////////////////////////////////////////////////////////////////////
302
303 ConditionFunction Outside::GetFunction(Property::Type valueType)
304 {
305   ConditionFunction function = NULL;
306
307   switch(valueType)
308   {
309     case Property::BOOLEAN:
310     {
311       function = Outside::EvalBoolean;
312       break;
313     }
314     case Property::INTEGER:
315     {
316       function = Outside::EvalInteger;
317       break;
318     }
319     case Property::FLOAT:
320     {
321       function = Outside::EvalFloat;
322       break;
323     }
324     case Property::VECTOR2:
325     {
326       function = Outside::EvalVector2;
327       break;
328     }
329     case Property::VECTOR3:
330     {
331       function = Outside::EvalVector3;
332       break;
333     }
334     case Property::VECTOR4:
335     {
336       function = Outside::EvalVector4;
337       break;
338     }
339     default:
340     {
341       function = Outside::EvalDefault;
342       break;
343     }
344   } // end switch
345
346   return function;
347 }
348
349 bool Outside::EvalBoolean( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
350 {
351   const bool valueBoolean = value.GetBoolean();
352   return ( (valueBoolean < arg[0]) || (valueBoolean > arg[1]) );
353 }
354
355 bool Outside::EvalInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
356 {
357   const int32_t valueInteger = value.GetInteger();
358   return ( ( valueInteger < static_cast<int32_t>( arg[0] ) ) || ( valueInteger > static_cast<int32_t>( arg[0] ) ) );
359 }
360
361 bool Outside::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
362 {
363   const float valueFloat = value.GetFloat();
364   return ( (valueFloat < arg[0]) || (valueFloat > arg[1]) );
365 }
366
367 bool Outside::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
368 {
369   const float length2 = value.GetVector2().LengthSquared();
370   return ( (length2 < arg[0]*arg[0]) || (length2 > arg[1]*arg[1]) );
371 }
372
373 bool Outside::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
374 {
375   const float length2 = value.GetVector3().LengthSquared();
376   return ( (length2 < arg[0]*arg[0]) || (length2 > arg[1]*arg[1]) );
377 }
378
379 bool Outside::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
380 {
381   const float length2 = value.GetVector4().LengthSquared();
382   return ( (length2 < arg[0]*arg[0]) || (length2 > arg[1]*arg[1]) );
383 }
384
385 bool Outside::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
386 {
387   return false;
388 }
389
390 } // namespace SceneGraph
391
392 } // namespace Internal
393
394 } // namespace Dali