Property refactor in dali-toolkit: Toolkit changes
[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/public-api/object/type-registry-helper.h>
24
25 namespace Dali
26 {
27
28 namespace Toolkit
29 {
30
31 namespace Internal
32 {
33
34 namespace
35 {
36 using namespace Dali;
37
38 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::PageTurnLandscapeView, Toolkit::PageTurnView, NULL )
39 DALI_TYPE_REGISTRATION_END()
40
41 }
42
43 PageTurnLandscapeView::PageTurnLandscapeView( PageFactory& pageFactory, const Vector2& pageSize )
44 : PageTurnView( pageFactory, pageSize )
45 {
46 }
47
48 PageTurnLandscapeView::~PageTurnLandscapeView()
49 {}
50
51 Toolkit::PageTurnLandscapeView PageTurnLandscapeView::New( PageFactory& pageFactory, const Vector2& pageSize )
52 {
53   // Create the implementation, temporarily owned on stack
54   IntrusivePtr< PageTurnLandscapeView > internalPageTurnView = new PageTurnLandscapeView( pageFactory, pageSize );
55
56   // Pass ownership to CustomActor
57   Dali::Toolkit::PageTurnLandscapeView 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 PageTurnLandscapeView::OnPageTurnViewInitialize()
67 {
68   mControlSize = Vector2( mPageSize.width * 2.f,  mPageSize.height  );
69   Self().SetSize( mControlSize );
70   mTurningPageLayer.SetParentOrigin( ParentOrigin::CENTER );
71 }
72
73 ImageActor PageTurnLandscapeView::NewPageFromRenderBuffer( int pageIndex )
74 {
75   int index = pageIndex % NUMBER_OF_CACHED_PAGES;
76   ImageActor page = ImageActor::New( mRenderedPage[ index ],
77                                      ImageActor::PixelArea( mPageSize.width, 0, mPageSize.width, mPageSize.height  ) );
78   if( pageIndex <= mTotalPageCount-1)
79   {
80     int nextIndex = (pageIndex+1) % NUMBER_OF_CACHED_PAGES;
81     page.Add( ImageActor::New( mRenderedPage[ nextIndex ],ImageActor::PixelArea( 0, 0, mPageSize.width, mPageSize.height  ) ) );
82   }
83   return page;
84 }
85
86 void PageTurnLandscapeView::OnAddPage( ImageActor newPage, bool isLeftSide )
87 {
88   newPage.SetParentOrigin( ParentOrigin::CENTER );
89   newPage.SetCullFace( CullBack );
90
91   if( 0 < newPage.GetChildCount() )
92   {
93      ImageActor backImage = ImageActor::DownCast( newPage.GetChildAt( 0 ) );
94      backImage.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
95      backImage.SetSize( mPageSize );
96      backImage.SetCullFace( CullFront );
97      backImage.SetZ( 0.25f * STATIC_PAGE_INTERVAL_DISTANCE );
98   }
99   if( isLeftSide )
100   {
101     SetShaderEffect( newPage, mSpineEffectBack );
102   }
103 }
104
105 Vector2 PageTurnLandscapeView::SetPanPosition( const Vector2& gesturePosition )
106 {
107   if( mIsTurnBack[mPanActor] )
108   {
109     return Vector2( mPageSize.width - gesturePosition.x, gesturePosition.y );
110   }
111   else
112   {
113     return Vector2( gesturePosition.x - mPageSize.width, gesturePosition.y );
114   }
115 }
116
117 void PageTurnLandscapeView::SetPanActor( const Vector2& panPosition )
118 {
119   if( panPosition.x > mPageSize.width  && mCurrentPageIndex < mTotalPageCount-1 )
120   {
121     mPanActor = mPageActors[mCurrentPageIndex%NUMBER_OF_CACHED_PAGES]; // right side page
122   }
123   else if( panPosition.x <= mPageSize.width && mCurrentPageIndex > 0 )
124   {
125     mPanActor = mPageActors[ (mCurrentPageIndex-1)%NUMBER_OF_CACHED_PAGES ]; // left side page
126   }
127   else
128   {
129     mPanActor.Reset();
130   }
131 }
132
133 void PageTurnLandscapeView::SetSpineEffect(ImageActor actor, bool isLeftSide)
134 {
135   if(isLeftSide)
136   {
137     SetShaderEffect( actor, mSpineEffectBack );
138   }
139   else
140   {
141     SetShaderEffect( actor, mSpineEffectFront );
142   }
143 }
144
145 } // namespace Internal
146
147 } // namespace Toolkit
148
149 } // namespace Dali