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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/dali.h>
23 #include <dali-toolkit/public-api/controls/control-impl.h>
24 #include <dali-toolkit/public-api/controls/page-turn-view/page-turn-view.h>
25 #include <dali-toolkit/internal/shader-effects/page-turn-effect-impl.h>
26 #include <dali-toolkit/public-api/shader-effects/page-turn-effect.h>
27 #include <dali-toolkit/public-api/shader-effects/page-turn-book-spine-effect.h>
28 #include <dali-toolkit/public-api/controls/page-turn-view/page-factory.h>
29 #include <dali-toolkit/public-api/controls/shadow-view/shadow-view.h>
40 class PageTurnView : public Control
46 * It initializes the PageTurnView members
48 PageTurnView( PageFactory& pageFactory, const Vector2& pageSize );
51 * A reference counted object may only be deleted by calling Unreference()
53 virtual ~PageTurnView();
58 * @copydoc Toolkit::PageTurnView::SetSpineShadowParameter
60 void SetSpineShadowParameter( const Vector2& spineShadowParameter );
63 * @copydoc Toolkit::PageTurnView::GetSpineShadowParameter
65 Vector2 GetSpineShadowParameter();
68 * @copydoc Toolkit::PageTurnView::GoToPage
70 void GoToPage( unsigned int pageId );
73 * @copydoc Toolkit::PageTurnView::GetCurrentPage
75 unsigned int GetCurrentPage();
78 * @copydoc Toolkit::PageTurnView::EnterEditMode
80 Actor EnterEditMode();
83 * @copydoc Toolkit::PageTurnView::LeaveEditMode
88 * @copydoc Toolkit::PageTurnView::GetHitActor
90 Actor GetHitActor( Vector2& screenCoordinates, Vector2& actorCoordinates );
93 * @copydoc Toolkit::PageTurnView::RefreshAll
98 * @copydoc Toolkit::PageTurnView::RefreshCurrentPage
100 void RefreshCurrentPage();
105 * This method gets a page from the factory and add to the control
106 * to keep NUMBER_OF_CACHED_PAGES_EACH_SIDE pages available in each side
107 * @param[in] pageIndex The index of the page to be added
109 void AddPage( int pageIndex );
112 * This method removes a page from the control
113 * to keep only NUMBER_OF_CACHED_PAGES_EACH_SIDE pages available in each side
114 * @param[in] pageIndex The index of the page to be removed
116 void RemovePage( int pageIndex );
119 * This method updates the actor and animation states after one page is turned over
120 * This method is a callback, connected when receiving the finished signal of a page turning over animation.
121 * @param [in] the page turning over animation handle
123 void TurnedOver( Animation& animation );
126 * This method organize the depth of the pages on stage
127 * It is called when there is page added or removed from the control
129 void OrganizePageDepth();
132 * Set shader Effect to the actor.
133 * If the actor has children, the shader effect is also applied to its first child
134 * @param[in] actor The actor which the shader effect would be applied onto
135 * @param[in] shaderEffect The shader effect to be set to the actor
137 void SetShaderEffect( Actor actor, ShaderEffect shaderEffect );
142 * Set up the render tasks for rendering the page actor to off-screen image
144 void SetupRenderTasks();
147 * Set up the shadow view control to cast shadow
149 void SetupShadowView();
152 * This method defines the processes when the pan started, gets called by OnPan( .. )
153 * @param[in] gesturePosition The current touch position in local page actor coordinates.
155 void PanStarted( const Vector2& gesturePosition );
158 * This method defines the processes when the pan continuing, gets called by OnPan( .. )
159 * @param[in] gesturePosition The current touch position in local page actor coordinates.
161 void PanContinuing( const Vector2& gesturePosition );
164 * This method defines the processes when the pan finished, gets called by OnPanGesture( .. )
165 * @param[in] gesturePosition The current touch position in local page actor coordinates.
166 * @param[in] gestureSpeed The speed of the pan ( in pixels per millisecond )
168 void PanFinished( const Vector2& gesturePosition, float gestureSpeed );
171 * This method updates the actor and the animation states after one page is slidden back instead of turned over
172 * This method is a callback, connected when receiving the finished signal of a page sliding back animation.
173 * @param [in] the page sliding back animation handle
175 void SliddenBack( Animation& animation );
178 * Refresh the given page.
179 @param[in] the page index.
181 void RenderPage( int pageIndex );
183 private: // from Control
186 * @copydoc Toolkit::Control::OnPan
188 virtual void OnPan( PanGesture gesture );
191 * @copydoc Toolkit::Control::OnInitialize
193 virtual void OnInitialize();
196 * @copydoc Toolkit::Control::OnControlStageConncection
198 virtual void OnControlStageConnection();
201 * @copydoc Toolkit::Control::OnControlStageDisConnection
203 virtual void OnControlStageDisconnection();
206 * @copydoc Toolkit::Control::OnControlSizeSet
208 virtual void OnControlSizeSet( const Vector3& size );
210 private: // implemented differently by PageTurnLandscapeView and PageTurnPortraitView
213 * This method is called after the pageTurnView initialization.
214 * To set the size of the control size and the parent origin of turning page layer
215 * Implemented in subclasses to provide specific behaviour.
217 virtual void OnPageTurnViewInitialize() = 0;
220 * Create the page actor from off screen buffer
221 * @param[in] The index of the page to be added
223 virtual ImageActor NewPageFromRenderBuffer( int pageIndex ) = 0;
226 * This method is called after the a new page is added to the stage.
227 * Could be re-implemented in subclasses to provide specific behaviour
228 * @param[in] newPage The added page actor
229 * @param[in] isLeftSide Which side the new page is added to
231 virtual void OnAddPage( ImageActor newPage, bool isLeftSide ) { }
234 * This method is called when pan started or continuing
235 * to calculate the pan position in local page actor coordinate given the pan position in control coordinate
236 * Implemented in subclasses to provide specific behaviour.
237 * @param[in] gesturePosition The pan position in the control coordinate
238 * @return The pan position in the page actor local coordinate
240 virtual Vector2 SetPanPosition( const Vector2& gesturePosition ) = 0;
243 * This method is called when pan started to determined which page is panned given the pan position in control coordinate
244 * Implemented in subclasses to provide specific behaviour.
245 * @param[in] gesturePosition The pan position in the control coordinate
247 virtual void SetPanActor( const Vector2& panPosition ) = 0;
250 * This method is called when a page is turned over or slidden back
251 * Remove PageTurnEffect and use a proper PageTurnBookSpineEffect
252 * Implemented in subclasses to provide specific behaviour.
253 * @param[in] actor The current page actor
254 * @param[in] isLeftSide Which side the current page is located
256 virtual void SetSpineEffect(Actor actor, bool isLeftSide) = 0;
259 * This method is called when pan finished to detect outwards flick
260 * In portrait view, start an animation of turning previous page back when outwards flick is detected
261 * In landscape view, nothing to do
262 * @param[in] panPosition The pan position in the page actor local coordinate
263 * @param[in] gestureSpeed The speed of the pan gesture( in pixels per millisecond )
265 virtual void OnPossibleOutwardsFlick( const Vector2& panPosition, float gestureSpeed ) { }
270 * @copydoc Toolkit::PageTurnView::PageTurnStartedSignal()
272 Toolkit::PageTurnView::PageTurnSignal& PageTurnStartedSignal();
275 * @copydoc Toolkit::PageTurnView::PageTurnFinishedSignal()
277 Toolkit::PageTurnView::PageTurnSignal& PageTurnFinishedSignal();
280 * @copydoc Toolkit::PageTurnView::PagePanStartSignal()
282 Toolkit::PageTurnView::PagePanSignal& PagePanStartedSignal();
285 * @copydoc Toolkit::PageTurnView::PagePanFinishedSignal()
287 Toolkit::PageTurnView::PagePanSignal& PagePanFinishedSignal();
292 PageTurnView( const PageTurnView& );
295 PageTurnView& operator=(const PageTurnView& rhs);
301 Vector2 mControlSize; ///< The size of the control, it is decided by the page size, the SetSize from application can not change it
302 Layer mTurningPageLayer; ///< The layer for the turning page, to avoid possible depth conflict
303 Toolkit::ShadowView mShadowView; ///< The shadow view control for shadow casting
304 ImageActor mShadowPlane; ///< The plane for the shadow to cast on
305 Actor mPointLight; ///< The point light used for shadow casting
306 Layer mShadowLayer; ///< The layer to display the shadow
308 PageFactory& mPageFactory; ///< The page factory which provides the page actors
309 Vector2 mPageSize; ///< The page size
310 int mTotalPageCount; ///< The total number of pages provided by the page factory
312 bool mIsEditMode; ///< The boolean to indicate the current page content is edit-able or not
314 bool mNeedOffscreenRendering; ///< The boolean to indicate whether off screen rendering is required for creating page image
315 std::vector<RenderTask> mOffscreenTask; ///< The vector of off screen rendering tasks
316 std::vector<Actor> mPageSourceActor; ///< The vector of page source actor
317 std::vector<FrameBufferImage> mRenderedPage; ///< The vector of off screen buffers
318 CameraActor mCameraActor; ///< The camera actor attached to the off screen tasks
319 bool mPanning; ///< The boolean to indicate whether the pan gesture is continuing
321 std::vector<Toolkit::PageTurnEffect> mTurnEffect; ///< The group of PageTurnEffects
322 PageTurnBookSpineEffect mSpineEffectFront; ///< The book spine shader effect without flipping image content
323 PageTurnBookSpineEffect mSpineEffectBack; ///< The book spine shader effect with image content flipped
324 Vector2 mSpineShadowParameter; ///< The spine shadow parameter for all the above shader effects
325 Vector2 mOriginalCenter; ///< The original center set to the PageTurnEffect
326 Vector2 mCurrentCenter; ///< The current center set to the PageTurnEffect
328 std::vector<ImageActor> mPageActors; ///< The vector of pages on stage
329 int mCurrentPageIndex; ///< The index of the current page, between 0 ~ mTotalPageCount-1
330 std::map<Actor,bool> mIsTurnBack; ///< The map to keep track the page actor's turning direction
331 std::map<Animation, Actor> mAnimationActorPair; ///< The map to keep track which page actor is the animation act on
332 std::map<Animation, int> mAnimationIndexPair; ///< The map to keep track which PageTurnEffect, PanDisplacementProperty, CurrentCenterProperty is used for the animation
333 int mIndex; ///< The index to keep track which PageTurnEffect, PanDisplacementProperty, CurrentCenterProperty is used for the current panning page
334 std::vector<bool> mIsAnimating; ///< The boolean vector to keep track which PageTurnEffect, PanDisplacementProperty, CurrentCenterProperty is available for using
335 std::vector<bool> mIsSliding; ///< The boolean vector to keep track whether there are animating pages sliding back
337 ImageActor mPanActor; ///< The page being panned by the pan gesture
338 Vector2 mPressDownPosition; ///< The first press down position of the pan gesture
339 bool mPress; ///< The boolean to keep track the state of the pageTurnEffect is activated or not
340 bool mPageUpdated; ///< The boolean to keep track whether is page is updated after any turning activity
342 float mDistanceUpCorner; ///< The distance between the original center of PageTurnEffect and the top-left corner of the page
343 float mDistanceBottomCorner; ///< The distance between the original center of PageTurnEffect and the bottom-left corner of the page
345 std::vector<Property::Index> mPropertyPanDisplacement; ///< The pan displacement property group
346 std::vector<Property::Index> mPropertyCurrentCenter; ///< The current center property group
347 float mPanDisplacement; ///< The displacement of the pan after the constrains are applied
348 bool mConstraints; ///< The boolean to keep track the constrains are applied or not
350 Toolkit::PageTurnView::PageTurnSignal mPageTurnStartedSignal; ///< The signal to notify that a page has started turning
351 Toolkit::PageTurnView::PageTurnSignal mPageTurnFinishedSignal; ///< The signal to notify that a page has finished turning
352 Toolkit::PageTurnView::PagePanSignal mPagePanStartedSignal; ///< The signal to notify that a page has started panning
353 Toolkit::PageTurnView::PagePanSignal mPagePanFinishedSignal; ///< The signal to notify that a page has finished panning
355 static const int MAXIMUM_TURNING_NUM; ///< How many pages are allowed to animating in the same time
356 static const int NUMBER_OF_CACHED_PAGES_EACH_SIDE; ///< The maximum number of pages kept, (MAXIMUM_ANIMATION_NUM+1) pages for each side
357 static const int NUMBER_OF_CACHED_PAGES; ///< The maximum number of pages kept, (MAXIMUM_ANIMATION_NUM+1)*2 pages in total
358 static const float STATIC_PAGE_INTERVAL_DISTANCE; ///< The depth interval between stacked pages (static pages)
361 } // namespace Internal
364 // Helpers for public-api forwarding methods
366 inline Toolkit::Internal::PageTurnView& GetImplementation(Toolkit::PageTurnView& pub)
368 DALI_ASSERT_ALWAYS(pub);
370 Dali::RefObject& handle = pub.GetImplementation();
372 return static_cast<Toolkit::Internal::PageTurnView&>(handle);
375 inline const Toolkit::Internal::PageTurnView& GetImplementation(const Toolkit::PageTurnView& pub)
377 DALI_ASSERT_ALWAYS(pub);
379 const Dali::RefObject& handle = pub.GetImplementation();
381 return static_cast<const Toolkit::Internal::PageTurnView&>(handle);
384 } // namespace Toolkit
387 #endif /* __DALI_TOOLKIT_INTERNAL_PAGE_TURN_VIEW_IMPL_H__ */