(Partial Update) Change damaged rect calcutation
[platform/core/uifw/dali-core.git] / dali / internal / update / common / property-condition-variable-step-functions.cpp
1 /*
2  * Copyright (c) 2021 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/internal/update/common/property-condition-variable-step-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>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 namespace SceneGraph
30 {
31 namespace
32 {
33 const int32_t ARGINDEX_STEP_INDEX = 0;
34 const int32_t ARGINDEX_LIST_SIZE  = 1;
35 const int32_t ARGINDEX_LIST_START = 2;
36
37 } // namespace
38
39 ConditionFunction VariableStep::GetFunction(Property::Type valueType)
40 {
41   ConditionFunction function = nullptr;
42
43   switch(valueType)
44   {
45     case Property::INTEGER:
46     {
47       function = EvalInteger;
48       break;
49     }
50     case Property::FLOAT:
51     {
52       function = EvalFloat;
53       break;
54     }
55     case Property::VECTOR2:
56     {
57       function = EvalVector2;
58       break;
59     }
60     case Property::VECTOR3:
61     {
62       function = EvalVector3;
63       break;
64     }
65     case Property::VECTOR4:
66     {
67       function = EvalVector4;
68       break;
69     }
70     default:
71     {
72       function = EvalDefault;
73       break;
74     }
75   } // end switch
76
77   return function;
78 }
79
80 bool VariableStep::Evaluate(const float propertyValue, PropertyNotification::RawArgumentContainer& arg)
81 {
82   const int32_t currentIndex = static_cast<int32_t>(arg[ARGINDEX_STEP_INDEX]); // truncated
83   const int32_t numSteps     = static_cast<int32_t>(arg[ARGINDEX_LIST_SIZE]);  // truncated
84   const float   first        = arg[ARGINDEX_LIST_START];
85   const float   last         = arg[ARGINDEX_LIST_START + (numSteps - 1)];
86   const bool    ascending    = (last > first) ? true : false;
87   int32_t       newIndex     = currentIndex;
88
89   // avoid loop if property currently not within any of the range values
90   if(ascending)
91   {
92     if(propertyValue < first)
93     {
94       newIndex = -1;
95     }
96     else if(propertyValue >= last)
97     {
98       newIndex = numSteps - 1;
99     }
100   }
101   else
102   {
103     // increments are in negative direction
104     if(propertyValue > first)
105     {
106       newIndex = -1;
107     }
108     else if(propertyValue <= last)
109     {
110       newIndex = numSteps - 1;
111     }
112   }
113   int32_t i = 0;
114   for(i = 0; i < numSteps - 1; ++i)
115   {
116     const float arg1 = arg[ARGINDEX_LIST_START + i];
117     const float arg2 = arg[ARGINDEX_LIST_START + (i + 1)];
118     if(ascending)
119     {
120       if((propertyValue >= arg1) && (propertyValue < arg2))
121       {
122         newIndex = i;
123         break;
124       }
125     }
126     else
127     {
128       // increments are in negative direction
129       if((propertyValue > arg2) && (propertyValue <= arg1))
130       {
131         newIndex = i;
132         break;
133       }
134     }
135   }
136   if(newIndex != currentIndex)
137   {
138     // have changed to new step
139     arg[ARGINDEX_STEP_INDEX] = static_cast<float>(newIndex);
140     return true;
141   }
142   return false;
143 }
144
145 bool VariableStep::EvalInteger(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
146 {
147   const float propertyValue = static_cast<float>(value.GetInteger());
148   return Evaluate(propertyValue, arg);
149 }
150
151 bool VariableStep::EvalFloat(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
152 {
153   const float propertyValue = value.GetFloat();
154   return Evaluate(propertyValue, arg);
155 }
156
157 bool VariableStep::EvalVector2(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
158 {
159   const float propertyValue = value.GetVector2().LengthSquared();
160   return Evaluate(propertyValue, arg);
161 }
162
163 bool VariableStep::EvalVector3(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
164 {
165   float propertyValue = value.GetVector3().LengthSquared();
166   return Evaluate(propertyValue, arg);
167 }
168
169 bool VariableStep::EvalVector4(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
170 {
171   const float propertyValue = value.GetVector4().LengthSquared();
172   return Evaluate(propertyValue, arg);
173 }
174
175 bool VariableStep::EvalDefault(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
176 {
177   return false;
178 }
179
180 } // namespace SceneGraph
181
182 } // namespace Internal
183
184 } // namespace Dali