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 )
41 : layoutItem( &layoutItem )
42 , layoutTransitionType( layoutTransitionType )
47 : layoutTransitionType( -1 )
51 bool operator==( const LayoutTransition& rhs )
53 return ( ( layoutItem.Get() == rhs.layoutItem.Get() ) && layoutTransitionType == rhs.layoutTransitionType );
56 LayoutItemPtr layoutItem;
57 int layoutTransitionType;
60 const float DEFAULT_TRANSITION_DURATION( 0.5f );
62 struct LayoutDataAnimator
64 enum class AnimatorType
73 : animatorType( AnimatorType::ANIMATE_TO ),
74 alphaFunction( AlphaFunction::LINEAR ),
75 timePeriod( 0.0f, DEFAULT_TRANSITION_DURATION ),
76 interpolation( Animation::Linear )
81 AnimatorType animatorType;
82 AlphaFunction alphaFunction;
83 TimePeriod timePeriod;
86 Animation::Interpolation interpolation;
92 using LayoutAnimatorArray = std::vector< LayoutDataAnimator >;
94 struct LayoutPositionData
96 LayoutPositionData( Handle handle, float left, float top, float right, float bottom, bool animated ) :
97 handle( handle ), left( left ), top( top ), right( right ), bottom( bottom ), animated( animated )
109 using LayoutPositionDataArray = std::vector< LayoutPositionData >;
111 struct LayoutDataElement
114 : propertyIndex( Property::INVALID_KEY ), animatorIndex( -1 ), positionDataIndex(-1 )
118 LayoutDataElement( Actor actor, Property::Index propertyIndex, Property::Value value )
120 propertyIndex( propertyIndex ),
121 targetValue( value ),
123 positionDataIndex( -1 )
128 Property::Index propertyIndex;
129 Property::Value initialValue;
130 Property::Value targetValue;
132 int positionDataIndex;
135 class LayoutTransitionData;
136 using LayoutTransitionDataPtr = IntrusivePtr<LayoutTransitionData>;
139 * LayoutTransitionData implementation class.
141 class DALI_TOOLKIT_API LayoutTransitionData : public BaseObject
144 struct PropertyAnimator
147 PropertyAnimator( Actor actor, Property::Map map );
148 PropertyAnimator( Actor actor, Property::Map map, Path path, Vector3 forward );
149 PropertyAnimator( Actor actor, Property::Map map, KeyFrames keyFrames, Animation::Interpolation interpolation );
156 Animation::Interpolation interpolation;
162 using PropertyAnimatorArray = std::vector< PropertyAnimator >;
164 static LayoutTransitionDataPtr New();
166 LayoutTransitionData( const LayoutTransitionData& ) = delete;
167 LayoutTransitionData& operator=( const LayoutTransitionData& ) = delete;
169 void AddPropertyAnimator( Actor actor, Property::Map map );
170 void AddPropertyAnimator( Actor actor, Property::Map map, KeyFrames keyFrames, Animation::Interpolation interpolation );
171 void AddPropertyAnimator( Actor actor, Property::Map map, Path path, Vector3 forward );
173 void ConvertToLayoutDataElements( Actor, LayoutData& layoutData );
176 * @copydoc Dali::Animation::FinishedSignal()
178 Dali::Toolkit::LayoutTransitionData::LayoutTransitionSignalType& FinishedSignal();
180 void EmitSignalFinish( int layoutTransitionType );
183 bool ConvertToLayoutAnimator( const Property::Map& animatorData, const PropertyAnimator& propertyAnimator, LayoutDataAnimator& layoutAnimator );
184 bool ConvertToLayoutDataElement( const PropertyAnimator& propertyAnimator, LayoutDataElement& layoutDataElement, LayoutData& layoutData );
186 PropertyAnimatorArray mPropertyAnimators;
189 * Ref counted object - Only allow construction via New().
191 LayoutTransitionData();
195 * A ref counted object may only be deleted by calling Unreference
197 virtual ~LayoutTransitionData();
199 Dali::Toolkit::LayoutTransitionData::LayoutTransitionSignalType mFinishedSignal;
202 using PropertyAnimatorArray = std::vector< LayoutTransitionData::PropertyAnimator >;
203 using LayoutTransitionDataArray = std::vector< LayoutTransitionDataPtr >;
204 using LayoutDataArray = std::vector< LayoutDataElement >;
208 LayoutData( LayoutTransition& layoutTransition, LayoutPositionDataArray& layoutPositionDataArray, LayoutDataArray& layoutDataArray,
209 LayoutAnimatorArray& layoutAnimatorArray, PropertyAnimatorArray& childrenPropertyAnimators )
210 : speculativeLayout( false ),
211 layoutTransition( layoutTransition ),
212 layoutPositionDataArray( layoutPositionDataArray ),
213 layoutDataArray( layoutDataArray),
214 layoutAnimatorArray( layoutAnimatorArray ),
215 childrenPropertyAnimators( childrenPropertyAnimators )
219 bool speculativeLayout;
220 LayoutTransition& layoutTransition;
221 LayoutPositionDataArray& layoutPositionDataArray;
222 LayoutDataArray& layoutDataArray;
223 LayoutAnimatorArray& layoutAnimatorArray;
224 PropertyAnimatorArray& childrenPropertyAnimators;
227 } //namespace Internal
229 inline Internal::LayoutTransitionData& GetImplementation( Dali::Toolkit::LayoutTransitionData& handle )
231 DALI_ASSERT_ALWAYS( handle && "LayoutTransitionData handle is empty" );
232 BaseObject& object = handle.GetBaseObject();
233 return static_cast< Internal::LayoutTransitionData& >( object );
236 inline const Internal::LayoutTransitionData& GetImplementation( const Dali::Toolkit::LayoutTransitionData& handle )
238 DALI_ASSERT_ALWAYS( handle && "LayoutTransitionData handle is empty" );
239 const BaseObject& object = handle.GetBaseObject();
240 return static_cast< const Internal::LayoutTransitionData& >( object );
243 } //namespace Toolkit
246 #endif // DALI_TOOLKIT_INTERNAL_LAYOUTING_LAYOUT_TRANSITION_DATA_IMPL_H