Make some visual use DecoratedVisualRenderer
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / transition-data-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TRANSITION_DATA_H
2 #define DALI_TOOLKIT_INTERNAL_TRANSITION_DATA_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 // EXTERNAL INCLUDES
21 #include <dali/devel-api/common/owner-container.h>
22 #include <dali/public-api/animation/alpha-function.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/object/property-key.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Internal
34 {
35 class TransitionData;
36 typedef IntrusivePtr<TransitionData> TransitionDataPtr;
37
38 /**
39  * TransitionData is an object that holds animator data.
40  */
41 class TransitionData : public BaseObject
42 {
43 public:
44   /**
45    * @brief TransitionDataElement Describes one animator of an transition.
46    */
47   struct Animator
48   {
49     Animator()
50     : propertyKey(Property::INVALID_INDEX),
51       alphaFunction(AlphaFunction::DEFAULT),
52       timePeriodDelay(0.0f),
53       timePeriodDuration(1.0f),
54       animate(false)
55     {
56     }
57
58     std::string         objectName;   ///< An identifier of the actor or visual
59     Property::Key       propertyKey;  ///< A property key of the property owner
60     Property::Value     initialValue; ///< The value to set at the start of the transition
61     Property::Value     targetValue;  ///< The value to set or animate to
62     Dali::AlphaFunction alphaFunction;
63     float               timePeriodDelay;
64     float               timePeriodDuration;
65     bool                animate;
66   };
67
68   /**
69    * @brief TransitionData holds the required data required to define an
70    * transition to be performed on a property owner
71    */
72   typedef Dali::OwnerContainer<Animator*> AnimatorList;
73   typedef AnimatorList::Iterator          Iterator;
74
75 public:
76   /**
77    * @copydoc Dali::Transition::New()
78    */
79   static TransitionDataPtr New(const Property::Array& value);
80
81   /**
82    * @copydoc Dali::Transition::New()
83    */
84   static TransitionDataPtr New(const Property::Map& value);
85
86   /**
87    * @brief Iterator to the beginning of the data
88    */
89   Iterator Begin() const;
90
91   /**
92    * @brief Iterator to the end of the data (one past last element)
93    */
94   Iterator End() const;
95
96   /**
97    * @copydoc Dali::Transition::Count()
98    */
99   size_t Count() const;
100
101   /**
102    * @copydoc Dali::Transition::GetAnimatorAt()
103    */
104   Property::Map GetAnimatorAt(size_t index);
105
106 private: // Implementation
107   /**
108    * Ref counted object - Only allow construction via New().
109    */
110   TransitionData();
111
112   /**
113    * Second stage initialiazation
114    */
115   void Initialize(const Property::Map& value);
116
117   /**
118    * Second stage initialiazation
119    */
120   void Initialize(const Property::Array& value);
121
122   /**
123    * @brief Adds one Animator to the list to describe a transition.
124    * @param[in] animator An animator data structure
125    */
126   void Add(Animator* animator);
127
128   /**
129    * Convert a Property map into Animator data
130    */
131   Animator* ConvertMap(const Property::Map& map);
132
133 protected:
134   /**
135    *  A ref counted object may only be deleted by calling Unreference
136    */
137   ~TransitionData() override;
138
139 private: // Unimplemented methods
140   TransitionData(const TransitionData&);
141   TransitionData& operator=(const TransitionData&);
142
143 private:                   // Data members
144   AnimatorList mAnimators; ///< A vector of individual property transitions from which to generate a Dali::Animation.
145 };
146
147 } // namespace Internal
148
149 // Helpers for public-api forwarding methods
150 inline Internal::TransitionData& GetImplementation(Dali::Toolkit::TransitionData& handle)
151 {
152   DALI_ASSERT_ALWAYS(handle && "TransitionData handle is empty");
153   BaseObject& object = handle.GetBaseObject();
154   return static_cast<Internal::TransitionData&>(object);
155 }
156
157 inline const Internal::TransitionData& GetImplementation(const Dali::Toolkit::TransitionData& handle)
158 {
159   DALI_ASSERT_ALWAYS(handle && "TransitionData handle is empty");
160   const BaseObject& object = handle.GetBaseObject();
161   return static_cast<const Internal::TransitionData&>(object);
162 }
163
164 } // namespace Toolkit
165 } // namespace Dali
166
167 #endif // DALI_TOOLKIT_INTERNAL_TRANSITION_DATA_H