(Touch) Remove Usage of TouchEvent
[platform/core/uifw/dali-demo.git] / demo / dali-table-view.h
1 #ifndef __DALI_DEMO_H__
2 #define __DALI_DEMO_H__
3
4 /*
5  * Copyright (c) 2015 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 #include <dali/dali.h>
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali-toolkit/devel-api/controls/popup/popup.h>
24
25 class Example;
26
27 typedef std::vector<Example> ExampleList;
28 typedef ExampleList::iterator ExampleListIter;
29 typedef ExampleList::const_iterator ExampleListConstIter;
30
31 typedef std::vector<Dali::Animation> AnimationList;
32 typedef AnimationList::iterator AnimationListIter;
33 typedef AnimationList::const_iterator AnimationListConstIter;
34
35
36 /**
37  * Example information
38  *
39  * Represents a single Example.
40  */
41 struct Example
42 {
43   // Constructors
44
45   /**
46    * @param[in] name unique name of example
47    * @param[in] title The caption for the example to appear on a tile button.
48    */
49   Example(std::string name, std::string title)
50   : name(name),
51     title(title)
52   {
53   }
54
55   Example()
56   {
57   }
58
59   // Data
60
61   std::string name;                       ///< unique name of example
62   std::string title;                      ///< title (caption) of example to appear on tile button.
63 };
64
65
66
67 /**
68  * Dali-Demo instance
69  */
70 class DaliTableView : public Dali::ConnectionTracker
71 {
72 public:
73
74   DaliTableView(Dali::Application& application);
75   ~DaliTableView();
76
77 public:
78
79   /**
80    * Adds an Example to our demo showcase
81    *
82    * @param[in] example The Example description.
83    *
84    * @note Should be called before the Application MainLoop is started.
85    */
86   void AddExample(Example example);
87
88   /**
89    * Sorts the example list alphabetically by Title if parameter is true.
90    *
91    * @param[in] sortAlphabetically If true, example list is sorted alphabetically.
92    *
93    * @note Should be called before the Application MainLoop is started.
94    * @note By default the examples are NOT sorted alphabetically by Title.
95    */
96   void SortAlphabetically( bool sortAlphabetically );
97
98 private: // Application callbacks & implementation
99
100   /**
101    * Shape enum for create function
102    */
103   enum ShapeType
104   {
105     CIRCLE,
106     SQUARE
107   };
108
109   /**
110    * Initialize application.
111    *
112    * @param[in] app Application instance
113    */
114   void Initialize( Dali::Application& app );
115
116   /**
117    * Populates the contents (ScrollView) with all the
118    * Examples that have been Added using the AddExample(...)
119    * call
120    */
121   void Populate();
122
123   /**
124    * Rotate callback from the device.
125    *
126    * @param[in] orientation that device notified.
127    */
128   void OrientationChanged( Dali::Orientation orientation );
129
130   /**
131    * Rotates RootActor orientation to that specified.
132    *
133    * @param[in] degrees The requested angle.
134    */
135   void Rotate( unsigned int degrees );
136
137   /**
138    * Creates a tile for the main menu and toolbar.
139    *
140    * @param[in] name The unique name for this Tile
141    * @param[in] title The text caption that appears on the Tile
142    * @param[in] parentSize Tile's parent size.
143    * @param[in] addBackground Whether to add a background graphic to the tile or not
144    *
145    * @return The Actor for the created tile.
146    */
147   Dali::Actor CreateTile( const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, bool addBackground );
148
149   /**
150    * Create a stencil image
151    *
152    * @return The stencil image
153    */
154   Dali::Toolkit::ImageView NewStencilImage();
155
156   // Signal handlers
157
158   /**
159    * Signal emitted when any tile has been pressed
160    *
161    * @param[in] actor The Actor representing this tile.
162    * @param[in] event The Touch information.
163    *
164    * @return Consume flag
165    */
166   bool OnTilePressed( Dali::Actor actor, const Dali::TouchData& event );
167
168   /**
169    * Called by OnTilePressed & Accessibility to do the appropriate action.
170    *
171    * @param[in] actor The Actor representing this tile.
172    * @param[in] state The Touch state
173    *
174    * @return Consume flag
175    */
176   bool DoTilePress( Dali::Actor actor, Dali::PointState::Type state );
177
178   /**
179    * Signal emitted when any tile has been hovered
180    *
181    * @param[in] actor The Actor representing this tile.
182    * @param[in] event The HoverEvent
183    *
184    * @return Consume flag
185    */
186   bool OnTileHovered( Dali::Actor actor, const Dali::HoverEvent& event );
187
188   /**
189    * Signal emitted when the pressed animation has completed.
190    *
191    * @param[in] source The animation source.
192    */
193   void OnPressedAnimationFinished(Dali::Animation& source);
194
195   /**
196    * Signal emitted when the button has been clicked
197    *
198    * @param[in] button The Button that is clicked.
199    *
200    * @return Consume flag
201    */
202   bool OnButtonClicked( Dali::Toolkit::Button& button );
203
204   /**
205    * Signal emitted when scrolling has started.
206    *
207    * @param[in] position The current position of the scroll contents.
208    */
209   void OnScrollStart(const Dali::Vector2& position);
210
211   /**
212    * Signal emitted when scrolling has completed.
213    *
214    * @param[in] position The current position of the scroll contents.
215    */
216   void OnScrollComplete(const Dali::Vector2& position);
217
218   /**
219    * Signal emitted when any Sensitive Actor has been touched
220    * (other than those touches consumed by OnTilePressed)
221    *
222    * @param[in] actor The Actor touched.
223    * @param[in] event The Touch information.
224    *
225    * @return Consume flag
226    */
227   bool OnScrollTouched( Dali::Actor actor, const Dali::TouchData& event );
228
229   /**
230    * Setup the effect on the scroll view
231    */
232   void ApplyScrollViewEffect();
233
234   /**
235    * Apply the cube effect to all the page actors
236    */
237   void ApplyCubeEffectToPages();
238
239   /**
240    * Setup the inner cube effect
241    */
242   void SetupInnerPageCubeEffect();
243
244   /**
245    * Apply a shader effect to a table tile
246    */
247   void ApplyEffectToTile(Dali::Actor tile);
248
249   /**
250    * Apply effect to the content of a tile
251    */
252   void ApplyEffectToTileContent(Dali::Actor tileContent);
253
254   /**
255    * Key event handler
256    */
257   void OnKeyEvent( const Dali::KeyEvent& event );
258
259   /**
260    * Create a depth field background
261    *
262    * @param[in] bubbleLayer Add the graphics to this layer
263    */
264   void SetupBackground( Dali::Actor bubbleLayer );
265
266   /**
267    * Create background actors for the given layer
268    *
269    * @param[in] layer The layer to add the actors to
270    * @param[in] count The number of actors to generate
271    * @param[in] distanceField The distance field bitmap to use
272    */
273   void AddBackgroundActors( Dali::Actor layer, int count, Dali::BufferImage distanceField );
274
275   /**
276    * Create a bitmap with the specified shape and also output a distance field
277    *
278    * @param[in] shapeType The shape to generate
279    * @param[in] size The size of the bitmap to create
280    * @param[out] distanceFieldOut The return depth field alpha map
281    */
282   void CreateShapeImage( ShapeType shapeType, const Dali::Size& size, Dali::BufferImage& distanceFieldOut );
283
284   /**
285    * Generate a square bit pattern and depth field
286    *
287    * @param[in] size The size of the bitmap to create
288    * @param[out] imageOut The return bitmap
289    * @param[out] distanceFieldOut The return depth field alpha map
290    */
291   void GenerateSquare( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut );
292
293   /**
294    * Generate a circle bit pattern and depth field
295    *
296    * @param[in] size The size of the bitmap to create
297    * @param[out] imageOut The return bitmap
298    * @param[out] distanceFieldOut The return depth field alpha map
299    */
300   void GenerateCircle( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut );
301
302   /**
303    * Creates the logo.
304    *
305    * @param[in] imagePath The path to the image file to load
306    *
307    * @return The created image actor
308    */
309   Dali::Toolkit::ImageView CreateLogo( std::string imagePath );
310
311   /**
312    * Timer handler for ending background animation
313    *
314    * @return Return value for timer handler
315    */
316   bool PauseBackgroundAnimation();
317
318   /**
319    * Pause all animations
320    */
321   void PauseAnimation();
322
323   /**
324    * Resume all animations
325    */
326   void PlayAnimation();
327
328   /**
329    * Callback when the keyboard focus is going to be changed.
330    *
331    * @param[in] current The current focused actor
332    * @param[in] proposed The actor proposed by the keyboard focus manager to move the focus to
333    * @param[in] direction The direction to move the focus
334    * @return The actor to move the keyboard focus to.
335    */
336   Dali::Actor OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction );
337
338   /**
339    * Callback when the keyboard focused actor is activated.
340    *
341    * @param[in] activatedActor The activated actor
342    */
343   void OnFocusedActorActivated( Dali::Actor activatedActor );
344
345   /**
346    * Called when the logo is tapped
347    *
348    * @param[in]  actor  The tapped actor
349    * @param[in]  tap    The tap information.
350    */
351   void OnLogoTapped( Dali::Actor actor, const Dali::TapGesture& tap );
352
353   /**
354    * Hides the popup
355    */
356   void HideVersionPopup();
357
358  /*
359   * @brief Callback called when the buttons page actor is relaid out
360   *
361   * @param[in] actor The page actor
362   */
363  void OnButtonsPageRelayout( const Dali::Actor& actor );
364
365  /**
366   * @brief Callback called to set up background actors
367   *
368   * @param[in] actor The actor raising the callback
369   */
370  void InitialiseBackgroundActors( Dali::Actor actor );
371
372 private:
373
374   Dali::Application&              mApplication;              ///< Application instance.
375   Dali::Layer                     mBackgroundLayer;          ///< Background resides on a separate layer.
376   Dali::Toolkit::TableView        mRootActor;                ///< All content (excluding background is anchored to this Actor)
377   Dali::Animation                 mRotateAnimation;          ///< Animation to rotate and resize mRootActor.
378   Dali::Animation                 mPressedAnimation;         ///< Button press scaling animation.
379   Dali::Layer                     mScrollViewLayer;          ///< ScrollView resides on a separate layer.
380   Dali::Toolkit::ScrollView       mScrollView;               ///< ScrollView container (for all Examples)
381   Dali::Toolkit::ScrollViewEffect mScrollViewEffect;         ///< Effect to be applied to the scroll view
382   Dali::Toolkit::RulerPtr         mScrollRulerX;             ///< ScrollView X (horizontal) ruler
383   Dali::Toolkit::RulerPtr         mScrollRulerY;             ///< ScrollView Y (vertical) ruler
384   Dali::Actor                     mPressedActor;             ///< The currently pressed actor.
385   Dali::Timer                     mAnimationTimer;           ///< Timer used to turn off animation after a specific time period
386   Dali::TapGestureDetector        mLogoTapDetector;          ///< To detect taps on the logo
387   Dali::Toolkit::Popup            mVersionPopup;             ///< Displays DALi library version information
388
389   std::vector< Dali::Actor >      mPages;                    ///< List of pages.
390   AnimationList                   mBackgroundAnimations;     ///< List of background bubble animations
391   ExampleList                     mExampleList;              ///< List of examples.
392
393   int                             mTotalPages;               ///< Total pages within scrollview.
394
395   bool                            mScrolling:1;              ///< Flag indicating whether view is currently being scrolled
396   bool                            mSortAlphabetically:1;     ///< Sort examples alphabetically.
397   bool                            mBackgroundAnimsPlaying:1; ///< Are background animations playing
398
399 };
400
401 #endif // __DALI_DEMO_H__