[Tizen] Add temporaty log to node
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / transform-manager-property.h
1 #ifndef TRANSFORM_MANAGER_PROPERTY_H_
2 #define TRANSFORM_MANAGER_PROPERTY_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 #include <dali/internal/update/common/animatable-property.h>
22 #include <dali/internal/update/manager/transform-manager.h>
23
24 namespace Dali
25 {
26 namespace Internal
27 {
28 namespace SceneGraph
29 {
30 template<typename T>
31 struct TransformManagerPropertyHandler : public AnimatablePropertyBase
32 {
33   /**
34    * Constructor
35    */
36   TransformManagerPropertyHandler() = default;
37
38   /**
39    * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
40    */
41   Dali::Property::Type GetType() const override = 0;
42
43   /**
44    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
45    */
46   virtual T& Get(BufferIndex bufferIndex) = 0;
47
48   /**
49    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
50    */
51   virtual const T& Get(BufferIndex bufferIndex) const = 0;
52
53   /**
54    * @copydoc Dali::PropertyInput::GetVector3()
55    */
56   const Vector3& GetVector3(BufferIndex bufferIndex) const override
57   {
58     return Vector3::ZERO;
59   }
60
61   /**
62    * Retrieve a component of property
63    * @param[in] component The component of the property
64    */
65   virtual const float& GetFloatComponent(uint32_t component) const
66   {
67     DALI_ASSERT_DEBUG(0 && "Invalid call");
68
69     static const float value = 0.0f;
70     return value;
71   }
72
73   /**
74    * Set the property value. This will only persist for the current frame; the property
75    * will be reset with the base value, at the beginning of the next frame.
76    * @param[in] bufferIndex Not used
77    * @param[in] value The new property value.
78    */
79   virtual void Set(BufferIndex bufferIndex, const T& value) = 0;
80
81   /**
82    * Change a component of property
83    * @param[in] value The new value of the component
84    * @param[in] component The component of the property
85    */
86   virtual void SetFloatComponent(float value, uint32_t component)
87   {
88   }
89
90   /**
91    * @copydoc Dali::AnimatableProperty::Bake()
92    */
93   virtual void Bake(BufferIndex bufferIndex, const T& value) = 0;
94
95   /**
96    * Bake a component of a property
97    * @param[in] value The new value of the component
98    * @param[in] component The component of the property
99    */
100   virtual void BakeFloatComponent(float value, uint32_t component)
101   {
102   }
103
104   /**
105    * @copydoc Dali::AnimatableProperty::BakeX()
106    */
107   virtual void BakeX(BufferIndex bufferIndex, float value)
108   {
109   }
110
111   /**
112    * @copydoc Dali::AnimatableProperty::BakeY()
113    */
114   virtual void BakeY(BufferIndex bufferIndex, float value)
115   {
116   }
117
118   /**
119    * @copydoc Dali::AnimatableProperty::BakeZ()
120    */
121   virtual void BakeZ(BufferIndex bufferIndex, float value)
122   {
123   }
124
125   /**
126    * @copydoc Dali::AnimatableProperty::BakeRelative()
127    */
128   virtual void BakeRelative(BufferIndex bufferIndex, const T& value) = 0;
129
130   /**
131    * @copydoc Dali::AnimatableProperty::BakeRelativeMultiply()
132    */
133   virtual void BakeRelativeMultiply(BufferIndex bufferIndex, const T& value){};
134
135   /**
136    * @copydoc Dali::AnimatableProperty::ResetToBaseValue()
137    */
138   void ResetToBaseValue(BufferIndex updateBufferIndex) override
139   {
140   }
141
142   /**
143    * @copydoc Dali::AnimatableProperty::IsClean()
144    */
145   bool IsClean() const override
146   {
147     return false;
148   }
149
150   /**
151    * Initializes the property
152    * @param[in] transformManager Pointer to the transform manager
153    * @param[in] Id of the transformation the property is associated with
154    */
155   void Initialize(TransformManagerData* data)
156   {
157     DALI_ASSERT_ALWAYS(data != nullptr && data->Manager() != nullptr);
158     mTxManagerData = data;
159   }
160
161   /**
162    * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
163    */
164   bool IsTransformManagerProperty() const override
165   {
166     return true;
167   }
168
169   TransformManagerData* mTxManagerData{nullptr};
170 };
171
172 template<TransformManagerProperty PropertyT>
173 struct TransformManagerPropertyVector3 final : public TransformManagerPropertyHandler<Vector3>
174 {
175   TransformManagerPropertyVector3() = default;
176
177   Dali::Property::Type GetType() const override
178   {
179     return Dali::PropertyTypes::Get<Vector3>();
180   }
181
182   Vector3& Get(BufferIndex bufferIndex) override
183   {
184     return mTxManagerData->Manager()->GetVector3PropertyValue(mTxManagerData->Id(), PropertyT);
185   }
186
187   const Vector3& Get(BufferIndex bufferIndex) const override
188   {
189     return mTxManagerData->
190         Manager()->
191         GetVector3PropertyValue(
192           mTxManagerData->Id(),
193           PropertyT);
194   }
195
196   const Vector3& GetVector3(BufferIndex bufferIndex) const override
197   {
198     return Get(bufferIndex);
199   }
200
201   const float& GetFloatComponent(uint32_t component) const override
202   {
203     return mTxManagerData->Manager()->GetVector3PropertyComponentValue(mTxManagerData->Id(), PropertyT, component);
204   }
205
206   void Set(BufferIndex bufferIndex, const Vector3& value) override
207   {
208     mTxManagerData->Manager()->SetVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
209   }
210
211   void SetComponent(BufferIndex bufferIndex, float value, uint32_t component)
212   {
213     mTxManagerData->Manager()->SetVector3PropertyComponentValue(mTxManagerData->Id(), PropertyT, value, component);
214   }
215
216   void BakeComponent(BufferIndex bufferIndex, float value, uint32_t component)
217   {
218     mTxManagerData->Manager()->BakeVector3PropertyComponentValue(mTxManagerData->Id(), PropertyT, value, component);
219   }
220
221   void Bake(BufferIndex bufferIndex, const Vector3& value) override
222   {
223     mTxManagerData->Manager()->BakeVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
224   }
225
226   void BakeX(BufferIndex bufferIndex, float value) override
227   {
228     mTxManagerData->Manager()->BakeXVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
229   }
230
231   void BakeY(BufferIndex bufferIndex, float value) override
232   {
233     mTxManagerData->Manager()->BakeYVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
234   }
235
236   void BakeZ(BufferIndex bufferIndex, float value) override
237   {
238     mTxManagerData->Manager()->BakeZVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
239   }
240
241   void SetFloatComponent(float value, uint32_t component) override
242   {
243     mTxManagerData->Manager()->SetVector3PropertyComponentValue(mTxManagerData->Id(), PropertyT, value, component);
244   }
245
246   void BakeFloatComponent(float value, uint32_t component) override
247   {
248     mTxManagerData->Manager()->BakeVector3PropertyComponentValue(mTxManagerData->Id(), PropertyT, value, component);
249   }
250
251   void BakeRelative(BufferIndex bufferIndex, const Vector3& value) override
252   {
253     mTxManagerData->Manager()->BakeRelativeVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
254   }
255
256   void BakeRelativeMultiply(BufferIndex bufferIndex, const Vector3& value) override
257   {
258     mTxManagerData->Manager()->BakeMultiplyVector3PropertyValue(mTxManagerData->Id(), PropertyT, value);
259   }
260 };
261
262 class TransformManagerPropertyQuaternion final : public TransformManagerPropertyHandler<Quaternion>
263 {
264 public:
265   TransformManagerPropertyQuaternion() = default;
266
267   Dali::Property::Type GetType() const override
268   {
269     return Dali::PropertyTypes::Get<Quaternion>();
270   }
271
272   Quaternion& Get(BufferIndex bufferIndex) override
273   {
274     return mTxManagerData->Manager()->GetQuaternionPropertyValue(mTxManagerData->Id());
275   }
276
277   const Quaternion& Get(BufferIndex bufferIndex) const override
278   {
279     return mTxManagerData->Manager()->GetQuaternionPropertyValue(mTxManagerData->Id());
280   }
281
282   void Set(BufferIndex bufferIndex, const Quaternion& value) override
283   {
284     return mTxManagerData->Manager()->SetQuaternionPropertyValue(mTxManagerData->Id(), value);
285   }
286
287   void Bake(BufferIndex bufferIndex, const Quaternion& value) override
288   {
289     return mTxManagerData->Manager()->BakeQuaternionPropertyValue(mTxManagerData->Id(), value);
290   }
291
292   void BakeRelative(BufferIndex bufferIndex, const Quaternion& value) override
293   {
294     return mTxManagerData->Manager()->BakeRelativeQuaternionPropertyValue(mTxManagerData->Id(), value);
295   }
296
297   const Quaternion& GetQuaternion(BufferIndex bufferIndex) const override
298   {
299     return Get(bufferIndex);
300   }
301 };
302
303 /**
304  * A Vector3 property used as input.
305  */
306 class TransformManagerVector3Input : public PropertyInputImpl
307 {
308 public:
309   /**
310    * Create an TransformManagerVector3Input
311    */
312   TransformManagerVector3Input(TransformManagerProperty property, const Vector3& initialValue)
313   : mProperty(property),
314     mValue(initialValue)
315   {
316   }
317
318   /**
319    * Virtual destructor.
320    */
321   ~TransformManagerVector3Input() override = default;
322
323   /**
324    * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
325    */
326   Dali::Property::Type GetType() const override
327   {
328     return Dali::PropertyTypes::Get<Vector3>();
329   }
330
331   /**
332    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
333    */
334   virtual bool IsClean() const
335   {
336     return false;
337   }
338
339   /**
340    * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
341    */
342   bool InputInitialized() const override
343   {
344     return true;
345   }
346
347   /**
348    * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
349    * @note A constraint can only receive the inherited property from the previous frame.
350    */
351   bool InputChanged() const override
352   {
353     return true;
354   }
355
356   /**
357    * Helper function to get the transform components out of the world matrix.
358    * It stores the value in the mValue member variable
359    */
360   void ComputeTransformComponent() const
361   {
362     if(mTxManagerData)
363     {
364       const Matrix& worldMatrix = mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
365
366       if(mProperty == TRANSFORM_PROPERTY_WORLD_POSITION)
367       {
368         mValue = worldMatrix.GetTranslation3();
369       }
370       else if(mProperty == TRANSFORM_PROPERTY_WORLD_SCALE)
371       {
372         Vector3    position;
373         Quaternion orientation;
374         worldMatrix.GetTransformComponents(position, orientation, mValue);
375       }
376     }
377   }
378
379   /**
380    * @copydoc Dali::PropertyInput::GetVector3()
381    */
382   const Vector3& GetVector3(BufferIndex bufferIndex) const override
383   {
384     ComputeTransformComponent();
385     return mValue;
386   }
387
388   /**
389    * @copydoc Dali::PropertyInput::GetConstraintInputVector3()
390    */
391   const Vector3& GetConstraintInputVector3(BufferIndex bufferIndex) const override
392   {
393     ComputeTransformComponent();
394     return mValue;
395   }
396
397   /**
398    * @copydoc Dali::SceneGraph::PropertyInterface::Get()
399    */
400   Vector3& Get(BufferIndex bufferIndex)
401   {
402     ComputeTransformComponent();
403     return mValue;
404   }
405
406   /**
407    * @copydoc Dali::SceneGraph::PropertyInterface::Get()
408    */
409   const Vector3& Get(BufferIndex bufferIndex) const
410   {
411     ComputeTransformComponent();
412     return mValue;
413   }
414
415   /**
416    * Retrieve the property value.
417    * @param[in] bufferIndex The buffer to read.
418    * @return The property value.
419    */
420   const Vector3& operator[](BufferIndex bufferIndex) const
421   {
422     ComputeTransformComponent();
423     return mValue;
424   }
425
426   /**
427    * Initializes the property
428    * @param[in] transformManager Pointer to the transform manager
429    * @param[in] Id of the transformation the property is associated with
430    */
431   void Initialize(TransformManagerData* data)
432   {
433     DALI_ASSERT_ALWAYS(data != nullptr && data->Manager() != nullptr);
434     mTxManagerData = data;
435   }
436
437   /**
438    * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
439    */
440   bool IsTransformManagerProperty() const override
441   {
442     return true;
443   }
444
445 private:
446   // Undefined
447   TransformManagerVector3Input(const TransformManagerVector3Input& property);
448
449   // Undefined
450   TransformManagerVector3Input& operator=(const TransformManagerVector3Input& rhs);
451
452 public:
453   TransformManagerData*    mTxManagerData{nullptr};
454   TransformManagerProperty mProperty;
455   mutable Vector3          mValue;
456 };
457
458 /**
459  * A Quaternion property used as input.
460  */
461 class TransformManagerQuaternionInput final : public PropertyInputImpl
462 {
463 public:
464   /**
465    * Constructor
466    */
467   TransformManagerQuaternionInput() = default;
468
469   /**
470    * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
471    */
472   Dali::Property::Type GetType() const override
473   {
474     return Dali::PropertyTypes::Get<Quaternion>();
475   }
476
477   /**
478    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
479    */
480   virtual bool IsClean() const
481   {
482     return false;
483   }
484
485   /**
486    * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
487    */
488   bool InputInitialized() const override
489   {
490     return true;
491   }
492
493   /**
494    * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
495    * @note A constraint can only receive the inherited property from the previous frame.
496    */
497   bool InputChanged() const override
498   {
499     return true;
500   }
501
502   /**
503    * Helper function to get the orientation out of the world matrix.
504    * It stores the result in the mValue member variable
505    */
506   void ComputeTransformComponent() const
507   {
508     if(mTxManagerData)
509     {
510       const Matrix& worldMatrix = mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
511       Vector3       position, scale;
512       worldMatrix.GetTransformComponents(position, mValue, scale);
513     }
514   }
515
516   /**
517    * @copydoc Dali::PropertyInput::GetQuaternion()
518    */
519   const Quaternion& GetQuaternion(BufferIndex bufferIndex) const override
520   {
521     ComputeTransformComponent();
522     return mValue;
523   }
524
525   /**
526    * @copydoc Dali::PropertyInput::GetConstraintInputQuaternion()
527    */
528   const Quaternion& GetConstraintInputQuaternion(BufferIndex bufferIndex) const override
529   {
530     ComputeTransformComponent();
531     return mValue;
532   }
533
534   /**
535    * @copydoc Dali::SceneGraph::PropertyInterface::Get()
536    */
537   Quaternion& Get(BufferIndex bufferIndex)
538   {
539     ComputeTransformComponent();
540     return mValue;
541   }
542
543   /**
544    * @copydoc Dali::SceneGraph::PropertyInterface::Get()
545    */
546   const Quaternion& Get(BufferIndex bufferIndex) const
547   {
548     ComputeTransformComponent();
549     return mValue;
550   }
551
552   /**
553    * Retrieve the property value.
554    * @param[in] bufferIndex The buffer to read.
555    * @return The property value.
556    */
557   const Quaternion& operator[](BufferIndex bufferIndex) const
558   {
559     ComputeTransformComponent();
560     return mValue;
561   }
562
563   /**
564    * Initializes the property
565    * @param[in] transformManager Pointer to the transform manager
566    * @param[in] Id of the transformation the property is associated with
567    */
568   void Initialize(TransformManagerData* data)
569   {
570     DALI_ASSERT_ALWAYS(data != nullptr && data->Manager() != nullptr);
571     mTxManagerData = data;
572   }
573
574   /**
575    * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
576    */
577   bool IsTransformManagerProperty() const override
578   {
579     return true;
580   }
581
582 private:
583   // Undefined
584   TransformManagerQuaternionInput(const TransformManagerQuaternionInput& property);
585
586   // Undefined
587   TransformManagerQuaternionInput& operator=(const TransformManagerQuaternionInput& rhs);
588
589 public:
590   TransformManagerData* mTxManagerData{nullptr};
591   mutable Quaternion    mValue;
592 };
593
594 /**
595  * A Matrix property used as input.
596  */
597 class TransformManagerMatrixInput final : public PropertyInputImpl
598 {
599 public:
600   /**
601    * Constructor
602    */
603   TransformManagerMatrixInput() = default;
604
605   /**
606    * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
607    */
608   Dali::Property::Type GetType() const override
609   {
610     return Dali::PropertyTypes::Get<Matrix>();
611   }
612
613   /**
614    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
615    */
616   virtual bool IsClean() const
617   {
618     return false;
619   }
620
621   /**
622    * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
623    */
624   bool InputInitialized() const override
625   {
626     return true;
627   }
628
629   /**
630    * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
631    * @note A constraint can only receive the inherited property from the previous frame.
632    */
633   bool InputChanged() const override
634   {
635     return true;
636   }
637
638   /**
639    * @copydoc Dali::PropertyInput::GetMatrix()
640    */
641   const Matrix& GetMatrix(BufferIndex bufferIndex) const override
642   {
643     if(mTxManagerData)
644     {
645       return mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
646     }
647
648     return Matrix::IDENTITY;
649   }
650
651   /**
652    * @copydoc Dali::PropertyInput::GetConstraintInputMatrix()
653    */
654   const Matrix& GetConstraintInputMatrix(BufferIndex bufferIndex) const override
655   {
656     if(mTxManagerData)
657     {
658       return mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
659     }
660
661     return Matrix::IDENTITY;
662   }
663
664   /**
665    * @copydoc Dali::SceneGraph::PropertyInterface::Get()
666    */
667   Matrix& Get(BufferIndex bufferIndex)
668   {
669     DALI_ASSERT_ALWAYS(mTxManagerData != nullptr);
670     return mTxManagerData->Manager()->GetWorldMatrix(mTxManagerData->Id());
671   }
672
673   /**
674    * @copydoc Dali::SceneGraph::PropertyInterface::Get()
675    */
676   const Matrix& Get(BufferIndex bufferIndex) const
677   {
678     return GetMatrix(bufferIndex);
679   }
680
681   /**
682    * Retrieve the property value.
683    * @param[in] bufferIndex The buffer to read.
684    * @return The property value.
685    */
686   const Matrix& operator[](BufferIndex bufferIndex) const
687   {
688     return GetMatrix(bufferIndex);
689   }
690
691   void Initialize(TransformManagerData* data)
692   {
693     DALI_ASSERT_ALWAYS(data != nullptr && data->Manager() != nullptr);
694     mTxManagerData = data;
695   }
696
697   /**
698    * @copydoc Dali::Internal::PropertyInputImpl::IsTransformManagerProperty()
699    */
700   bool IsTransformManagerProperty() const override
701   {
702     return true;
703   }
704
705 private:
706   // Undefined
707   TransformManagerMatrixInput(const TransformManagerMatrixInput& property);
708
709   // Undefined
710   TransformManagerMatrixInput& operator=(const TransformManagerMatrixInput& rhs);
711
712 public:
713   TransformManagerData* mTxManagerData{nullptr};
714 };
715
716 } //namespace SceneGraph
717 } //namespace Internal
718 } //namespace Dali
719
720 #endif // TRANSFORM_MANAGER_PROPERTY_H_