5 * Copyright (c) 2016 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;
38 * Represents a single Example.
45 * @param[in] name unique name of example
46 * @param[in] title The caption for the example to appear on a tile button.
48 Example(std::string name, std::string title)
60 std::string name; ///< unique name of example
61 std::string title; ///< title (caption) of example to appear on tile button.
69 class DaliTableView : public Dali::ConnectionTracker
73 DaliTableView(Dali::Application& application);
79 * Adds an Example to our demo showcase
81 * @param[in] example The Example description.
83 * @note Should be called before the Application MainLoop is started.
85 void AddExample(Example example);
88 * Sorts the example list alphabetically by Title if parameter is true.
90 * @param[in] sortAlphabetically If true, example list is sorted alphabetically.
92 * @note Should be called before the Application MainLoop is started.
93 * @note By default the examples are NOT sorted alphabetically by Title.
95 void SortAlphabetically( bool sortAlphabetically );
97 private: // Application callbacks & implementation
99 static const unsigned int FOCUS_ANIMATION_ACTOR_NUMBER = 2; ///< The number of elements used to form the custom focus effect
102 * Shape enum for create function
111 * Initialize application.
113 * @param[in] app Application instance
115 void Initialize( Dali::Application& app );
118 * Populates the contents (ScrollView) with all the
119 * Examples that have been Added using the AddExample(...)
125 * Rotate callback from the device.
127 * @param[in] orientation that device notified.
129 void OrientationChanged( Dali::Orientation orientation );
132 * Rotates RootActor orientation to that specified.
134 * @param[in] degrees The requested angle.
136 void Rotate( unsigned int degrees );
139 * Creates a tile for the main menu.
141 * @param[in] name The unique name for this Tile
142 * @param[in] title The text caption that appears on the Tile
143 * @param[in] parentSize Tile's parent size.
144 * @param[in] position The tiles relative position within a page
146 * @return The Actor for the created tile.
148 Dali::Actor CreateTile( const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, Dali::Vector2& position );
153 * Signal emitted when any tile has been pressed
155 * @param[in] actor The Actor representing this tile.
156 * @param[in] event The Touch information.
158 * @return Consume flag
160 bool OnTilePressed( Dali::Actor actor, const Dali::TouchData& event );
163 * Called by OnTilePressed & Accessibility to do the appropriate action.
165 * @param[in] actor The Actor representing this tile.
166 * @param[in] state The Touch state
168 * @return Consume flag
170 bool DoTilePress( Dali::Actor actor, Dali::PointState::Type state );
173 * Signal emitted when any tile has been hovered
175 * @param[in] actor The Actor representing this tile.
176 * @param[in] event The HoverEvent
178 * @return Consume flag
180 bool OnTileHovered( Dali::Actor actor, const Dali::HoverEvent& event );
183 * Signal emitted when the pressed animation has completed.
185 * @param[in] source The animation source.
187 void OnPressedAnimationFinished(Dali::Animation& source);
190 * Signal emitted when the button has been clicked
192 * @param[in] button The Button that is clicked.
194 * @return Consume flag
196 bool OnButtonClicked( Dali::Toolkit::Button& button );
199 * Signal emitted when scrolling has started.
201 * @param[in] position The current position of the scroll contents.
203 void OnScrollStart(const Dali::Vector2& position);
206 * Signal emitted when scrolling has completed.
208 * @param[in] position The current position of the scroll contents.
210 void OnScrollComplete(const Dali::Vector2& position);
213 * Signal emitted when any Sensitive Actor has been touched
214 * (other than those touches consumed by OnTilePressed)
216 * @param[in] actor The Actor touched.
217 * @param[in] event The Touch information.
219 * @return Consume flag
221 bool OnScrollTouched( Dali::Actor actor, const Dali::TouchData& event );
224 * Setup the effect on the scroll view
226 void ApplyScrollViewEffect();
229 * Apply the cube effect to all the page actors
231 void ApplyCubeEffectToPages();
234 * Setup the inner cube effect
236 void SetupInnerPageCubeEffect();
239 * Apply a shader effect to a table tile
241 void ApplyEffectToTile(Dali::Actor tile);
244 * Apply effect to the content of a tile
246 void ApplyEffectToTileContent(Dali::Actor tileContent);
251 void OnKeyEvent( const Dali::KeyEvent& event );
254 * Create a depth field background
256 * @param[in] bubbleLayer Add the graphics to this layer
258 void SetupBackground( Dali::Actor bubbleLayer );
261 * Create background actors for the given layer
263 * @param[in] layer The layer to add the actors to
264 * @param[in] count The number of actors to generate
265 * @param[in] distanceField A array (pointer) to 2 distance field types to use
267 void AddBackgroundActors( Dali::Actor layer, int count, Dali::BufferImage* distanceField );
270 * Create a bitmap with the specified shape and also output a distance field
272 * @param[in] shapeType The shape to generate
273 * @param[in] size The size of the bitmap to create
274 * @param[out] distanceFieldOut The return depth field alpha map
276 void CreateShapeImage( ShapeType shapeType, const Dali::Size& size, Dali::BufferImage& distanceFieldOut );
279 * Generate a square bit pattern and depth field
281 * @param[in] size The size of the bitmap to create
282 * @param[out] imageOut The return bitmap
283 * @param[out] distanceFieldOut The return depth field alpha map
285 void GenerateSquare( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut );
288 * Generate a circle bit pattern and depth field
290 * @param[in] size The size of the bitmap to create
291 * @param[out] imageOut The return bitmap
292 * @param[out] distanceFieldOut The return depth field alpha map
293 * @param[in] hollow Optional - Set to true for a thick circle outline without fill
295 void GenerateCircle( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut, bool hollow = false );
300 * @param[in] imagePath The path to the image file to load
302 * @return The created image actor
304 Dali::Toolkit::ImageView CreateLogo( std::string imagePath );
307 * Timer handler for ending background animation
309 * @return Return value for timer handler
311 bool PauseBackgroundAnimation();
314 * Pause all animations
316 void PauseAnimation();
319 * Resume all animations
321 void PlayAnimation();
324 * @brief Creates and sets up the custom effect used for the keyboard (and mouse) focus.
326 void CreateFocusEffect();
329 * Callback when the keyboard focus is going to be changed.
331 * @param[in] current The current focused actor
332 * @param[in] proposed The actor proposed by the keyboard focus manager to move the focus to
333 * @param[in] direction The direction to move the focus
334 * @return The actor to move the keyboard focus to.
336 Dali::Actor OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction );
339 * Callback when the keyboard focused actor is activated.
341 * @param[in] activatedActor The activated actor
343 void OnFocusedActorActivated( Dali::Actor activatedActor );
346 * Called when the logo is tapped
348 * @param[in] actor The tapped actor
349 * @param[in] tap The tap information.
351 void OnLogoTapped( Dali::Actor actor, const Dali::TapGesture& tap );
356 void HideVersionPopup();
359 * @brief Callback called when the buttons page actor is relaid out
361 * @param[in] actor The page actor
363 void OnButtonsPageRelayout( const Dali::Actor& actor );
366 * @brief The is connected to the keyboard focus highlight actor, and called when it is placed on stage.
367 * @param[in] actor The actor that has been placed on stage.
369 void OnStageConnect( Dali::Actor actor );
372 * @brief Callback called to set up background actors
374 * @param[in] actor The actor raising the callback
376 void InitialiseBackgroundActors( Dali::Actor actor );
380 Dali::Application& mApplication; ///< Application instance.
381 Dali::Toolkit::Control mRootActor; ///< All content (excluding background is anchored to this Actor)
382 Dali::Animation mRotateAnimation; ///< Animation to rotate and resize mRootActor.
383 Dali::Animation mPressedAnimation; ///< Button press scaling animation.
384 Dali::Toolkit::ScrollView mScrollView; ///< ScrollView container (for all Examples)
385 Dali::Toolkit::ScrollViewEffect mScrollViewEffect; ///< Effect to be applied to the scroll view
386 Dali::Toolkit::RulerPtr mScrollRulerX; ///< ScrollView X (horizontal) ruler
387 Dali::Toolkit::RulerPtr mScrollRulerY; ///< ScrollView Y (vertical) ruler
388 Dali::Actor mPressedActor; ///< The currently pressed actor.
389 Dali::Timer mAnimationTimer; ///< Timer used to turn off animation after a specific time period
390 Dali::TapGestureDetector mLogoTapDetector; ///< To detect taps on the logo
391 Dali::Toolkit::Popup mVersionPopup; ///< Displays DALi library version information
394 * This struct encapsulates all data relevant to each of the elements used within the custom keyboard focus effect.
398 Dali::Toolkit::ImageView actor; ///< The parent keyboard focus highlight actor
399 Dali::Animation animation; ///< The animation for the parent keyboard focus highlight actor
401 FocusEffect mFocusEffect[FOCUS_ANIMATION_ACTOR_NUMBER]; ///< The elements used to create the custom focus effect
403 std::vector< Dali::Actor > mPages; ///< List of pages.
404 AnimationList mBackgroundAnimations; ///< List of background bubble animations
405 ExampleList mExampleList; ///< List of examples.
407 float mPageWidth; ///< The width of a page within the scroll-view, used to calculate the domain
408 int mTotalPages; ///< Total pages within scrollview.
410 bool mScrolling:1; ///< Flag indicating whether view is currently being scrolled
411 bool mSortAlphabetically:1; ///< Sort examples alphabetically.
412 bool mBackgroundAnimsPlaying:1; ///< Are background animations playing
416 #endif // DALI_DEMO_H