Merge remote-tracking branch 'origin/tizen' into devel/new_mesh
[platform/core/uifw/dali-core.git] / dali / internal / update / common / property-condition-step-functions.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
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>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 namespace SceneGraph
32 {
33
34 namespace
35 {
36
37 const int ARGINDEX_REF_VALUE = 0;
38 const int ARGINDEX_STEP_SIZE = 1;
39 const int ARGINDEX_CURRENT_STEP = 2;
40
41 } // namespace
42
43 ConditionFunction Step::GetFunction(Property::Type valueType)
44 {
45   ConditionFunction function = NULL;
46
47   switch(valueType)
48   {
49     case Property::INTEGER:
50     {
51       function = EvalInteger;
52       break;
53     }
54     case Property::UNSIGNED_INTEGER:
55     {
56       function = EvalUnsignedInteger;
57       break;
58     }
59     case Property::FLOAT:
60     {
61       function = EvalFloat;
62       break;
63     }
64     case Property::VECTOR2:
65     {
66       function = EvalVector2;
67       break;
68     }
69     case Property::VECTOR3:
70     {
71       function = EvalVector3;
72       break;
73     }
74     case Property::VECTOR4:
75     {
76       function = EvalVector4;
77       break;
78     }
79     default:
80     {
81       function = EvalDefault;
82       break;
83     }
84   } // end switch
85
86   return function;
87 }
88
89 bool Step::Evaluate( const float propertyValue, PropertyNotification::RawArgumentContainer& arg )
90 {
91   const float refValue = arg[ARGINDEX_REF_VALUE];
92   const float step = arg[ARGINDEX_STEP_SIZE];
93   const int currentStep = static_cast<int>(arg[ARGINDEX_CURRENT_STEP]);
94   const float distance = (propertyValue - refValue);
95   // step is actual 1.0f / step so can multiply instead of dividing
96   const int newStep = static_cast<int>(floorf(distance * step));
97
98   if( newStep != currentStep )
99   {
100     // in new section
101     arg[ARGINDEX_CURRENT_STEP] = static_cast<float>(newStep);
102     return true;
103   }
104   return false;
105 }
106
107
108 bool Step::EvalInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
109 {
110   const float propertyValue = static_cast<float>( value.GetInteger() );
111   return Evaluate( propertyValue, arg );
112 }
113
114 bool Step::EvalUnsignedInteger( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
115 {
116   const float propertyValue = static_cast<float>( value.GetUnsignedInteger() );
117   return Evaluate( propertyValue, arg );
118 }
119
120 bool Step::EvalFloat( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
121 {
122   const float propertyValue = value.GetFloat();
123   return Evaluate( propertyValue, arg );
124 }
125 bool Step::EvalVector2( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
126 {
127   const float propertyValue = value.GetVector2().LengthSquared();
128   return Evaluate( propertyValue, arg );
129 }
130
131 bool Step::EvalVector3( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
132 {
133   float propertyValue = value.GetVector3().LengthSquared();
134   return Evaluate( propertyValue, arg );
135 }
136
137 bool Step::EvalVector4( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
138 {
139   const float propertyValue = value.GetVector4().LengthSquared();
140   return Evaluate( propertyValue, arg );
141 }
142
143 bool Step::EvalDefault( const Dali::PropertyInput& value, PropertyNotification::RawArgumentContainer& arg )
144 {
145   return false;
146 }
147
148 } // namespace SceneGraph
149
150 } // namespace Internal
151
152 } // namespace Dali