e30c74d8e60c8955e0b3a8c32b7da5083a7c502a
[platform/core/uifw/dali-core.git] / dali / public-api / object / property-conditions.cpp
1 /*
2  * Copyright (c) 2020 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 // CLASS HEADER
19 #include <dali/public-api/object/property-conditions.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/object/property-value.h>
23 #include <dali/internal/event/common/property-conditions-impl.h>
24
25 namespace Dali
26 {
27
28 PropertyCondition::PropertyCondition()
29 : BaseHandle(new Internal::PropertyCondition())
30 {
31
32 }
33
34 PropertyCondition::~PropertyCondition()
35 {
36
37 }
38
39 PropertyCondition::PropertyCondition( const PropertyCondition& handle ) = default;
40
41 PropertyCondition& PropertyCondition::operator=( const PropertyCondition& rhs ) = default;
42
43 PropertyCondition::PropertyCondition( PropertyCondition&& rhs ) = default;
44
45 PropertyCondition& PropertyCondition::operator=( PropertyCondition&& rhs ) = default;
46
47 std::size_t PropertyCondition::GetArgumentCount() const
48 {
49   return GetImplementation(*this).arguments.Count();
50 }
51
52 float PropertyCondition::GetArgument( std::size_t index ) const
53 {
54   return GetImplementation(*this).arguments[ index ];
55 }
56
57 PropertyCondition LessThanCondition( float arg )
58 {
59   PropertyCondition condition;
60   Internal::PropertyCondition& impl = GetImplementation( condition );
61   impl.type = Internal::PropertyCondition::LessThan;
62   impl.arguments.PushBack( arg );
63
64   return condition;
65 }
66
67 PropertyCondition GreaterThanCondition( float arg )
68 {
69   PropertyCondition condition;
70   Internal::PropertyCondition& impl = GetImplementation( condition );
71   impl.type = Internal::PropertyCondition::GreaterThan;
72   impl.arguments.PushBack( arg );
73
74   return condition;
75 }
76
77 PropertyCondition InsideCondition( float arg0, float arg1 )
78 {
79   PropertyCondition condition;
80   Internal::PropertyCondition& impl = GetImplementation( condition );
81   impl.type = Internal::PropertyCondition::Inside;
82   impl.arguments.PushBack( arg0 );
83   impl.arguments.PushBack( arg1 );
84
85   return condition;
86 }
87
88 PropertyCondition OutsideCondition( float arg0, float arg1 )
89 {
90   PropertyCondition condition;
91   Internal::PropertyCondition& impl = GetImplementation( condition );
92   impl.type = Internal::PropertyCondition::Outside;
93   impl.arguments.PushBack( arg0 );
94   impl.arguments.PushBack( arg1 );
95
96   return condition;
97 }
98
99 PropertyCondition StepCondition( float stepAmount, float referenceValue )
100 {
101   PropertyCondition condition;
102   Internal::PropertyCondition& impl = GetImplementation( condition );
103   impl.type = Internal::PropertyCondition::Step;
104   impl.arguments.PushBack( referenceValue );
105   impl.arguments.PushBack( 1.0f / stepAmount );
106   impl.arguments.PushBack( 0.0f ); // current step
107
108   return condition;
109 }
110
111 PropertyCondition VariableStepCondition( const Dali::Vector<float>& stepAmount )
112 {
113   PropertyCondition condition;
114   Internal::PropertyCondition& impl = GetImplementation( condition );
115   impl.type = Internal::PropertyCondition::VariableStep;
116   impl.arguments.PushBack( 0.0f ); // current step
117   Dali::Vector<float>::SizeType count = stepAmount.Count();
118   impl.arguments.PushBack( float( count ) ); // store number of steps
119   for( Dali::Vector<float>::SizeType index = 0; index < count; ++index )
120   {
121     impl.arguments.PushBack( stepAmount[index] );
122   }
123
124   return condition;
125 }
126
127 } // namespace Dali