Merge "Add TouchDelegateArea property." into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / update / animation / property-component-accessor.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_COMPONENT_ACCESSOR_H
2 #define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_COMPONENT_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/common/dali-common.h>
23 #include <dali/internal/update/common/animatable-property.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 /**
32  * A wrapper class for getting/setting a float component of another property.
33  * Animators use this instead of accessing properties directly.
34  */
35 template < typename PropertyType >
36 class PropertyComponentAccessorX
37 {
38 public:
39
40   /**
41    * Create a property component.
42    * @param [in] property The property which holds a float component.
43    */
44   PropertyComponentAccessorX( SceneGraph::PropertyBase* property )
45   : mProperty( static_cast< SceneGraph::AnimatableProperty<PropertyType>* >(property) ) // we know the type
46   {
47   }
48
49   /**
50    * Non-virtual destructor; PropertyComponentAccessorX is not suitable as a base class.
51    */
52   ~PropertyComponentAccessorX()
53   {
54   }
55
56   /**
57    * Query whether the accessor is set.
58    * @return True if set.
59    */
60   bool IsSet() const
61   {
62     return mProperty != nullptr;
63   }
64
65   /**
66    * Reset the property accessor
67    * @post Calling any other PropertyComponentAccessorX is invalid.
68    */
69   void Reset()
70   {
71     mProperty = nullptr;
72   }
73
74   /**
75    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
76    */
77   bool IsClean() const
78   {
79     return mProperty->IsClean();
80   }
81
82   /**
83    * Read access to the property.
84    * @param [in] bufferIndex The current update buffer index.
85    */
86   float Get( BufferIndex bufferIndex ) const
87   {
88     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorX::Get() mProperty was nullptr" );
89     return mProperty->Get( bufferIndex ).x; // X Component only!
90   }
91
92   /**
93    * @copydoc SceneGraph::AnimatableProperty<float>::Set()
94    */
95   void Set( BufferIndex bufferIndex, float value ) const
96   {
97     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorX::Set() mProperty was nullptr" );
98     mProperty->SetX( bufferIndex, value );
99   }
100
101   /**
102    * @copydoc SceneGraph::AnimatableProperty<float>::Bake()
103    */
104   void Bake( BufferIndex bufferIndex, float value ) const
105   {
106     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorX::Bake() mProperty was nullptr" );
107     mProperty->BakeX( bufferIndex, value );
108   }
109
110 private:
111
112   // Undefined
113   PropertyComponentAccessorX() = delete;
114   PropertyComponentAccessorX(const PropertyComponentAccessorX& property) = delete;
115   PropertyComponentAccessorX& operator=(const PropertyComponentAccessorX& rhs) = delete;
116
117 private:
118
119   SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
120
121 };
122
123 /**
124  * A wrapper class for getting/setting a float component of another property.
125  * Animators use this instead of accessing properties directly.
126  */
127 template < typename PropertyType >
128 class PropertyComponentAccessorY
129 {
130 public:
131
132   /**
133    * Create a property component.
134    * @param [in] property The property which holds a float component.
135    */
136   PropertyComponentAccessorY( SceneGraph::PropertyBase* property )
137   : mProperty( static_cast< SceneGraph::AnimatableProperty<PropertyType>* >(property) ) // we know the type
138   {
139   }
140
141   /**
142    * Non-virtual destructor; PropertyComponentAccessorY is not suitable as a base class.
143    */
144   ~PropertyComponentAccessorY()
145   {
146   }
147
148   /**
149    * Query whether the accessor is set.
150    * @return True if set.
151    */
152   bool IsSet() const
153   {
154     return mProperty != nullptr;
155   }
156
157   /**
158    * Reset the property accessor
159    * @post Calling any other PropertyComponentAccessorY is invalid.
160    */
161   void Reset()
162   {
163     mProperty = nullptr;
164   }
165
166   /**
167    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
168    */
169   bool IsClean() const
170   {
171     return mProperty->IsClean();
172   }
173
174   /**
175    * Read access to the property.
176    * @param [in] bufferIndex The current update buffer index.
177    */
178   float Get( BufferIndex bufferIndex ) const
179   {
180     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorY::Get() mProperty was nullptr" );
181     return mProperty->Get( bufferIndex ).y; // Y Component only!
182   }
183
184   /**
185    * @copydoc SceneGraph::AnimatableProperty<float>::Set()
186    */
187   void Set( BufferIndex bufferIndex, float value ) const
188   {
189     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorY::Set() mProperty was nullptr" );
190     mProperty->SetY( bufferIndex, value );
191   }
192
193   /**
194    * @copydoc SceneGraph::AnimatableProperty<float>::Bake()
195    */
196   void Bake( BufferIndex bufferIndex, float value ) const
197   {
198     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorY::Bake() mProperty was nullptr" );
199     mProperty->BakeY( bufferIndex, value );
200   }
201
202 private:
203
204   // Undefined
205   PropertyComponentAccessorY() = delete;
206   PropertyComponentAccessorY(const PropertyComponentAccessorY& property) = delete;
207   PropertyComponentAccessorY& operator=(const PropertyComponentAccessorY& rhs) = delete;
208
209 private:
210
211   SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
212 };
213
214 /**
215  * A wrapper class for getting/setting a float component of another property.
216  * Animators use this instead of accessing properties directly.
217  */
218 template < typename PropertyType >
219 class PropertyComponentAccessorZ
220 {
221 public:
222
223   /**
224    * Create a property component.
225    * @param [in] property The property which holds a float component.
226    */
227   PropertyComponentAccessorZ( SceneGraph::PropertyBase* property )
228   : mProperty( static_cast< SceneGraph::AnimatableProperty<PropertyType>* >(property) ) // we know the type
229   {
230   }
231
232   /**
233    * Non-virtual destructor; PropertyComponentAccessorZ is not suitable as a base class.
234    */
235   ~PropertyComponentAccessorZ()
236   {
237   }
238
239   /**
240    * Query whether the accessor is set.
241    * @return True if set.
242    */
243   bool IsSet() const
244   {
245     return mProperty != nullptr;
246   }
247
248   /**
249    * Reset the property accessor
250    * @post Calling any other PropertyComponentAccessorZ is invalid.
251    */
252   void Reset()
253   {
254     mProperty = nullptr;
255   }
256
257   /**
258    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
259    */
260   bool IsClean() const
261   {
262     return mProperty->IsClean();
263   }
264
265   /**
266    * Read access to the property.
267    * @param [in] bufferIndex The current update buffer index.
268    */
269   float Get( BufferIndex bufferIndex ) const
270   {
271     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorZ::Get() mProperty was nullptr" );
272     return mProperty->Get( bufferIndex ).z; // Z Component only!
273   }
274
275   /**
276    * @copydoc SceneGraph::AnimatableProperty<float>::Set()
277    */
278   void Set( BufferIndex bufferIndex, float value ) const
279   {
280     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorZ::Set() mProperty was nullptr" );
281     mProperty->SetZ( bufferIndex, value );
282   }
283
284   /**
285    * @copydoc SceneGraph::AnimatableProperty<float>::Bake()
286    */
287   void Bake( BufferIndex bufferIndex, float value ) const
288   {
289     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorZ::Bake() mProperty was nullptr" );
290     mProperty->BakeZ( bufferIndex, value );
291   }
292
293 private:
294
295   // Undefined
296   PropertyComponentAccessorZ() = delete;
297   PropertyComponentAccessorZ(const PropertyComponentAccessorZ& property) = delete;
298   PropertyComponentAccessorZ& operator=(const PropertyComponentAccessorZ& rhs) = delete;
299
300 private:
301
302   SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
303 };
304
305 /**
306  * A wrapper class for getting/setting a float component of another property.
307  * Animators use this instead of accessing properties directly.
308  */
309 template < typename PropertyType >
310 class PropertyComponentAccessorW
311 {
312 public:
313
314   /**
315    * Create a property component.
316    * @param [in] property The property which holds a float component.
317    */
318   PropertyComponentAccessorW( SceneGraph::PropertyBase* property )
319   : mProperty( static_cast< SceneGraph::AnimatableProperty<PropertyType>* >(property) ) // we know the type
320   {
321   }
322
323   /**
324    * Non-virtual destructor; PropertyComponentAccessorW is not suitable as a base class.
325    */
326   ~PropertyComponentAccessorW()
327   {
328   }
329
330   /**
331    * Query whether the accessor is set.
332    * @return True if set.
333    */
334   bool IsSet() const
335   {
336     return mProperty != nullptr;
337   }
338
339   /**
340    * Reset the property accessor
341    * @post Calling any other PropertyComponentAccessorW is invalid.
342    */
343   void Reset()
344   {
345     mProperty = nullptr;
346   }
347
348   /**
349    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
350    */
351   bool IsClean() const
352   {
353     return mProperty->IsClean();
354   }
355
356   /**
357    * Read access to the property.
358    * @param [in] bufferIndex The current update buffer index.
359    */
360   float Get( BufferIndex bufferIndex ) const
361   {
362     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorW::Get() mProperty was nullptr" );
363     return mProperty->Get( bufferIndex ).w; // W Component only!
364   }
365
366   /**
367    * @copydoc SceneGraph::AnimatableProperty<float>::Set()
368    */
369   void Set( BufferIndex bufferIndex, float value ) const
370   {
371     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorW::Set() mProperty was nullptr" );
372     mProperty->SetW( bufferIndex, value );
373   }
374
375   /**
376    * @copydoc SceneGraph::AnimatableProperty<float>::Bake()
377    */
378   void Bake( BufferIndex bufferIndex, float value ) const
379   {
380     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorW::Bake() mProperty was nullptr" );
381     mProperty->BakeW( bufferIndex, value );
382   }
383
384 private:
385
386   // Undefined
387   PropertyComponentAccessorW() = delete;
388   PropertyComponentAccessorW(const PropertyComponentAccessorW& property) = delete;
389   PropertyComponentAccessorW& operator=(const PropertyComponentAccessorW& rhs) = delete;
390
391 private:
392
393   SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
394
395 };
396
397 } // namespace Internal
398
399 } // namespace Dali
400
401 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_COMPONENT_ACCESSOR_H