[dali_1.9.22] Merge branch 'devel/master'
[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 )
40 : BaseHandle(handle)
41 {
42 }
43
44 PropertyCondition& PropertyCondition::operator=( const PropertyCondition& rhs )
45 {
46   BaseHandle::operator=(rhs);
47   return *this;
48 }
49
50 PropertyCondition::PropertyCondition( PropertyCondition&& rhs ) = default;
51
52 PropertyCondition& PropertyCondition::operator=( PropertyCondition&& rhs ) = default;
53
54 std::size_t PropertyCondition::GetArgumentCount() const
55 {
56   return GetImplementation(*this).arguments.Count();
57 }
58
59 float PropertyCondition::GetArgument( std::size_t index ) const
60 {
61   return GetImplementation(*this).arguments[ index ];
62 }
63
64 PropertyCondition LessThanCondition( float arg )
65 {
66   PropertyCondition condition;
67   Internal::PropertyCondition& impl = GetImplementation( condition );
68   impl.type = Internal::PropertyCondition::LessThan;
69   impl.arguments.PushBack( arg );
70
71   return condition;
72 }
73
74 PropertyCondition GreaterThanCondition( float arg )
75 {
76   PropertyCondition condition;
77   Internal::PropertyCondition& impl = GetImplementation( condition );
78   impl.type = Internal::PropertyCondition::GreaterThan;
79   impl.arguments.PushBack( arg );
80
81   return condition;
82 }
83
84 PropertyCondition InsideCondition( float arg0, float arg1 )
85 {
86   PropertyCondition condition;
87   Internal::PropertyCondition& impl = GetImplementation( condition );
88   impl.type = Internal::PropertyCondition::Inside;
89   impl.arguments.PushBack( arg0 );
90   impl.arguments.PushBack( arg1 );
91
92   return condition;
93 }
94
95 PropertyCondition OutsideCondition( float arg0, float arg1 )
96 {
97   PropertyCondition condition;
98   Internal::PropertyCondition& impl = GetImplementation( condition );
99   impl.type = Internal::PropertyCondition::Outside;
100   impl.arguments.PushBack( arg0 );
101   impl.arguments.PushBack( arg1 );
102
103   return condition;
104 }
105
106 PropertyCondition StepCondition( float stepAmount, float referenceValue )
107 {
108   PropertyCondition condition;
109   Internal::PropertyCondition& impl = GetImplementation( condition );
110   impl.type = Internal::PropertyCondition::Step;
111   impl.arguments.PushBack( referenceValue );
112   impl.arguments.PushBack( 1.0f / stepAmount );
113   impl.arguments.PushBack( 0.0f ); // current step
114
115   return condition;
116 }
117
118 PropertyCondition VariableStepCondition( const Dali::Vector<float>& stepAmount )
119 {
120   PropertyCondition condition;
121   Internal::PropertyCondition& impl = GetImplementation( condition );
122   impl.type = Internal::PropertyCondition::VariableStep;
123   impl.arguments.PushBack( 0.0f ); // current step
124   Dali::Vector<float>::SizeType count = stepAmount.Count();
125   impl.arguments.PushBack( float( count ) ); // store number of steps
126   for( Dali::Vector<float>::SizeType index = 0; index < count; ++index )
127   {
128     impl.arguments.PushBack( stepAmount[index] );
129   }
130
131   return condition;
132 }
133
134 } // namespace Dali