1 #ifndef DALI_TOOLKIT_INTERNAL_LAYOUTING_LAYOUT_TRANSITION_DATA_IMPL_H
2 #define DALI_TOOLKIT_INTERNAL_LAYOUTING_LAYOUT_TRANSITION_DATA_IMPL_H
4 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <dali/public-api/common/intrusive-ptr.h>
22 #include <dali/public-api/object/base-object.h>
23 #include <dali/public-api/object/property-map.h>
24 #include <dali/public-api/object/type-registry.h>
25 #include <dali/public-api/actors/actor-enumerations.h>
26 #include <dali/public-api/animation/animation.h>
28 #include <dali-toolkit/devel-api/layouting/layout-item-impl.h>
29 #include <dali-toolkit/devel-api/layouting/layout-transition-data.h>
38 struct LayoutTransition
40 LayoutTransition( LayoutItem& layoutItem, int layoutTransitionType, Actor gainedChild, Actor lostChild )
41 : layoutItem( &layoutItem )
42 , layoutTransitionType( layoutTransitionType )
43 , gainedChild( gainedChild )
44 , lostChild( lostChild )
49 : layoutTransitionType( -1 )
53 bool operator==( const LayoutTransition& rhs )
55 return ( layoutItem.Get() == rhs.layoutItem.Get()
56 && layoutTransitionType == rhs.layoutTransitionType
57 && gainedChild == rhs.gainedChild
58 && lostChild == rhs.lostChild );
61 LayoutItemPtr layoutItem;
62 int layoutTransitionType;
67 const float DEFAULT_TRANSITION_DURATION( 0.5f );
69 struct LayoutDataAnimator
71 enum class AnimatorType
80 : animatorType( AnimatorType::ANIMATE_TO ),
81 alphaFunction( AlphaFunction::LINEAR ),
82 timePeriod( 0.0f, DEFAULT_TRANSITION_DURATION ),
83 interpolation( Animation::Linear )
88 AnimatorType animatorType;
89 AlphaFunction alphaFunction;
90 TimePeriod timePeriod;
93 Animation::Interpolation interpolation;
99 using LayoutAnimatorArray = std::vector< LayoutDataAnimator >;
101 struct LayoutPositionData
103 LayoutPositionData( Handle handle, float left, float top, float right, float bottom, bool animated ) :
104 handle( handle ), left( left ), top( top ), right( right ), bottom( bottom ), animated( animated )
116 using LayoutPositionDataArray = std::vector< LayoutPositionData >;
118 struct LayoutDataElement
121 : propertyIndex( Property::INVALID_KEY ),
123 positionDataIndex(-1 ),
124 condition( Dali::Toolkit::LayoutTransitionData::Condition::NONE )
129 Property::Index propertyIndex;
130 Property::Value initialValue;
131 Property::Value targetValue;
133 int positionDataIndex;
137 class LayoutTransitionData;
138 using LayoutTransitionDataPtr = IntrusivePtr<LayoutTransitionData>;
141 * LayoutTransitionData implementation class.
143 class DALI_TOOLKIT_API LayoutTransitionData : public BaseObject
146 struct PropertyAnimator
149 PropertyAnimator( Actor actor, Property::Map map );
150 PropertyAnimator( Actor actor, Property::Map map, Path path, Vector3 forward );
151 PropertyAnimator( Actor actor, Property::Map map, KeyFrames keyFrames, Animation::Interpolation interpolation );
158 Animation::Interpolation interpolation;
164 using PropertyAnimatorArray = std::vector< PropertyAnimator >;
166 static LayoutTransitionDataPtr New();
168 LayoutTransitionData( const LayoutTransitionData& ) = delete;
169 LayoutTransitionData& operator=( const LayoutTransitionData& ) = delete;
172 * @brief Add a property animator for an actor in the transition
173 * @param[in] actor The actor
174 * @param[in] map The map containing the transition animator keys
176 * This will add the property animator to the list of animators related to this transition
178 void AddPropertyAnimator( Actor actor, Property::Map map );
181 * @brief Add a property animator for an actor in the transition
182 * @param[in] actor The actor
183 * @param[in] map The map containing the transition animator keys
184 * @param[in] keyFrames The key frames used by the property animator
185 * @param[in] interpolation The interpolation used by the property animator
187 * This will add the property animator to the list of animators related to this transition
189 void AddPropertyAnimator( Actor actor, Property::Map map, KeyFrames keyFrames, Animation::Interpolation interpolation );
192 * @brief Add a property animator for an actor in the transition
193 * @param[in] actor The actor
194 * @param[in] map The map containing the transition animator keys
195 * @param[in] path The path for the property animator
196 * @param[in] forward The forward vector for the property animator
198 * This will add the property animator to the list of animators related to this transition
200 void AddPropertyAnimator( Actor actor, Property::Map map, Path path, Vector3 forward );
203 * @brief Convert the transition property animators to the layout data elements
204 * @param[in] actor The actor the transition property animators are applied to
205 * @param[in] layoutData The layout data containing layout data elements array for the layout update
207 * This will parse the property animators and add the layout data elements to the layout data elements array
209 void ConvertToLayoutDataElements( Actor, LayoutData& layoutData );
212 * @brief Convert the transition children property animators to the layout data elements
213 * @param[in] actor The actor the transition property animators are applied to
214 * @param[in] layoutData The layout data containing layout data elements array for the layout update
216 * This will parse the children property animators and add the layout data elements to the layout data elements array
218 static void ConvertChildrenAnimatorsToLayoutDataElements( Actor, LayoutData& layoutData );
221 * @copydoc Dali::Toolkit::LayoutTransitionData::FinishedSignal()
223 Dali::Toolkit::LayoutTransitionData::LayoutTransitionSignalType& FinishedSignal();
226 * @brief Emit the transition finish signal
227 * @param[in] layoutTransitionType The transition type
229 void EmitSignalFinish( int layoutTransitionType );
233 * @brief Convert the property animator data to the layout data animator
234 * @param[in] animatorData The animator data map
235 * @param[in] propertyAnimator The property animator
236 * @param[in] layoutAnimator The layout animator
238 * This will parse the property animator data and add the layout data element animator
240 static bool ConvertToLayoutAnimator( const Property::Map& animatorData, const PropertyAnimator& propertyAnimator, LayoutDataAnimator& layoutAnimator );
243 * @brief Convert the property animator to the layout data element
244 * @param[in] propertyAnimator The property animator
245 * @param[in] layoutDataElement The layout data element
246 * @param[in] layoutDataElement The layout data
248 * This will parse the children property animators and add the layout data elements to the layout data elements array
250 static bool ConvertToLayoutDataElement( const PropertyAnimator& propertyAnimator, LayoutDataElement& layoutDataElement, LayoutData& layoutData );
252 PropertyAnimatorArray mPropertyAnimators;
255 * Ref counted object - Only allow construction via New().
257 LayoutTransitionData();
261 * A ref counted object may only be deleted by calling Unreference
263 virtual ~LayoutTransitionData();
265 Dali::Toolkit::LayoutTransitionData::LayoutTransitionSignalType mFinishedSignal;
268 using PropertyAnimatorArray = std::vector< LayoutTransitionData::PropertyAnimator >;
269 using LayoutTransitionDataArray = std::vector< LayoutTransitionDataPtr >;
270 using LayoutDataArray = std::vector< LayoutDataElement >;
274 LayoutData( LayoutTransition& layoutTransition, LayoutPositionDataArray& layoutPositionDataArray, LayoutDataArray& layoutDataArray,
275 LayoutAnimatorArray& layoutAnimatorArray, PropertyAnimatorArray& childrenPropertyAnimators )
276 : speculativeLayout( false ),
277 layoutTransition( layoutTransition ),
278 layoutPositionDataArray( layoutPositionDataArray ),
279 layoutDataArray( layoutDataArray),
280 layoutAnimatorArray( layoutAnimatorArray ),
281 childrenPropertyAnimators( childrenPropertyAnimators )
285 bool speculativeLayout;
286 LayoutTransition& layoutTransition;
287 LayoutPositionDataArray& layoutPositionDataArray;
288 LayoutDataArray& layoutDataArray;
289 LayoutAnimatorArray& layoutAnimatorArray;
290 PropertyAnimatorArray& childrenPropertyAnimators;
293 } //namespace Internal
295 inline Internal::LayoutTransitionData& GetImplementation( Dali::Toolkit::LayoutTransitionData& handle )
297 DALI_ASSERT_ALWAYS( handle && "LayoutTransitionData handle is empty" );
298 BaseObject& object = handle.GetBaseObject();
299 return static_cast< Internal::LayoutTransitionData& >( object );
302 inline const Internal::LayoutTransitionData& GetImplementation( const Dali::Toolkit::LayoutTransitionData& handle )
304 DALI_ASSERT_ALWAYS( handle && "LayoutTransitionData handle is empty" );
305 const BaseObject& object = handle.GetBaseObject();
306 return static_cast< const Internal::LayoutTransitionData& >( object );
309 } //namespace Toolkit
312 #endif // DALI_TOOLKIT_INTERNAL_LAYOUTING_LAYOUT_TRANSITION_DATA_IMPL_H