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.
21 #include <dali/dali.h>
22 #include <dali-toolkit/dali-toolkit.h>
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;
33 typedef std::vector<Dali::Toolkit::TableView> TableViewList;
34 typedef TableViewList::iterator TableViewListIter;
35 typedef TableViewList::const_iterator TableViewListConstIter;
37 typedef std::vector<Dali::ImageActor> ImageActorList;
38 typedef ImageActorList::iterator ImageActorListIter;
39 typedef ImageActorList::const_iterator ImageActorListConstIter;
41 typedef std::vector<Dali::Animation> AnimationList;
42 typedef AnimationList::iterator AnimationListIter;
43 typedef AnimationList::const_iterator AnimationListConstIter;
49 * Represents a single Example.
56 * @param[in] name unique name of example
57 * @param[in] title The caption for the example to appear on a tile button.
59 Example(std::string name, std::string title)
71 std::string name; ///< unique name of example
72 std::string title; ///< title (caption) of example to appear on tile button.
80 class DaliTableView : public Dali::ConnectionTracker
84 DaliTableView(Dali::Application& application);
90 * Adds an Example to our demo showcase
92 * @param[in] example The Example description.
94 * @note Should be called before the Application MainLoop is started.
96 void AddExample(Example example);
99 * Sets the background image PATH.
101 * @param[in] imagePath The file path to the image to use as the background.
103 * @note Should be called before the Application MainLoop is started.
105 void SetBackgroundPath( std::string imagePath );
108 * Sorts the example list alphabetically by Title if parameter is true.
110 * @param[in] sortAlphabetically If true, example list is sorted alphabetically.
112 * @note Should be called before the Application MainLoop is started.
113 * @note By default the examples are NOT sorted alphabetically by Title.
115 void SortAlphabetically( bool sortAlphabetically );
117 private: // Application callbacks & implementation
120 * Shape enum for create function
129 * Initialize application.
131 * @param[in] app Application instance
133 void Initialize( Dali::Application& app );
136 * Populates the contents (ScrollView) with all the
137 * Examples that have been Added using the AddExample(...)
143 * Rotate callback from the device.
145 * @param[in] orientation that device notified.
147 void OrientationChanged( Dali::Orientation orientation );
150 * Rotates RootActor orientation to that specified.
152 * @param[in] degrees The requested angle.
154 void Rotate( unsigned int degrees );
157 * Creates a tile for the main menu and toolbar.
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
164 * @return The Actor for the created tile.
166 Dali::Actor CreateTile( const std::string& name, const std::string& title, const Dali::Size& parentSize, bool addBackground );
169 * Create a stencil image
171 * @return The stencil image
173 Dali::ImageActor NewStencilImage();
178 * Signal emitted when any tile has been pressed
180 * @param[in] actor The Actor representing this tile.
181 * @param[in] event The TouchEvent
183 * @return Consume flag
185 bool OnTilePressed( Dali::Actor actor, const Dali::TouchEvent& event );
188 * Signal emitted when the pressed animation has completed.
190 * @param[in] source The animation source.
192 void OnPressedAnimationFinished(Dali::Animation& source);
195 * Signal emitted when the button has been clicked
197 * @param[in] button The Button that is clicked.
199 * @return Consume flag
201 bool OnButtonClicked( Dali::Toolkit::Button& button );
204 * Signal emitted when scrolling has started.
206 * @param[in] position The current position of the scroll contents.
208 void OnScrollStart(const Dali::Vector3& position);
211 * Signal emitted when scrolling has completed.
213 * @param[in] position The current position of the scroll contents.
215 void OnScrollComplete(const Dali::Vector3& position);
218 * Signal emitted when any Sensitive Actor has been touched
219 * (other than those touches consumed by OnTilePressed)
221 * @param[in] actor The Actor touched.
222 * @param[in] event The TouchEvent
224 * @return Consume flag
226 bool OnScrollTouched( Dali::Actor actor, const Dali::TouchEvent& event );
229 * Setup the effect on the scroll view
231 void ApplyScrollViewEffect();
234 * Setup the inner cube effect
236 void SetupInnerPageCubeEffect();
239 * Apply the scroll view effect to a page
241 void ApplyEffectToPage(Dali::Actor page, const Dali::Vector3& tableRelativeSize);
244 * Apply a custom effect scroll view effect to a page
246 void ApplyCustomEffectToPage(Dali::Actor page);
249 * Apply a shader effect to a table tile
251 void ApplyEffectToTile(Dali::Actor tile);
254 * Apply effect to the content of a tile
256 void ApplyEffectToTileContent(Dali::Actor tileContent);
261 void OnKeyEvent( const Dali::KeyEvent& event );
264 * Create a depth field background
266 * @param[in] addToLayer Add the graphics to this layer
268 void SetupBackground( Dali::Actor addToLayer, const Dali::Vector2& size );
271 * Create background actors for the given layer
273 * @param[in] layer The layer to add the actors to
274 * @param[in] count The number of actors to generate
275 * @param[in] distanceField The distance field bitmap to use
276 * @param[in] size The size of the actor
278 void AddBackgroundActors( Dali::Actor layer, int count, Dali::BitmapImage distanceField, const Dali::Vector2& size );
281 * Create a bitmap with the specified shape and also output a distance field
283 * @param[in] shapeType The shape to generate
284 * @param[in] size The size of the bitmap to create
285 * @param[out] imageOut The return bitmap
286 * @param[out] distanceFieldOut The return depth field alpha map
288 void CreateShapeImage( ShapeType shapeType, const Dali::Size& size, Dali::BitmapImage& distanceFieldOut );
291 * Generate a square bit pattern and depth field
293 * @param[in] size The size of the bitmap to create
294 * @param[out] imageOut The return bitmap
295 * @param[out] distanceFieldOut The return depth field alpha map
297 void GenerateSquare( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut );
300 * Generate a circle bit pattern and depth field
302 * @param[in] size The size of the bitmap to create
303 * @param[out] imageOut The return bitmap
304 * @param[out] distanceFieldOut The return depth field alpha map
306 void GenerateCircle( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut );
311 * @param[in] imagePath The path to the image file to load
313 * @return The created image actor
315 Dali::ImageActor CreateLogo( std::string imagePath );
318 * Callback for when the logo image is loaded
320 * @param[in] image The loaded logo image
322 void OnLogoLoaded( Dali::Image image );
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 );
360 Dali::Application& mApplication; ///< Application instance.
361 Dali::Layer mBackgroundLayer; ///< Background resides on a separate layer.
362 Dali::Toolkit::TableView mRootActor; ///< All content (excluding background is anchored to this Actor)
363 Dali::Animation mRotateAnimation; ///< Animation to rotate and resize mRootActor.
364 Dali::ImageActor mBackground; ///< Background's static image.
365 Dali::ImageActor mLogo; ///< Logo's static image.
366 Dali::Animation mPressedAnimation; ///< Button press scaling animation.
367 Dali::Layer mScrollViewLayer; ///< ScrollView resides on a separate layer.
368 Dali::Toolkit::ScrollView mScrollView; ///< ScrollView container (for all Examples)
369 Dali::Toolkit::ScrollViewEffect mScrollViewEffect; ///< Effect to be applied to the scroll view
370 bool mScrolling; ///< Flag indicating whether view is currently being scrolled
371 Dali::Toolkit::RulerPtr mScrollRulerX; ///< ScrollView X (horizontal) ruler
372 Dali::Toolkit::RulerPtr mScrollRulerY; ///< ScrollView Y (vertical) ruler
373 Dali::Toolkit::TableView mButtons; ///< Navigation buttons
374 ExampleList mExampleList; ///< List of examples.
375 ExampleMap mExampleMap; ///< Map LUT for examples.
376 TableViewList mTableViewList; ///< List of tableviews
377 Dali::Actor mPressedActor; ///< The currently pressed actor.
378 int mTotalPages; ///< Total pages within scrollview.
379 std::string mBackgroundImagePath; ///< The path to the background image.
380 bool mSortAlphabetically; ///< Sort examples alphabetically.
382 Dali::ActorContainer mTableViewImages; ///< Offscreen render of tableview
383 Dali::ActorContainer mBackgroundActors; ///< List of background actors used in the effect
385 AnimationList mBackgroundAnimations;///< List of background bubble animations
386 Dali::Timer mAnimationTimer; ///< Timer used to turn off animation after a specific time period
387 bool mBackgroundAnimsPlaying; ///< Are background animations playing
390 #endif // __DALI_DEMO_H__