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