1 #ifndef __DALI_DEMO_H__
2 #define __DALI_DEMO_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <dali/dali.h>
24 #include <dali-toolkit/dali-toolkit.h>
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;
35 typedef std::vector<Dali::Toolkit::TableView> TableViewList;
36 typedef TableViewList::iterator TableViewListIter;
37 typedef TableViewList::const_iterator TableViewListConstIter;
39 typedef std::vector<Dali::ImageActor> ImageActorList;
40 typedef ImageActorList::iterator ImageActorListIter;
41 typedef ImageActorList::const_iterator ImageActorListConstIter;
43 typedef std::vector<Dali::Animation> AnimationList;
44 typedef AnimationList::iterator AnimationListIter;
45 typedef AnimationList::const_iterator AnimationListConstIter;
51 * Represents a single Example.
58 * @param[in] name unique name of example
59 * @param[in] title The caption for the example to appear on a tile button.
61 Example(std::string name, std::string title)
73 std::string name; ///< unique name of example
74 std::string title; ///< title (caption) of example to appear on tile button.
82 class DaliTableView : public Dali::ConnectionTracker
86 DaliTableView(Dali::Application& application);
92 * Adds an Example to our demo showcase
94 * @param[in] example The Example description.
96 * @note Should be called before the Application MainLoop is started.
98 void AddExample(Example example);
101 * Sets the background image PATH.
103 * @param[in] imagePath The file path to the image to use as the background.
105 * @note Should be called before the Application MainLoop is started.
107 void SetBackgroundPath( std::string imagePath );
110 * Sorts the example list alphabetically by Title if parameter is true.
112 * @param[in] sortAlphabetically If true, example list is sorted alphabetically.
114 * @note Should be called before the Application MainLoop is started.
115 * @note By default the examples are NOT sorted alphabetically by Title.
117 void SortAlphabetically( bool sortAlphabetically );
119 private: // Application callbacks & implementation
122 * Shape enum for create function
131 * Initialize application.
133 * @param[in] app Application instance
135 void Initialize( Dali::Application& app );
138 * Populates the contents (ScrollView) with all the
139 * Examples that have been Added using the AddExample(...)
145 * Rotate callback from the device.
147 * @param[in] orientation that device notified.
149 void OrientationChanged( Dali::Orientation orientation );
152 * Rotates RootActor orientation to that specified.
154 * @param[in] degrees The requested angle.
156 void Rotate( unsigned int degrees );
159 * Creates a tile for the main menu and toolbar.
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
166 * @return The Actor for the created tile.
168 Dali::Actor CreateTile( const std::string& name, const std::string& title, const Dali::Size& parentSize, bool addBackground );
171 * Create a stencil image
173 * @return The stencil image
175 Dali::ImageActor NewStencilImage();
180 * Signal emitted when any tile has been pressed
182 * @param[in] actor The Actor representing this tile.
183 * @param[in] event The TouchEvent
185 * @return Consume flag
187 bool OnTilePressed( Dali::Actor actor, const Dali::TouchEvent& event );
190 * Signal emitted when any tile has been hovered
192 * @param[in] actor The Actor representing this tile.
193 * @param[in] event The HoverEvent
195 * @return Consume flag
197 bool OnTileHovered( Dali::Actor actor, const Dali::HoverEvent& event );
200 * Signal emitted when the pressed animation has completed.
202 * @param[in] source The animation source.
204 void OnPressedAnimationFinished(Dali::Animation& source);
207 * Signal emitted when the button has been clicked
209 * @param[in] button The Button that is clicked.
211 * @return Consume flag
213 bool OnButtonClicked( Dali::Toolkit::Button& button );
216 * Signal emitted when scrolling has started.
218 * @param[in] position The current position of the scroll contents.
220 void OnScrollStart(const Dali::Vector3& position);
223 * Signal emitted when scrolling has completed.
225 * @param[in] position The current position of the scroll contents.
227 void OnScrollComplete(const Dali::Vector3& position);
230 * Signal emitted when any Sensitive Actor has been touched
231 * (other than those touches consumed by OnTilePressed)
233 * @param[in] actor The Actor touched.
234 * @param[in] event The TouchEvent
236 * @return Consume flag
238 bool OnScrollTouched( Dali::Actor actor, const Dali::TouchEvent& event );
241 * Setup the effect on the scroll view
243 void ApplyScrollViewEffect();
246 * Setup the inner cube effect
248 void SetupInnerPageCubeEffect();
251 * Apply the scroll view effect to a page
253 void ApplyEffectToPage(Dali::Actor page, const Dali::Vector3& tableRelativeSize);
256 * Apply a custom effect scroll view effect to a page
258 void ApplyCustomEffectToPage(Dali::Actor page);
261 * Apply a shader effect to a table tile
263 void ApplyEffectToTile(Dali::Actor tile);
266 * Apply effect to the content of a tile
268 void ApplyEffectToTileContent(Dali::Actor tileContent);
273 void OnKeyEvent( const Dali::KeyEvent& event );
276 * Create a depth field background
278 * @param[in] addToLayer Add the graphics to this layer
280 void SetupBackground( Dali::Actor addToLayer, const Dali::Vector2& size );
283 * Create background actors for the given layer
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 * @param[in] size The size of the actor
290 void AddBackgroundActors( Dali::Actor layer, int count, Dali::BitmapImage distanceField, const Dali::Vector2& size );
293 * Create a bitmap with the specified shape and also output a distance field
295 * @param[in] shapeType The shape to generate
296 * @param[in] size The size of the bitmap to create
297 * @param[out] imageOut The return bitmap
298 * @param[out] distanceFieldOut The return depth field alpha map
300 void CreateShapeImage( ShapeType shapeType, const Dali::Size& size, Dali::BitmapImage& distanceFieldOut );
303 * Generate a square bit pattern and depth field
305 * @param[in] size The size of the bitmap to create
306 * @param[out] imageOut The return bitmap
307 * @param[out] distanceFieldOut The return depth field alpha map
309 void GenerateSquare( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut );
312 * Generate a circle bit pattern and depth field
314 * @param[in] size The size of the bitmap to create
315 * @param[out] imageOut The return bitmap
316 * @param[out] distanceFieldOut The return depth field alpha map
318 void GenerateCircle( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut );
323 * @param[in] imagePath The path to the image file to load
325 * @return The created image actor
327 Dali::ImageActor CreateLogo( std::string imagePath );
330 * Callback for when the logo image is loaded
332 * @param[in] image The loaded logo image
334 void OnLogoLoaded( Dali::Image image );
337 * Timer handler for ending background animation
339 * @return Return value for timer handler
341 bool PauseBackgroundAnimation();
344 * Pause all animations
346 void PauseAnimation();
349 * Resume all animations
351 void PlayAnimation();
354 * Callback when the keyboard focus is going to be changed.
356 * @param[in] current The current focused actor
357 * @param[in] proposed The actor proposed by the keyboard focus manager to move the focus to
358 * @param[in] direction The direction to move the focus
359 * @return The actor to move the keyboard focus to.
361 Dali::Actor OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocusNavigationDirection direction );
364 * Callback when the keyboard focused actor is activated.
366 * @param[in] activatedActor The activated actor
368 void OnFocusedActorActivated( Dali::Actor activatedActor );
372 Dali::Application& mApplication; ///< Application instance.
373 Dali::Layer mBackgroundLayer; ///< Background resides on a separate layer.
374 Dali::Toolkit::TableView mRootActor; ///< All content (excluding background is anchored to this Actor)
375 Dali::Animation mRotateAnimation; ///< Animation to rotate and resize mRootActor.
376 Dali::ImageActor mBackground; ///< Background's static image.
377 Dali::ImageActor mLogo; ///< Logo's static image.
378 Dali::Animation mPressedAnimation; ///< Button press scaling animation.
379 Dali::Layer mScrollViewLayer; ///< ScrollView resides on a separate layer.
380 Dali::Toolkit::ScrollView mScrollView; ///< ScrollView container (for all Examples)
381 Dali::Toolkit::ScrollViewEffect mScrollViewEffect; ///< Effect to be applied to the scroll view
382 bool mScrolling; ///< Flag indicating whether view is currently being scrolled
383 Dali::Toolkit::RulerPtr mScrollRulerX; ///< ScrollView X (horizontal) ruler
384 Dali::Toolkit::RulerPtr mScrollRulerY; ///< ScrollView Y (vertical) ruler
385 Dali::Toolkit::TableView mButtons; ///< Navigation buttons
386 ExampleList mExampleList; ///< List of examples.
387 ExampleMap mExampleMap; ///< Map LUT for examples.
388 TableViewList mTableViewList; ///< List of tableviews
389 Dali::Actor mPressedActor; ///< The currently pressed actor.
390 int mTotalPages; ///< Total pages within scrollview.
391 std::string mBackgroundImagePath; ///< The path to the background image.
392 bool mSortAlphabetically; ///< Sort examples alphabetically.
394 Dali::ActorContainer mTableViewImages; ///< Offscreen render of tableview
395 Dali::ActorContainer mBackgroundActors; ///< List of background actors used in the effect
397 AnimationList mBackgroundAnimations;///< List of background bubble animations
398 Dali::Timer mAnimationTimer; ///< Timer used to turn off animation after a specific time period
399 bool mBackgroundAnimsPlaying; ///< Are background animations playing
402 #endif // __DALI_DEMO_H__