Changed ShadowView to use new custom effects and ImageView.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / page-turn-view / page-turn-view-impl.h
index 1354c19..5be63cf 100644 (file)
@@ -1,31 +1,35 @@
 #ifndef __DALI_TOOLKIT_INTERNAL_PAGE_TURN_VIEW_IMPL_H__
 #define __DALI_TOOLKIT_INTERNAL_PAGE_TURN_VIEW_IMPL_H__
 
-//
-// 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.
-//
+/*
+ * 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.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/devel-api/common/map-wrapper.h>
+#include <dali/public-api/actors/layer.h>
+#include <dali/public-api/actors/camera-actor.h>
+#include <dali/public-api/images/frame-buffer-image.h>
+#include <dali/public-api/render-tasks/render-task.h>
 
 // INTERNAL INCLUDES
-#include <dali/dali.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
 #include <dali-toolkit/public-api/controls/page-turn-view/page-turn-view.h>
-#include <dali-toolkit/internal/shader-effects/page-turn-effect-impl.h>
-#include <dali-toolkit/public-api/shader-effects/page-turn-effect.h>
-#include <dali-toolkit/public-api/shader-effects/page-turn-book-spine-effect.h>
 #include <dali-toolkit/public-api/controls/page-turn-view/page-factory.h>
-#include <dali-toolkit/public-api/controls/shadow-view/shadow-view.h>
+#include <dali-toolkit/devel-api/controls/shadow-view/shadow-view.h>
 
 namespace Dali
 {
@@ -36,7 +40,7 @@ namespace Toolkit
 namespace Internal
 {
 
-class PageTurnView : public ControlImpl
+class PageTurnView : public Control
 {
 protected:
 
@@ -54,49 +58,42 @@ protected:
 public:
 
   /**
-   * @copydoc Toolkit::PageTurnView::SetSpineShadowParameter
+   * Set the page size
+   * @param[in] pageSize The size of pages
    */
-  void SetSpineShadowParameter( const Vector2& spineShadowParameter );
-
-  /**
-   * @copydoc Toolkit::PageTurnView::GetSpineShadowParameter
-   */
-  Vector2 GetSpineShadowParameter();
-
-  /**
-   * @copydoc Toolkit::PageTurnView::GoToPage
-   */
-  void GoToPage( unsigned int pageId );
-
-  /**
-   * @copydoc Toolkit::PageTurnView::GetCurrentPage
-   */
-  unsigned int GetCurrentPage();
+  void SetPageSize( const Vector2& pageSize );
 
   /**
-   * @copydoc Toolkit::PageTurnView::EnterEditMode
+   * Retrieve the page size.
+   * @return The page size.
    */
-  Actor EnterEditMode();
+  Vector2 GetPageSize();
 
   /**
-   * @copydoc Toolkit::PageTurnView::LeaveEditMode
+   * Set the spine shadow parameter to the shader effects.
+   * The two parameters are the major&minor radius (in pixels) to form an ellipse shape.
+   * The top-left quarter of this ellipse is used to calculate spine normal for simulating shadow.
+   * @param [in] spineShadowParameter The major&minor ellipse radius for the simulated spine shadow.
    */
-  void LeaveEditMode();
+  void SetSpineShadowParameter( const Vector2& spineShadowParameter );
 
   /**
-   * @copydoc Toolkit::PageTurnView::GetHitActor
+   * Retrieve the spine shadow parameter of the shader effects.
+   * @return The spine shadow parameter.
    */
-  Actor GetHitActor( Vector2& screenCoordinates, Vector2& actorCoordinates );
+  Vector2 GetSpineShadowParameter();
 
-  /**
-   * @copydoc Toolkit::PageTurnView::RefreshAll
+  /*
+   * Jump to a given page.
+   * @param[in] pageId The new current page id.
    */
-  void RefreshAll();
+  void GoToPage( unsigned int pageId );
 
   /**
-   * @copydoc Toolkit::PageTurnView::RefreshCurrentPage
+   * Retrieve the id of the current Page.
+   * @return The current page id.
    */
-  void RefreshCurrentPage();
+  unsigned int GetCurrentPage();
 
 protected:
 
@@ -133,15 +130,10 @@ protected:
    * @param[in] actor The actor which the shader effect would be applied onto
    * @param[in] shaderEffect The shader effect to be set to the actor
    */
-  void SetShaderEffect( Actor actor, ShaderEffect shaderEffect );
+  void SetShaderEffect( ImageActor actor, ShaderEffect shaderEffect );
 
 private:
 
-  /**
-   * Set up the render tasks for rendering the page actor to off-screen image
-   */
-  void SetupRenderTasks();
-
  /**
   * Set up the shadow view control to cast shadow
   */
@@ -173,18 +165,13 @@ private:
    */
   void SliddenBack( Animation& animation );
 
-  /**
-   * Refresh the given page.
-   @param[in] the page index.
-   */
-  void RenderPage( int pageIndex );
 
-private: // from ControlImpl
+private: // from Control
 
   /**
    * @copydoc Toolkit::Control::OnPan
    */
-  virtual void OnPan( PanGesture gesture );
+  virtual void OnPan( const PanGesture& gesture );
 
   /**
    * @copydoc Toolkit::Control::OnInitialize
@@ -192,19 +179,14 @@ private: // from ControlImpl
   virtual void OnInitialize();
 
   /**
-   * @copydoc Toolkit::Control::OnControlStageConncection
-   */
-  virtual void OnControlStageConnection();
-
-  /**
-   * @copydoc Toolkit::Control::OnControlStageDisConnection
+   * @copydoc CustomActorImpl::OnStageConnection()
    */
-  virtual void OnControlStageDisconnection();
+  virtual void OnStageConnection( int depth );
 
   /**
-   * @copydoc Toolkit::Control::OnControlSizeSet
+   * @copydoc CustomActorImpl::OnStageDisconnection()
    */
-  virtual void OnControlSizeSet( const Vector3& size );
+  virtual void OnStageDisconnection();
 
 private: // implemented differently by PageTurnLandscapeView and PageTurnPortraitView
 
@@ -216,12 +198,6 @@ private: // implemented differently by PageTurnLandscapeView and PageTurnPortrai
   virtual void OnPageTurnViewInitialize() = 0;
 
   /**
-   * Create the page actor from off screen buffer
-   * @param[in] The index of the page to be added
-   */
-  virtual ImageActor NewPageFromRenderBuffer( int pageIndex ) = 0;
-
-  /**
    * This method is called after the a new page is added to the stage.
    * Could be re-implemented in subclasses to provide specific behaviour
    * @param[in] newPage The added page actor
@@ -252,7 +228,7 @@ private: // implemented differently by PageTurnLandscapeView and PageTurnPortrai
    * @param[in] actor The current page actor
    * @param[in] isLeftSide Which side the current page is located
    */
-  virtual void SetSpineEffect(Actor actor, bool isLeftSide) = 0;
+  virtual void SetSpineEffect(ImageActor actor, bool isLeftSide) = 0;
 
   /**
    * This method is called when pan finished to detect outwards flick
@@ -263,7 +239,15 @@ private: // implemented differently by PageTurnLandscapeView and PageTurnPortrai
    */
   virtual void OnPossibleOutwardsFlick( const Vector2& panPosition, float gestureSpeed ) { }
 
-public: //signal
+  /**
+   * This method is called when page is turned over
+   * In portrait view, the page on the left side is not rendered
+   * @param[in] actor The page actor
+   * @param[in] isLeftSide Which side the page is turned to
+   */
+  virtual void OnTurnedOver( ImageActor actor, bool isLeftSide ) { }
+
+public: //signal and property
 
   /**
    * @copydoc Toolkit::PageTurnView::PageTurnStartedSignal()
@@ -285,6 +269,35 @@ public: //signal
    */
   Toolkit::PageTurnView::PagePanSignal& PagePanFinishedSignal();
 
+  /**
+    * Connects a callback function with the object's signals.
+    * @param[in] object The object providing the signal.
+    * @param[in] tracker Used to disconnect the signal.
+    * @param[in] signalName The signal to connect to.
+    * @param[in] functor A newly allocated FunctorDelegate.
+    * @return True if the signal was connected.
+    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
+    */
+  static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
+
+   // Properties
+
+  /**
+   * Called when a property of an object of this type is set.
+   * @param[in] object The object whose property is set.
+   * @param[in] index The property index.
+   * @param[in] value The new property value.
+   */
+  static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
+
+  /**
+   * Called to retrieve a property of an object of this type.
+   * @param[in] object The object whose property is to be retrieved.
+   * @param[in] index The property index.
+   * @return The current value of the property.
+   */
+  static Property::Value GetProperty( BaseObject* object, Property::Index index );
+
 private:
 
   //Undefined
@@ -295,39 +308,30 @@ private:
 
 protected:
 
-  Actor                          mRootOnScreen;
-
   Vector2                        mControlSize;             ///< The size of the control, it is decided by the page size, the SetSize from application can not change it
   Layer                          mTurningPageLayer;        ///< The layer for the turning page, to avoid possible depth conflict
   Toolkit::ShadowView            mShadowView;              ///< The shadow view control for shadow casting
-  ImageActor                     mShadowPlane;             ///< The plane for the shadow to cast on
+  Actor                          mShadowPlaneBackground;   ///< The plane for the shadow to cast on
   Actor                          mPointLight;              ///< The point light used for shadow casting
-  Layer                          mShadowLayer;             ///< The layer to display the shadow
 
   PageFactory&                   mPageFactory;             ///< The page factory which provides the page actors
   Vector2                        mPageSize;                ///< The page size
   int                            mTotalPageCount;          ///< The total number of pages provided by the page factory
 
-  bool                           mIsEditMode;              ///< The boolean to indicate the current page content is edit-able or not
-
-  bool                           mNeedOffscreenRendering;  ///< The boolean to indicate whether off screen rendering is required for creating page image
-  std::vector<RenderTask>        mOffscreenTask;           ///< The vector of off screen rendering tasks
-  std::vector<Actor>             mPageSourceActor;         ///< The vector of page source actor
-  std::vector<FrameBufferImage>  mRenderedPage;            ///< The vector of off screen buffers
-  CameraActor                    mCameraActor;             ///< The camera actor attached to the off screen tasks
   bool                           mPanning;                 ///< The boolean to indicate whether the pan gesture is continuing
 
-  std::vector<Toolkit::PageTurnEffect>    mTurnEffect;     ///< The group of PageTurnEffects
-  PageTurnBookSpineEffect        mSpineEffectFront;        ///< The book spine shader effect without flipping image content
-  PageTurnBookSpineEffect        mSpineEffectBack;         ///< The book spine shader effect with image content flipped
+  std::vector<ShaderEffect>      mTurnEffect;              ///< The group of PageTurnEffects
+  ShaderEffect                   mSpineEffectFront;        ///< The book spine shader effect without flipping image content
+  ShaderEffect                   mSpineEffectBack;         ///< The book spine shader effect with image content flipped
   Vector2                        mSpineShadowParameter;    ///< The spine shadow parameter for all the above shader effects
   Vector2                        mOriginalCenter;          ///< The original center set to the PageTurnEffect
   Vector2                        mCurrentCenter;           ///< The current center set to the PageTurnEffect
 
   std::vector<ImageActor>        mPageActors;              ///< The vector of pages on stage
   int                            mCurrentPageIndex;        ///< The index of the current page, between 0 ~ mTotalPageCount-1
-  std::map<Actor,bool>           mIsTurnBack;              ///< The map to keep track the page actor's turning direction
-  std::map<Animation, Actor>     mAnimationActorPair;      ///< The map to keep track which page actor is the animation act on
+  int                            mTurningPageIndex;        ///< The index of the turning page
+  std::map<ImageActor,bool>      mIsTurnBack;              ///< The map to keep track the page actor's turning direction
+  std::map<Animation,int>        mAnimationPageIdPair;     ///< The map to keep track which page actor is the animation act on
   std::map<Animation, int>       mAnimationIndexPair;      ///< The map to keep track which PageTurnEffect, PanDisplacementProperty, CurrentCenterProperty is used for the animation
   int                            mIndex;                   ///< The index to keep track which PageTurnEffect, PanDisplacementProperty, CurrentCenterProperty is used for the current panning page
   std::vector<bool>              mIsAnimating;             ///< The boolean vector to keep track which PageTurnEffect, PanDisplacementProperty, CurrentCenterProperty is available for using