Remove more public Setter/Getter APIs from Dali::Actor
[platform/core/uifw/dali-demo.git] / examples / homescreen-benchmark / homescreen-benchmark.cpp
index 64ff1ad..52e64a6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
@@ -168,15 +168,15 @@ public:
 
     mScrollParent = Actor::New();
     mScrollParent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-    mScrollParent.SetAnchorPoint( AnchorPoint::CENTER );
-    mScrollParent.SetParentOrigin( ParentOrigin::CENTER );
+    mScrollParent.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+    mScrollParent.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
 
     // create background
     Toolkit::ImageView background = Toolkit::ImageView::New( BACKGROUND_IMAGE );
     Stage::GetCurrent().Add( background );
     background.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-    background.SetAnchorPoint( AnchorPoint::CENTER );
-    background.SetParentOrigin( ParentOrigin::CENTER );
+    background.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+    background.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
 
     PopulatePages();
 
@@ -184,6 +184,9 @@ public:
 
     // Respond to a click anywhere on the stage.
     stage.GetRootLayer().TouchSignal().Connect( this, &HomescreenBenchmark::OnTouch );
+
+    // Respond to key events
+    stage.KeyEventSignal().Connect( this, &HomescreenBenchmark::OnKeyEvent );
   }
 
   bool OnTouch( Actor actor, const TouchData& touch )
@@ -196,26 +199,22 @@ public:
   Actor AddPage()
   {
     // Create root page actor.
-    Actor pageActor;
+    Toolkit::Control pageActor;
 
     if( mConfig.mTableViewEnabled )
     {
-      Toolkit::TableView tableView = Toolkit::TableView::New( mConfig.mRows, mConfig.mCols );
-
-      // Create geometry batcher for table view.
-      tableView.SetBackgroundColor( Vector4( 0.0f, 0.0f, 0.0f, 0.5f ) );
-      pageActor = tableView;
+      pageActor = Toolkit::TableView::New( mConfig.mRows, mConfig.mCols );
     }
     else
     {
       pageActor = Toolkit::Control::New();
-      pageActor.SetProperty( Toolkit::Control::Property::BACKGROUND_COLOR, Vector4( 0.0f, 0.0f, 0.0f, 0.5f ) );
     }
 
-    pageActor.SetParentOrigin( ParentOrigin::CENTER );
-    pageActor.SetAnchorPoint( AnchorPoint::CENTER );
+    pageActor.SetBackgroundColor( Vector4( 0.0f, 0.0f, 0.0f, 0.5f ) );
+    pageActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+    pageActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
     pageActor.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
-    pageActor.SetSizeModeFactor( Vector3( PAGE_SCALE_FACTOR_X, PAGE_SCALE_FACTOR_Y, 1.0f ) );
+    pageActor.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( PAGE_SCALE_FACTOR_X, PAGE_SCALE_FACTOR_Y, 1.0f ) );
     return pageActor;
   }
 
@@ -232,10 +231,10 @@ public:
 
     imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map );
     imageView.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
-    imageView.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
-    imageView.SetAnchorPoint( AnchorPoint::CENTER );
-    imageView.SetParentOrigin( ParentOrigin::CENTER );
-    imageView.SetSizeModeFactor( Vector3( IMAGE_AREA, IMAGE_AREA, 1.0f ) );
+    imageView.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
+    imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+    imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+    imageView.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( IMAGE_AREA, IMAGE_AREA, 1.0f ) );
 
     return imageView;
   }
@@ -244,9 +243,9 @@ public:
   {
     Toolkit::CheckBoxButton button = Toolkit::CheckBoxButton::New();
     button.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
-    button.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
-    button.SetAnchorPoint( AnchorPoint::CENTER );
-    button.SetParentOrigin( ParentOrigin::CENTER );
+    button.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
+    button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+    button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
     button.SetProperty( Toolkit::Button::Property::SELECTED, ( currentIconIndex % 2 == 0 ) ); // Select half the button
 
     return button;
@@ -271,8 +270,8 @@ public:
       {
         // Create parent icon view
         Toolkit::Control iconView = Toolkit::Control::New();
-        iconView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-        iconView.SetParentOrigin( ParentOrigin::TOP_LEFT );
+        iconView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+        iconView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
 
         if( !mConfig.mTableViewEnabled )
         {
@@ -284,7 +283,7 @@ public:
         else
         {
           iconView.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
-          iconView.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
+          iconView.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
         }
 
         Actor icon;
@@ -309,8 +308,8 @@ public:
           if( useTextLabel )
           {
             Toolkit::TextLabel textLabel = Toolkit::TextLabel::New( DEMO_APPS_NAMES[currentIconIndex] );
-            textLabel.SetAnchorPoint( AnchorPoint::TOP_CENTER );
-            textLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
+            textLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
+            textLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER );
             textLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
             textLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); // White.
             textLabel.SetProperty( Toolkit::TextLabel::Property::POINT_SIZE, ( ( static_cast<float>( ROW_HEIGHT * LABEL_AREA ) * 72.0f )  / dpi.y ) * 0.25f );
@@ -330,8 +329,8 @@ public:
 
             Toolkit::Control control = Toolkit::Control::New();
             control.SetProperty( Toolkit::Control::Property::BACKGROUND, map );
-            control.SetAnchorPoint( AnchorPoint::TOP_CENTER );
-            control.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
+            control.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
+            control.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER );
             icon.Add( control );
           }
         }
@@ -384,13 +383,13 @@ public:
       AddIconsToPage( page, mConfig.mUseTextLabel );
 
       // Move page 'a little bit up'.
-      page.SetParentOrigin( ParentOrigin::CENTER );
-      page.SetAnchorPoint( AnchorPoint::CENTER );
+      page.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+      page.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
       page.SetPosition( Vector3( stageSize.x * i, 0.0f, 0.0f ) );
       mScrollParent.Add( page );
     }
 
-    mScrollParent.SetOpacity( 1.0f );
+    mScrollParent.SetProperty( DevelActor::Property::OPACITY, 1.0f );
     mScrollParent.SetScale( Vector3::ONE );
 
     // Fade in.
@@ -442,6 +441,17 @@ public:
     }
   }
 
+  void OnKeyEvent( const KeyEvent& event )
+  {
+    if( event.state == KeyEvent::Down )
+    {
+      if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
+      {
+        mApplication.Quit();
+      }
+    }
+  }
+
 private:
 
   Application&                mApplication;
@@ -454,26 +464,6 @@ private:
   int                         mCurrentPage;
 };
 
-void RunTest( Application& application, const HomescreenBenchmark::Config& config, bool printHelpAndExit )
-{
-  HomescreenBenchmark test( application, config );
-
-  if( printHelpAndExit )
-  {
-    PrintHelp( "c<num>",               " Number of columns" );
-    PrintHelp( "r<num>",               " Number of rows" );
-    PrintHelp( "p<num>",               " Number of pages ( must be greater than 1 )" );
-    PrintHelp( "-disable-tableview",   " Disables the use of TableView for layouting" );
-    PrintHelp( "-disable-icon-labels", " Disables labels for each icon" );
-    PrintHelp( "-use-checkbox",        " Uses checkboxes for icons" );
-    PrintHelp( "-use-text-label",      " Uses TextLabel instead of a TextVisual" );
-    return;
-  }
-
-  application.MainLoop();
-}
-
-// Entry point for Linux & Tizen applications.
 int DALI_EXPORT_API main( int argc, char **argv )
 {
   // Default settings.
@@ -519,8 +509,21 @@ int DALI_EXPORT_API main( int argc, char **argv )
   }
 
   Application application = Application::New( &argc, &argv );
+  HomescreenBenchmark test( application, config );
 
-  RunTest( application, config, printHelpAndExit );
+  if( printHelpAndExit )
+  {
+    PrintHelp( "c<num>",               " Number of columns" );
+    PrintHelp( "r<num>",               " Number of rows" );
+    PrintHelp( "p<num>",               " Number of pages ( must be greater than 1 )" );
+    PrintHelp( "-disable-tableview",   " Disables the use of TableView for layouting" );
+    PrintHelp( "-disable-icon-labels", " Disables labels for each icon" );
+    PrintHelp( "-use-checkbox",        " Uses checkboxes for icons" );
+    PrintHelp( "-use-text-label",      " Uses TextLabel instead of a TextVisual" );
+    return 0;
+  }
+
+  application.MainLoop();
 
   return 0;
 }