[dali_2.3.25] Merge branch 'devel/master'
[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     enum class AnimationType : uint8_t
45   {
46     TO,     ///< Animating TO the given value
47     BY,     ///< Animating BY the given value
48     BETWEEN ///< Animating BETWEEN key-frames
49   };
50
51   /**
52    * @brief TransitionDataElement Describes one animator of an transition.
53    */
54   struct Animator
55   {
56     Animator()
57     : propertyKey(Property::INVALID_INDEX),
58       alphaFunction(AlphaFunction::DEFAULT),
59       timePeriodDelay(0.0f),
60       timePeriodDuration(1.0f),
61       animationType(AnimationType::TO),
62       animate(false)
63     {
64     }
65
66     std::string         objectName;   ///< An identifier of the actor or visual
67     Property::Key       propertyKey;  ///< A property key of the property owner
68     Property::Value     initialValue; ///< The value to set at the start of the transition
69     Property::Value     targetValue;  ///< The value to set or animate to
70     Dali::AlphaFunction alphaFunction;
71     float               timePeriodDelay;
72     float               timePeriodDuration;
73     AnimationType       animationType;
74     bool                animate;
75   };
76
77   /**
78    * @brief TransitionData holds the required data required to define an
79    * transition to be performed on a property owner
80    */
81   typedef Dali::OwnerContainer<Animator*> AnimatorList;
82   typedef AnimatorList::Iterator          Iterator;
83
84 public:
85   /**
86    * @copydoc Dali::Transition::New()
87    */
88   static TransitionDataPtr New(const Property::Array& value);
89
90   /**
91    * @copydoc Dali::Transition::New()
92    */
93   static TransitionDataPtr New(const Property::Map& value);
94
95   /**
96    * @brief Iterator to the beginning of the data
97    */
98   Iterator Begin() const;
99
100   /**
101    * @brief Iterator to the end of the data (one past last element)
102    */
103   Iterator End() const;
104
105   /**
106    * @copydoc Dali::Transition::Count()
107    */
108   size_t Count() const;
109
110   /**
111    * @copydoc Dali::Transition::GetAnimatorAt()
112    */
113   Property::Map GetAnimatorAt(size_t index);
114
115 private: // Implementation
116   /**
117    * Ref counted object - Only allow construction via New().
118    */
119   TransitionData();
120
121   /**
122    * Second stage initialiazation
123    */
124   void Initialize(const Property::Map& value);
125
126   /**
127    * Second stage initialiazation
128    */
129   void Initialize(const Property::Array& value);
130
131   /**
132    * @brief Adds one Animator to the list to describe a transition.
133    * @param[in] animator An animator data structure
134    */
135   void Add(Animator* animator);
136
137   /**
138    * Convert a Property map into Animator data
139    */
140   Animator* ConvertMap(const Property::Map& map);
141
142 protected:
143   /**
144    *  A ref counted object may only be deleted by calling Unreference
145    */
146   ~TransitionData() override;
147
148 private: // Unimplemented methods
149   TransitionData(const TransitionData&);
150   TransitionData& operator=(const TransitionData&);
151
152 private:                   // Data members
153   AnimatorList mAnimators; ///< A vector of individual property transitions from which to generate a Dali::Animation.
154 };
155
156 } // namespace Internal
157
158 // Helpers for public-api forwarding methods
159 inline Internal::TransitionData& GetImplementation(Dali::Toolkit::TransitionData& handle)
160 {
161   DALI_ASSERT_ALWAYS(handle && "TransitionData handle is empty");
162   BaseObject& object = handle.GetBaseObject();
163   return static_cast<Internal::TransitionData&>(object);
164 }
165
166 inline const Internal::TransitionData& GetImplementation(const Dali::Toolkit::TransitionData& handle)
167 {
168   DALI_ASSERT_ALWAYS(handle && "TransitionData handle is empty");
169   const BaseObject& object = handle.GetBaseObject();
170   return static_cast<const Internal::TransitionData&>(object);
171 }
172
173 } // namespace Toolkit
174 } // namespace Dali
175
176 #endif // DALI_TOOLKIT_INTERNAL_TRANSITION_DATA_H