Split dali-toolkit into Base & Optional
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / internal / controls / page-turn-view / page-turn-landscape-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-landscape-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::PageTurnLandscapeView), typeid(Toolkit::PageTurnView), NULL );
33 }
34
35 PageTurnLandscapeView::PageTurnLandscapeView( PageFactory& pageFactory, const Vector2& pageSize )
36 : PageTurnView( pageFactory, pageSize )
37 {
38 }
39
40 PageTurnLandscapeView::~PageTurnLandscapeView()
41 {}
42
43 Toolkit::PageTurnLandscapeView PageTurnLandscapeView::New( PageFactory& pageFactory, const Vector2& pageSize )
44 {
45   // Create the implementation, temporarily owned on stack
46   IntrusivePtr< PageTurnLandscapeView > internalPageTurnView = new PageTurnLandscapeView( pageFactory, pageSize );
47
48   // Pass ownership to CustomActor
49   Dali::Toolkit::PageTurnLandscapeView pageTurnView( *internalPageTurnView );
50
51   // Second-phase init of the implementation
52   // This can only be done after the CustomActor connection has been made...
53   internalPageTurnView->Initialize();
54
55   return pageTurnView;
56 }
57
58 void PageTurnLandscapeView::OnPageTurnViewInitialize()
59 {
60   mControlSize = Vector2( mPageSize.width * 2.f,  mPageSize.height  );
61   Self().SetSize( mControlSize );
62   mTurningPageLayer.SetParentOrigin( ParentOrigin::CENTER );
63 }
64
65 ImageActor PageTurnLandscapeView::NewPageFromRenderBuffer( int pageIndex )
66 {
67   int index = pageIndex % NUMBER_OF_CACHED_PAGES;
68   ImageActor page = ImageActor::New( mRenderedPage[ index ],
69                                      ImageActor::PixelArea( mPageSize.width, 0, mPageSize.width, mPageSize.height  ) );
70   if( pageIndex <= mTotalPageCount-1)
71   {
72     int nextIndex = (pageIndex+1) % NUMBER_OF_CACHED_PAGES;
73     page.Add( ImageActor::New( mRenderedPage[ nextIndex ],ImageActor::PixelArea( 0, 0, mPageSize.width, mPageSize.height  ) ) );
74   }
75   return page;
76 }
77
78 void PageTurnLandscapeView::OnAddPage( ImageActor newPage, bool isLeftSide )
79 {
80   newPage.SetParentOrigin( ParentOrigin::CENTER );
81   newPage.SetCullFace( CullBack );
82
83   if( 0 < newPage.GetChildCount() )
84   {
85      ImageActor backImage = ImageActor::DownCast( newPage.GetChildAt( 0 ) );
86      backImage.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
87      backImage.SetSize( mPageSize );
88      backImage.SetCullFace( CullFront );
89      backImage.SetZ( 0.25f * STATIC_PAGE_INTERVAL_DISTANCE );
90   }
91   if( isLeftSide )
92   {
93     SetShaderEffect( newPage, mSpineEffectBack );
94   }
95 }
96
97 Vector2 PageTurnLandscapeView::SetPanPosition( const Vector2& gesturePosition )
98 {
99   if( mIsTurnBack[mPanActor] )
100   {
101     return Vector2( mPageSize.width - gesturePosition.x, gesturePosition.y );
102   }
103   else
104   {
105     return Vector2( gesturePosition.x - mPageSize.width, gesturePosition.y );
106   }
107 }
108
109 void PageTurnLandscapeView::SetPanActor( const Vector2& panPosition )
110 {
111   if( panPosition.x > mPageSize.width  && mCurrentPageIndex < mTotalPageCount-1 )
112   {
113     mPanActor = mPageActors[mCurrentPageIndex%NUMBER_OF_CACHED_PAGES]; // right side page
114   }
115   else if( panPosition.x <= mPageSize.width && mCurrentPageIndex > 0 )
116   {
117     mPanActor = mPageActors[ (mCurrentPageIndex-1)%NUMBER_OF_CACHED_PAGES ]; // left side page
118   }
119   else
120   {
121     mPanActor.Reset();
122   }
123 }
124
125 void PageTurnLandscapeView::SetSpineEffect(Actor actor, bool isLeftSide)
126 {
127   if(isLeftSide)
128   {
129     SetShaderEffect( actor, mSpineEffectBack );
130   }
131   else
132   {
133     SetShaderEffect( actor, mSpineEffectFront );
134   }
135 }
136
137 } // namespace Internal
138
139 } // namespace Toolkit
140
141 } // namespace Dali