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/public-api/actors/layer.h>
23 #include <dali/public-api/actors/camera-actor.h>
24 #include <dali/public-api/common/map-wrapper.h>
25 #include <dali/public-api/images/frame-buffer-image.h>
26 #include <dali/public-api/render-tasks/render-task.h>
29 #include <dali-toolkit/public-api/controls/control-impl.h>
30 #include <dali-toolkit/public-api/controls/page-turn-view/page-turn-view.h>
31 #include <dali-toolkit/internal/shader-effects/page-turn-effect-impl.h>
32 #include <dali-toolkit/public-api/shader-effects/page-turn-effect.h>
33 #include <dali-toolkit/public-api/shader-effects/page-turn-book-spine-effect.h>
34 #include <dali-toolkit/public-api/controls/page-turn-view/page-factory.h>
35 #include <dali-toolkit/public-api/controls/shadow-view/shadow-view.h>
46 class PageTurnView : public Control
52 * It initializes the PageTurnView members
54 PageTurnView( PageFactory& pageFactory, const Vector2& pageSize );
57 * A reference counted object may only be deleted by calling Unreference()
59 virtual ~PageTurnView();
64 * @copydoc Toolkit::PageTurnView::SetSpineShadowParameter
66 void SetSpineShadowParameter( const Vector2& spineShadowParameter );
69 * @copydoc Toolkit::PageTurnView::GetSpineShadowParameter
71 Vector2 GetSpineShadowParameter();
74 * @copydoc Toolkit::PageTurnView::GoToPage
76 void GoToPage( unsigned int pageId );
79 * @copydoc Toolkit::PageTurnView::GetCurrentPage
81 unsigned int GetCurrentPage();
84 * @copydoc Toolkit::PageTurnView::EnterEditMode
86 Actor EnterEditMode();
89 * @copydoc Toolkit::PageTurnView::LeaveEditMode
94 * @copydoc Toolkit::PageTurnView::GetHitActor
96 Actor GetHitActor( Vector2& screenCoordinates, Vector2& actorCoordinates );
99 * @copydoc Toolkit::PageTurnView::RefreshAll
104 * @copydoc Toolkit::PageTurnView::RefreshCurrentPage
106 void RefreshCurrentPage();
111 * This method gets a page from the factory and add to the control
112 * to keep NUMBER_OF_CACHED_PAGES_EACH_SIDE pages available in each side
113 * @param[in] pageIndex The index of the page to be added
115 void AddPage( int pageIndex );
118 * This method removes a page from the control
119 * to keep only NUMBER_OF_CACHED_PAGES_EACH_SIDE pages available in each side
120 * @param[in] pageIndex The index of the page to be removed
122 void RemovePage( int pageIndex );
125 * This method updates the actor and animation states after one page is turned over
126 * This method is a callback, connected when receiving the finished signal of a page turning over animation.
127 * @param [in] the page turning over animation handle
129 void TurnedOver( Animation& animation );
132 * This method organize the depth of the pages on stage
133 * It is called when there is page added or removed from the control
135 void OrganizePageDepth();
138 * Set shader Effect to the actor.
139 * If the actor has children, the shader effect is also applied to its first child
140 * @param[in] actor The actor which the shader effect would be applied onto
141 * @param[in] shaderEffect The shader effect to be set to the actor
143 void SetShaderEffect( ImageActor actor, ShaderEffect shaderEffect );
148 * Set up the render tasks for rendering the page actor to off-screen image
150 void SetupRenderTasks();
153 * Set up the shadow view control to cast shadow
155 void SetupShadowView();
158 * This method defines the processes when the pan started, gets called by OnPan( .. )
159 * @param[in] gesturePosition The current touch position in local page actor coordinates.
161 void PanStarted( const Vector2& gesturePosition );
164 * This method defines the processes when the pan continuing, gets called by OnPan( .. )
165 * @param[in] gesturePosition The current touch position in local page actor coordinates.
167 void PanContinuing( const Vector2& gesturePosition );
170 * This method defines the processes when the pan finished, gets called by OnPanGesture( .. )
171 * @param[in] gesturePosition The current touch position in local page actor coordinates.
172 * @param[in] gestureSpeed The speed of the pan ( in pixels per millisecond )
174 void PanFinished( const Vector2& gesturePosition, float gestureSpeed );
177 * This method updates the actor and the animation states after one page is slidden back instead of turned over
178 * This method is a callback, connected when receiving the finished signal of a page sliding back animation.
179 * @param [in] the page sliding back animation handle
181 void SliddenBack( Animation& animation );
184 * Refresh the given page.
185 @param[in] the page index.
187 void RenderPage( int pageIndex );
189 private: // from Control
192 * @copydoc Toolkit::Control::OnPan
194 virtual void OnPan( const PanGesture& gesture );
197 * @copydoc Toolkit::Control::OnInitialize
199 virtual void OnInitialize();
202 * @copydoc Toolkit::Control::OnControlStageConncection
204 virtual void OnControlStageConnection();
207 * @copydoc Toolkit::Control::OnControlStageDisConnection
209 virtual void OnControlStageDisconnection();
212 * @copydoc Toolkit::Control::OnControlSizeSet
214 virtual void OnControlSizeSet( const Vector3& size );
216 private: // implemented differently by PageTurnLandscapeView and PageTurnPortraitView
219 * This method is called after the pageTurnView initialization.
220 * To set the size of the control size and the parent origin of turning page layer
221 * Implemented in subclasses to provide specific behaviour.
223 virtual void OnPageTurnViewInitialize() = 0;
226 * Create the page actor from off screen buffer
227 * @param[in] The index of the page to be added
229 virtual ImageActor NewPageFromRenderBuffer( int pageIndex ) = 0;
232 * This method is called after the a new page is added to the stage.
233 * Could be re-implemented in subclasses to provide specific behaviour
234 * @param[in] newPage The added page actor
235 * @param[in] isLeftSide Which side the new page is added to
237 virtual void OnAddPage( ImageActor newPage, bool isLeftSide ) { }
240 * This method is called when pan started or continuing
241 * to calculate the pan position in local page actor coordinate given the pan position in control coordinate
242 * Implemented in subclasses to provide specific behaviour.
243 * @param[in] gesturePosition The pan position in the control coordinate
244 * @return The pan position in the page actor local coordinate
246 virtual Vector2 SetPanPosition( const Vector2& gesturePosition ) = 0;
249 * This method is called when pan started to determined which page is panned given the pan position in control coordinate
250 * Implemented in subclasses to provide specific behaviour.
251 * @param[in] gesturePosition The pan position in the control coordinate
253 virtual void SetPanActor( const Vector2& panPosition ) = 0;
256 * This method is called when a page is turned over or slidden back
257 * Remove PageTurnEffect and use a proper PageTurnBookSpineEffect
258 * Implemented in subclasses to provide specific behaviour.
259 * @param[in] actor The current page actor
260 * @param[in] isLeftSide Which side the current page is located
262 virtual void SetSpineEffect(ImageActor actor, bool isLeftSide) = 0;
265 * This method is called when pan finished to detect outwards flick
266 * In portrait view, start an animation of turning previous page back when outwards flick is detected
267 * In landscape view, nothing to do
268 * @param[in] panPosition The pan position in the page actor local coordinate
269 * @param[in] gestureSpeed The speed of the pan gesture( in pixels per millisecond )
271 virtual void OnPossibleOutwardsFlick( const Vector2& panPosition, float gestureSpeed ) { }
276 * @copydoc Toolkit::PageTurnView::PageTurnStartedSignal()
278 Toolkit::PageTurnView::PageTurnSignal& PageTurnStartedSignal();
281 * @copydoc Toolkit::PageTurnView::PageTurnFinishedSignal()
283 Toolkit::PageTurnView::PageTurnSignal& PageTurnFinishedSignal();
286 * @copydoc Toolkit::PageTurnView::PagePanStartSignal()
288 Toolkit::PageTurnView::PagePanSignal& PagePanStartedSignal();
291 * @copydoc Toolkit::PageTurnView::PagePanFinishedSignal()
293 Toolkit::PageTurnView::PagePanSignal& PagePanFinishedSignal();
298 PageTurnView( const PageTurnView& );
301 PageTurnView& operator=(const PageTurnView& rhs);
307 Vector2 mControlSize; ///< The size of the control, it is decided by the page size, the SetSize from application can not change it
308 Layer mTurningPageLayer; ///< The layer for the turning page, to avoid possible depth conflict
309 Toolkit::ShadowView mShadowView; ///< The shadow view control for shadow casting
310 ImageActor mShadowPlane; ///< The plane for the shadow to cast on
311 Actor mPointLight; ///< The point light used for shadow casting
312 Layer mShadowLayer; ///< The layer to display the shadow
314 PageFactory& mPageFactory; ///< The page factory which provides the page actors
315 Vector2 mPageSize; ///< The page size
316 int mTotalPageCount; ///< The total number of pages provided by the page factory
318 bool mIsEditMode; ///< The boolean to indicate the current page content is edit-able or not
320 bool mNeedOffscreenRendering; ///< The boolean to indicate whether off screen rendering is required for creating page image
321 std::vector<RenderTask> mOffscreenTask; ///< The vector of off screen rendering tasks
322 std::vector<Actor> mPageSourceActor; ///< The vector of page source actor
323 std::vector<FrameBufferImage> mRenderedPage; ///< The vector of off screen buffers
324 CameraActor mCameraActor; ///< The camera actor attached to the off screen tasks
325 bool mPanning; ///< The boolean to indicate whether the pan gesture is continuing
327 std::vector<Toolkit::PageTurnEffect> mTurnEffect; ///< The group of PageTurnEffects
328 PageTurnBookSpineEffect mSpineEffectFront; ///< The book spine shader effect without flipping image content
329 PageTurnBookSpineEffect mSpineEffectBack; ///< The book spine shader effect with image content flipped
330 Vector2 mSpineShadowParameter; ///< The spine shadow parameter for all the above shader effects
331 Vector2 mOriginalCenter; ///< The original center set to the PageTurnEffect
332 Vector2 mCurrentCenter; ///< The current center set to the PageTurnEffect
334 std::vector<ImageActor> mPageActors; ///< The vector of pages on stage
335 int mCurrentPageIndex; ///< The index of the current page, between 0 ~ mTotalPageCount-1
336 std::map<ImageActor,bool> mIsTurnBack; ///< The map to keep track the page actor's turning direction
337 std::map<Animation,ImageActor> mAnimationActorPair; ///< The map to keep track which page actor is the animation act on
338 std::map<Animation, int> mAnimationIndexPair; ///< The map to keep track which PageTurnEffect, PanDisplacementProperty, CurrentCenterProperty is used for the animation
339 int mIndex; ///< The index to keep track which PageTurnEffect, PanDisplacementProperty, CurrentCenterProperty is used for the current panning page
340 std::vector<bool> mIsAnimating; ///< The boolean vector to keep track which PageTurnEffect, PanDisplacementProperty, CurrentCenterProperty is available for using
341 std::vector<bool> mIsSliding; ///< The boolean vector to keep track whether there are animating pages sliding back
343 ImageActor mPanActor; ///< The page being panned by the pan gesture
344 Vector2 mPressDownPosition; ///< The first press down position of the pan gesture
345 bool mPress; ///< The boolean to keep track the state of the pageTurnEffect is activated or not
346 bool mPageUpdated; ///< The boolean to keep track whether is page is updated after any turning activity
348 float mDistanceUpCorner; ///< The distance between the original center of PageTurnEffect and the top-left corner of the page
349 float mDistanceBottomCorner; ///< The distance between the original center of PageTurnEffect and the bottom-left corner of the page
351 std::vector<Property::Index> mPropertyPanDisplacement; ///< The pan displacement property group
352 std::vector<Property::Index> mPropertyCurrentCenter; ///< The current center property group
353 float mPanDisplacement; ///< The displacement of the pan after the constrains are applied
354 bool mConstraints; ///< The boolean to keep track the constrains are applied or not
356 Toolkit::PageTurnView::PageTurnSignal mPageTurnStartedSignal; ///< The signal to notify that a page has started turning
357 Toolkit::PageTurnView::PageTurnSignal mPageTurnFinishedSignal; ///< The signal to notify that a page has finished turning
358 Toolkit::PageTurnView::PagePanSignal mPagePanStartedSignal; ///< The signal to notify that a page has started panning
359 Toolkit::PageTurnView::PagePanSignal mPagePanFinishedSignal; ///< The signal to notify that a page has finished panning
361 static const int MAXIMUM_TURNING_NUM; ///< How many pages are allowed to animating in the same time
362 static const int NUMBER_OF_CACHED_PAGES_EACH_SIDE; ///< The maximum number of pages kept, (MAXIMUM_ANIMATION_NUM+1) pages for each side
363 static const int NUMBER_OF_CACHED_PAGES; ///< The maximum number of pages kept, (MAXIMUM_ANIMATION_NUM+1)*2 pages in total
364 static const float STATIC_PAGE_INTERVAL_DISTANCE; ///< The depth interval between stacked pages (static pages)
367 } // namespace Internal
370 // Helpers for public-api forwarding methods
372 inline Toolkit::Internal::PageTurnView& GetImplementation(Toolkit::PageTurnView& pub)
374 DALI_ASSERT_ALWAYS(pub);
376 Dali::RefObject& handle = pub.GetImplementation();
378 return static_cast<Toolkit::Internal::PageTurnView&>(handle);
381 inline const Toolkit::Internal::PageTurnView& GetImplementation(const Toolkit::PageTurnView& pub)
383 DALI_ASSERT_ALWAYS(pub);
385 const Dali::RefObject& handle = pub.GetImplementation();
387 return static_cast<const Toolkit::Internal::PageTurnView&>(handle);
390 } // namespace Toolkit
393 #endif /* __DALI_TOOLKIT_INTERNAL_PAGE_TURN_VIEW_IMPL_H__ */