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>
25 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
26 #include <dali-toolkit/devel-api/controls/popup/popup.h>
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;
37 typedef std::vector<Dali::Toolkit::TableView> TableViewList;
38 typedef TableViewList::iterator TableViewListIter;
39 typedef TableViewList::const_iterator TableViewListConstIter;
41 typedef std::vector<Dali::ImageActor> ImageActorList;
42 typedef ImageActorList::iterator ImageActorListIter;
43 typedef ImageActorList::const_iterator ImageActorListConstIter;
45 typedef std::vector<Dali::Animation> AnimationList;
46 typedef AnimationList::iterator AnimationListIter;
47 typedef AnimationList::const_iterator AnimationListConstIter;
53 * Represents a single Example.
60 * @param[in] name unique name of example
61 * @param[in] title The caption for the example to appear on a tile button.
63 Example(std::string name, std::string title)
75 std::string name; ///< unique name of example
76 std::string title; ///< title (caption) of example to appear on tile button.
84 class DaliTableView : public Dali::ConnectionTracker
88 DaliTableView(Dali::Application& application);
94 * Adds an Example to our demo showcase
96 * @param[in] example The Example description.
98 * @note Should be called before the Application MainLoop is started.
100 void AddExample(Example example);
103 * Sets the background image PATH.
105 * @param[in] imagePath The file path to the image to use as the background.
107 * @note Should be called before the Application MainLoop is started.
109 void SetBackgroundPath( std::string imagePath );
112 * Sorts the example list alphabetically by Title if parameter is true.
114 * @param[in] sortAlphabetically If true, example list is sorted alphabetically.
116 * @note Should be called before the Application MainLoop is started.
117 * @note By default the examples are NOT sorted alphabetically by Title.
119 void SortAlphabetically( bool sortAlphabetically );
121 private: // Application callbacks & implementation
124 * Shape enum for create function
133 * Initialize application.
135 * @param[in] app Application instance
137 void Initialize( Dali::Application& app );
140 * Populates the contents (ScrollView) with all the
141 * Examples that have been Added using the AddExample(...)
147 * Rotate callback from the device.
149 * @param[in] orientation that device notified.
151 void OrientationChanged( Dali::Orientation orientation );
154 * Rotates RootActor orientation to that specified.
156 * @param[in] degrees The requested angle.
158 void Rotate( unsigned int degrees );
161 * Creates a tile for the main menu and toolbar.
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
168 * @return The Actor for the created tile.
170 Dali::Actor CreateTile( const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, bool addBackground );
173 * Create a stencil image
175 * @return The stencil image
177 Dali::ImageActor NewStencilImage();
182 * Signal emitted when any tile has been pressed
184 * @param[in] actor The Actor representing this tile.
185 * @param[in] event The TouchEvent
187 * @return Consume flag
189 bool OnTilePressed( Dali::Actor actor, const Dali::TouchEvent& event );
192 * Signal emitted when any tile has been hovered
194 * @param[in] actor The Actor representing this tile.
195 * @param[in] event The HoverEvent
197 * @return Consume flag
199 bool OnTileHovered( Dali::Actor actor, const Dali::HoverEvent& event );
202 * Signal emitted when the pressed animation has completed.
204 * @param[in] source The animation source.
206 void OnPressedAnimationFinished(Dali::Animation& source);
209 * Signal emitted when the button has been clicked
211 * @param[in] button The Button that is clicked.
213 * @return Consume flag
215 bool OnButtonClicked( Dali::Toolkit::Button& button );
218 * Signal emitted when scrolling has started.
220 * @param[in] position The current position of the scroll contents.
222 void OnScrollStart(const Dali::Vector2& position);
225 * Signal emitted when scrolling has completed.
227 * @param[in] position The current position of the scroll contents.
229 void OnScrollComplete(const Dali::Vector2& position);
232 * Signal emitted when any Sensitive Actor has been touched
233 * (other than those touches consumed by OnTilePressed)
235 * @param[in] actor The Actor touched.
236 * @param[in] event The TouchEvent
238 * @return Consume flag
240 bool OnScrollTouched( Dali::Actor actor, const Dali::TouchEvent& event );
243 * Setup the effect on the scroll view
245 void ApplyScrollViewEffect();
248 * Apply the cube effect to all the page actors
250 void ApplyCubeEffectToPages();
253 * Setup the inner cube effect
255 void SetupInnerPageCubeEffect();
258 * Apply a shader effect to a table tile
260 void ApplyEffectToTile(Dali::Actor tile);
263 * Apply effect to the content of a tile
265 void ApplyEffectToTileContent(Dali::Actor tileContent);
270 void OnKeyEvent( const Dali::KeyEvent& event );
273 * Create a depth field background
275 * @param[in] bubbleLayer Add the graphics to this layer
277 void SetupBackground( Dali::Actor bubbleLayer );
280 * Create background actors for the given layer
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
286 void AddBackgroundActors( Dali::Actor layer, int count, Dali::BufferImage distanceField );
289 * Create a bitmap with the specified shape and also output a distance field
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
295 void CreateShapeImage( ShapeType shapeType, const Dali::Size& size, Dali::BufferImage& distanceFieldOut );
298 * Generate a square bit pattern and depth field
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
304 void GenerateSquare( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut );
307 * Generate a circle bit pattern and depth field
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
313 void GenerateCircle( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut );
318 * @param[in] imagePath The path to the image file to load
320 * @return The created image actor
322 Dali::ImageActor CreateLogo( std::string imagePath );
325 * Timer handler for ending background animation
327 * @return Return value for timer handler
329 bool PauseBackgroundAnimation();
332 * Pause all animations
334 void PauseAnimation();
337 * Resume all animations
339 void PlayAnimation();
342 * Callback when the keyboard focus is going to be changed.
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.
349 Dali::Actor OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocusNavigationDirection direction );
352 * Callback when the keyboard focused actor is activated.
354 * @param[in] activatedActor The activated actor
356 void OnFocusedActorActivated( Dali::Actor activatedActor );
359 * Called when the logo is tapped
361 * @param[in] actor The tapped actor
362 * @param[in] tap The tap information.
364 void OnLogoTapped( Dali::Actor actor, const Dali::TapGesture& tap );
369 void HideVersionPopup();
372 * Called when the popup is completely hidden
377 * @brief Callback called when the buttons page actor is relaid out
379 * @param[in] actor The page actor
381 void OnButtonsPageRelayout( const Dali::Actor& actor );
384 * @brief Callback called to set up background actors
386 * @param[in] actor The actor raising the callback
388 void InitialiseBackgroundActors( Dali::Actor actor );
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
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.
417 std::string mBackgroundImagePath; ///< The path to the background image.
418 int mTotalPages; ///< Total pages within scrollview.
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
427 #endif // __DALI_DEMO_H__