Conversion to Apache 2.0 license
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / public-api / controls / page-turn-view / page-turn-view.h
1 #ifndef __DALI_TOOLKIT_PAGE_TURN_VIEW_H__
2 #define __DALI_TOOLKIT_PAGE_TURN_VIEW_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/control.h>
23
24 namespace Dali DALI_IMPORT_API
25 {
26
27 namespace Toolkit
28 {
29
30 // Forward declarations
31 class PageFactory;
32
33 namespace Internal DALI_INTERNAL
34 {
35 class PageTurnView;
36 }
37
38 /**
39  * PageTurnView is a base class of different mode of pageTurnViews ( portrait or landscape )
40  * Page actors are provided from an external PageFactory
41  * PanGesture is used to activate the page bending, streching and tuning forward/backward
42  *
43  * Signal usage: There are four signals. Two matching pairs for panning and page turning:
44  * PagePanStarted/PagePanFinished and PageTurnStarted/PageTurnFinished. Panning relates to user interaction with
45  * the screen while page turning refers to animation of the page. There are three scenarios for these
46  * events: normal page turn (forwards or backwards), aborted page turn (forwards or backwards)
47  * and pan with no animation. The order of events is as follows:
48  * 1) Normal page turn: PagePanStarted -> PageTurnStarted direction -> PagePanFinished -> PageTurnFinished direction
49  * 2) Aborted page turn: PagePanStarted -> PageTurnStarted direction -> PageTurnStarted opposite direction
50  *                       -> PagePanFinished -> PageTurnFinished opposite direction
51  * 3) Pan with no animation: PagePanStarted -> PagePanFinished
52  * Pan with no animation will occur when the user touches the page in an area that does not start the
53  * page turning.
54  */
55 class PageTurnView : public Control
56 {
57 public:
58
59   /**
60    * Creates an empty PageTurnView handle. Only derived versions can be instantiated.
61    * Calling member function with an uninitialized handle is not allowed.
62    */
63   PageTurnView();
64
65   /**
66    * Copy constructor. Creates another handle that points to the same real object
67    * @param[in] handle Handle to copy from
68    */
69   PageTurnView( const PageTurnView& handle );
70
71   /**
72    * Assignment operator. Changes this handle to point to another real object
73    */
74   PageTurnView& operator=( const PageTurnView& handle );
75
76   /**
77    * Virtual destructor.
78    */
79   virtual ~PageTurnView();
80
81   /**
82    * Downcast an Object handle to PageTurnView.
83    * If handle points to an PageTurnView the downcast produces valid handle.
84    * If not the returned handle is left uninitialized.
85    * @param[in] handle Handle to an object
86    * @return handle to a PageTurnView or an uninitialized handle
87    */
88   static PageTurnView DownCast( BaseHandle handle );
89
90   /**
91    * Set the spine shadow parameter to the shader effects
92    * The two parameters are the major&minor radius (in pixels) to form an ellipse shape
93    * The top-left quarter of this ellipse is used to calculate spine normal for simulating shadow
94    * @param [in] spineShadowParameter The major&minor ellipse radius for the simulated spine shadow
95    */
96   void SetSpineShadowParameter( const Vector2& spineShadowParameter );
97
98   /**
99    * Retrieve the spine shadow parameter of the shader effects
100    * @return The major&minor ellipse radius for the simulated spine shadow
101    */
102   Vector2 GetSpineShadowParameter();
103
104   /*
105    * Go to a specific page
106    * @param[in] pageId The new current page index
107    */
108   void GoToPage( unsigned int pageId );
109
110   /**
111    * Retrieve the index of the current Page
112    * @return The index of the current page
113    */
114   unsigned int GetCurrentPage();
115
116   /**
117    * Enter edit mode
118    * Case 1, the page factory passes image actor into the view as page content, do nothing.
119    * Case 2, the page factory passes an actor tree into the view as page content,
120    *    the actor tree will receive the touch event in edit mode, and set the refresh rate of the off screen render task to always
121    * @return an empty actor in case 1; the actor tree root of the current page
122    */
123   Actor EnterEditMode();
124
125   /**
126    * Leave edit mode
127    * Case 1, the page factory passes image actor into the view as page content, do nothing.
128    * Case 2, the page factory passes an actor tree into the view as page content,
129    *   the page actor will receive all the touch event, and set the refresh rage of the off screen render task to once.
130    */
131   void LeaveEditMode();
132
133   /**
134    * Return the actor get hit in the actor tree of the current page by given the touch position on the PageTurnView
135    * @param[in] screenCoordinates The hit position of the PageTurnView
136    * @param[out] actorCoordinates The local hit position of the hitted actor
137    * @return the hitted actor
138    */
139   Actor GetHitActor( Vector2& screenCoordinates, Vector2& actorCoordinates );
140
141   /**
142    * Refresh all the cached pages by calling the render task to refresh.
143    */
144   void RefreshAll();
145
146   /**
147    * Refresh current page by calling the render task to refresh
148    */
149   void RefreshCurrentPage();
150
151 public: //Signal
152
153   // Page Turned signal, with page index and boolean turning direction (true = forward, false = backward)
154   typedef SignalV2< void ( PageTurnView, unsigned int, bool ) > PageTurnSignal;
155   typedef SignalV2< void ( PageTurnView ) > PagePanSignal;
156
157   /**
158    * Signal emitted when a page has started to turn over.
159    * A callback of the following type may be connected:
160    * @code
161    *   void YourCallBackName( PageTurnView pageTurnView, unsigned int pageIndex, bool isTurningForward );
162    * @endcode
163    * @return The signal to connect to
164    */
165   PageTurnSignal& PageTurnStartedSignal();
166
167   /**
168    * Signal emitted when a page has finished turning over.
169    * A callback of the following type may be connected:
170    * @code
171    *   void YourCallBackName( PageTurnView pageTurnView, unsigned int pageIndex, bool isTurningForward );
172    * @endcode
173    * @return The signal to connect to
174    */
175   PageTurnSignal& PageTurnFinishedSignal();
176
177   /**
178    * Signal emitted when a page pan has commenced
179    * A callback of the following type may be connected:
180    * @code
181    *   void YourCallBackName( PageTurnView pageTurnView );
182    * @endcode
183    * @return The signal to connect to
184    */
185   PagePanSignal& PagePanStartedSignal();
186
187   /**
188    * Signal emitted when a page pan has finished
189    * A callback of the following type may be connected:
190    * @code
191    *   void YourCallBackName( PageTurnView pageTurnView );
192    * @endcode
193    * @return The signal to connect to
194    */
195   PagePanSignal& PagePanFinishedSignal();
196
197 public: // Not intended for application developers
198
199   /**
200    * Creates a handle using the Toolkit::Internal implementation.
201    * @param[in]  implementation  The Control implementation.
202    */
203   DALI_INTERNAL PageTurnView(Internal::PageTurnView& implementation);
204
205   /**
206    * Allows the creation of this Control from an Internal::CustomActor pointer.
207    * @param[in]  internal  A pointer to the internal CustomActor.
208    */
209   DALI_INTERNAL PageTurnView(Dali::Internal::CustomActor* internal);
210 };
211
212 } // namespace Toolkit
213
214 } // namespace Dali
215
216 #endif /* __DALI_TOOLKIT_PAGE_TURN_VIEW_H__ */