Merge "Type registry helper: Toolkit change to correct Programming Guide for Custom...
[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
37 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::PageTurnLandscapeView, Toolkit::PageTurnView, NULL )
38 DALI_TYPE_REGISTRATION_END()
39
40 }
41
42 PageTurnLandscapeView::PageTurnLandscapeView( PageFactory& pageFactory, const Vector2& pageSize )
43 : PageTurnView( pageFactory, pageSize )
44 {
45 }
46
47 PageTurnLandscapeView::~PageTurnLandscapeView()
48 {}
49
50 Toolkit::PageTurnLandscapeView PageTurnLandscapeView::New( PageFactory& pageFactory, const Vector2& pageSize )
51 {
52   // Create the implementation, temporarily owned on stack
53   IntrusivePtr< PageTurnLandscapeView > internalPageTurnView = new PageTurnLandscapeView( pageFactory, pageSize );
54
55   // Pass ownership to CustomActor
56   Dali::Toolkit::PageTurnLandscapeView pageTurnView( *internalPageTurnView );
57
58   // Second-phase init of the implementation
59   // This can only be done after the CustomActor connection has been made...
60   internalPageTurnView->Initialize();
61
62   return pageTurnView;
63 }
64
65 void PageTurnLandscapeView::OnPageTurnViewInitialize()
66 {
67   mTurnEffectShader.RegisterProperty(PROPERTY_TEXTURE_WIDTH, 2.f );
68   mSpineEffectShader.RegisterProperty(PROPERTY_TEXTURE_WIDTH, 2.f );
69
70   mControlSize = Vector2( mPageSize.width * 2.f,  mPageSize.height  );
71   Self().SetSize( mControlSize );
72   mTurningPageLayer.SetParentOrigin( ParentOrigin::CENTER );
73 }
74
75 void PageTurnLandscapeView::OnAddPage( Actor newPage, bool isLeftSide )
76 {
77   newPage.SetParentOrigin( ParentOrigin::CENTER );
78 }
79
80 Vector2 PageTurnLandscapeView::SetPanPosition( const Vector2& gesturePosition )
81 {
82   if( mPages[mIndex].isTurnBack )
83   {
84     return Vector2( mPageSize.width - gesturePosition.x, gesturePosition.y );
85   }
86   else
87   {
88     return Vector2( gesturePosition.x - mPageSize.width, gesturePosition.y );
89   }
90 }
91
92 void PageTurnLandscapeView::SetPanActor( const Vector2& panPosition )
93 {
94   if( panPosition.x > mPageSize.width  && mCurrentPageIndex < mTotalPageCount )
95   {
96     mTurningPageIndex = mCurrentPageIndex;
97   }
98   else if( panPosition.x <= mPageSize.width && mCurrentPageIndex > 0 )
99   {
100     mTurningPageIndex = mCurrentPageIndex - 1;
101   }
102   else
103   {
104     mTurningPageIndex = -1;
105   }
106 }
107
108 } // namespace Internal
109
110 } // namespace Toolkit
111
112 } // namespace Dali