2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/controls/page-turn-view/page-turn-landscape-view-impl.h>
22 #include <dali/public-api/object/type-registry.h>
36 TypeRegistration mType( typeid(Toolkit::PageTurnLandscapeView), typeid(Toolkit::PageTurnView), NULL );
39 PageTurnLandscapeView::PageTurnLandscapeView( PageFactory& pageFactory, const Vector2& pageSize )
40 : PageTurnView( pageFactory, pageSize )
44 PageTurnLandscapeView::~PageTurnLandscapeView()
47 Toolkit::PageTurnLandscapeView PageTurnLandscapeView::New( PageFactory& pageFactory, const Vector2& pageSize )
49 // Create the implementation, temporarily owned on stack
50 IntrusivePtr< PageTurnLandscapeView > internalPageTurnView = new PageTurnLandscapeView( pageFactory, pageSize );
52 // Pass ownership to CustomActor
53 Dali::Toolkit::PageTurnLandscapeView pageTurnView( *internalPageTurnView );
55 // Second-phase init of the implementation
56 // This can only be done after the CustomActor connection has been made...
57 internalPageTurnView->Initialize();
62 void PageTurnLandscapeView::OnPageTurnViewInitialize()
64 mControlSize = Vector2( mPageSize.width * 2.f, mPageSize.height );
65 Self().SetSize( mControlSize );
66 mTurningPageLayer.SetParentOrigin( ParentOrigin::CENTER );
69 ImageActor PageTurnLandscapeView::NewPageFromRenderBuffer( int pageIndex )
71 int index = pageIndex % NUMBER_OF_CACHED_PAGES;
72 ImageActor page = ImageActor::New( mRenderedPage[ index ],
73 ImageActor::PixelArea( mPageSize.width, 0, mPageSize.width, mPageSize.height ) );
74 if( pageIndex <= mTotalPageCount-1)
76 int nextIndex = (pageIndex+1) % NUMBER_OF_CACHED_PAGES;
77 page.Add( ImageActor::New( mRenderedPage[ nextIndex ],ImageActor::PixelArea( 0, 0, mPageSize.width, mPageSize.height ) ) );
82 void PageTurnLandscapeView::OnAddPage( ImageActor newPage, bool isLeftSide )
84 newPage.SetParentOrigin( ParentOrigin::CENTER );
85 newPage.SetCullFace( CullBack );
87 if( 0 < newPage.GetChildCount() )
89 ImageActor backImage = ImageActor::DownCast( newPage.GetChildAt( 0 ) );
90 backImage.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
91 backImage.SetSize( mPageSize );
92 backImage.SetCullFace( CullFront );
93 backImage.SetZ( 0.25f * STATIC_PAGE_INTERVAL_DISTANCE );
97 SetShaderEffect( newPage, mSpineEffectBack );
101 Vector2 PageTurnLandscapeView::SetPanPosition( const Vector2& gesturePosition )
103 if( mIsTurnBack[mPanActor] )
105 return Vector2( mPageSize.width - gesturePosition.x, gesturePosition.y );
109 return Vector2( gesturePosition.x - mPageSize.width, gesturePosition.y );
113 void PageTurnLandscapeView::SetPanActor( const Vector2& panPosition )
115 if( panPosition.x > mPageSize.width && mCurrentPageIndex < mTotalPageCount-1 )
117 mPanActor = mPageActors[mCurrentPageIndex%NUMBER_OF_CACHED_PAGES]; // right side page
119 else if( panPosition.x <= mPageSize.width && mCurrentPageIndex > 0 )
121 mPanActor = mPageActors[ (mCurrentPageIndex-1)%NUMBER_OF_CACHED_PAGES ]; // left side page
129 void PageTurnLandscapeView::SetSpineEffect(ImageActor actor, bool isLeftSide)
133 SetShaderEffect( actor, mSpineEffectBack );
137 SetShaderEffect( actor, mSpineEffectFront );
141 } // namespace Internal
143 } // namespace Toolkit