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