[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / page-turn-view / page-turn-landscape-view-impl.cpp
index a831641..daa4852 100644 (file)
@@ -1,52 +1,56 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-//CLASS HEADER
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
 #include <dali-toolkit/internal/controls/page-turn-view/page-turn-landscape-view-impl.h>
 
+// EXTERNAL INCLUDES
+#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/public-api/object/type-registry.h>
+
 namespace Dali
 {
-
 namespace Toolkit
 {
-
 namespace Internal
 {
-
 namespace
 {
-using namespace Dali;
-TypeRegistration mType( typeid(Toolkit::PageTurnLandscapeView), typeid(Toolkit::PageTurnView), NULL );
-}
+DALI_TYPE_REGISTRATION_BEGIN(Toolkit::PageTurnLandscapeView, Toolkit::PageTurnView, NULL)
+DALI_TYPE_REGISTRATION_END()
+
+} // namespace
 
-PageTurnLandscapeView::PageTurnLandscapeView( PageFactory& pageFactory, const Vector2& pageSize )
-: PageTurnView( pageFactory, pageSize )
+PageTurnLandscapeView::PageTurnLandscapeView(PageFactory& pageFactory, const Vector2& viewPageSize)
+: PageTurnView(pageFactory, viewPageSize)
 {
 }
 
 PageTurnLandscapeView::~PageTurnLandscapeView()
-{}
+{
+}
 
-Toolkit::PageTurnLandscapeView PageTurnLandscapeView::New( PageFactory& pageFactory, const Vector2& pageSize )
+Toolkit::PageTurnLandscapeView PageTurnLandscapeView::New(PageFactory& pageFactory, const Vector2& viewPageSize)
 {
   // Create the implementation, temporarily owned on stack
-  IntrusivePtr< PageTurnLandscapeView > internalPageTurnView = new PageTurnLandscapeView( pageFactory, pageSize );
+  IntrusivePtr<PageTurnLandscapeView> internalPageTurnView = new PageTurnLandscapeView(pageFactory, viewPageSize);
 
   // Pass ownership to CustomActor
-  Dali::Toolkit::PageTurnLandscapeView pageTurnView( *internalPageTurnView );
+  Dali::Toolkit::PageTurnLandscapeView pageTurnView(*internalPageTurnView);
 
   // Second-phase init of the implementation
   // This can only be done after the CustomActor connection has been made...
@@ -57,80 +61,44 @@ Toolkit::PageTurnLandscapeView PageTurnLandscapeView::New( PageFactory& pageFact
 
 void PageTurnLandscapeView::OnPageTurnViewInitialize()
 {
-  mControlSize = Vector2( mPageSize.width * 2.f,  mPageSize.height  );
-  Self().SetSize( mControlSize );
-  mTurningPageLayer.SetParentOrigin( ParentOrigin::CENTER );
-}
+  mTurnEffectShader.RegisterProperty(PROPERTY_TEXTURE_WIDTH, 2.f);
+  mSpineEffectShader.RegisterProperty(PROPERTY_TEXTURE_WIDTH, 2.f);
 
-ImageActor PageTurnLandscapeView::NewPageFromRenderBuffer( int pageIndex )
-{
-  int index = pageIndex % NUMBER_OF_CACHED_PAGES;
-  ImageActor page = ImageActor::New( mRenderedPage[ index ],
-                                     ImageActor::PixelArea( mPageSize.width, 0, mPageSize.width, mPageSize.height  ) );
-  if( pageIndex <= mTotalPageCount-1)
-  {
-    int nextIndex = (pageIndex+1) % NUMBER_OF_CACHED_PAGES;
-    page.Add( ImageActor::New( mRenderedPage[ nextIndex ],ImageActor::PixelArea( 0, 0, mPageSize.width, mPageSize.height  ) ) );
-  }
-  return page;
+  mControlSize = Vector2(mPageSize.width * 2.f, mPageSize.height);
+  Self().SetProperty(Actor::Property::SIZE, mControlSize);
+  mTurningPageLayer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
 }
 
-void PageTurnLandscapeView::OnAddPage( ImageActor newPage, bool isLeftSide )
+void PageTurnLandscapeView::OnAddPage(Actor newPage, bool isLeftSide)
 {
-  newPage.SetParentOrigin( ParentOrigin::CENTER );
-  newPage.SetCullFace( CullBack );
-
-  if( 0 < newPage.GetChildCount() )
-  {
-     ImageActor backImage = ImageActor::DownCast( newPage.GetChildAt( 0 ) );
-     backImage.SetPositionInheritanceMode( USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
-     backImage.SetSize( mPageSize );
-     backImage.SetCullFace( CullFront );
-     backImage.SetZ( 0.25f * STATIC_PAGE_INTERVAL_DISTANCE );
-  }
-  if( isLeftSide )
-  {
-    SetShaderEffect( newPage, mSpineEffectBack );
-  }
+  newPage.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
 }
 
-Vector2 PageTurnLandscapeView::SetPanPosition( const Vector2& gesturePosition )
+Vector2 PageTurnLandscapeView::SetPanPosition(const Vector2& gesturePosition)
 {
-  if( mIsTurnBack[mPanActor] )
+  if(mPages[mIndex].isTurnBack)
   {
-    return Vector2( mPageSize.width - gesturePosition.x, gesturePosition.y );
+    return Vector2(mPageSize.width - gesturePosition.x, gesturePosition.y);
   }
   else
   {
-    return Vector2( gesturePosition.x - mPageSize.width, gesturePosition.y );
+    return Vector2(gesturePosition.x - mPageSize.width, gesturePosition.y);
   }
 }
 
-void PageTurnLandscapeView::SetPanActor( const Vector2& panPosition )
+void PageTurnLandscapeView::SetPanActor(const Vector2& panPosition)
 {
-  if( panPosition.x > mPageSize.width  && mCurrentPageIndex < mTotalPageCount-1 )
-  {
-    mPanActor = mPageActors[mCurrentPageIndex%NUMBER_OF_CACHED_PAGES]; // right side page
-  }
-  else if( panPosition.x <= mPageSize.width && mCurrentPageIndex > 0 )
+  if(panPosition.x > mPageSize.width && mCurrentPageIndex < mTotalPageCount)
   {
-    mPanActor = mPageActors[ (mCurrentPageIndex-1)%NUMBER_OF_CACHED_PAGES ]; // left side page
+    mTurningPageIndex = mCurrentPageIndex;
   }
-  else
-  {
-    mPanActor.Reset();
-  }
-}
-
-void PageTurnLandscapeView::SetSpineEffect(Actor actor, bool isLeftSide)
-{
-  if(isLeftSide)
+  else if(panPosition.x <= mPageSize.width && mCurrentPageIndex > 0)
   {
-    SetShaderEffect( actor, mSpineEffectBack );
+    mTurningPageIndex = mCurrentPageIndex - 1;
   }
   else
   {
-    SetShaderEffect( actor, mSpineEffectFront );
+    mTurningPageIndex = -1;
   }
 }