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