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