Merge "Stop using ImageActor in PageTurnView" into devel/master
[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
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   mTurnEffectShader.RegisterProperty(PROPERTY_TEXTURE_WIDTH, 2.f );
69   mSpineEffectShader.RegisterProperty(PROPERTY_TEXTURE_WIDTH, 2.f );
70
71   mControlSize = Vector2( mPageSize.width * 2.f,  mPageSize.height  );
72   Self().SetSize( mControlSize );
73   mTurningPageLayer.SetParentOrigin( ParentOrigin::CENTER );
74 }
75
76 void PageTurnLandscapeView::OnAddPage( Actor newPage, bool isLeftSide )
77 {
78   newPage.SetParentOrigin( ParentOrigin::CENTER );
79 }
80
81 Vector2 PageTurnLandscapeView::SetPanPosition( const Vector2& gesturePosition )
82 {
83   if( mPages[mIndex].isTurnBack )
84   {
85     return Vector2( mPageSize.width - gesturePosition.x, gesturePosition.y );
86   }
87   else
88   {
89     return Vector2( gesturePosition.x - mPageSize.width, gesturePosition.y );
90   }
91 }
92
93 void PageTurnLandscapeView::SetPanActor( const Vector2& panPosition )
94 {
95   if( panPosition.x > mPageSize.width  && mCurrentPageIndex < mTotalPageCount )
96   {
97     mTurningPageIndex = mCurrentPageIndex;
98   }
99   else if( panPosition.x <= mPageSize.width && mCurrentPageIndex > 0 )
100   {
101     mTurningPageIndex = mCurrentPageIndex - 1;
102   }
103   else
104   {
105     mTurningPageIndex = -1;
106   }
107 }
108
109 } // namespace Internal
110
111 } // namespace Toolkit
112
113 } // namespace Dali