Merge "Clean up the code to build successfully on macOS" into devel/master
[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) 2019 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/public-api/object/property-types.h>
23 #include <dali/internal/event/common/property-input-impl.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 class PropertyInputAccessor
32 {
33 public:
34
35   /**
36    * Create the PropertyInputAccessor.
37    */
38   PropertyInputAccessor()
39   : mInput( nullptr ),
40     mComponentIndex( -1 )
41   {
42   }
43
44   /**
45    * Create the PropertyInputAccessor.
46    */
47   PropertyInputAccessor( const PropertyInputImpl* input, int32_t componentIndex )
48   : mInput( input ),
49     mComponentIndex( componentIndex )
50   {
51   }
52
53   /**
54    * Copy from a PropertyInputAccessor
55    */
56   PropertyInputAccessor(const PropertyInputAccessor& accessor) = default;
57
58   /**
59    * Copy from a PropertyInputAccessor
60    */
61   PropertyInputAccessor& operator=(const PropertyInputAccessor& accessor)
62   {
63     if( this != &accessor )
64     {
65       mInput = accessor.mInput;
66       mComponentIndex = accessor.mComponentIndex;
67     }
68     return *this;
69   }
70
71   /**
72    * Set the property input.
73    */
74   void SetInput( const PropertyInputImpl& input, int32_t componentIndex )
75   {
76     mInput = &input;
77     mComponentIndex = componentIndex;
78   }
79
80   /**
81    * Retrieve the property input.
82    */
83   const PropertyInputImpl* GetInput() const
84   {
85     return mInput;
86   }
87
88   /**
89    * @copydoc Dali::Internal::PropertyInputImpl::GetType()
90    */
91   Property::Type GetType() const
92   {
93     return mInput->GetType();
94   }
95
96   /**
97    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputBoolean()
98    */
99   const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
100   {
101     return mInput->GetConstraintInputBoolean( updateBufferIndex );
102   }
103
104   /**
105    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputInteger() const
106    */
107   const int& GetConstraintInputInteger( BufferIndex updateBufferIndex ) const
108   {
109     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
110
111     return mInput->GetConstraintInputInteger( updateBufferIndex );
112   }
113
114   /**
115    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputFloat()
116    */
117   const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const
118   {
119     // Invalid index is ok
120     if ( mComponentIndex < 0 )
121     {
122       // Not a Vector2, Vector3 or Vector4 component, expecting float type
123       return mInput->GetConstraintInputFloat( updateBufferIndex );
124     }
125     else if ( PropertyTypes::Get< Vector2 >() == mInput->GetType() )
126     {
127       if ( 0 == mComponentIndex )
128       {
129         return mInput->GetConstraintInputVector2( updateBufferIndex ).x;
130       }
131
132       DALI_ASSERT_DEBUG( 1 == mComponentIndex && "Invalid Vector2 component index" );
133       return mInput->GetConstraintInputVector2( updateBufferIndex ).y;
134     }
135     else if ( PropertyTypes::Get< Vector3 >() == mInput->GetType() )
136     {
137       if ( 0 == mComponentIndex )
138       {
139         return mInput->GetConstraintInputVector3( updateBufferIndex ).x;
140       }
141       else if ( 1 == mComponentIndex )
142       {
143         return mInput->GetConstraintInputVector3( updateBufferIndex ).y;
144       }
145
146       DALI_ASSERT_DEBUG( 2 == mComponentIndex && "Invalid Vector3 component index" );
147       return mInput->GetConstraintInputVector3( updateBufferIndex ).z;
148     }
149
150     // Expecting Vector4
151     if ( 0 == mComponentIndex )
152     {
153       return mInput->GetConstraintInputVector4( updateBufferIndex ).x;
154     }
155     else if ( 1 == mComponentIndex )
156     {
157       return mInput->GetConstraintInputVector4( updateBufferIndex ).y;
158     }
159     else if ( 2 == mComponentIndex )
160     {
161       return mInput->GetConstraintInputVector4( updateBufferIndex ).z;
162     }
163
164     DALI_ASSERT_DEBUG( 3 == mComponentIndex && "Invalid Vector4 component index" );
165     return mInput->GetConstraintInputVector4( updateBufferIndex ).w;
166   }
167
168   /**
169    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector2()
170    */
171   const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
172   {
173     return mInput->GetConstraintInputVector2( updateBufferIndex );
174   }
175
176   /**
177    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector3()
178    */
179   const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
180   {
181     return mInput->GetConstraintInputVector3( updateBufferIndex );
182   }
183
184   /**
185    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector4()
186    */
187   const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
188   {
189     return mInput->GetConstraintInputVector4( updateBufferIndex );
190   }
191
192   /**
193    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputQuaternion()
194    */
195   const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
196   {
197     return mInput->GetConstraintInputQuaternion( updateBufferIndex );
198   }
199
200   /**
201    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix3()
202    */
203   const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
204   {
205     return mInput->GetConstraintInputMatrix3( updateBufferIndex );
206   }
207
208   /**
209    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix()
210    */
211   const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
212   {
213     return mInput->GetConstraintInputMatrix( updateBufferIndex );
214   }
215
216 public:
217
218   const PropertyInputImpl* mInput;
219   int32_t mComponentIndex;
220
221 };
222
223 } // namespace Internal
224
225 } // namespace Dali
226
227 #endif // DALI_PROPERTY_INPUT_ACCESSOR_H