1 #ifndef DALI_TOOLKIT_INTERNAL_PAGE_TURN_VIEW_IMPL_H
2 #define DALI_TOOLKIT_INTERNAL_PAGE_TURN_VIEW_IMPL_H
5 * Copyright (c) 2016 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/devel-api/common/map-wrapper.h>
23 #include <dali/public-api/actors/layer.h>
24 #include <dali/public-api/rendering/renderer.h>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/devel-api/controls/page-turn-view/page-turn-view.h>
29 #include <dali-toolkit/devel-api/controls/page-turn-view/page-factory.h>
30 #include <dali-toolkit/devel-api/controls/shadow-view/shadow-view.h>
41 class PageTurnView : public Control
60 * Set the page texture content
61 * @param[in] texture The content of the page.
63 void SetTexture( Texture texture );
66 * Apply an effect onto the page actor.
67 * @param[in] newShader The shader for rendering effect.
69 void UseEffect(Shader newShader);
72 * Apply an effect onto the page actor.
73 * @param[in] newShader The shader for rendering effect.
74 * @param[in] geometry The geometry for rendering effect.
76 void UseEffect(Shader newShader, Geometry geometry);
79 * Change the page turning direction.
81 void ChangeTurnDirection();
84 * Set the pan displacement property
85 * @param[in] value The property value
87 void SetPanDisplacement(float value);
90 * Set the pan center property
91 * @param[in] value The property value
93 void SetPanCenter( const Vector2& value );
96 * Set the original center property to be used by shader
97 * @param[in] value The property value
99 void SetOriginalCenter( const Vector2& value );
102 * Set the current center property to be used by shader
103 * @param[in] value The property value
105 void SetCurrentCenter( const Vector2& value );
107 Actor actor; ///< The page actor
108 Shader shader; ///< The shader used by the actor
109 TextureSet textureSet; ///< The set of textures used by the actor
110 Renderer renderer; ///< The renderer of the actor
111 bool isTurnBack; ///< The turning direction
112 Property::Index propertyPanDisplacement; ///< The horizontal displacement of the pan
113 Property::Index propertyPanCenter; ///< The current pan position
114 Property::Index propertyOriginalCenter; ///< The original center to be used by the shader
115 Property::Index propertyCurrentCenter; ///< The current center to be used by the shader
116 Property::Index propertyTurnDirection; ///< The turning direction property
124 * It initializes the PageTurnView members
126 PageTurnView( PageFactory& pageFactory, const Vector2& viewPageSize );
129 * A reference counted object may only be deleted by calling Unreference()
131 virtual ~PageTurnView();
137 * @param[in] viewPageSize The size of pages
139 void SetPageSize( const Vector2& viewPageSize );
142 * Retrieve the page size.
143 * @return The page size.
145 Vector2 GetPageSize();
148 * Set the spine shadow parameter to the shader effects.
149 * The two parameters are the major&minor radius (in pixels) to form an ellipse shape.
150 * The top-left quarter of this ellipse is used to calculate spine normal for simulating shadow.
151 * @param [in] spineShadowParameter The major&minor ellipse radius for the simulated spine shadow.
153 void SetSpineShadowParameter( const Vector2& spineShadowParameter );
156 * Retrieve the spine shadow parameter of the shader effects.
157 * @return The spine shadow parameter.
159 Vector2 GetSpineShadowParameter();
162 * Jump to a given page.
163 * @param[in] pageId The new current page id.
165 void GoToPage( unsigned int pageId );
168 * Retrieve the id of the current Page.
169 * @return The current page id.
171 unsigned int GetCurrentPage();
176 * This method gets a page from the factory and add to the control
177 * to keep NUMBER_OF_CACHED_PAGES_EACH_SIDE pages available in each side
178 * @param[in] pageIndex The index of the page to be added
180 void AddPage( int pageIndex );
183 * This method removes a page from the control
184 * to keep only NUMBER_OF_CACHED_PAGES_EACH_SIDE pages available in each side
185 * @param[in] pageIndex The index of the page to be removed
187 void RemovePage( int pageIndex );
190 * This method updates the actor and animation states after one page is turned over
191 * This method is a callback, connected when receiving the finished signal of a page turning over animation.
192 * @param [in] the page turning over animation handle
194 void TurnedOver( Animation& animation );
197 * This method organize the depth of the pages on stage
198 * It is called when there is page added or removed from the control
200 void OrganizePageDepth();
205 * Create shader from a property map.
206 * @param[in] shaderMap The shader property map;
207 * @return The created shader.
209 Shader CreateShader( const Property::Map& shaderMap );
212 * Set up the shadow view control to cast shadow
214 void SetupShadowView();
217 * This method defines the processes when the pan started, gets called by OnPan( .. )
218 * @param[in] gesturePosition The current touch position in local page actor coordinates.
220 void PanStarted( const Vector2& gesturePosition );
223 * This method defines the processes when the pan continuing, gets called by OnPan( .. )
224 * @param[in] gesturePosition The current touch position in local page actor coordinates.
226 void PanContinuing( const Vector2& gesturePosition );
229 * This method defines the processes when the pan finished, gets called by OnPanGesture( .. )
230 * @param[in] gesturePosition The current touch position in local page actor coordinates.
231 * @param[in] gestureSpeed The speed of the pan ( in pixels per millisecond )
233 void PanFinished( const Vector2& gesturePosition, float gestureSpeed );
236 * This method updates the actor and the animation states after one page is slidden back instead of turned over
237 * This method is a callback, connected when receiving the finished signal of a page sliding back animation.
238 * @param [in] the page sliding back animation handle
240 void SliddenBack( Animation& animation );
243 * Stop the page turning animation and contraint.
244 * This method should be called when taking off stage or jump to a specified page.
248 private: // from Control
251 * @copydoc Toolkit::Control::OnPan
253 void OnPan( const PanGesture& gesture ) override;
256 * @copydoc Toolkit::Control::OnInitialize
258 void OnInitialize() override;
261 * @copydoc CustomActorImpl::OnSceneConnection()
263 void OnSceneConnection( int depth ) override;
266 * @copydoc CustomActorImpl::OnSceneDisconnection()
268 void OnSceneDisconnection() override;
270 private: // implemented differently by PageTurnLandscapeView and PageTurnPortraitView
273 * This method is called after the pageTurnView initialization.
274 * To set the size of the control size and the parent origin of turning page layer
275 * Implemented in subclasses to provide specific behaviour.
277 virtual void OnPageTurnViewInitialize() = 0;
280 * This method is called after the a new page is added to the stage.
281 * Could be re-implemented in subclasses to provide specific behaviour
282 * @param[in] newPage The added page actor
283 * @param[in] isLeftSide Which side the new page is added to
285 virtual void OnAddPage( Actor newPage, bool isLeftSide ) { }
288 * This method is called when pan started or continuing
289 * to calculate the pan position in local page actor coordinate given the pan position in control coordinate
290 * Implemented in subclasses to provide specific behaviour.
291 * @param[in] gesturePosition The pan position in the control coordinate
292 * @return The pan position in the page actor local coordinate
294 virtual Vector2 SetPanPosition( const Vector2& gesturePosition ) = 0;
297 * This method is called when pan started to determined which page is panned given the pan position in control coordinate
298 * Implemented in subclasses to provide specific behaviour.
299 * @param[in] gesturePosition The pan position in the control coordinate
301 virtual void SetPanActor( const Vector2& panPosition ) = 0;
304 * This method is called when pan finished to detect outwards flick
305 * In portrait view, start an animation of turning previous page back when outwards flick is detected
306 * In landscape view, nothing to do
307 * @param[in] panPosition The pan position in the page actor local coordinate
308 * @param[in] gestureSpeed The speed of the pan gesture( in pixels per millisecond )
310 virtual void OnPossibleOutwardsFlick( const Vector2& panPosition, float gestureSpeed ) { }
313 * This method is called when page is turned over
314 * In portrait view, the page on the left side is not rendered
315 * @param[in] actor The page actor
316 * @param[in] isLeftSide Which side the page is turned to
318 virtual void OnTurnedOver( Actor actor, bool isLeftSide ) { }
320 public: //signal and property
323 * @copydoc Toolkit::PageTurnView::PageTurnStartedSignal()
325 Toolkit::PageTurnView::PageTurnSignal& PageTurnStartedSignal();
328 * @copydoc Toolkit::PageTurnView::PageTurnFinishedSignal()
330 Toolkit::PageTurnView::PageTurnSignal& PageTurnFinishedSignal();
333 * @copydoc Toolkit::PageTurnView::PagePanStartSignal()
335 Toolkit::PageTurnView::PagePanSignal& PagePanStartedSignal();
338 * @copydoc Toolkit::PageTurnView::PagePanFinishedSignal()
340 Toolkit::PageTurnView::PagePanSignal& PagePanFinishedSignal();
343 * Connects a callback function with the object's signals.
344 * @param[in] object The object providing the signal.
345 * @param[in] tracker Used to disconnect the signal.
346 * @param[in] signalName The signal to connect to.
347 * @param[in] functor A newly allocated FunctorDelegate.
348 * @return True if the signal was connected.
349 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
351 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
356 * Called when a property of an object of this type is set.
357 * @param[in] object The object whose property is set.
358 * @param[in] index The property index.
359 * @param[in] value The new property value.
361 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
364 * Called to retrieve a property of an object of this type.
365 * @param[in] object The object whose property is to be retrieved.
366 * @param[in] index The property index.
367 * @return The current value of the property.
369 static Property::Value GetProperty( BaseObject* object, Property::Index index );
374 PageTurnView( const PageTurnView& );
377 PageTurnView& operator=(const PageTurnView& rhs);
381 Layer mTurningPageLayer; ///< The layer for the turning page, to avoid possible depth conflict
382 Toolkit::ShadowView mShadowView; ///< The shadow view control for shadow casting
383 Actor mShadowPlaneBackground; ///< The plane for the shadow to cast on
384 Actor mPointLight; ///< The point light used for shadow casting
386 PageFactory* const mPageFactory; ///< The factory which provides the page actors
387 Shader mTurnEffectShader; ///< The group of PageTurnEffects
388 Shader mSpineEffectShader; ///< The book spine shader effect
389 Geometry mGeometry; ///< The grid geometry for pages
391 std::vector<Page> mPages; ///< The vector of pages on stage
392 std::map<Animation,int> mAnimationPageIdPair; ///< The map to keep track which page actor is the animation act on
394 Vector2 mPageSize; ///< The page size
395 Vector2 mControlSize; ///< The size of the control, it is decided by the page size, the SetSize from application can not change it
396 Vector2 mSpineShadowParameter; ///< The spine shadow parameter for all the above shader effects
397 Vector2 mOriginalCenter; ///< The original center set to the PageTurnEffect
398 Vector2 mCurrentCenter; ///< The current center set to the PageTurnEffect
399 Vector2 mPressDownPosition; ///< The first press down position of the pan gesture
401 float mDistanceUpCorner; ///< The distance between the original center of PageTurnEffect and the top-left corner of the page
402 float mDistanceBottomCorner; ///< The distance between the original center of PageTurnEffect and the bottom-left corner of the page
403 float mPanDisplacement; ///< The displacement of the pan after the constrains are applied
405 int mTotalPageCount; ///< The total number of pages provided by the page factory
406 int mCurrentPageIndex; ///< The index of the current page, between 0 ~ mTotalPageCount-1
407 int mTurningPageIndex; ///< The index of the turning page
408 int mIndex; ///< The index to keep track which PanDisplacementProperty, CurrentCenterProperty is used for the current panning page
409 int mSlidingCount; ///< The boolean vector to keep track whether there are animating pages sliding back
410 int mAnimatingCount; ///< The boolean vector to keep track which PageTurnEffect, PanDisplacementProperty, CurrentCenterProperty is available for using
412 bool mConstraints; ///< The boolean to keep track the constrains are applied or not
413 bool mPress; ///< The boolean to keep track the state of the pageTurnEffect is activated or not
414 bool mPageUpdated; ///< The boolean to keep track whether is page is updated after any turning activity
416 Toolkit::PageTurnView::PageTurnSignal mPageTurnStartedSignal; ///< The signal to notify that a page has started turning
417 Toolkit::PageTurnView::PageTurnSignal mPageTurnFinishedSignal; ///< The signal to notify that a page has finished turning
418 Toolkit::PageTurnView::PagePanSignal mPagePanStartedSignal; ///< The signal to notify that a page has started panning
419 Toolkit::PageTurnView::PagePanSignal mPagePanFinishedSignal; ///< The signal to notify that a page has finished panning
421 static const char * const PROPERTY_TEXTURE_WIDTH; ///< The uniform name of texture width
422 static const char * const PROPERTY_ORIGINAL_CENTER; ///< The property name of original center, which is used to constrain the uniforms
423 static const char * const PROPERTY_CURRENT_CENTER; ///< The property name of current center, which is used to constrain the uniforms
425 static const int MAXIMUM_TURNING_NUM; ///< How many pages are allowed to animating in the same time
426 static const int NUMBER_OF_CACHED_PAGES_EACH_SIDE; ///< The maximum number of pages kept, (MAXIMUM_ANIMATION_NUM+1) pages for each side
427 static const int NUMBER_OF_CACHED_PAGES; ///< The maximum number of pages kept, (MAXIMUM_ANIMATION_NUM+1)*2 pages in total
428 static const float STATIC_PAGE_INTERVAL_DISTANCE; ///< The depth interval between stacked pages (static pages)
431 } // namespace Internal
434 // Helpers for public-api forwarding methods
436 inline Toolkit::Internal::PageTurnView& GetImplementation(Toolkit::PageTurnView& pub)
438 DALI_ASSERT_ALWAYS(pub);
440 Dali::RefObject& handle = pub.GetImplementation();
442 return static_cast<Toolkit::Internal::PageTurnView&>(handle);
445 inline const Toolkit::Internal::PageTurnView& GetImplementation(const Toolkit::PageTurnView& pub)
447 DALI_ASSERT_ALWAYS(pub);
449 const Dali::RefObject& handle = pub.GetImplementation();
451 return static_cast<const Toolkit::Internal::PageTurnView&>(handle);
454 } // namespace Toolkit
458 #endif // DALI_TOOLKIT_INTERNAL_PAGE_TURN_VIEW_IMPL_H