dali-table-view.h 12.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
#ifndef __DALI_DEMO_H__
#define __DALI_DEMO_H__

/*
 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <map>

#include <dali/dali.h>
#include <dali-toolkit/dali-toolkit.h>
#include <dali-toolkit/devel-api/controls/popup/popup.h>

class Example;

typedef std::vector<Example> ExampleList;
typedef std::map<std::string,Example> ExampleMap;
typedef ExampleList::iterator ExampleListIter;
typedef ExampleList::const_iterator ExampleListConstIter;
typedef ExampleMap::iterator ExampleMapIter;
typedef ExampleMap::const_iterator ExampleMapConstIter;

typedef std::vector<Dali::Toolkit::TableView> TableViewList;
typedef TableViewList::iterator TableViewListIter;
typedef TableViewList::const_iterator TableViewListConstIter;

typedef std::vector<Dali::ImageActor> ImageActorList;
typedef ImageActorList::iterator ImageActorListIter;
typedef ImageActorList::const_iterator ImageActorListConstIter;

typedef std::vector<Dali::Animation> AnimationList;
typedef AnimationList::iterator AnimationListIter;
typedef AnimationList::const_iterator AnimationListConstIter;


/**
 * Example information
 *
 * Represents a single Example.
 */
struct Example
{
  // Constructors

  /**
   * @param[in] name unique name of example
   * @param[in] title The caption for the example to appear on a tile button.
   */
  Example(std::string name, std::string title)
  : name(name),
    title(title)
  {
  }

  Example()
  {
  }

  // Data

  std::string name;                       ///< unique name of example
  std::string title;                      ///< title (caption) of example to appear on tile button.
};



/**
 * Dali-Demo instance
 */
class DaliTableView : public Dali::ConnectionTracker
{
public:

  DaliTableView(Dali::Application& application);
  ~DaliTableView();

public:

  /**
   * Adds an Example to our demo showcase
   *
   * @param[in] example The Example description.
   *
   * @note Should be called before the Application MainLoop is started.
   */
  void AddExample(Example example);

  /**
   * Sets the background image PATH.
   *
   * @param[in] imagePath The file path to the image to use as the background.
   *
   * @note Should be called before the Application MainLoop is started.
   */
  void SetBackgroundPath( std::string imagePath );

  /**
   * Sorts the example list alphabetically by Title if parameter is true.
   *
   * @param[in] sortAlphabetically If true, example list is sorted alphabetically.
   *
   * @note Should be called before the Application MainLoop is started.
   * @note By default the examples are NOT sorted alphabetically by Title.
   */
  void SortAlphabetically( bool sortAlphabetically );

private: // Application callbacks & implementation

  /**
   * Shape enum for create function
   */
  enum ShapeType
  {
    CIRCLE,
    SQUARE
  };

  /**
   * Initialize application.
   *
   * @param[in] app Application instance
   */
  void Initialize( Dali::Application& app );

  /**
   * Populates the contents (ScrollView) with all the
   * Examples that have been Added using the AddExample(...)
   * call
   */
  void Populate();

  /**
   * Rotate callback from the device.
   *
   * @param[in] orientation that device notified.
   */
  void OrientationChanged( Dali::Orientation orientation );

  /**
   * Rotates RootActor orientation to that specified.
   *
   * @param[in] degrees The requested angle.
   */
  void Rotate( unsigned int degrees );

  /**
   * Creates a tile for the main menu and toolbar.
   *
   * @param[in] name The unique name for this Tile
   * @param[in] title The text caption that appears on the Tile
   * @param[in] parentSize Tile's parent size.
   * @param[in] addBackground Whether to add a background graphic to the tile or not
   *
   * @return The Actor for the created tile.
   */
  Dali::Actor CreateTile( const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, bool addBackground );

  /**
   * Create a stencil image
   *
   * @return The stencil image
   */
  Dali::ImageActor NewStencilImage();

  // Signal handlers

  /**
   * Signal emitted when any tile has been pressed
   *
   * @param[in] actor The Actor representing this tile.
   * @param[in] event The TouchEvent
   *
   * @return Consume flag
   */
  bool OnTilePressed( Dali::Actor actor, const Dali::TouchEvent& event );

  /**
   * Signal emitted when any tile has been hovered
   *
   * @param[in] actor The Actor representing this tile.
   * @param[in] event The HoverEvent
   *
   * @return Consume flag
   */
  bool OnTileHovered( Dali::Actor actor, const Dali::HoverEvent& event );

  /**
   * Signal emitted when the pressed animation has completed.
   *
   * @param[in] source The animation source.
   */
  void OnPressedAnimationFinished(Dali::Animation& source);

  /**
   * Signal emitted when the button has been clicked
   *
   * @param[in] button The Button that is clicked.
   *
   * @return Consume flag
   */
  bool OnButtonClicked( Dali::Toolkit::Button& button );

  /**
   * Signal emitted when scrolling has started.
   *
   * @param[in] position The current position of the scroll contents.
   */
  void OnScrollStart(const Dali::Vector2& position);

  /**
   * Signal emitted when scrolling has completed.
   *
   * @param[in] position The current position of the scroll contents.
   */
  void OnScrollComplete(const Dali::Vector2& position);

  /**
   * Signal emitted when any Sensitive Actor has been touched
   * (other than those touches consumed by OnTilePressed)
   *
   * @param[in] actor The Actor touched.
   * @param[in] event The TouchEvent
   *
   * @return Consume flag
   */
  bool OnScrollTouched( Dali::Actor actor, const Dali::TouchEvent& event );

  /**
   * Setup the effect on the scroll view
   */
  void ApplyScrollViewEffect();

  /**
   * Apply the cube effect to all the page actors
   */
  void ApplyCubeEffectToPages();

  /**
   * Setup the inner cube effect
   */
  void SetupInnerPageCubeEffect();

  /**
   * Apply a shader effect to a table tile
   */
  void ApplyEffectToTile(Dali::Actor tile);

  /**
   * Apply effect to the content of a tile
   */
  void ApplyEffectToTileContent(Dali::Actor tileContent);

  /**
   * Key event handler
   */
  void OnKeyEvent( const Dali::KeyEvent& event );

  /**
   * Create a depth field background
   *
   * @param[in] bubbleLayer Add the graphics to this layer
   */
  void SetupBackground( Dali::Actor bubbleLayer );

  /**
   * Create background actors for the given layer
   *
   * @param[in] layer The layer to add the actors to
   * @param[in] count The number of actors to generate
   * @param[in] distanceField The distance field bitmap to use
   */
  void AddBackgroundActors( Dali::Actor layer, int count, Dali::BufferImage distanceField );

  /**
   * Create a bitmap with the specified shape and also output a distance field
   *
   * @param[in] shapeType The shape to generate
   * @param[in] size The size of the bitmap to create
   * @param[out] distanceFieldOut The return depth field alpha map
   */
  void CreateShapeImage( ShapeType shapeType, const Dali::Size& size, Dali::BufferImage& distanceFieldOut );

  /**
   * Generate a square bit pattern and depth field
   *
   * @param[in] size The size of the bitmap to create
   * @param[out] imageOut The return bitmap
   * @param[out] distanceFieldOut The return depth field alpha map
   */
  void GenerateSquare( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut );

  /**
   * Generate a circle bit pattern and depth field
   *
   * @param[in] size The size of the bitmap to create
   * @param[out] imageOut The return bitmap
   * @param[out] distanceFieldOut The return depth field alpha map
   */
  void GenerateCircle( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut );

  /**
   * Creates the logo.
   *
   * @param[in] imagePath The path to the image file to load
   *
   * @return The created image actor
   */
  Dali::ImageActor CreateLogo( std::string imagePath );

  /**
   * Timer handler for ending background animation
   *
   * @return Return value for timer handler
   */
  bool PauseBackgroundAnimation();

  /**
   * Pause all animations
   */
  void PauseAnimation();

  /**
   * Resume all animations
   */
  void PlayAnimation();

  /**
   * Callback when the keyboard focus is going to be changed.
   *
   * @param[in] current The current focused actor
   * @param[in] proposed The actor proposed by the keyboard focus manager to move the focus to
   * @param[in] direction The direction to move the focus
   * @return The actor to move the keyboard focus to.
   */
  Dali::Actor OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction );

  /**
   * Callback when the keyboard focused actor is activated.
   *
   * @param[in] activatedActor The activated actor
   */
  void OnFocusedActorActivated( Dali::Actor activatedActor );

  /**
   * Called when the logo is tapped
   *
   * @param[in]  actor  The tapped actor
   * @param[in]  tap    The tap information.
   */
  void OnLogoTapped( Dali::Actor actor, const Dali::TapGesture& tap );

  /**
   * Hides the popup
   */
  void HideVersionPopup();

  /**
   * Called when the popup is completely hidden
   */
  void PopupHidden();

 /*
  * @brief Callback called when the buttons page actor is relaid out
  *
  * @param[in] actor The page actor
  */
 void OnButtonsPageRelayout( const Dali::Actor& actor );

 /**
  * @brief Callback called to set up background actors
  *
  * @param[in] actor The actor raising the callback
  */
 void InitialiseBackgroundActors( Dali::Actor actor );

private:

  Dali::Application&              mApplication;              ///< Application instance.
  Dali::Layer                     mBackgroundLayer;          ///< Background resides on a separate layer.
  Dali::Toolkit::TableView        mRootActor;                ///< All content (excluding background is anchored to this Actor)
  Dali::Animation                 mRotateAnimation;          ///< Animation to rotate and resize mRootActor.
  Dali::ImageActor                mBackground;               ///< Background's static image.
  Dali::Animation                 mPressedAnimation;         ///< Button press scaling animation.
  Dali::Layer                     mScrollViewLayer;          ///< ScrollView resides on a separate layer.
  Dali::Toolkit::ScrollView       mScrollView;               ///< ScrollView container (for all Examples)
  Dali::Toolkit::ScrollViewEffect mScrollViewEffect;         ///< Effect to be applied to the scroll view
  Dali::Toolkit::RulerPtr         mScrollRulerX;             ///< ScrollView X (horizontal) ruler
  Dali::Toolkit::RulerPtr         mScrollRulerY;             ///< ScrollView Y (vertical) ruler
  Dali::Toolkit::TableView        mButtons;                  ///< Navigation buttons
  Dali::Actor                     mPressedActor;             ///< The currently pressed actor.
  Dali::Timer                     mAnimationTimer;           ///< Timer used to turn off animation after a specific time period
  Dali::TapGestureDetector        mLogoTapDetector;          ///< To detect taps on the logo
  Dali::Toolkit::Popup            mVersionPopup;             ///< Displays DALi library version information
  Dali::Vector3                   mButtonsPageRelativeSize;  ///< Size of a buttons page relative to the stage size

  std::vector< Dali::Actor >      mPages;                    ///< List of pages.
  std::vector< Dali::Actor >      mTableViewImages;          ///< Offscreen render of tableview
  std::vector< Dali::Actor >      mBackgroundActors;         ///< List of background actors used in the effect
  AnimationList                   mBackgroundAnimations;     ///< List of background bubble animations
  ExampleList                     mExampleList;              ///< List of examples.
  ExampleMap                      mExampleMap;               ///< Map LUT for examples.

  std::string                     mBackgroundImagePath;      ///< The path to the background image.
  int                             mTotalPages;               ///< Total pages within scrollview.

  bool                            mScrolling:1;              ///< Flag indicating whether view is currently being scrolled
  bool                            mSortAlphabetically:1;     ///< Sort examples alphabetically.
  bool                            mBackgroundAnimsPlaying:1; ///< Are background animations playing
  bool                            mVersionPopupShown:1;      ///< Whehter the version popup is shown or not

};

#endif // __DALI_DEMO_H__