Revert "Changes after TouchData renamed to TouchEvent"
[platform/core/uifw/dali-demo.git] / examples / image-scaling-irregular-grid / image-scaling-irregular-grid-example.cpp
index 70f662e..cd6c837 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -47,6 +47,9 @@
 #include <dali-toolkit/dali-toolkit.h>
 #include <iostream>
 #include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/devel-api/controls/scroll-bar/scroll-bar.h>
+#include <random>       // std::default_random_engine
+#include <chrono>       // std::chrono::system_clock
 
 // INTERNAL INCLUDES
 #include "grid-flags.h"
@@ -280,11 +283,11 @@ public:
   void ResourceReadySignal( Toolkit::Control control )
   {
     mImagesLoaded++;
-    // To allow fast startup, we only place a small number of ImageViews on stage first
+    // To allow fast startup, we only place a small number of ImageViews on window first
     if ( mImagesLoaded == INITIAL_IMAGES_TO_LOAD )
     {
-      // Adding the ImageViews to the stage will trigger loading of the Images
-      mGridActor.Add( mOffStageImageViews );
+      // Adding the ImageViews to the window will trigger loading of the Images
+      mGridActor.Add( mOffWindowImageViews );
     }
   }
 
@@ -296,14 +299,11 @@ public:
   {
     std::cout << "ImageScalingIrregularGridController::Create" << std::endl;
 
-    // Get a handle to the stage:
-    Stage stage = Stage::GetCurrent();
+    // Get a handle to the window:
+    Window window = application.GetWindow();
 
     // Connect to input event signals:
-    stage.KeyEventSignal().Connect(this, &ImageScalingIrregularGridController::OnKeyEvent);
-
-    // Hide the indicator bar
-    mApplication.GetWindow().ShowIndicator(Dali::Window::INVISIBLE);
+    window.KeyEventSignal().Connect(this, &ImageScalingIrregularGridController::OnKeyEvent);
 
     // Create a default view with a default tool bar:
     mContentLayer = DemoHelper::CreateView( mApplication,
@@ -322,10 +322,10 @@ public:
 
     SetTitle( APPLICATION_TITLE );
 
-    mOffStageImageViews = Actor::New();
-    mOffStageImageViews.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
-    mOffStageImageViews.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
-    mOffStageImageViews.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+    mOffWindowImageViews = Actor::New();
+    mOffWindowImageViews.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+    mOffWindowImageViews.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
+    mOffWindowImageViews.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
 
     // Build the main content of the widow:
     PopulateContentLayer( DEFAULT_SCALING_MODE );
@@ -336,11 +336,11 @@ public:
    */
   void PopulateContentLayer( const Dali::FittingMode::Type fittingMode )
   {
-    Stage stage = Stage::GetCurrent();
-    Vector2 stageSize = stage.GetSize();
+    Window window = mApplication.GetWindow();
+    Vector2 windowSize = window.GetSize();
 
     float fieldHeight;
-    Actor imageField = BuildImageField( stageSize.x, GRID_WIDTH, GRID_MAX_HEIGHT, fittingMode, fieldHeight );
+    Actor imageField = BuildImageField( windowSize.x, GRID_WIDTH, GRID_MAX_HEIGHT, fittingMode, fieldHeight );
 
     mScrollView = ScrollView::New();
 
@@ -357,12 +357,12 @@ public:
 
     // Restrict scrolling to mostly vertical only, but with some horizontal wiggle-room:
 
-    RulerPtr rulerX = new FixedRuler( stageSize.width ); //< Pull the view back to the grid's centre-line when touch is release using a snapping ruler.
-    rulerX->SetDomain( RulerDomain( stageSize.width * -0.125f, stageSize.width * 1.125f ) ); //< Scroll slightly left/right of image field.
+    RulerPtr rulerX = new FixedRuler( windowSize.width ); //< Pull the view back to the grid's centre-line when touch is release using a snapping ruler.
+    rulerX->SetDomain( RulerDomain( windowSize.width * -0.125f, windowSize.width * 1.125f ) ); //< Scroll slightly left/right of image field.
     mScrollView.SetRulerX ( rulerX );
 
-    RulerPtr rulerY = new DefaultRuler(); //< Snap in multiples of a screen / stage height
-    rulerY->SetDomain( RulerDomain( - fieldHeight * 0.5f + stageSize.height * 0.5f - GRID_CELL_PADDING, fieldHeight * 0.5f + stageSize.height * 0.5f + GRID_CELL_PADDING ) );
+    RulerPtr rulerY = new DefaultRuler(); //< Snap in multiples of a screen / window height
+    rulerY->SetDomain( RulerDomain( - fieldHeight * 0.5f + windowSize.height * 0.5f - GRID_CELL_PADDING, fieldHeight * 0.5f + windowSize.height * 0.5f + GRID_CELL_PADDING ) );
     mScrollView.SetRulerY ( rulerY );
 
     mContentLayer.Add( mScrollView );
@@ -419,8 +419,10 @@ public:
       }
     }
     // Stir-up the list to get some nice irregularity in the generated field:
-    std::random_shuffle( configurations.begin(), configurations.end() );
-    std::random_shuffle( configurations.begin(), configurations.end() );
+    unsigned int seed = std::chrono::system_clock::now().time_since_epoch().count();
+    std::shuffle( configurations.begin(), configurations.end(), std::default_random_engine(seed) );
+    seed = std::chrono::system_clock::now().time_since_epoch().count();
+    std::shuffle( configurations.begin(), configurations.end(), std::default_random_engine(seed) );
 
     // Place the images in the grid:
 
@@ -477,18 +479,18 @@ public:
       image.SetProperty( Actor::Property::SIZE, imageSize );
       image.TouchSignal().Connect( this, &ImageScalingIrregularGridController::OnTouchImage );
       image.ResourceReadySignal().Connect( this, &ImageScalingIrregularGridController::ResourceReadySignal );
-      mFittingModes[image.GetId()] = fittingMode;
-      mResourceUrls[image.GetId()] = imageSource.configuration.path;
-      mSizes[image.GetId()] = imageSize;
+      mFittingModes[image.GetProperty< int >( Actor::Property::ID )] = fittingMode;
+      mResourceUrls[image.GetProperty< int >( Actor::Property::ID )] = imageSource.configuration.path;
+      mSizes[image.GetProperty< int >( Actor::Property::ID )] = imageSize;
       if ( count < INITIAL_IMAGES_TO_LOAD )
       {
         gridActor.Add( image );
       }
       else
       {
-        // Store the ImageView in an offstage actor until the inital batch of ImageViews have finished loading their images
+        // Store the ImageView in an offwindow actor until the inital batch of ImageViews have finished loading their images
         // Required
-        mOffStageImageViews.Add( image );
+        mOffWindowImageViews.Add( image );
       }
     }
 
@@ -512,9 +514,9 @@ public:
         animation.Play();
 
         // Change the scaling mode:
-        const unsigned id = actor.GetId();
+        const unsigned id = actor.GetProperty< int >( Actor::Property::ID );
         Dali::FittingMode::Type newMode = NextMode( mFittingModes[id] );
-        const Vector2 imageSize = mSizes[actor.GetId()];
+        const Vector2 imageSize = mSizes[actor.GetProperty< int >( Actor::Property::ID )];
 
         ImageView imageView = ImageView::DownCast( actor );
         if( imageView)
@@ -565,7 +567,7 @@ public:
       if( gridImageView )
       {
         // Cycle the scaling mode options:
-        unsigned int id = gridImageView.GetId();
+        unsigned int id = gridImageView.GetProperty< int >( Actor::Property::ID );
 
         const Vector2 imageSize = mSizes[ id ];
         Dali::FittingMode::Type newMode = NextMode( mFittingModes[ id ] );
@@ -632,7 +634,7 @@ private:
   Toolkit::ToolBar mToolBar;          ///< The View's Toolbar.
   TextLabel mTitleActor;               ///< The Toolbar's Title.
   Actor mGridActor;                   ///< The container for the grid of images
-  Actor mOffStageImageViews;          ///< ImageViews held off stage until the inital batch have loaded their images
+  Actor mOffWindowImageViews;          ///< ImageViews held off window until the inital batch have loaded their images
   ScrollView mScrollView;             ///< ScrollView UI Component
   ScrollBar mScrollBarVertical;
   ScrollBar mScrollBarHorizontal;