2 * Copyright (c) 2018 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/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-variable-step-functions.h>
37 const int32_t ARGINDEX_STEP_INDEX = 0;
38 const int32_t ARGINDEX_LIST_SIZE = 1;
39 const int32_t ARGINDEX_LIST_START = 2;
43 ConditionFunction VariableStep::GetFunction( Property::Type valueType )
45 ConditionFunction function = NULL;
49 case Property::INTEGER:
51 function = EvalInteger;
59 case Property::VECTOR2:
61 function = EvalVector2;
64 case Property::VECTOR3:
66 function = EvalVector3;
69 case Property::VECTOR4:
71 function = EvalVector4;
76 function = EvalDefault;
84 bool VariableStep::Evaluate( const float propertyValue, PropertyNotification::RawArgumentContainer& arg )
86 const int32_t currentIndex = static_cast<int32_t>( arg[ARGINDEX_STEP_INDEX] ); // truncated
87 const int32_t numSteps = static_cast<int32_t>( arg[ARGINDEX_LIST_SIZE] ); // truncated
88 const float first = arg[ARGINDEX_LIST_START];
89 const float last = arg[ARGINDEX_LIST_START + (numSteps - 1)];
90 const bool ascending = (last > first) ? true : false;
91 int32_t newIndex = currentIndex;
93 // avoid loop if property currently not within any of the range values
96 if( propertyValue < first )
100 else if( propertyValue >= last )
102 newIndex = numSteps - 1;
107 // increments are in negative direction
108 if( propertyValue > first )
112 else if( propertyValue <= last )
114 newIndex = numSteps - 1;
118 for( i = 0 ; i < numSteps - 1 ; ++i )
120 const float arg1 = arg[ARGINDEX_LIST_START + i];
121 const float arg2 = arg[ARGINDEX_LIST_START + (i + 1)];
124 if( ( propertyValue >= arg1 )
125 && ( propertyValue < arg2 ) )
133 // increments are in negative direction
134 if( ( propertyValue > arg2 )
135 && ( propertyValue <= arg1 ) )
142 if( newIndex != currentIndex )
144 // have changed to new step
145 arg[ARGINDEX_STEP_INDEX] = static_cast<float>(newIndex);
151 bool VariableStep::EvalInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
153 const float propertyValue = static_cast<float>( value.GetInteger() );
154 return Evaluate( propertyValue, arg );
157 bool VariableStep::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
159 const float propertyValue = value.GetFloat();
160 return Evaluate( propertyValue, arg );
163 bool VariableStep::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
165 const float propertyValue = value.GetVector2().LengthSquared();
166 return Evaluate( propertyValue, arg );
169 bool VariableStep::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
171 float propertyValue = value.GetVector3().LengthSquared();
172 return Evaluate( propertyValue, arg );
175 bool VariableStep::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
177 const float propertyValue = value.GetVector4().LengthSquared();
178 return Evaluate( propertyValue, arg );
181 bool VariableStep::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
186 } // namespace SceneGraph
188 } // namespace Internal