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