2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
17 #include <dali/public-api/common/dali-common.h>
18 #include <dali/public-api/math/vector2.h>
19 #include <dali/public-api/math/vector3.h>
20 #include <dali/public-api/math/vector4.h>
21 #include <dali/public-api/object/property-input.h>
22 #include <dali/internal/update/common/property-condition-step-functions.h>
36 const int ARGINDEX_REF_VALUE = 0;
37 const int ARGINDEX_STEP_SIZE = 1;
38 const int ARGINDEX_CURRENT_STEP = 2;
42 ConditionFunction Step::GetFunction(Property::Type valueType)
44 ConditionFunction function = NULL;
53 case Property::VECTOR2:
55 function = EvalVector2;
58 case Property::VECTOR3:
60 function = EvalVector3;
63 case Property::VECTOR4:
65 function = EvalVector4;
70 function = EvalDefault;
78 bool Step::Evaluate( const float propertyValue, PropertyNotification::RawArgumentContainer& arg )
80 const float refValue = arg[ARGINDEX_REF_VALUE];
81 const float step = arg[ARGINDEX_STEP_SIZE];
82 const int currentStep = static_cast<int>(arg[ARGINDEX_CURRENT_STEP]);
83 const float distance = (propertyValue - refValue);
84 // step is actual 1.0f / step so can multiply instead of dividing
85 const int newStep = static_cast<int>(floorf(distance * step));
87 if( newStep != currentStep )
90 arg[ARGINDEX_CURRENT_STEP] = static_cast<float>(newStep);
96 bool Step::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
98 const float propertyValue = value.GetFloat();
99 return Evaluate( propertyValue, arg );
102 bool Step::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
104 const float propertyValue = value.GetVector2().LengthSquared();
105 return Evaluate( propertyValue, arg );
108 bool Step::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
110 float propertyValue = value.GetVector3().LengthSquared();
111 return Evaluate( propertyValue, arg );
114 bool Step::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
116 const float propertyValue = value.GetVector4().LengthSquared();
117 return Evaluate( propertyValue, arg );
120 bool Step::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
125 } // namespace SceneGraph
127 } // namespace Internal