Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / update / common / property-condition-step-functions.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #include <dali/public-api/common/dali-common.h>
18 #include <dali/public-api/math/vector2.h>
19 #include <dali/public-api/math/vector3.h>
20 #include <dali/public-api/math/vector4.h>
21 #include <dali/public-api/object/property-input.h>
22 #include <dali/internal/update/common/property-condition-step-functions.h>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29
30 namespace SceneGraph
31 {
32
33 namespace
34 {
35
36 const int ARGINDEX_REF_VALUE = 0;
37 const int ARGINDEX_STEP_SIZE = 1;
38 const int ARGINDEX_CURRENT_STEP = 2;
39
40 } // namespace
41
42 ConditionFunction Step::GetFunction(Property::Type valueType)
43 {
44   ConditionFunction function = NULL;
45
46   switch(valueType)
47   {
48     case Property::FLOAT:
49     {
50       function = EvalFloat;
51       break;
52     }
53     case Property::VECTOR2:
54     {
55       function = EvalVector2;
56       break;
57     }
58     case Property::VECTOR3:
59     {
60       function = EvalVector3;
61       break;
62     }
63     case Property::VECTOR4:
64     {
65       function = EvalVector4;
66       break;
67     }
68     default:
69     {
70       function = EvalDefault;
71       break;
72     }
73   } // end switch
74
75   return function;
76 }
77
78 bool Step::Evaluate( const float propertyValue, PropertyNotification::RawArgumentContainer& arg )
79 {
80   const float refValue = arg[ARGINDEX_REF_VALUE];
81   const float step = arg[ARGINDEX_STEP_SIZE];
82   const int currentStep = static_cast<int>(arg[ARGINDEX_CURRENT_STEP]);
83   const float distance = (propertyValue - refValue);
84   // step is actual 1.0f / step so can multiply instead of dividing
85   const int newStep = static_cast<int>(floorf(distance * step));
86
87   if( newStep != currentStep )
88   {
89     // in new section
90     arg[ARGINDEX_CURRENT_STEP] = static_cast<float>(newStep);
91     return true;
92   }
93   return false;
94 }
95
96 bool Step::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
97 {
98   const float propertyValue = value.GetFloat();
99   return Evaluate( propertyValue, arg );
100 }
101
102 bool Step::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
103 {
104   const float propertyValue = value.GetVector2().LengthSquared();
105   return Evaluate( propertyValue, arg );
106 }
107
108 bool Step::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
109 {
110   float propertyValue = value.GetVector3().LengthSquared();
111   return Evaluate( propertyValue, arg );
112 }
113
114 bool Step::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
115 {
116   const float propertyValue = value.GetVector4().LengthSquared();
117   return Evaluate( propertyValue, arg );
118 }
119
120 bool Step::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
121 {
122   return false;
123 }
124
125 } // namespace SceneGraph
126
127 } // namespace Internal
128
129 } // namespace Dali