f7785d5abc3cf475a3a677d57752251ed3719d0e
[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     BUBBLE
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.
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] position The tiles relative position within a page
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, Dali::Vector2& position );
148
149   // Signal handlers
150
151   /**
152    * Signal emitted when any tile has been pressed
153    *
154    * @param[in] actor The Actor representing this tile.
155    * @param[in] event The Touch information.
156    *
157    * @return Consume flag
158    */
159   bool OnTilePressed( Dali::Actor actor, const Dali::TouchData& event );
160
161   /**
162    * Called by OnTilePressed & Accessibility to do the appropriate action.
163    *
164    * @param[in] actor The Actor representing this tile.
165    * @param[in] state The Touch state
166    *
167    * @return Consume flag
168    */
169   bool DoTilePress( Dali::Actor actor, Dali::PointState::Type state );
170
171   /**
172    * Signal emitted when any tile has been hovered
173    *
174    * @param[in] actor The Actor representing this tile.
175    * @param[in] event The HoverEvent
176    *
177    * @return Consume flag
178    */
179   bool OnTileHovered( Dali::Actor actor, const Dali::HoverEvent& event );
180
181   /**
182    * Signal emitted when the pressed animation has completed.
183    *
184    * @param[in] source The animation source.
185    */
186   void OnPressedAnimationFinished(Dali::Animation& source);
187
188   /**
189    * Signal emitted when the button has been clicked
190    *
191    * @param[in] button The Button that is clicked.
192    *
193    * @return Consume flag
194    */
195   bool OnButtonClicked( Dali::Toolkit::Button& button );
196
197   /**
198    * Signal emitted when scrolling has started.
199    *
200    * @param[in] position The current position of the scroll contents.
201    */
202   void OnScrollStart(const Dali::Vector2& position);
203
204   /**
205    * Signal emitted when scrolling has completed.
206    *
207    * @param[in] position The current position of the scroll contents.
208    */
209   void OnScrollComplete(const Dali::Vector2& position);
210
211   /**
212    * Signal emitted when any Sensitive Actor has been touched
213    * (other than those touches consumed by OnTilePressed)
214    *
215    * @param[in] actor The Actor touched.
216    * @param[in] event The Touch information.
217    *
218    * @return Consume flag
219    */
220   bool OnScrollTouched( Dali::Actor actor, const Dali::TouchData& event );
221
222   /**
223    * Setup the effect on the scroll view
224    */
225   void ApplyScrollViewEffect();
226
227   /**
228    * Apply the cube effect to all the page actors
229    */
230   void ApplyCubeEffectToPages();
231
232   /**
233    * Setup the inner cube effect
234    */
235   void SetupInnerPageCubeEffect();
236
237   /**
238    * Apply a shader effect to a table tile
239    */
240   void ApplyEffectToTile(Dali::Actor tile);
241
242   /**
243    * Apply effect to the content of a tile
244    */
245   void ApplyEffectToTileContent(Dali::Actor tileContent);
246
247   /**
248    * Key event handler
249    */
250   void OnKeyEvent( const Dali::KeyEvent& event );
251
252   /**
253    * Create a depth field background
254    *
255    * @param[in] bubbleLayer Add the graphics to this layer
256    */
257   void SetupBackground( Dali::Actor bubbleLayer );
258
259   /**
260    * Create background actors for the given layer
261    *
262    * @param[in] layer The layer to add the actors to
263    * @param[in] count The number of actors to generate
264    * @param[in] distanceField A array (pointer) to 2 distance field types to use
265    */
266   void AddBackgroundActors( Dali::Actor layer, int count, Dali::BufferImage* distanceField );
267
268   /**
269    * Create a bitmap with the specified shape and also output a distance field
270    *
271    * @param[in] shapeType The shape to generate
272    * @param[in] size The size of the bitmap to create
273    * @param[out] distanceFieldOut The return depth field alpha map
274    */
275   void CreateShapeImage( ShapeType shapeType, const Dali::Size& size, Dali::BufferImage& distanceFieldOut );
276
277   /**
278    * Generate a square bit pattern and depth field
279    *
280    * @param[in] size The size of the bitmap to create
281    * @param[out] imageOut The return bitmap
282    * @param[out] distanceFieldOut The return depth field alpha map
283    */
284   void GenerateSquare( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut );
285
286   /**
287    * Generate a circle bit pattern and depth field
288    *
289    * @param[in] size The size of the bitmap to create
290    * @param[out] imageOut The return bitmap
291    * @param[out] distanceFieldOut The return depth field alpha map
292    * @param[in] hollow Optional - Set to true for a thick circle outline without fill
293    */
294   void GenerateCircle( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut, bool hollow = false );
295
296   /**
297    * Creates the logo.
298    *
299    * @param[in] imagePath The path to the image file to load
300    *
301    * @return The created image actor
302    */
303   Dali::Toolkit::ImageView CreateLogo( std::string imagePath );
304
305   /**
306    * Timer handler for ending background animation
307    *
308    * @return Return value for timer handler
309    */
310   bool PauseBackgroundAnimation();
311
312   /**
313    * Pause all animations
314    */
315   void PauseAnimation();
316
317   /**
318    * Resume all animations
319    */
320   void PlayAnimation();
321
322   /**
323    * Callback when the keyboard focus is going to be changed.
324    *
325    * @param[in] current The current focused actor
326    * @param[in] proposed The actor proposed by the keyboard focus manager to move the focus to
327    * @param[in] direction The direction to move the focus
328    * @return The actor to move the keyboard focus to.
329    */
330   Dali::Actor OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction );
331
332   /**
333    * Callback when the keyboard focused actor is activated.
334    *
335    * @param[in] activatedActor The activated actor
336    */
337   void OnFocusedActorActivated( Dali::Actor activatedActor );
338
339   /**
340    * Called when the logo is tapped
341    *
342    * @param[in]  actor  The tapped actor
343    * @param[in]  tap    The tap information.
344    */
345   void OnLogoTapped( Dali::Actor actor, const Dali::TapGesture& tap );
346
347   /**
348    * Hides the popup
349    */
350   void HideVersionPopup();
351
352  /*
353   * @brief Callback called when the buttons page actor is relaid out
354   *
355   * @param[in] actor The page actor
356   */
357  void OnButtonsPageRelayout( const Dali::Actor& actor );
358
359  /**
360   * @brief Callback called to set up background actors
361   *
362   * @param[in] actor The actor raising the callback
363   */
364  void InitialiseBackgroundActors( Dali::Actor actor );
365
366 private:
367
368   Dali::Application&              mApplication;              ///< Application instance.
369   Dali::Toolkit::Control          mRootActor;                ///< All content (excluding background is anchored to this Actor)
370   Dali::Animation                 mRotateAnimation;          ///< Animation to rotate and resize mRootActor.
371   Dali::Animation                 mPressedAnimation;         ///< Button press scaling animation.
372   Dali::Toolkit::ScrollView       mScrollView;               ///< ScrollView container (for all Examples)
373   Dali::Toolkit::ScrollViewEffect mScrollViewEffect;         ///< Effect to be applied to the scroll view
374   Dali::Toolkit::RulerPtr         mScrollRulerX;             ///< ScrollView X (horizontal) ruler
375   Dali::Toolkit::RulerPtr         mScrollRulerY;             ///< ScrollView Y (vertical) ruler
376   Dali::Actor                     mPressedActor;             ///< The currently pressed actor.
377   Dali::Timer                     mAnimationTimer;           ///< Timer used to turn off animation after a specific time period
378   Dali::TapGestureDetector        mLogoTapDetector;          ///< To detect taps on the logo
379   Dali::Toolkit::Popup            mVersionPopup;             ///< Displays DALi library version information
380
381   std::vector< Dali::Actor >      mPages;                    ///< List of pages.
382   AnimationList                   mBackgroundAnimations;     ///< List of background bubble animations
383   ExampleList                     mExampleList;              ///< List of examples.
384
385   float                           mPageWidth;                ///< The width of a page within the scroll-view, used to calculate the domain
386   int                             mTotalPages;               ///< Total pages within scrollview.
387
388   bool                            mScrolling:1;              ///< Flag indicating whether view is currently being scrolled
389   bool                            mSortAlphabetically:1;     ///< Sort examples alphabetically.
390   bool                            mBackgroundAnimsPlaying:1; ///< Are background animations playing
391
392 };
393
394 #endif // __DALI_DEMO_H__