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