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;
54 case Property::VECTOR2:
56 function = EvalVector2;
59 case Property::VECTOR3:
61 function = EvalVector3;
64 case Property::VECTOR4:
66 function = EvalVector4;
71 function = EvalDefault;
79 bool VariableStep::Evaluate( const float propertyValue, PropertyNotification::RawArgumentContainer& arg )
81 const int currentIndex = arg[ARGINDEX_STEP_INDEX];
82 const int numSteps = arg[ARGINDEX_LIST_SIZE];
83 const float first = arg[ARGINDEX_LIST_START];
84 const float last = arg[ARGINDEX_LIST_START + (numSteps - 1)];
85 const bool ascending = (last > first) ? true : false;
86 int newIndex = currentIndex;
88 // avoid loop if property currently not within any of the range values
91 if( propertyValue < first )
95 else if( propertyValue >= last )
97 newIndex = numSteps - 1;
102 // increments are in negative direction
103 if( propertyValue > first )
107 else if( propertyValue <= last )
109 newIndex = numSteps - 1;
113 for( i = 0 ; i < numSteps - 1 ; ++i )
115 const float arg1 = arg[ARGINDEX_LIST_START + i];
116 const float arg2 = arg[ARGINDEX_LIST_START + (i + 1)];
119 if( ( propertyValue >= arg1 )
120 && ( propertyValue < arg2 ) )
128 // increments are in negative direction
129 if( ( propertyValue > arg2 )
130 && ( propertyValue <= arg1 ) )
137 if( newIndex != currentIndex )
139 // have changed to new step
140 arg[ARGINDEX_STEP_INDEX] = static_cast<float>(newIndex);
146 bool VariableStep::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
148 const float propertyValue = value.GetFloat();
149 return Evaluate( propertyValue, arg );
152 bool VariableStep::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
154 const float propertyValue = value.GetVector2().LengthSquared();
155 return Evaluate( propertyValue, arg );
158 bool VariableStep::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
160 float propertyValue = value.GetVector3().LengthSquared();
161 return Evaluate( propertyValue, arg );
164 bool VariableStep::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
166 const float propertyValue = value.GetVector4().LengthSquared();
167 return Evaluate( propertyValue, arg );
170 bool VariableStep::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
175 } // namespace SceneGraph
177 } // namespace Internal