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