License conversion from Flora to Apache 2.0
[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::FLOAT:
48     {
49       function = LessThan::EvalFloat;
50       break;
51     }
52     case Property::VECTOR2:
53     {
54       function = LessThan::EvalVector2;
55       break;
56     }
57     case Property::VECTOR3:
58     {
59       function = LessThan::EvalVector3;
60       break;
61     }
62     case Property::VECTOR4:
63     {
64       function = LessThan::EvalVector4;
65       break;
66     }
67     default:
68     {
69       function = LessThan::EvalDefault;
70       break;
71     }
72   } // end switch
73
74   return function;
75 }
76
77 bool LessThan::EvalBoolean( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
78 {
79   const float arg0 = arg[0];
80   return (value.GetBoolean() < arg0);
81 }
82
83 bool LessThan::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
84 {
85   const float arg0 = arg[0];
86   return (value.GetFloat() < arg0);
87 }
88
89 bool LessThan::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
90 {
91   const float arg0 = arg[0];
92   return (value.GetVector2().LengthSquared() < arg0 * arg0);
93 }
94
95 bool LessThan::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
96 {
97   const float arg0 = arg[0];
98   return (value.GetVector3().LengthSquared() < arg0 * arg0);
99 }
100
101 bool LessThan::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
102 {
103   const float arg0 = arg[0];
104   return (value.GetVector4().LengthSquared() < arg0 * arg0);
105 }
106
107 bool LessThan::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
108 {
109   return false;
110 }
111
112 // GreaterThan ///////////////////////////////////////////////////////////////////
113
114 ConditionFunction GreaterThan::GetFunction(Property::Type valueType)
115 {
116   ConditionFunction function = NULL;
117
118   switch(valueType)
119   {
120     case Property::BOOLEAN:
121     {
122       function = GreaterThan::EvalBoolean;
123       break;
124     }
125     case Property::FLOAT:
126     {
127       function = GreaterThan::EvalFloat;
128       break;
129     }
130     case Property::VECTOR2:
131     {
132       function = GreaterThan::EvalVector2;
133       break;
134     }
135     case Property::VECTOR3:
136     {
137       function = GreaterThan::EvalVector3;
138       break;
139     }
140     case Property::VECTOR4:
141     {
142       function = GreaterThan::EvalVector4;
143       break;
144     }
145     default:
146     {
147       function = GreaterThan::EvalDefault;
148       break;
149     }
150   } // end switch
151
152   return function;
153 }
154
155 bool GreaterThan::EvalBoolean( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
156 {
157   const float arg0 = arg[0];
158   return (value.GetBoolean() > arg0);
159 }
160
161 bool GreaterThan::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
162 {
163   const float arg0 = arg[0];
164   return (value.GetFloat() > arg0);
165 }
166
167 bool GreaterThan::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
168 {
169   const float arg0 = arg[0];
170   return (value.GetVector2().LengthSquared() > arg0 * arg0);
171 }
172
173 bool GreaterThan::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
174 {
175   const float arg0 = arg[0];
176   return (value.GetVector3().LengthSquared() > arg0 * arg0);
177 }
178
179 bool GreaterThan::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
180 {
181   const float arg0 = arg[0];
182   return (value.GetVector4().LengthSquared() > arg0 * arg0);
183 }
184
185 bool GreaterThan::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
186 {
187   return false;
188 }
189
190 // Inside /////////////////////////////////////////////////////////////////////
191
192 ConditionFunction Inside::GetFunction(Property::Type valueType)
193 {
194   ConditionFunction function = NULL;
195
196   switch(valueType)
197   {
198     case Property::BOOLEAN:
199     {
200       function = Inside::EvalBoolean;
201       break;
202     }
203     case Property::FLOAT:
204     {
205       function = Inside::EvalFloat;
206       break;
207     }
208     case Property::VECTOR2:
209     {
210       function = Inside::EvalVector2;
211       break;
212     }
213     case Property::VECTOR3:
214     {
215       function = Inside::EvalVector3;
216       break;
217     }
218     case Property::VECTOR4:
219     {
220       function = Inside::EvalVector4;
221       break;
222     }
223     default:
224     {
225       function = Inside::EvalDefault;
226       break;
227     }
228   } // end switch
229
230   return function;
231 }
232
233 bool Inside::EvalBoolean( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
234 {
235   const bool valueBoolean = value.GetBoolean();
236   return ( (valueBoolean > arg[0]) && (valueBoolean < arg[1]) );
237 }
238
239 bool Inside::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
240 {
241   const float valueFloat = value.GetFloat();
242   return ( (valueFloat > arg[0]) && (valueFloat < arg[1]) );
243 }
244
245 bool Inside::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
246 {
247   const float length2 = value.GetVector2().LengthSquared();
248   return ( (length2 > arg[0]*arg[0]) && (length2 < arg[1]*arg[1]) );
249 }
250
251 bool Inside::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
252 {
253   const float length2 = value.GetVector3().LengthSquared();
254   return ( (length2 > arg[0]*arg[0]) && (length2 < arg[1]*arg[1]) );
255 }
256
257 bool Inside::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
258 {
259   const float length2 = value.GetVector4().LengthSquared();
260   return ( (length2 > arg[0]*arg[0]) && (length2 < arg[1]*arg[1]) );
261 }
262
263 bool Inside::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
264 {
265   return false;
266 }
267
268 // Outside ////////////////////////////////////////////////////////////////////
269
270 ConditionFunction Outside::GetFunction(Property::Type valueType)
271 {
272   ConditionFunction function = NULL;
273
274   switch(valueType)
275   {
276     case Property::BOOLEAN:
277     {
278       function = Outside::EvalBoolean;
279       break;
280     }
281     case Property::FLOAT:
282     {
283       function = Outside::EvalFloat;
284       break;
285     }
286     case Property::VECTOR2:
287     {
288       function = Outside::EvalVector2;
289       break;
290     }
291     case Property::VECTOR3:
292     {
293       function = Outside::EvalVector3;
294       break;
295     }
296     case Property::VECTOR4:
297     {
298       function = Outside::EvalVector4;
299       break;
300     }
301     default:
302     {
303       function = Outside::EvalDefault;
304       break;
305     }
306   } // end switch
307
308   return function;
309 }
310
311 bool Outside::EvalBoolean( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
312 {
313   const bool valueBoolean = value.GetBoolean();
314   return ( (valueBoolean < arg[0]) || (valueBoolean > arg[1]) );
315 }
316
317 bool Outside::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
318 {
319   const float valueFloat = value.GetFloat();
320   return ( (valueFloat < arg[0]) || (valueFloat > arg[1]) );
321 }
322
323 bool Outside::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
324 {
325   const float length2 = value.GetVector2().LengthSquared();
326   return ( (length2 < arg[0]*arg[0]) || (length2 > arg[1]*arg[1]) );
327 }
328
329 bool Outside::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
330 {
331   const float length2 = value.GetVector3().LengthSquared();
332   return ( (length2 < arg[0]*arg[0]) || (length2 > arg[1]*arg[1]) );
333 }
334
335 bool Outside::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
336 {
337   const float length2 = value.GetVector4().LengthSquared();
338   return ( (length2 < arg[0]*arg[0]) || (length2 > arg[1]*arg[1]) );
339 }
340
341 bool Outside::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
342 {
343   return false;
344 }
345
346 } // namespace SceneGraph
347
348 } // namespace Internal
349
350 } // namespace Dali