Add 'ExclusiveArch: armv7l' limit build to arm architecture
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / page-turn-view / page-turn-portrait-view-impl.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 //CLASS HEADER
18 #include <dali-toolkit/internal/controls/page-turn-view/page-turn-portrait-view-impl.h>
19
20 namespace Dali
21 {
22
23 namespace Toolkit
24 {
25
26 namespace Internal
27 {
28
29 namespace
30 {
31 using namespace Dali;
32 TypeRegistration mType( typeid(Toolkit::PageTurnPortraitView), typeid(Toolkit::PageTurnView), NULL );
33
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);
36
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);
39 }
40
41 PageTurnPortraitView::PageTurnPortraitView( PageFactory& pageFactory, const Vector2& pageSize )
42 : PageTurnView( pageFactory, pageSize )
43 {
44
45 }
46
47 PageTurnPortraitView::~PageTurnPortraitView()
48 {
49 }
50
51 Toolkit::PageTurnPortraitView PageTurnPortraitView::New( PageFactory& pageFactory, const Vector2& pageSize )
52 {
53   // Create the implementation, temporarily owned on stack
54   IntrusivePtr< PageTurnPortraitView > internalPageTurnView = new PageTurnPortraitView( pageFactory, pageSize );
55
56   // Pass ownership to CustomActor
57   Dali::Toolkit::PageTurnPortraitView pageTurnView( *internalPageTurnView );
58
59   // Second-phase init of the implementation
60   // This can only be done after the CustomActor connection has been made...
61   internalPageTurnView->Initialize();
62
63   return pageTurnView;
64 }
65
66 void PageTurnPortraitView::OnPageTurnViewInitialize()
67 {
68   mControlSize = mPageSize;
69   Self().SetSize( mPageSize );
70   mTurningPageLayer.SetParentOrigin( ParentOrigin::CENTER_LEFT );
71 }
72
73 ImageActor PageTurnPortraitView::NewPageFromRenderBuffer( int pageIndex )
74 {
75   return ImageActor::New(mRenderedPage[pageIndex % NUMBER_OF_CACHED_PAGES]);
76 }
77
78 Vector2 PageTurnPortraitView::SetPanPosition( const Vector2& gesturePosition )
79 {
80   return gesturePosition;
81 }
82
83 void PageTurnPortraitView::SetPanActor( const Vector2& panPosition )
84 {
85   if( mCurrentPageIndex < mTotalPageCount )
86   {
87     mPanActor = mPageActors[mCurrentPageIndex%NUMBER_OF_CACHED_PAGES];
88   }
89   else
90   {
91     mPanActor.Reset();
92   }
93 }
94
95 void PageTurnPortraitView::SetSpineEffect(Actor actor, bool isLeftSide)
96 {
97   if(isLeftSide)
98   {
99     actor.RemoveShaderEffect();
100   }
101   else
102   {
103     actor.SetShaderEffect( mSpineEffectFront );
104   }
105 }
106
107 void PageTurnPortraitView::OnPossibleOutwardsFlick( const Vector2& panPosition, float gestureSpeed )
108 {
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 ))
112   {
113     Actor actor = mPageActors[ (mCurrentPageIndex-1) % NUMBER_OF_CACHED_PAGES ];
114     if(actor.GetParent() != mRootOnScreen)
115     {
116       return;
117     }
118
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 );
123
124     //update pages
125     mCurrentPageIndex--;
126     RemovePage( mCurrentPageIndex+NUMBER_OF_CACHED_PAGES_EACH_SIDE );
127     AddPage( mCurrentPageIndex-NUMBER_OF_CACHED_PAGES_EACH_SIDE );
128     OrganizePageDepth();
129
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 ));
139
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;
144
145     animation.AnimateTo( Property( mTurnEffect[mIndex], mTurnEffect[mIndex].PageTurnEffect::GetCurrentCenterPropertyName() ),
146                          originalCenter,
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 );
149     animation.Play();
150     ImageActor::DownCast(actor).SetCullFace( CullBack );
151     animation.FinishedSignal().Connect( this, &PageTurnPortraitView::OnTurnedOver );
152   }
153 }
154
155 void PageTurnPortraitView::OnTurnedOver( Animation& animation )
156 {
157   ImageActor::DownCast(mAnimationActorPair[animation]).SetCullFace( CullNone );
158   TurnedOver( animation );
159 }
160
161 } // namespace Internal
162
163 } // namespace Toolkit
164
165 } // namespace Dali