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-step-functions.h>
37 const int32_t ARGINDEX_REF_VALUE = 0;
38 const int32_t ARGINDEX_STEP_SIZE = 1;
39 const int32_t ARGINDEX_CURRENT_STEP = 2;
43 ConditionFunction Step::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 Step::Evaluate( const float propertyValue, PropertyNotification::RawArgumentContainer& arg )
86 const float refValue = arg[ARGINDEX_REF_VALUE];
87 const float step = arg[ARGINDEX_STEP_SIZE];
88 const int32_t currentStep = static_cast<int32_t>(arg[ARGINDEX_CURRENT_STEP]);
89 const float distance = (propertyValue - refValue);
90 // step is actual 1.0f / step so can multiply instead of dividing
91 const int32_t newStep = static_cast<int32_t>(floorf(distance * step));
93 if( newStep != currentStep )
96 arg[ARGINDEX_CURRENT_STEP] = static_cast<float>(newStep);
103 bool Step::EvalInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
105 const float propertyValue = static_cast<float>( value.GetInteger() );
106 return Evaluate( propertyValue, arg );
109 bool Step::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
111 const float propertyValue = value.GetFloat();
112 return Evaluate( propertyValue, arg );
114 bool Step::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
116 const float propertyValue = value.GetVector2().LengthSquared();
117 return Evaluate( propertyValue, arg );
120 bool Step::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
122 float propertyValue = value.GetVector3().LengthSquared();
123 return Evaluate( propertyValue, arg );
126 bool Step::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
128 const float propertyValue = value.GetVector4().LengthSquared();
129 return Evaluate( propertyValue, arg );
132 bool Step::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
137 } // namespace SceneGraph
139 } // namespace Internal