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>
22 #include <dali/public-api/animation/animation.h>
23 #include <dali/public-api/object/type-registry.h>
37 TypeRegistration mType( typeid(Toolkit::PageTurnPortraitView), typeid(Toolkit::PageTurnView), NULL );
39 // 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
40 const float GESTURE_SPEED_THRESHOLD(0.3f);
42 // the animation duration of turning the previous page back when an outwards flick is detected
43 const float PAGE_TURN_OVER_ANIMATION_DURATION(0.5f);
46 PageTurnPortraitView::PageTurnPortraitView( PageFactory& pageFactory, const Vector2& pageSize )
47 : PageTurnView( pageFactory, pageSize )
52 PageTurnPortraitView::~PageTurnPortraitView()
56 Toolkit::PageTurnPortraitView PageTurnPortraitView::New( PageFactory& pageFactory, const Vector2& pageSize )
58 // Create the implementation, temporarily owned on stack
59 IntrusivePtr< PageTurnPortraitView > internalPageTurnView = new PageTurnPortraitView( pageFactory, pageSize );
61 // Pass ownership to CustomActor
62 Dali::Toolkit::PageTurnPortraitView pageTurnView( *internalPageTurnView );
64 // Second-phase init of the implementation
65 // This can only be done after the CustomActor connection has been made...
66 internalPageTurnView->Initialize();
71 void PageTurnPortraitView::OnPageTurnViewInitialize()
73 mControlSize = mPageSize;
74 Self().SetSize( mPageSize );
75 mTurningPageLayer.SetParentOrigin( ParentOrigin::CENTER_LEFT );
78 ImageActor PageTurnPortraitView::NewPageFromRenderBuffer( int pageIndex )
80 return ImageActor::New(mRenderedPage[pageIndex % NUMBER_OF_CACHED_PAGES]);
83 Vector2 PageTurnPortraitView::SetPanPosition( const Vector2& gesturePosition )
85 return gesturePosition;
88 void PageTurnPortraitView::SetPanActor( const Vector2& panPosition )
90 if( mCurrentPageIndex < mTotalPageCount )
92 mPanActor = mPageActors[mCurrentPageIndex%NUMBER_OF_CACHED_PAGES];
100 void PageTurnPortraitView::SetSpineEffect(ImageActor actor, bool isLeftSide)
104 actor.RemoveShaderEffect();
108 actor.SetShaderEffect( mSpineEffectFront );
112 void PageTurnPortraitView::OnPossibleOutwardsFlick( const Vector2& panPosition, float gestureSpeed )
114 Vector2 offset = panPosition - mPressDownPosition;
115 // There is previous page and an outwards flick is detected
116 if( mCurrentPageIndex > 0 && gestureSpeed > GESTURE_SPEED_THRESHOLD && offset.x > fabs( offset.y ))
118 ImageActor actor = mPageActors[ (mCurrentPageIndex-1) % NUMBER_OF_CACHED_PAGES ];
119 if(actor.GetParent() != mRootOnScreen)
124 // Guard against destruction during signal emission
125 //Emit signal, to notify that page[mCurrentPageIndex-1] is turning backwards
126 Toolkit::PageTurnView handle( GetOwner() );
127 mPageTurnStartedSignal.Emit( handle, static_cast<unsigned int>(mCurrentPageIndex-1), false );
131 RemovePage( mCurrentPageIndex+NUMBER_OF_CACHED_PAGES_EACH_SIDE );
132 AddPage( mCurrentPageIndex-NUMBER_OF_CACHED_PAGES_EACH_SIDE );
135 // Add the page to tuning page layer and set up PageTurnEffect
136 mShadowView.Add( actor );
137 actor.SetShaderEffect( mTurnEffect[mIndex] );
138 GetImpl( mTurnEffect[mIndex] ).ApplyInternalConstraint();
139 mIsAnimating[mIndex] = true;
140 mTurnEffect[mIndex].SetIsTurningBack( true );
141 Vector2 originalCenter( mPageSize.width*1.5f, 0.5f*mPageSize.height );
142 mTurnEffect[mIndex].SetOriginalCenter( originalCenter );
143 mTurnEffect[mIndex].SetCurrentCenter( Vector2( mPageSize.width*0.5f, mPageSize.height*0.5f ));
145 // Start an animation to turn the previous page back
146 Animation animation = Animation::New( PAGE_TURN_OVER_ANIMATION_DURATION );
147 mAnimationActorPair[animation] = actor;
148 mAnimationIndexPair[animation] = mIndex;
150 animation.AnimateTo( Property( mTurnEffect[mIndex], mTurnEffect[mIndex].PageTurnEffect::GetCurrentCenterPropertyName() ),
152 AlphaFunctions::EaseOut, PAGE_TURN_OVER_ANIMATION_DURATION*0.75f );
153 animation.AnimateBy( Property( actor, Actor::Property::Rotation ), AngleAxis( Degree( 180.0f ), Vector3::YAXIS ) ,AlphaFunctions::EaseOut );
155 ImageActor::DownCast(actor).SetCullFace( CullBack );
156 animation.FinishedSignal().Connect( this, &PageTurnPortraitView::OnTurnedOver );
160 void PageTurnPortraitView::OnTurnedOver( Animation& animation )
162 ImageActor::DownCast(mAnimationActorPair[animation]).SetCullFace( CullNone );
163 TurnedOver( animation );
166 } // namespace Internal
168 } // namespace Toolkit