Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / property-input-accessor.h
1 #ifndef DALI_PROPERTY_INPUT_ACCESSOR_H
2 #define DALI_PROPERTY_INPUT_ACCESSOR_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/common/property-input-impl.h>
23 #include <dali/public-api/object/property-types.h>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 class PropertyInputAccessor
30 {
31 public:
32   /**
33    * Create the PropertyInputAccessor.
34    */
35   PropertyInputAccessor()
36   : mInput(nullptr),
37     mComponentIndex(-1)
38   {
39   }
40
41   /**
42    * Create the PropertyInputAccessor.
43    */
44   PropertyInputAccessor(const PropertyInputImpl* input, int32_t componentIndex)
45   : mInput(input),
46     mComponentIndex(componentIndex)
47   {
48   }
49
50   /**
51    * Copy from a PropertyInputAccessor
52    */
53   PropertyInputAccessor(const PropertyInputAccessor& accessor) = default;
54
55   /**
56    * Copy from a PropertyInputAccessor
57    */
58   PropertyInputAccessor& operator=(const PropertyInputAccessor& accessor)
59   {
60     if(this != &accessor)
61     {
62       mInput          = accessor.mInput;
63       mComponentIndex = accessor.mComponentIndex;
64     }
65     return *this;
66   }
67
68   /**
69    * Set the property input.
70    */
71   void SetInput(const PropertyInputImpl& input, int32_t componentIndex)
72   {
73     mInput          = &input;
74     mComponentIndex = componentIndex;
75   }
76
77   /**
78    * Retrieve the property input.
79    */
80   const PropertyInputImpl* GetInput() const
81   {
82     return mInput;
83   }
84
85   /**
86    * @copydoc Dali::Internal::PropertyInputImpl::GetType()
87    */
88   Property::Type GetType() const
89   {
90     return mInput->GetType();
91   }
92
93   /**
94    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputBoolean()
95    */
96   const bool& GetConstraintInputBoolean(BufferIndex updateBufferIndex) const
97   {
98     return mInput->GetConstraintInputBoolean(updateBufferIndex);
99   }
100
101   /**
102    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputInteger() const
103    */
104   const int& GetConstraintInputInteger(BufferIndex updateBufferIndex) const
105   {
106     DALI_ASSERT_DEBUG(mComponentIndex < 0 && "Did not expect valid component index");
107
108     return mInput->GetConstraintInputInteger(updateBufferIndex);
109   }
110
111   /**
112    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputFloat()
113    */
114   const float& GetConstraintInputFloat(BufferIndex updateBufferIndex) const
115   {
116     // Invalid index is ok
117     if(mComponentIndex < 0)
118     {
119       // Not a Vector2, Vector3 or Vector4 component, expecting float type
120       return mInput->GetConstraintInputFloat(updateBufferIndex);
121     }
122     else if(PropertyTypes::Get<Vector2>() == mInput->GetType())
123     {
124       if(0 == mComponentIndex)
125       {
126         return mInput->GetConstraintInputVector2(updateBufferIndex).x;
127       }
128
129       DALI_ASSERT_DEBUG(1 == mComponentIndex && "Invalid Vector2 component index");
130       return mInput->GetConstraintInputVector2(updateBufferIndex).y;
131     }
132     else if(PropertyTypes::Get<Vector3>() == mInput->GetType())
133     {
134       if(0 == mComponentIndex)
135       {
136         return mInput->GetConstraintInputVector3(updateBufferIndex).x;
137       }
138       else if(1 == mComponentIndex)
139       {
140         return mInput->GetConstraintInputVector3(updateBufferIndex).y;
141       }
142
143       DALI_ASSERT_DEBUG(2 == mComponentIndex && "Invalid Vector3 component index");
144       return mInput->GetConstraintInputVector3(updateBufferIndex).z;
145     }
146
147     // Expecting Vector4
148     if(0 == mComponentIndex)
149     {
150       return mInput->GetConstraintInputVector4(updateBufferIndex).x;
151     }
152     else if(1 == mComponentIndex)
153     {
154       return mInput->GetConstraintInputVector4(updateBufferIndex).y;
155     }
156     else if(2 == mComponentIndex)
157     {
158       return mInput->GetConstraintInputVector4(updateBufferIndex).z;
159     }
160
161     DALI_ASSERT_DEBUG(3 == mComponentIndex && "Invalid Vector4 component index");
162     return mInput->GetConstraintInputVector4(updateBufferIndex).w;
163   }
164
165   /**
166    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector2()
167    */
168   const Vector2& GetConstraintInputVector2(BufferIndex updateBufferIndex) const
169   {
170     return mInput->GetConstraintInputVector2(updateBufferIndex);
171   }
172
173   /**
174    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector3()
175    */
176   const Vector3& GetConstraintInputVector3(BufferIndex updateBufferIndex) const
177   {
178     return mInput->GetConstraintInputVector3(updateBufferIndex);
179   }
180
181   /**
182    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector4()
183    */
184   const Vector4& GetConstraintInputVector4(BufferIndex updateBufferIndex) const
185   {
186     return mInput->GetConstraintInputVector4(updateBufferIndex);
187   }
188
189   /**
190    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputQuaternion()
191    */
192   const Quaternion& GetConstraintInputQuaternion(BufferIndex updateBufferIndex) const
193   {
194     return mInput->GetConstraintInputQuaternion(updateBufferIndex);
195   }
196
197   /**
198    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix3()
199    */
200   const Matrix3& GetConstraintInputMatrix3(BufferIndex updateBufferIndex) const
201   {
202     return mInput->GetConstraintInputMatrix3(updateBufferIndex);
203   }
204
205   /**
206    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix()
207    */
208   const Matrix& GetConstraintInputMatrix(BufferIndex updateBufferIndex) const
209   {
210     return mInput->GetConstraintInputMatrix(updateBufferIndex);
211   }
212
213 public:
214   const PropertyInputImpl* mInput;
215   int32_t                  mComponentIndex;
216 };
217
218 } // namespace Internal
219
220 } // namespace Dali
221
222 #endif // DALI_PROPERTY_INPUT_ACCESSOR_H