1 #ifndef __DALI_TOOLKIT_INTERNAL_PAGE_TURN_VIEW_IMPL_H__
2 #define __DALI_TOOLKIT_INTERNAL_PAGE_TURN_VIEW_IMPL_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://floralicense.org/license/
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
21 #include <dali/dali.h>
22 #include <dali-toolkit/public-api/controls/control-impl.h>
23 #include <dali-toolkit/public-api/controls/page-turn-view/page-turn-view.h>
24 #include <dali-toolkit/internal/shader-effects/page-turn-effect-impl.h>
25 #include <dali-toolkit/public-api/shader-effects/page-turn-effect.h>
26 #include <dali-toolkit/public-api/shader-effects/page-turn-book-spine-effect.h>
27 #include <dali-toolkit/public-api/controls/page-turn-view/page-factory.h>
28 #include <dali-toolkit/public-api/controls/shadow-view/shadow-view.h>
39 class PageTurnView : public ControlImpl
45 * It initializes the PageTurnView members
47 PageTurnView( PageFactory& pageFactory, const Vector2& pageSize );
50 * A reference counted object may only be deleted by calling Unreference()
52 virtual ~PageTurnView();
57 * @copydoc Toolkit::PageTurnView::SetSpineShadowParameter
59 void SetSpineShadowParameter( const Vector2& spineShadowParameter );
62 * @copydoc Toolkit::PageTurnView::GetSpineShadowParameter
64 Vector2 GetSpineShadowParameter();
67 * @copydoc Toolkit::PageTurnView::GoToPage
69 void GoToPage( unsigned int pageId );
72 * @copydoc Toolkit::PageTurnView::GetCurrentPage
74 unsigned int GetCurrentPage();
77 * @copydoc Toolkit::PageTurnView::EnterEditMode
79 Actor EnterEditMode();
82 * @copydoc Toolkit::PageTurnView::LeaveEditMode
87 * @copydoc Toolkit::PageTurnView::GetHitActor
89 Actor GetHitActor( Vector2& screenCoordinates, Vector2& actorCoordinates );
92 * @copydoc Toolkit::PageTurnView::RefreshAll
97 * @copydoc Toolkit::PageTurnView::RefreshCurrentPage
99 void RefreshCurrentPage();
104 * This method gets a page from the factory and add to the control
105 * to keep NUMBER_OF_CACHED_PAGES_EACH_SIDE pages available in each side
106 * @param[in] pageIndex The index of the page to be added
108 void AddPage( int pageIndex );
111 * This method removes a page from the control
112 * to keep only NUMBER_OF_CACHED_PAGES_EACH_SIDE pages available in each side
113 * @param[in] pageIndex The index of the page to be removed
115 void RemovePage( int pageIndex );
118 * This method updates the actor and animation states after one page is turned over
119 * This method is a callback, connected when receiving the finished signal of a page turning over animation.
120 * @param [in] the page turning over animation handle
122 void TurnedOver( Animation& animation );
125 * This method organize the depth of the pages on stage
126 * It is called when there is page added or removed from the control
128 void OrganizePageDepth();
131 * Set shader Effect to the actor.
132 * If the actor has children, the shader effect is also applied to its first child
133 * @param[in] actor The actor which the shader effect would be applied onto
134 * @param[in] shaderEffect The shader effect to be set to the actor
136 void SetShaderEffect( Actor actor, ShaderEffect shaderEffect );
141 * Set up the render tasks for rendering the page actor to off-screen image
143 void SetupRenderTasks();
146 * Set up the shadow view control to cast shadow
148 void SetupShadowView();
151 * This method defines the processes when the pan started, gets called by OnPan( .. )
152 * @param[in] gesturePosition The current touch position in local page actor coordinates.
154 void PanStarted( const Vector2& gesturePosition );
157 * This method defines the processes when the pan continuing, gets called by OnPan( .. )
158 * @param[in] gesturePosition The current touch position in local page actor coordinates.
160 void PanContinuing( const Vector2& gesturePosition );
163 * This method defines the processes when the pan finished, gets called by OnPanGesture( .. )
164 * @param[in] gesturePosition The current touch position in local page actor coordinates.
165 * @param[in] gestureSpeed The speed of the pan ( in pixels per millisecond )
167 void PanFinished( const Vector2& gesturePosition, float gestureSpeed );
170 * This method updates the actor and the animation states after one page is slidden back instead of turned over
171 * This method is a callback, connected when receiving the finished signal of a page sliding back animation.
172 * @param [in] the page sliding back animation handle
174 void SliddenBack( Animation& animation );
177 * Refresh the given page.
178 @param[in] the page index.
180 void RenderPage( int pageIndex );
182 private: // from ControlImpl
185 * @copydoc Toolkit::Control::OnPan
187 virtual void OnPan( PanGesture gesture );
190 * @copydoc Toolkit::Control::OnInitialize
192 virtual void OnInitialize();
195 * @copydoc Toolkit::Control::OnControlStageConncection
197 virtual void OnControlStageConnection();
200 * @copydoc Toolkit::Control::OnControlStageDisConnection
202 virtual void OnControlStageDisconnection();
205 * @copydoc Toolkit::Control::OnControlSizeSet
207 virtual void OnControlSizeSet( const Vector3& size );
209 private: // implemented differently by PageTurnLandscapeView and PageTurnPortraitView
212 * This method is called after the pageTurnView initialization.
213 * To set the size of the control size and the parent origin of turning page layer
214 * Implemented in subclasses to provide specific behaviour.
216 virtual void OnPageTurnViewInitialize() = 0;
219 * Create the page actor from off screen buffer
220 * @param[in] The index of the page to be added
222 virtual ImageActor NewPageFromRenderBuffer( int pageIndex ) = 0;
225 * This method is called after the a new page is added to the stage.
226 * Could be re-implemented in subclasses to provide specific behaviour
227 * @param[in] newPage The added page actor
228 * @param[in] isLeftSide Which side the new page is added to
230 virtual void OnAddPage( ImageActor newPage, bool isLeftSide ) { }
233 * This method is called when pan started or continuing
234 * to calculate the pan position in local page actor coordinate given the pan position in control coordinate
235 * Implemented in subclasses to provide specific behaviour.
236 * @param[in] gesturePosition The pan position in the control coordinate
237 * @return The pan position in the page actor local coordinate
239 virtual Vector2 SetPanPosition( const Vector2& gesturePosition ) = 0;
242 * This method is called when pan started to determined which page is panned given the pan position in control coordinate
243 * Implemented in subclasses to provide specific behaviour.
244 * @param[in] gesturePosition The pan position in the control coordinate
246 virtual void SetPanActor( const Vector2& panPosition ) = 0;
249 * This method is called when a page is turned over or slidden back
250 * Remove PageTurnEffect and use a proper PageTurnBookSpineEffect
251 * Implemented in subclasses to provide specific behaviour.
252 * @param[in] actor The current page actor
253 * @param[in] isLeftSide Which side the current page is located
255 virtual void SetSpineEffect(Actor actor, bool isLeftSide) = 0;
258 * This method is called when pan finished to detect outwards flick
259 * In portrait view, start an animation of turning previous page back when outwards flick is detected
260 * In landscape view, nothing to do
261 * @param[in] panPosition The pan position in the page actor local coordinate
262 * @param[in] gestureSpeed The speed of the pan gesture( in pixels per millisecond )
264 virtual void OnPossibleOutwardsFlick( const Vector2& panPosition, float gestureSpeed ) { }
269 * @copydoc Toolkit::PageTurnView::PageTurnStartedSignal()
271 Toolkit::PageTurnView::PageTurnSignal& PageTurnStartedSignal();
274 * @copydoc Toolkit::PageTurnView::PageTurnFinishedSignal()
276 Toolkit::PageTurnView::PageTurnSignal& PageTurnFinishedSignal();
279 * @copydoc Toolkit::PageTurnView::PagePanStartSignal()
281 Toolkit::PageTurnView::PagePanSignal& PagePanStartedSignal();
284 * @copydoc Toolkit::PageTurnView::PagePanFinishedSignal()
286 Toolkit::PageTurnView::PagePanSignal& PagePanFinishedSignal();
291 PageTurnView( const PageTurnView& );
294 PageTurnView& operator=(const PageTurnView& rhs);
300 Vector2 mControlSize; ///< The size of the control, it is decided by the page size, the SetSize from application can not change it
301 Layer mTurningPageLayer; ///< The layer for the turning page, to avoid possible depth conflict
302 Toolkit::ShadowView mShadowView; ///< The shadow view control for shadow casting
303 ImageActor mShadowPlane; ///< The plane for the shadow to cast on
304 Actor mPointLight; ///< The point light used for shadow casting
305 Layer mShadowLayer; ///< The layer to display the shadow
307 PageFactory& mPageFactory; ///< The page factory which provides the page actors
308 Vector2 mPageSize; ///< The page size
309 int mTotalPageCount; ///< The total number of pages provided by the page factory
311 bool mIsEditMode; ///< The boolean to indicate the current page content is edit-able or not
313 bool mNeedOffscreenRendering; ///< The boolean to indicate whether off screen rendering is required for creating page image
314 std::vector<RenderTask> mOffscreenTask; ///< The vector of off screen rendering tasks
315 std::vector<Actor> mPageSourceActor; ///< The vector of page source actor
316 std::vector<FrameBufferImage> mRenderedPage; ///< The vector of off screen buffers
317 CameraActor mCameraActor; ///< The camera actor attached to the off screen tasks
318 bool mPanning; ///< The boolean to indicate whether the pan gesture is continuing
320 std::vector<Toolkit::PageTurnEffect> mTurnEffect; ///< The group of PageTurnEffects
321 PageTurnBookSpineEffect mSpineEffectFront; ///< The book spine shader effect without flipping image content
322 PageTurnBookSpineEffect mSpineEffectBack; ///< The book spine shader effect with image content flipped
323 Vector2 mSpineShadowParameter; ///< The spine shadow parameter for all the above shader effects
324 Vector2 mOriginalCenter; ///< The original center set to the PageTurnEffect
325 Vector2 mCurrentCenter; ///< The current center set to the PageTurnEffect
327 std::vector<ImageActor> mPageActors; ///< The vector of pages on stage
328 int mCurrentPageIndex; ///< The index of the current page, between 0 ~ mTotalPageCount-1
329 std::map<Actor,bool> mIsTurnBack; ///< The map to keep track the page actor's turning direction
330 std::map<Animation, Actor> mAnimationActorPair; ///< The map to keep track which page actor is the animation act on
331 std::map<Animation, int> mAnimationIndexPair; ///< The map to keep track which PageTurnEffect, PanDisplacementProperty, CurrentCenterProperty is used for the animation
332 int mIndex; ///< The index to keep track which PageTurnEffect, PanDisplacementProperty, CurrentCenterProperty is used for the current panning page
333 std::vector<bool> mIsAnimating; ///< The boolean vector to keep track which PageTurnEffect, PanDisplacementProperty, CurrentCenterProperty is available for using
334 std::vector<bool> mIsSliding; ///< The boolean vector to keep track whether there are animating pages sliding back
336 ImageActor mPanActor; ///< The page being panned by the pan gesture
337 Vector2 mPressDownPosition; ///< The first press down position of the pan gesture
338 bool mPress; ///< The boolean to keep track the state of the pageTurnEffect is activated or not
339 bool mPageUpdated; ///< The boolean to keep track whether is page is updated after any turning activity
341 float mDistanceUpCorner; ///< The distance between the original center of PageTurnEffect and the top-left corner of the page
342 float mDistanceBottomCorner; ///< The distance between the original center of PageTurnEffect and the bottom-left corner of the page
344 std::vector<Property::Index> mPropertyPanDisplacement; ///< The pan displacement property group
345 std::vector<Property::Index> mPropertyCurrentCenter; ///< The current center property group
346 float mPanDisplacement; ///< The displacement of the pan after the constrains are applied
347 bool mConstraints; ///< The boolean to keep track the constrains are applied or not
349 Toolkit::PageTurnView::PageTurnSignal mPageTurnStartedSignal; ///< The signal to notify that a page has started turning
350 Toolkit::PageTurnView::PageTurnSignal mPageTurnFinishedSignal; ///< The signal to notify that a page has finished turning
351 Toolkit::PageTurnView::PagePanSignal mPagePanStartedSignal; ///< The signal to notify that a page has started panning
352 Toolkit::PageTurnView::PagePanSignal mPagePanFinishedSignal; ///< The signal to notify that a page has finished panning
354 static const int MAXIMUM_TURNING_NUM; ///< How many pages are allowed to animating in the same time
355 static const int NUMBER_OF_CACHED_PAGES_EACH_SIDE; ///< The maximum number of pages kept, (MAXIMUM_ANIMATION_NUM+1) pages for each side
356 static const int NUMBER_OF_CACHED_PAGES; ///< The maximum number of pages kept, (MAXIMUM_ANIMATION_NUM+1)*2 pages in total
357 static const float STATIC_PAGE_INTERVAL_DISTANCE; ///< The depth interval between stacked pages (static pages)
360 } // namespace Internal
363 // Helpers for public-api forwarding methods
365 inline Toolkit::Internal::PageTurnView& GetImplementation(Toolkit::PageTurnView& pub)
367 DALI_ASSERT_ALWAYS(pub);
369 Dali::RefObject& handle = pub.GetImplementation();
371 return static_cast<Toolkit::Internal::PageTurnView&>(handle);
374 inline const Toolkit::Internal::PageTurnView& GetImplementation(const Toolkit::PageTurnView& pub)
376 DALI_ASSERT_ALWAYS(pub);
378 const Dali::RefObject& handle = pub.GetImplementation();
380 return static_cast<const Toolkit::Internal::PageTurnView&>(handle);
383 } // namespace Toolkit
386 #endif /* __DALI_TOOLKIT_INTERNAL_PAGE_TURN_VIEW_IMPL_H__ */