2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/controls/page-turn-view/page-turn-portrait-view-impl.h>
33 TypeRegistration mType( typeid(Toolkit::PageTurnPortraitView), typeid(Toolkit::PageTurnView), NULL );
35 // 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
36 const float GESTURE_SPEED_THRESHOLD(0.3f);
38 // the animation duration of turning the previous page back when an outwards flick is detected
39 const float PAGE_TURN_OVER_ANIMATION_DURATION(0.5f);
42 PageTurnPortraitView::PageTurnPortraitView( PageFactory& pageFactory, const Vector2& pageSize )
43 : PageTurnView( pageFactory, pageSize )
48 PageTurnPortraitView::~PageTurnPortraitView()
52 Toolkit::PageTurnPortraitView PageTurnPortraitView::New( PageFactory& pageFactory, const Vector2& pageSize )
54 // Create the implementation, temporarily owned on stack
55 IntrusivePtr< PageTurnPortraitView > internalPageTurnView = new PageTurnPortraitView( pageFactory, pageSize );
57 // Pass ownership to CustomActor
58 Dali::Toolkit::PageTurnPortraitView pageTurnView( *internalPageTurnView );
60 // Second-phase init of the implementation
61 // This can only be done after the CustomActor connection has been made...
62 internalPageTurnView->Initialize();
67 void PageTurnPortraitView::OnPageTurnViewInitialize()
69 mControlSize = mPageSize;
70 Self().SetSize( mPageSize );
71 mTurningPageLayer.SetParentOrigin( ParentOrigin::CENTER_LEFT );
74 ImageActor PageTurnPortraitView::NewPageFromRenderBuffer( int pageIndex )
76 return ImageActor::New(mRenderedPage[pageIndex % NUMBER_OF_CACHED_PAGES]);
79 Vector2 PageTurnPortraitView::SetPanPosition( const Vector2& gesturePosition )
81 return gesturePosition;
84 void PageTurnPortraitView::SetPanActor( const Vector2& panPosition )
86 if( mCurrentPageIndex < mTotalPageCount )
88 mPanActor = mPageActors[mCurrentPageIndex%NUMBER_OF_CACHED_PAGES];
96 void PageTurnPortraitView::SetSpineEffect(ImageActor actor, bool isLeftSide)
100 actor.RemoveShaderEffect();
104 actor.SetShaderEffect( mSpineEffectFront );
108 void PageTurnPortraitView::OnPossibleOutwardsFlick( const Vector2& panPosition, float gestureSpeed )
110 Vector2 offset = panPosition - mPressDownPosition;
111 // There is previous page and an outwards flick is detected
112 if( mCurrentPageIndex > 0 && gestureSpeed > GESTURE_SPEED_THRESHOLD && offset.x > fabs( offset.y ))
114 ImageActor actor = mPageActors[ (mCurrentPageIndex-1) % NUMBER_OF_CACHED_PAGES ];
115 if(actor.GetParent() != mRootOnScreen)
120 // Guard against destruction during signal emission
121 //Emit signal, to notify that page[mCurrentPageIndex-1] is turning backwards
122 Toolkit::PageTurnView handle( GetOwner() );
123 mPageTurnStartedSignal.Emit( handle, static_cast<unsigned int>(mCurrentPageIndex-1), false );
127 RemovePage( mCurrentPageIndex+NUMBER_OF_CACHED_PAGES_EACH_SIDE );
128 AddPage( mCurrentPageIndex-NUMBER_OF_CACHED_PAGES_EACH_SIDE );
131 // Add the page to tuning page layer and set up PageTurnEffect
132 mShadowView.Add( actor );
133 actor.SetShaderEffect( mTurnEffect[mIndex] );
134 GetImpl( mTurnEffect[mIndex] ).ApplyInternalConstraint();
135 mIsAnimating[mIndex] = true;
136 mTurnEffect[mIndex].SetIsTurningBack( true );
137 Vector2 originalCenter( mPageSize.width*1.5f, 0.5f*mPageSize.height );
138 mTurnEffect[mIndex].SetOriginalCenter( originalCenter );
139 mTurnEffect[mIndex].SetCurrentCenter( Vector2( mPageSize.width*0.5f, mPageSize.height*0.5f ));
141 // Start an animation to turn the previous page back
142 Animation animation = Animation::New( PAGE_TURN_OVER_ANIMATION_DURATION );
143 mAnimationActorPair[animation] = actor;
144 mAnimationIndexPair[animation] = mIndex;
146 animation.AnimateTo( Property( mTurnEffect[mIndex], mTurnEffect[mIndex].PageTurnEffect::GetCurrentCenterPropertyName() ),
148 AlphaFunctions::EaseOut, PAGE_TURN_OVER_ANIMATION_DURATION*0.75f );
149 animation.AnimateBy( Property( actor, Actor::ROTATION ), AngleAxis( Degree( 180.0f ), Vector3::YAXIS ) ,AlphaFunctions::EaseOut );
151 ImageActor::DownCast(actor).SetCullFace( CullBack );
152 animation.FinishedSignal().Connect( this, &PageTurnPortraitView::OnTurnedOver );
156 void PageTurnPortraitView::OnTurnedOver( Animation& animation )
158 ImageActor::DownCast(mAnimationActorPair[animation]).SetCullFace( CullNone );
159 TurnedOver( animation );
162 } // namespace Internal
164 } // namespace Toolkit