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