Remove more public Setter/Getter APIs from Dali::Actor
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / page-turn-view / page-turn-view-impl.cpp
index f6d5e7a..9204fa4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
 #include <cstring> // for strcmp
 #include <dali/public-api/animation/animation.h>
 #include <dali/public-api/animation/constraint.h>
-#include <dali/public-api/images/resource-image.h>
 #include <dali/public-api/object/type-registry.h>
 #include <dali/public-api/object/type-registry-helper.h>
-#include <dali/devel-api/images/texture-set-image.h>
 #include <dali/integration-api/debug.h>
 
 // INTERNAL INCLUDES
@@ -39,9 +37,6 @@ using namespace Dali;
 
 namespace //Unnamed namespace
 {
-// broken image is loaded if there is no valid image provided for the page
-const char * const BROKEN_IMAGE_URL( DALI_IMAGE_DIR "broken.png");
-
 // properties set on shader, these properties have the constant value in regardless of the page status
 const char * const PROPERTY_SPINE_SHADOW ( "uSpineShadowParameter" ); // uniform for both spine and turn effect
 
@@ -56,13 +51,13 @@ const char * const PROPERTY_PAN_CENTER( "panCenter" );// property used to constr
 // default grid density for page turn effect, 20 pixels by 20 pixels
 const float DEFAULT_GRID_DENSITY(20.0f);
 
-// to bent the page, the minimal horizontal pan start position is pageSize.x * MINIMUM_START_POSITION_RATIO
+// to bent the page, the minimal horizontal pan start position is viewPageSize.x * MINIMUM_START_POSITION_RATIO
 const float MINIMUM_START_POSITION_RATIO(0.6f);
 
-// the maximum vertical displacement of pan gesture, if exceed, will reduce it: pageSize.y * MAXIMUM_VERTICAL_MOVEMENT_RATIO
+// the maximum vertical displacement of pan gesture, if exceed, will reduce it: viewPageSize.y * MAXIMUM_VERTICAL_MOVEMENT_RATIO
 const float MAXIMUM_VERTICAL_MOVEMENT_RATIO(0.15f);
 
-// when the x component of pan position reaches pageSize.x * PAGE_TURN_OVER_THRESHOLD_RATIO, page starts to turn over
+// when the x component of pan position reaches viewPageSize.x * PAGE_TURN_OVER_THRESHOLD_RATIO, page starts to turn over
 const float PAGE_TURN_OVER_THRESHOLD_RATIO(0.5f);
 
 // duration of animation, shorter for faster speed
@@ -242,7 +237,7 @@ BaseHandle Create()
 // Setup properties, signals and actions using the type-registry.
 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::PageTurnView, Toolkit::Control, Create );
 
-DALI_PROPERTY_REGISTRATION( Toolkit, PageTurnView, "pageSize",        VECTOR2, PAGE_SIZE )
+DALI_PROPERTY_REGISTRATION( Toolkit, PageTurnView, "viewPageSize",        VECTOR2, VIEW_PAGE_SIZE )
 DALI_PROPERTY_REGISTRATION( Toolkit, PageTurnView, "currentPageId",   INTEGER, CURRENT_PAGE_ID )
 DALI_PROPERTY_REGISTRATION( Toolkit, PageTurnView, "spineShadow",     VECTOR2, SPINE_SHADOW )
 
@@ -268,9 +263,9 @@ PageTurnView::Page::Page()
 : isTurnBack( false )
 {
   actor = Actor::New();
-  actor.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
-  actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
-  actor.SetVisible( false );
+  actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT );
+  actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_LEFT );
+  actor.SetProperty( Actor::Property::VISIBLE, false );
 
   propertyPanDisplacement = actor.RegisterProperty( PROPERTY_PAN_DISPLACEMENT, 0.f );
   propertyPanCenter = actor.RegisterProperty(PROPERTY_PAN_CENTER, Vector2::ZERO);
@@ -282,14 +277,13 @@ PageTurnView::Page::Page()
   propertyTurnDirection = actor.RegisterProperty(PROPERTY_TURN_DIRECTION, -1.f);
 }
 
-void PageTurnView::Page::SetImage( Image image  )
+void PageTurnView::Page::SetTexture( Texture texture )
 {
   if( !textureSet )
   {
     textureSet = TextureSet::New();
   }
-
-  TextureSetImage( textureSet, 0u, image );
+  textureSet.SetTexture( 0u, texture );
 }
 
 void PageTurnView::Page::UseEffect(Shader newShader)
@@ -346,10 +340,10 @@ void PageTurnView::Page::SetCurrentCenter( const Vector2& value )
   actor.SetProperty( propertyCurrentCenter, value );
 }
 
-PageTurnView::PageTurnView( PageFactory& pageFactory, const Vector2& pageSize )
+PageTurnView::PageTurnView( PageFactory& pageFactory, const Vector2& viewPageSize )
 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
   mPageFactory( &pageFactory ),
-  mPageSize( pageSize ),
+  mPageSize( viewPageSize ),
   mSpineShadowParameter( DEFAULT_SPINE_SHADOW_PARAMETER ),
   mDistanceUpCorner( 0.f ),
   mDistanceBottomCorner( 0.f ),
@@ -398,9 +392,9 @@ void PageTurnView::OnInitialize()
     Self().Add( mPages[i].actor );
   }
 
-  // create the layer for turning images
+  // create the layer for turning pages
   mTurningPageLayer = Layer::New();
-  mTurningPageLayer.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
+  mTurningPageLayer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT );
   mTurningPageLayer.SetBehavior(Layer::LAYER_3D);
   mTurningPageLayer.Raise();
 
@@ -416,7 +410,7 @@ void PageTurnView::OnInitialize()
     AddPage( i );
     mPages[i].actor.SetZ( -static_cast<float>( i )*STATIC_PAGE_INTERVAL_DISTANCE );
   }
-  mPages[0].actor.SetVisible(true);
+  mPages[0].actor.SetProperty( Actor::Property::VISIBLE,true);
 
   // enable the pan gesture which is attached to the control
   EnableGestureDetection(Gesture::Type(Gesture::Pan));
@@ -454,21 +448,21 @@ Shader PageTurnView::CreateShader( const Property::Map& shaderMap )
 void PageTurnView::SetupShadowView()
 {
   mShadowView = Toolkit::ShadowView::New( 0.25f, 0.25f );
-  Vector3 origin = mTurningPageLayer.GetCurrentParentOrigin();
-  mShadowView.SetParentOrigin( origin );
-  mShadowView.SetAnchorPoint( origin );
+  Vector3 origin = mTurningPageLayer.GetCurrentProperty< Vector3 >( Actor::Property::PARENT_ORIGIN );
+  mShadowView.SetProperty( Actor::Property::PARENT_ORIGIN, origin );
+  mShadowView.SetProperty( Actor::Property::ANCHOR_POINT, origin );
   mShadowView.SetPointLightFieldOfView( Math::PI / 2.0f);
   mShadowView.SetShadowColor(DEFAULT_SHADOW_COLOR);
 
   mShadowPlaneBackground = Actor::New();
-  mShadowPlaneBackground.SetParentOrigin( ParentOrigin::CENTER );
+  mShadowPlaneBackground.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
   mShadowPlaneBackground.SetSize( mControlSize );
   Self().Add( mShadowPlaneBackground );
   mShadowView.SetShadowPlaneBackground( mShadowPlaneBackground );
 
   mPointLight = Actor::New();
-  mPointLight.SetAnchorPoint( origin );
-  mPointLight.SetParentOrigin( origin );
+  mPointLight.SetProperty( Actor::Property::ANCHOR_POINT, origin );
+  mPointLight.SetProperty( Actor::Property::PARENT_ORIGIN, origin );
   mPointLight.SetPosition( 0.f, 0.f, mPageSize.width*POINT_LIGHT_HEIGHT_RATIO );
   Self().Add( mPointLight );
   mShadowView.SetPointLight( mPointLight );
@@ -479,9 +473,9 @@ void PageTurnView::SetupShadowView()
 
 void PageTurnView::OnStageConnection( int depth )
 {
-  Control::OnStageConnection( depth );
-
   SetupShadowView();
+
+  Control::OnStageConnection( depth );
 }
 
 void PageTurnView::OnStageDisconnection()
@@ -500,9 +494,9 @@ void PageTurnView::OnStageDisconnection()
   Control::OnStageDisconnection();
 }
 
-void PageTurnView::SetPageSize( const Vector2& pageSize )
+void PageTurnView::SetPageSize( const Vector2& viewPageSize )
 {
-  mPageSize = pageSize;
+  mPageSize = viewPageSize;
 
   if( mPointLight )
   {
@@ -563,10 +557,10 @@ void PageTurnView::GoToPage( unsigned int pageId )
     AddPage( i );
   }
 
-  mPages[pageId%NUMBER_OF_CACHED_PAGES].actor.SetVisible(true);
+  mPages[pageId%NUMBER_OF_CACHED_PAGES].actor.SetProperty( Actor::Property::VISIBLE,true);
   if( pageId > 0 )
   {
-    mPages[(pageId-1)%NUMBER_OF_CACHED_PAGES].actor.SetVisible(true);
+    mPages[(pageId-1)%NUMBER_OF_CACHED_PAGES].actor.SetProperty( Actor::Property::VISIBLE,true);
   }
   // set ordered depth to the stacked pages
   OrganizePageDepth();
@@ -584,13 +578,9 @@ void PageTurnView::AddPage( int pageIndex )
   {
     int index = pageIndex % NUMBER_OF_CACHED_PAGES;
 
-    Image newPageImage;
-    newPageImage = mPageFactory->NewPage( pageIndex );
-
-    if( !newPageImage ) // load the broken image
-    {
-      newPageImage = ResourceImage::New( BROKEN_IMAGE_URL );
-    }
+    Texture newPage;
+    newPage = mPageFactory->NewPage( pageIndex );
+    DALI_ASSERT_ALWAYS( newPage && "must pass in valid texture" );
 
     bool isLeftSide = ( pageIndex < mCurrentPageIndex );
     if( mPages[index].isTurnBack != isLeftSide )
@@ -599,14 +589,14 @@ void PageTurnView::AddPage( int pageIndex )
     }
 
     float degree = isLeftSide ? 180.f :0.f;
-    mPages[index].actor.SetOrientation( Degree( degree ), Vector3::YAXIS );
-    mPages[index].actor.SetVisible( false );
+    mPages[index].actor.SetProperty( Actor::Property::ORIENTATION, Quaternion( Degree( degree ), Vector3::YAXIS ) );
+    mPages[index].actor.SetProperty( Actor::Property::VISIBLE, false );
     mPages[index].UseEffect( mSpineEffectShader, mGeometry );
-    mPages[index].SetImage( newPageImage );
+    mPages[index].SetTexture( newPage );
 
     // For Portrait, nothing to do
     // For Landscape, set the parent origin to CENTER
-     OnAddPage( mPages[index].actor, isLeftSide );
+    OnAddPage( mPages[index].actor, isLeftSide );
   }
 }
 
@@ -615,7 +605,7 @@ void PageTurnView::RemovePage( int pageIndex )
   if( pageIndex > -1 && pageIndex < mTotalPageCount)
   {
     int index = pageIndex % NUMBER_OF_CACHED_PAGES;
-    mPages[index].actor.SetVisible(false);
+    mPages[index].actor.SetProperty( Actor::Property::VISIBLE,false);
   }
 }
 
@@ -722,7 +712,7 @@ void PageTurnView::PanContinuing( const Vector2& gesturePosition )
       int id = mTurningPageIndex + (mPages[mIndex].isTurnBack ? -1 : 1);
       if( id >=0 && id < mTotalPageCount )
       {
-        mPages[id%NUMBER_OF_CACHED_PAGES].actor.SetVisible(true);
+        mPages[id%NUMBER_OF_CACHED_PAGES].actor.SetProperty( Actor::Property::VISIBLE,true);
       }
 
       mShadowView.RemoveConstraints();
@@ -914,13 +904,13 @@ void PageTurnView::TurnedOver( Animation& animation )
   mAnimationPageIdPair.erase( animation );
 
   float degree = mPages[index].isTurnBack ? 180.f : 0.f;
-  mPages[index].actor.SetOrientation( Degree(degree), Vector3::YAXIS );
+  mPages[index].actor.SetProperty( Actor::Property::ORIENTATION, Quaternion( Degree(degree), Vector3::YAXIS ) );
   mPages[index].UseEffect( mSpineEffectShader );
 
   int id = pageId + (mPages[index].isTurnBack ? -1 : 1);
   if( id >=0 && id < mTotalPageCount )
   {
-    mPages[id%NUMBER_OF_CACHED_PAGES].actor.SetVisible(false);
+    mPages[id%NUMBER_OF_CACHED_PAGES].actor.SetProperty( Actor::Property::VISIBLE,false);
   }
 
   OnTurnedOver( mPages[index].actor, mPages[index].isTurnBack );
@@ -944,7 +934,7 @@ void PageTurnView::SliddenBack( Animation& animation )
   int id = pageId + (mPages[index].isTurnBack ? -1 : 1);
   if( id >=0 && id < mTotalPageCount )
   {
-    mPages[id%NUMBER_OF_CACHED_PAGES].actor.SetVisible(false);
+    mPages[id%NUMBER_OF_CACHED_PAGES].actor.SetProperty( Actor::Property::VISIBLE,false);
   }
 
   // Guard against destruction during signal emission
@@ -979,7 +969,7 @@ void PageTurnView::StopTurning()
     mPages[ index ].actor.RemoveConstraints();
     mPages[ index ].UseEffect( mSpineEffectShader );
     float degree = mTurningPageIndex==mCurrentPageIndex ? 0.f :180.f;
-    mPages[index].actor.SetOrientation( Degree(degree), Vector3::YAXIS );
+    mPages[index].actor.SetProperty( Actor::Property::ORIENTATION, Quaternion( Degree(degree), Vector3::YAXIS ) );
     mPageUpdated = true;
   }
 
@@ -1054,7 +1044,7 @@ void PageTurnView::SetProperty( BaseObject* object, Property::Index index, const
 
     switch( index )
     {
-      case Toolkit::PageTurnView::Property::PAGE_SIZE:
+      case Toolkit::PageTurnView::Property::VIEW_PAGE_SIZE:
       {
         pageTurnViewImpl.SetPageSize( value.Get<Vector2>() );
         break;
@@ -1085,7 +1075,7 @@ Property::Value PageTurnView::GetProperty( BaseObject* object, Property::Index i
 
     switch( index )
     {
-      case Toolkit::PageTurnView::Property::PAGE_SIZE:
+      case Toolkit::PageTurnView::Property::VIEW_PAGE_SIZE:
       {
         value = pageTurnViewImpl.GetPageSize();
         break;