Merge "DALi Version 1.0.4" into tizen
[platform/core/uifw/dali-core.git] / dali / public-api / object / property-conditions.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 // 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::operator=(BaseHandle::NullType* rhs)
51 {
52   DALI_ASSERT_ALWAYS( (rhs == NULL) && "Can only assign NULL pointer to handle");
53   Reset();
54   return *this;
55 }
56
57 PropertyCondition::ArgumentContainer PropertyCondition::GetArguments()
58 {
59   return GetImplementation(*this).arguments;
60 }
61
62 const PropertyCondition::ArgumentContainer& PropertyCondition::GetArguments() const
63 {
64   return GetImplementation(*this).arguments;
65 }
66
67 PropertyCondition LessThanCondition(float arg)
68 {
69   PropertyCondition condition;
70   GetImplementation(condition).type = Internal::PropertyCondition::LessThan;
71   GetImplementation(condition).arguments.push_back(Property::Value(arg));
72
73   return condition;
74 }
75
76 PropertyCondition GreaterThanCondition(float arg)
77 {
78   PropertyCondition condition;
79   GetImplementation(condition).type = Internal::PropertyCondition::GreaterThan;
80   GetImplementation(condition).arguments.push_back(Property::Value(arg));
81
82   return condition;
83 }
84
85 PropertyCondition InsideCondition(float arg0, float arg1)
86 {
87   PropertyCondition condition;
88   GetImplementation(condition).type = Internal::PropertyCondition::Inside;
89   GetImplementation(condition).arguments.push_back(Property::Value(arg0));
90   GetImplementation(condition).arguments.push_back(Property::Value(arg1));
91
92   return condition;
93 }
94
95 PropertyCondition OutsideCondition(float arg0, float arg1)
96 {
97   PropertyCondition condition;
98   GetImplementation(condition).type = Internal::PropertyCondition::Outside;
99   GetImplementation(condition).arguments.push_back(Property::Value(arg0));
100   GetImplementation(condition).arguments.push_back(Property::Value(arg1));
101
102   return condition;
103 }
104
105 PropertyCondition StepCondition(float stepAmount, float referenceValue)
106 {
107   PropertyCondition condition;
108   GetImplementation(condition).type = Internal::PropertyCondition::Step;
109   GetImplementation(condition).arguments.push_back(Property::Value(referenceValue));
110   GetImplementation(condition).arguments.push_back(Property::Value(1.0f / stepAmount));
111   GetImplementation(condition).arguments.push_back(Property::Value(0.0f)); // current step
112
113   return condition;
114 }
115
116 PropertyCondition VariableStepCondition(const std::vector<float>& stepAmount)
117 {
118   PropertyCondition condition;
119   GetImplementation(condition).type = Internal::PropertyCondition::VariableStep;
120   GetImplementation(condition).arguments.push_back(Property::Value(0.0f)); // current step
121   int size = stepAmount.size();
122   GetImplementation(condition).arguments.push_back(Property::Value(static_cast<float>(size))); // store number of steps
123   for( std::vector<float>::const_iterator it = stepAmount.begin(), endIt = stepAmount.end(); it != endIt; ++it )
124   {
125     GetImplementation(condition).arguments.push_back(Property::Value( *it ));
126   }
127
128   return condition;
129 }
130
131 } // namespace Dali