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