1 #ifndef __DALI_DEMO_H__
2 #define __DALI_DEMO_H__
5 * Copyright (c) 2015 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>
23 #include <dali-toolkit/devel-api/controls/popup/popup.h>
27 typedef std::vector<Example> ExampleList;
28 typedef ExampleList::iterator ExampleListIter;
29 typedef ExampleList::const_iterator ExampleListConstIter;
31 typedef std::vector<Dali::Animation> AnimationList;
32 typedef AnimationList::iterator AnimationListIter;
33 typedef AnimationList::const_iterator AnimationListConstIter;
39 * Represents a single Example.
46 * @param[in] name unique name of example
47 * @param[in] title The caption for the example to appear on a tile button.
49 Example(std::string name, std::string title)
61 std::string name; ///< unique name of example
62 std::string title; ///< title (caption) of example to appear on tile button.
70 class DaliTableView : public Dali::ConnectionTracker
74 DaliTableView(Dali::Application& application);
80 * Adds an Example to our demo showcase
82 * @param[in] example The Example description.
84 * @note Should be called before the Application MainLoop is started.
86 void AddExample(Example example);
89 * Sorts the example list alphabetically by Title if parameter is true.
91 * @param[in] sortAlphabetically If true, example list is sorted alphabetically.
93 * @note Should be called before the Application MainLoop is started.
94 * @note By default the examples are NOT sorted alphabetically by Title.
96 void SortAlphabetically( bool sortAlphabetically );
98 private: // Application callbacks & implementation
101 * Shape enum for create function
110 * Initialize application.
112 * @param[in] app Application instance
114 void Initialize( Dali::Application& app );
117 * Populates the contents (ScrollView) with all the
118 * Examples that have been Added using the AddExample(...)
124 * Rotate callback from the device.
126 * @param[in] orientation that device notified.
128 void OrientationChanged( Dali::Orientation orientation );
131 * Rotates RootActor orientation to that specified.
133 * @param[in] degrees The requested angle.
135 void Rotate( unsigned int degrees );
138 * Creates a tile for the main menu.
140 * @param[in] name The unique name for this Tile
141 * @param[in] title The text caption that appears on the Tile
142 * @param[in] parentSize Tile's parent size.
143 * @param[in] position The tiles relative position within a page
145 * @return The Actor for the created tile.
147 Dali::Actor CreateTile( const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, Dali::Vector2& position );
152 * Signal emitted when any tile has been pressed
154 * @param[in] actor The Actor representing this tile.
155 * @param[in] event The Touch information.
157 * @return Consume flag
159 bool OnTilePressed( Dali::Actor actor, const Dali::TouchData& event );
162 * Called by OnTilePressed & Accessibility to do the appropriate action.
164 * @param[in] actor The Actor representing this tile.
165 * @param[in] state The Touch state
167 * @return Consume flag
169 bool DoTilePress( Dali::Actor actor, Dali::PointState::Type state );
172 * Signal emitted when any tile has been hovered
174 * @param[in] actor The Actor representing this tile.
175 * @param[in] event The HoverEvent
177 * @return Consume flag
179 bool OnTileHovered( Dali::Actor actor, const Dali::HoverEvent& event );
182 * Signal emitted when the pressed animation has completed.
184 * @param[in] source The animation source.
186 void OnPressedAnimationFinished(Dali::Animation& source);
189 * Signal emitted when the button has been clicked
191 * @param[in] button The Button that is clicked.
193 * @return Consume flag
195 bool OnButtonClicked( Dali::Toolkit::Button& button );
198 * Signal emitted when scrolling has started.
200 * @param[in] position The current position of the scroll contents.
202 void OnScrollStart(const Dali::Vector2& position);
205 * Signal emitted when scrolling has completed.
207 * @param[in] position The current position of the scroll contents.
209 void OnScrollComplete(const Dali::Vector2& position);
212 * Signal emitted when any Sensitive Actor has been touched
213 * (other than those touches consumed by OnTilePressed)
215 * @param[in] actor The Actor touched.
216 * @param[in] event The Touch information.
218 * @return Consume flag
220 bool OnScrollTouched( Dali::Actor actor, const Dali::TouchData& event );
223 * Setup the effect on the scroll view
225 void ApplyScrollViewEffect();
228 * Apply the cube effect to all the page actors
230 void ApplyCubeEffectToPages();
233 * Setup the inner cube effect
235 void SetupInnerPageCubeEffect();
238 * Apply a shader effect to a table tile
240 void ApplyEffectToTile(Dali::Actor tile);
243 * Apply effect to the content of a tile
245 void ApplyEffectToTileContent(Dali::Actor tileContent);
250 void OnKeyEvent( const Dali::KeyEvent& event );
253 * Create a depth field background
255 * @param[in] bubbleLayer Add the graphics to this layer
257 void SetupBackground( Dali::Actor bubbleLayer );
260 * Create background actors for the given layer
262 * @param[in] layer The layer to add the actors to
263 * @param[in] count The number of actors to generate
264 * @param[in] distanceField A array (pointer) to 2 distance field types to use
266 void AddBackgroundActors( Dali::Actor layer, int count, Dali::BufferImage* distanceField );
269 * Create a bitmap with the specified shape and also output a distance field
271 * @param[in] shapeType The shape to generate
272 * @param[in] size The size of the bitmap to create
273 * @param[out] distanceFieldOut The return depth field alpha map
275 void CreateShapeImage( ShapeType shapeType, const Dali::Size& size, Dali::BufferImage& distanceFieldOut );
278 * Generate a square bit pattern and depth field
280 * @param[in] size The size of the bitmap to create
281 * @param[out] imageOut The return bitmap
282 * @param[out] distanceFieldOut The return depth field alpha map
284 void GenerateSquare( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut );
287 * Generate a circle bit pattern and depth field
289 * @param[in] size The size of the bitmap to create
290 * @param[out] imageOut The return bitmap
291 * @param[out] distanceFieldOut The return depth field alpha map
292 * @param[in] hollow Optional - Set to true for a thick circle outline without fill
294 void GenerateCircle( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut, bool hollow = false );
299 * @param[in] imagePath The path to the image file to load
301 * @return The created image actor
303 Dali::Toolkit::ImageView CreateLogo( std::string imagePath );
306 * Timer handler for ending background animation
308 * @return Return value for timer handler
310 bool PauseBackgroundAnimation();
313 * Pause all animations
315 void PauseAnimation();
318 * Resume all animations
320 void PlayAnimation();
323 * Callback when the keyboard focus is going to be changed.
325 * @param[in] current The current focused actor
326 * @param[in] proposed The actor proposed by the keyboard focus manager to move the focus to
327 * @param[in] direction The direction to move the focus
328 * @return The actor to move the keyboard focus to.
330 Dali::Actor OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction );
333 * Callback when the keyboard focused actor is activated.
335 * @param[in] activatedActor The activated actor
337 void OnFocusedActorActivated( Dali::Actor activatedActor );
340 * Called when the logo is tapped
342 * @param[in] actor The tapped actor
343 * @param[in] tap The tap information.
345 void OnLogoTapped( Dali::Actor actor, const Dali::TapGesture& tap );
350 void HideVersionPopup();
353 * @brief Callback called when the buttons page actor is relaid out
355 * @param[in] actor The page actor
357 void OnButtonsPageRelayout( const Dali::Actor& actor );
360 * @brief The is connected to the keyboard focus highlight actor, and called when it is placed on stage.
361 * @param[in] actor The actor that has been placed on stage.
363 void OnStageConnect( Dali::Actor actor );
366 * @brief Callback called to set up background actors
368 * @param[in] actor The actor raising the callback
370 void InitialiseBackgroundActors( Dali::Actor actor );
374 Dali::Application& mApplication; ///< Application instance.
375 Dali::Toolkit::Control mRootActor; ///< All content (excluding background is anchored to this Actor)
376 Dali::Animation mRotateAnimation; ///< Animation to rotate and resize mRootActor.
377 Dali::Animation mPressedAnimation; ///< Button press scaling animation.
378 Dali::Toolkit::ScrollView mScrollView; ///< ScrollView container (for all Examples)
379 Dali::Toolkit::ScrollViewEffect mScrollViewEffect; ///< Effect to be applied to the scroll view
380 Dali::Toolkit::RulerPtr mScrollRulerX; ///< ScrollView X (horizontal) ruler
381 Dali::Toolkit::RulerPtr mScrollRulerY; ///< ScrollView Y (vertical) ruler
382 Dali::Actor mPressedActor; ///< The currently pressed actor.
383 Dali::Timer mAnimationTimer; ///< Timer used to turn off animation after a specific time period
384 Dali::TapGestureDetector mLogoTapDetector; ///< To detect taps on the logo
385 Dali::Toolkit::Popup mVersionPopup; ///< Displays DALi library version information
387 Dali::Toolkit::ImageView mFocusContainer; ///< The parent keyboard focus highlight actor
388 Dali::Toolkit::ImageView mFocusInner; ///< The child keyboard focus highlight actor
389 Dali::Animation mFocusAnimation; ///< The animation for the parent keyboard focus highlight actor
390 Dali::Animation mFocusAnimationInner; ///< The animation for the child keyboard focus highlight actor
392 std::vector< Dali::Actor > mPages; ///< List of pages.
393 AnimationList mBackgroundAnimations; ///< List of background bubble animations
394 ExampleList mExampleList; ///< List of examples.
396 float mPageWidth; ///< The width of a page within the scroll-view, used to calculate the domain
397 int mTotalPages; ///< Total pages within scrollview.
399 bool mScrolling:1; ///< Flag indicating whether view is currently being scrolled
400 bool mSortAlphabetically:1; ///< Sort examples alphabetically.
401 bool mBackgroundAnimsPlaying:1; ///< Are background animations playing
405 #endif // __DALI_DEMO_H__