2 * Copyright (c) 2014 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 int ARGINDEX_STEP_INDEX = 0;
38 const int ARGINDEX_LIST_SIZE = 1;
39 const int ARGINDEX_LIST_START = 2;
43 ConditionFunction VariableStep::GetFunction( Property::Type valueType )
45 ConditionFunction function = NULL;
49 case Property::INTEGER:
51 function = EvalInteger;
54 case Property::UNSIGNED_INTEGER:
56 function = EvalUnsignedInteger;
64 case Property::VECTOR2:
66 function = EvalVector2;
69 case Property::VECTOR3:
71 function = EvalVector3;
74 case Property::VECTOR4:
76 function = EvalVector4;
81 function = EvalDefault;
89 bool VariableStep::Evaluate( const float propertyValue, PropertyNotification::RawArgumentContainer& arg )
91 const int currentIndex = arg[ARGINDEX_STEP_INDEX];
92 const int numSteps = arg[ARGINDEX_LIST_SIZE];
93 const float first = arg[ARGINDEX_LIST_START];
94 const float last = arg[ARGINDEX_LIST_START + (numSteps - 1)];
95 const bool ascending = (last > first) ? true : false;
96 int newIndex = currentIndex;
98 // avoid loop if property currently not within any of the range values
101 if( propertyValue < first )
105 else if( propertyValue >= last )
107 newIndex = numSteps - 1;
112 // increments are in negative direction
113 if( propertyValue > first )
117 else if( propertyValue <= last )
119 newIndex = numSteps - 1;
123 for( i = 0 ; i < numSteps - 1 ; ++i )
125 const float arg1 = arg[ARGINDEX_LIST_START + i];
126 const float arg2 = arg[ARGINDEX_LIST_START + (i + 1)];
129 if( ( propertyValue >= arg1 )
130 && ( propertyValue < arg2 ) )
138 // increments are in negative direction
139 if( ( propertyValue > arg2 )
140 && ( propertyValue <= arg1 ) )
147 if( newIndex != currentIndex )
149 // have changed to new step
150 arg[ARGINDEX_STEP_INDEX] = static_cast<float>(newIndex);
156 bool VariableStep::EvalInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
158 const float propertyValue = static_cast<float>( value.GetInteger() );
159 return Evaluate( propertyValue, arg );
162 bool VariableStep::EvalUnsignedInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
164 const float propertyValue = static_cast<float>( value.GetUnsignedInteger() );
165 return Evaluate( propertyValue, arg );
168 bool VariableStep::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
170 const float propertyValue = value.GetFloat();
171 return Evaluate( propertyValue, arg );
174 bool VariableStep::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
176 const float propertyValue = value.GetVector2().LengthSquared();
177 return Evaluate( propertyValue, arg );
180 bool VariableStep::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
182 float propertyValue = value.GetVector3().LengthSquared();
183 return Evaluate( propertyValue, arg );
186 bool VariableStep::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
188 const float propertyValue = value.GetVector4().LengthSquared();
189 return Evaluate( propertyValue, arg );
192 bool VariableStep::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
197 } // namespace SceneGraph
199 } // namespace Internal