Updated all cpp files to new format
[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-helper.h>
23 #include <dali/public-api/object/type-registry.h>
24
25 namespace Dali
26 {
27 namespace Toolkit
28 {
29 namespace Internal
30 {
31 namespace
32 {
33 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::PageTurnLandscapeView, Toolkit::PageTurnView, NULL)
34 DALI_TYPE_REGISTRATION_END()
35
36 } // namespace
37
38 PageTurnLandscapeView::PageTurnLandscapeView(PageFactory& pageFactory, const Vector2& viewPageSize)
39 : PageTurnView(pageFactory, viewPageSize)
40 {
41 }
42
43 PageTurnLandscapeView::~PageTurnLandscapeView()
44 {
45 }
46
47 Toolkit::PageTurnLandscapeView PageTurnLandscapeView::New(PageFactory& pageFactory, const Vector2& viewPageSize)
48 {
49   // Create the implementation, temporarily owned on stack
50   IntrusivePtr<PageTurnLandscapeView> internalPageTurnView = new PageTurnLandscapeView(pageFactory, viewPageSize);
51
52   // Pass ownership to CustomActor
53   Dali::Toolkit::PageTurnLandscapeView pageTurnView(*internalPageTurnView);
54
55   // Second-phase init of the implementation
56   // This can only be done after the CustomActor connection has been made...
57   internalPageTurnView->Initialize();
58
59   return pageTurnView;
60 }
61
62 void PageTurnLandscapeView::OnPageTurnViewInitialize()
63 {
64   mTurnEffectShader.RegisterProperty(PROPERTY_TEXTURE_WIDTH, 2.f);
65   mSpineEffectShader.RegisterProperty(PROPERTY_TEXTURE_WIDTH, 2.f);
66
67   mControlSize = Vector2(mPageSize.width * 2.f, mPageSize.height);
68   Self().SetProperty(Actor::Property::SIZE, mControlSize);
69   mTurningPageLayer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
70 }
71
72 void PageTurnLandscapeView::OnAddPage(Actor newPage, bool isLeftSide)
73 {
74   newPage.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
75 }
76
77 Vector2 PageTurnLandscapeView::SetPanPosition(const Vector2& gesturePosition)
78 {
79   if(mPages[mIndex].isTurnBack)
80   {
81     return Vector2(mPageSize.width - gesturePosition.x, gesturePosition.y);
82   }
83   else
84   {
85     return Vector2(gesturePosition.x - mPageSize.width, gesturePosition.y);
86   }
87 }
88
89 void PageTurnLandscapeView::SetPanActor(const Vector2& panPosition)
90 {
91   if(panPosition.x > mPageSize.width && mCurrentPageIndex < mTotalPageCount)
92   {
93     mTurningPageIndex = mCurrentPageIndex;
94   }
95   else if(panPosition.x <= mPageSize.width && mCurrentPageIndex > 0)
96   {
97     mTurningPageIndex = mCurrentPageIndex - 1;
98   }
99   else
100   {
101     mTurningPageIndex = -1;
102   }
103 }
104
105 } // namespace Internal
106
107 } // namespace Toolkit
108
109 } // namespace Dali