2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
33 const int32_t ARGINDEX_STEP_INDEX = 0;
34 const int32_t ARGINDEX_LIST_SIZE = 1;
35 const int32_t ARGINDEX_LIST_START = 2;
39 ConditionFunction VariableStep::GetFunction(Property::Type valueType)
41 ConditionFunction function = nullptr;
45 case Property::INTEGER:
47 function = EvalInteger;
55 case Property::VECTOR2:
57 function = EvalVector2;
60 case Property::VECTOR3:
62 function = EvalVector3;
65 case Property::VECTOR4:
67 function = EvalVector4;
72 function = EvalDefault;
80 bool VariableStep::Evaluate(const float propertyValue, PropertyNotification::RawArgumentContainer& arg)
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;
89 // avoid loop if property currently not within any of the range values
92 if(propertyValue < first)
96 else if(propertyValue >= last)
98 newIndex = numSteps - 1;
103 // increments are in negative direction
104 if(propertyValue > first)
108 else if(propertyValue <= last)
110 newIndex = numSteps - 1;
114 for(i = 0; i < numSteps - 1; ++i)
116 const float arg1 = arg[ARGINDEX_LIST_START + i];
117 const float arg2 = arg[ARGINDEX_LIST_START + (i + 1)];
120 if((propertyValue >= arg1) && (propertyValue < arg2))
128 // increments are in negative direction
129 if((propertyValue > arg2) && (propertyValue <= arg1))
136 if(newIndex != currentIndex)
138 // have changed to new step
139 arg[ARGINDEX_STEP_INDEX] = static_cast<float>(newIndex);
145 bool VariableStep::EvalInteger(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
147 const float propertyValue = static_cast<float>(value.GetInteger());
148 return Evaluate(propertyValue, arg);
151 bool VariableStep::EvalFloat(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
153 const float propertyValue = value.GetFloat();
154 return Evaluate(propertyValue, arg);
157 bool VariableStep::EvalVector2(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
159 const float propertyValue = value.GetVector2().LengthSquared();
160 return Evaluate(propertyValue, arg);
163 bool VariableStep::EvalVector3(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
165 float propertyValue = value.GetVector3().LengthSquared();
166 return Evaluate(propertyValue, arg);
169 bool VariableStep::EvalVector4(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
171 const float propertyValue = value.GetVector4().LengthSquared();
172 return Evaluate(propertyValue, arg);
175 bool VariableStep::EvalDefault(const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg)
180 } // namespace SceneGraph
182 } // namespace Internal