Added animation and constraint support for UNSIGNED_INTEGER property type
[platform/core/uifw/dali-core.git] / dali / internal / update / common / property-condition-functions.cpp
1 /*
2  * Copyright (c) 2014 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::UNSIGNED_INTEGER:
53     {
54       function = LessThan::EvalUnsignedInteger;
55       break;
56     }
57     case Property::FLOAT:
58     {
59       function = LessThan::EvalFloat;
60       break;
61     }
62     case Property::VECTOR2:
63     {
64       function = LessThan::EvalVector2;
65       break;
66     }
67     case Property::VECTOR3:
68     {
69       function = LessThan::EvalVector3;
70       break;
71     }
72     case Property::VECTOR4:
73     {
74       function = LessThan::EvalVector4;
75       break;
76     }
77     default:
78     {
79       function = LessThan::EvalDefault;
80       break;
81     }
82   } // end switch
83
84   return function;
85 }
86
87 bool LessThan::EvalBoolean( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
88 {
89   const float arg0 = arg[0];
90   return (value.GetBoolean() < arg0);
91 }
92
93 bool LessThan::EvalInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
94 {
95   const int arg0 = arg[0];
96   return (value.GetInteger() < arg0);
97 }
98
99 bool LessThan::EvalUnsignedInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
100 {
101   const unsigned int arg0 = arg[0];
102   return (value.GetUnsignedInteger() < arg0);
103 }
104
105 bool LessThan::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
106 {
107   const float arg0 = arg[0];
108   return (value.GetFloat() < arg0);
109 }
110
111 bool LessThan::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
112 {
113   const float arg0 = arg[0];
114   return (value.GetVector2().LengthSquared() < arg0 * arg0);
115 }
116
117 bool LessThan::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
118 {
119   const float arg0 = arg[0];
120   return (value.GetVector3().LengthSquared() < arg0 * arg0);
121 }
122
123 bool LessThan::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
124 {
125   const float arg0 = arg[0];
126   return (value.GetVector4().LengthSquared() < arg0 * arg0);
127 }
128
129 bool LessThan::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
130 {
131   return false;
132 }
133
134 // GreaterThan ///////////////////////////////////////////////////////////////////
135
136 ConditionFunction GreaterThan::GetFunction(Property::Type valueType)
137 {
138   ConditionFunction function = NULL;
139
140   switch(valueType)
141   {
142     case Property::BOOLEAN:
143     {
144       function = GreaterThan::EvalBoolean;
145       break;
146     }
147     case Property::INTEGER:
148     {
149       function = GreaterThan::EvalInteger;
150       break;
151     }
152     case Property::UNSIGNED_INTEGER:
153     {
154       function = GreaterThan::EvalUnsignedInteger;
155       break;
156     }
157     case Property::FLOAT:
158     {
159       function = GreaterThan::EvalFloat;
160       break;
161     }
162     case Property::VECTOR2:
163     {
164       function = GreaterThan::EvalVector2;
165       break;
166     }
167     case Property::VECTOR3:
168     {
169       function = GreaterThan::EvalVector3;
170       break;
171     }
172     case Property::VECTOR4:
173     {
174       function = GreaterThan::EvalVector4;
175       break;
176     }
177     default:
178     {
179       function = GreaterThan::EvalDefault;
180       break;
181     }
182   } // end switch
183
184   return function;
185 }
186
187 bool GreaterThan::EvalBoolean( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
188 {
189   const float arg0 = arg[0];
190   return (value.GetBoolean() > arg0);
191 }
192
193 bool GreaterThan::EvalInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
194 {
195   const int arg0 = arg[0];
196   return (value.GetInteger() > arg0);
197 }
198
199 bool GreaterThan::EvalUnsignedInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
200 {
201   const unsigned int arg0 = arg[0];
202   return (value.GetUnsignedInteger() > arg0);
203 }
204
205 bool GreaterThan::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
206 {
207   const float arg0 = arg[0];
208   return (value.GetFloat() > arg0);
209 }
210
211 bool GreaterThan::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
212 {
213   const float arg0 = arg[0];
214   return (value.GetVector2().LengthSquared() > arg0 * arg0);
215 }
216
217 bool GreaterThan::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
218 {
219   const float arg0 = arg[0];
220   return (value.GetVector3().LengthSquared() > arg0 * arg0);
221 }
222
223 bool GreaterThan::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
224 {
225   const float arg0 = arg[0];
226   return (value.GetVector4().LengthSquared() > arg0 * arg0);
227 }
228
229 bool GreaterThan::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
230 {
231   return false;
232 }
233
234 // Inside /////////////////////////////////////////////////////////////////////
235
236 ConditionFunction Inside::GetFunction(Property::Type valueType)
237 {
238   ConditionFunction function = NULL;
239
240   switch(valueType)
241   {
242     case Property::BOOLEAN:
243     {
244       function = Inside::EvalBoolean;
245       break;
246     }
247     case Property::INTEGER:
248     {
249       function = Inside::EvalInteger;
250       break;
251     }
252     case Property::UNSIGNED_INTEGER:
253     {
254       function = Inside::EvalUnsignedInteger;
255       break;
256     }
257     case Property::FLOAT:
258     {
259       function = Inside::EvalFloat;
260       break;
261     }
262     case Property::VECTOR2:
263     {
264       function = Inside::EvalVector2;
265       break;
266     }
267     case Property::VECTOR3:
268     {
269       function = Inside::EvalVector3;
270       break;
271     }
272     case Property::VECTOR4:
273     {
274       function = Inside::EvalVector4;
275       break;
276     }
277     default:
278     {
279       function = Inside::EvalDefault;
280       break;
281     }
282   } // end switch
283
284   return function;
285 }
286
287 bool Inside::EvalBoolean( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
288 {
289   const bool valueBoolean = value.GetBoolean();
290   return ( (valueBoolean > arg[0]) && (valueBoolean < arg[1]) );
291 }
292
293 bool Inside::EvalInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
294 {
295   const int valueInteger = value.GetInteger();
296   return ( (valueInteger > arg[0]) && (valueInteger < arg[1]) );
297 }
298
299 bool Inside::EvalUnsignedInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
300 {
301   const unsigned int valueUInt = value.GetUnsignedInteger();
302   return ( (valueUInt > arg[0]) && (valueUInt < arg[1]) );
303 }
304
305 bool Inside::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
306 {
307   const float valueFloat = value.GetFloat();
308   return ( (valueFloat > arg[0]) && (valueFloat < arg[1]) );
309 }
310
311 bool Inside::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
312 {
313   const float length2 = value.GetVector2().LengthSquared();
314   return ( (length2 > arg[0]*arg[0]) && (length2 < arg[1]*arg[1]) );
315 }
316
317 bool Inside::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
318 {
319   const float length2 = value.GetVector3().LengthSquared();
320   return ( (length2 > arg[0]*arg[0]) && (length2 < arg[1]*arg[1]) );
321 }
322
323 bool Inside::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
324 {
325   const float length2 = value.GetVector4().LengthSquared();
326   return ( (length2 > arg[0]*arg[0]) && (length2 < arg[1]*arg[1]) );
327 }
328
329 bool Inside::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
330 {
331   return false;
332 }
333
334 // Outside ////////////////////////////////////////////////////////////////////
335
336 ConditionFunction Outside::GetFunction(Property::Type valueType)
337 {
338   ConditionFunction function = NULL;
339
340   switch(valueType)
341   {
342     case Property::BOOLEAN:
343     {
344       function = Outside::EvalBoolean;
345       break;
346     }
347     case Property::INTEGER:
348     {
349       function = Outside::EvalInteger;
350       break;
351     }
352     case Property::UNSIGNED_INTEGER:
353     {
354       function = Outside::EvalUnsignedInteger;
355       break;
356     }
357     case Property::FLOAT:
358     {
359       function = Outside::EvalFloat;
360       break;
361     }
362     case Property::VECTOR2:
363     {
364       function = Outside::EvalVector2;
365       break;
366     }
367     case Property::VECTOR3:
368     {
369       function = Outside::EvalVector3;
370       break;
371     }
372     case Property::VECTOR4:
373     {
374       function = Outside::EvalVector4;
375       break;
376     }
377     default:
378     {
379       function = Outside::EvalDefault;
380       break;
381     }
382   } // end switch
383
384   return function;
385 }
386
387 bool Outside::EvalBoolean( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
388 {
389   const bool valueBoolean = value.GetBoolean();
390   return ( (valueBoolean < arg[0]) || (valueBoolean > arg[1]) );
391 }
392
393 bool Outside::EvalInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
394 {
395   const int valueInteger = value.GetInteger();
396   return ( (valueInteger < arg[0]) || (valueInteger > arg[1]) );
397 }
398
399 bool Outside::EvalUnsignedInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
400 {
401   const unsigned int valueUInt = value.GetUnsignedInteger();
402   return ( (valueUInt < arg[0]) || (valueUInt > arg[1]) );
403 }
404
405 bool Outside::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
406 {
407   const float valueFloat = value.GetFloat();
408   return ( (valueFloat < arg[0]) || (valueFloat > arg[1]) );
409 }
410
411 bool Outside::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
412 {
413   const float length2 = value.GetVector2().LengthSquared();
414   return ( (length2 < arg[0]*arg[0]) || (length2 > arg[1]*arg[1]) );
415 }
416
417 bool Outside::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
418 {
419   const float length2 = value.GetVector3().LengthSquared();
420   return ( (length2 < arg[0]*arg[0]) || (length2 > arg[1]*arg[1]) );
421 }
422
423 bool Outside::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
424 {
425   const float length2 = value.GetVector4().LengthSquared();
426   return ( (length2 < arg[0]*arg[0]) || (length2 > arg[1]*arg[1]) );
427 }
428
429 bool Outside::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
430 {
431   return false;
432 }
433
434 } // namespace SceneGraph
435
436 } // namespace Internal
437
438 } // namespace Dali