2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 #include <dali-toolkit/internal/controls/page-turn-view/page-turn-portrait-view-impl.h>
32 TypeRegistration mType( typeid(Toolkit::PageTurnPortraitView), typeid(Toolkit::PageTurnView), NULL );
34 // the panning speed threshold, no matter how far is the pan displacement, pan fast to left/right quickly (speed > 0.3) will turn over/back the page
35 const float GESTURE_SPEED_THRESHOLD(0.3f);
37 // the animation duration of turning the previous page back when an outwards flick is detected
38 const float PAGE_TURN_OVER_ANIMATION_DURATION(0.5f);
41 PageTurnPortraitView::PageTurnPortraitView( PageFactory& pageFactory, const Vector2& pageSize )
42 : PageTurnView( pageFactory, pageSize )
47 PageTurnPortraitView::~PageTurnPortraitView()
51 Toolkit::PageTurnPortraitView PageTurnPortraitView::New( PageFactory& pageFactory, const Vector2& pageSize )
53 // Create the implementation, temporarily owned on stack
54 IntrusivePtr< PageTurnPortraitView > internalPageTurnView = new PageTurnPortraitView( pageFactory, pageSize );
56 // Pass ownership to CustomActor
57 Dali::Toolkit::PageTurnPortraitView pageTurnView( *internalPageTurnView );
59 // Second-phase init of the implementation
60 // This can only be done after the CustomActor connection has been made...
61 internalPageTurnView->Initialize();
66 void PageTurnPortraitView::OnPageTurnViewInitialize()
68 mControlSize = mPageSize;
69 Self().SetSize( mPageSize );
70 mTurningPageLayer.SetParentOrigin( ParentOrigin::CENTER_LEFT );
73 ImageActor PageTurnPortraitView::NewPageFromRenderBuffer( int pageIndex )
75 return ImageActor::New(mRenderedPage[pageIndex % NUMBER_OF_CACHED_PAGES]);
78 Vector2 PageTurnPortraitView::SetPanPosition( const Vector2& gesturePosition )
80 return gesturePosition;
83 void PageTurnPortraitView::SetPanActor( const Vector2& panPosition )
85 if( mCurrentPageIndex < mTotalPageCount )
87 mPanActor = mPageActors[mCurrentPageIndex%NUMBER_OF_CACHED_PAGES];
95 void PageTurnPortraitView::SetSpineEffect(Actor actor, bool isLeftSide)
99 actor.RemoveShaderEffect();
103 actor.SetShaderEffect( mSpineEffectFront );
107 void PageTurnPortraitView::OnPossibleOutwardsFlick( const Vector2& panPosition, float gestureSpeed )
109 Vector2 offset = panPosition - mPressDownPosition;
110 // There is previous page and an outwards flick is detected
111 if( mCurrentPageIndex > 0 && gestureSpeed > GESTURE_SPEED_THRESHOLD && offset.x > fabs( offset.y ))
113 Actor actor = mPageActors[ (mCurrentPageIndex-1) % NUMBER_OF_CACHED_PAGES ];
114 if(actor.GetParent() != mRootOnScreen)
119 // Guard against destruction during signal emission
120 //Emit signal, to notify that page[mCurrentPageIndex-1] is turning backwards
121 Toolkit::PageTurnView handle( GetOwner() );
122 mPageTurnStartedSignal.Emit( handle, static_cast<unsigned int>(mCurrentPageIndex-1), false );
126 RemovePage( mCurrentPageIndex+NUMBER_OF_CACHED_PAGES_EACH_SIDE );
127 AddPage( mCurrentPageIndex-NUMBER_OF_CACHED_PAGES_EACH_SIDE );
130 // Add the page to tuning page layer and set up PageTurnEffect
131 mShadowView.Add( actor );
132 actor.SetShaderEffect( mTurnEffect[mIndex] );
133 GetImpl( mTurnEffect[mIndex] ).ApplyInternalConstraint();
134 mIsAnimating[mIndex] = true;
135 mTurnEffect[mIndex].SetIsTurningBack( true );
136 Vector2 originalCenter( mPageSize.width*1.5f, 0.5f*mPageSize.height );
137 mTurnEffect[mIndex].SetOriginalCenter( originalCenter );
138 mTurnEffect[mIndex].SetCurrentCenter( Vector2( mPageSize.width*0.5f, mPageSize.height*0.5f ));
140 // Start an animation to turn the previous page back
141 Animation animation = Animation::New( PAGE_TURN_OVER_ANIMATION_DURATION );
142 mAnimationActorPair[animation] = actor;
143 mAnimationIndexPair[animation] = mIndex;
145 animation.AnimateTo( Property( mTurnEffect[mIndex], mTurnEffect[mIndex].PageTurnEffect::GetCurrentCenterPropertyName() ),
147 AlphaFunctions::EaseOut, PAGE_TURN_OVER_ANIMATION_DURATION*0.75f );
148 animation.AnimateBy( Property( actor, Actor::ROTATION ), AngleAxis( Degree( 180.0f ), Vector3::YAXIS ) ,AlphaFunctions::EaseOut );
150 ImageActor::DownCast(actor).SetCullFace( CullBack );
151 animation.FinishedSignal().Connect( this, &PageTurnPortraitView::OnTurnedOver );
155 void PageTurnPortraitView::OnTurnedOver( Animation& animation )
157 ImageActor::DownCast(mAnimationActorPair[animation]).SetCullFace( CullNone );
158 TurnedOver( animation );
161 } // namespace Internal
163 } // namespace Toolkit