Merge "Removing unused variables" into devel/master
[platform/core/uifw/dali-demo.git] / examples / perf-scroll / perf-scroll.cpp
index ddfd9b8..8a7d2a0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 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.
@@ -15,9 +15,8 @@
  *
  */
 
-#include <dali/public-api/rendering/renderer.h>
 #include <dali-toolkit/dali-toolkit.h>
-
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 #include "shared/utility.h"
 
 using namespace Dali;
@@ -149,13 +148,6 @@ struct VertexWithTexture
   Vector2 texCoord;
 };
 
-VertexWithTexture gQuadWithTexture[] = {
-                                        { Vector2( -0.5f, -0.5f ), Vector2( 0.0f, 0.0f ) },
-                                        { Vector2(  0.5f, -0.5f ), Vector2( 1.0f, 0.0f ) },
-                                        { Vector2( -0.5f,  0.5f ), Vector2( 0.0f, 1.0f ) },
-                                        { Vector2(  0.5f,  0.5f ), Vector2( 1.0f, 1.0f ) }
-};
-
 const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
     attribute mediump vec2 aPosition;\n
     attribute mediump vec2 aTexCoord;\n
@@ -231,21 +223,24 @@ public:
   // The Init signal is received once (only) during the Application lifetime
   void Create( Application& application )
   {
-    // Get a handle to the stage
-    Stage stage = Stage::GetCurrent();
-    stage.SetBackgroundColor( Color::WHITE );
-    Vector2 stageSize = stage.GetSize();
+    // Get a handle to the window
+    Window window = application.GetWindow();
+    window.SetBackgroundColor( Color::WHITE );
+    Vector2 windowSize = window.GetSize();
 
-    stage.GetRootLayer().SetDepthTestDisabled(true);
+    window.GetRootLayer().SetProperty( Layer::Property::DEPTH_TEST, false );
 
-    mSize = Vector3( stageSize.x / mColumnsPerPage, stageSize.y / mRowsPerPage, 0.0f );
+    mSize = Vector3( windowSize.x / mColumnsPerPage, windowSize.y / mRowsPerPage, 0.0f );
 
-    // Respond to a click anywhere on the stage
-    stage.GetRootLayer().TouchSignal().Connect( this, &PerfScroll::OnTouch );
+    // Respond to a click anywhere on the window
+    window.GetRootLayer().TouchSignal().Connect( this, &PerfScroll::OnTouch );
+
+    // Respond to key events
+    window.KeyEventSignal().Connect( this, &PerfScroll::OnKeyEvent );
 
     mParent = Actor::New();
-    mParent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-    stage.Add(mParent);
+    mParent.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+    window.Add(mParent);
 
     if( gUseMesh )
     {
@@ -259,7 +254,7 @@ public:
     ShowAnimation();
   }
 
-  bool OnTouch( Actor actor, const TouchData& touch )
+  bool OnTouch( Actor actor, const TouchEvent& touch )
   {
     // quit the application
     mApplication.Quit();
@@ -273,14 +268,20 @@ public:
 
   void CreateImageViews()
   {
-    Stage stage = Stage::GetCurrent();
+    Window window = mApplication.GetWindow();
     unsigned int actorCount( mRowsPerPage*mColumnsPerPage * mPageCount );
     mImageView.resize( actorCount );
 
     for( size_t i(0); i<actorCount; ++i )
     {
-      mImageView[i] = ImageView::New( ImagePath(i) );
-      mImageView[i].SetSize( Vector3(0.0f,0.0f,0.0f) );
+      mImageView[i] = ImageView::New();
+      Property::Map propertyMap;
+      propertyMap.Insert(Toolkit::ImageVisual::Property::URL, ImagePath(i));
+      propertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
+      propertyMap.Insert(Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL);
+      mImageView[i].SetProperty(Toolkit::ImageView::Property::IMAGE, propertyMap);
+
+      mImageView[i].SetProperty( Actor::Property::SIZE, Vector3(0.0f,0.0f,0.0f) );
       mImageView[i].SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
       mParent.Add( mImageView[i] );
     }
@@ -300,14 +301,14 @@ public:
     }
 
     //Create the actors
-    Stage stage = Stage::GetCurrent();
+    Window window = mApplication.GetWindow();
     unsigned int actorCount(mRowsPerPage*mColumnsPerPage * mPageCount);
     mActor.resize(actorCount);
     for( size_t i(0); i<actorCount; ++i )
     {
       mActor[i] = Actor::New();
       mActor[i].AddRenderer( renderers[i % numImages] );
-      mActor[i].SetSize(0.0f,0.0f,0.0f);
+      mActor[i].SetProperty( Actor::Property::SIZE, Vector3(0.0f,0.0f,0.0f) );
       mParent.Add(mActor[i]);
     }
   }
@@ -330,8 +331,8 @@ public:
 
   void ShowAnimation()
   {
-    Stage stage = Stage::GetCurrent();
-    Vector3 initialPosition( stage.GetSize().x * 0.5f, stage.GetSize().y*0.5f, 1000.0f );
+    Window window = mApplication.GetWindow();
+    Vector3 initialPosition( window.GetSize().GetWidth() * 0.5f, window.GetSize().GetHeight() * 0.5f, 1000.0f );
 
     unsigned int totalColumns = mColumnsPerPage * mPageCount;
 
@@ -354,24 +355,24 @@ public:
 
         float delay = 0.0f;
         float duration = 0.0f;
-        if( count < mRowsPerPage*mColumnsPerPage )
+        if( count < ( static_cast< size_t >( mRowsPerPage ) * mColumnsPerPage ) )
         {
           duration = durationPerActor;
           delay = delayBetweenActors * count;
         }
         if( gUseMesh )
         {
-          mActor[count].SetPosition( initialPosition );
-          mActor[count].SetSize( Vector3(0.0f,0.0f,0.0f) );
-          mActor[count].SetOrientation( Quaternion( Radian( 0.0f ), Vector3::XAXIS ) );
+          mActor[count].SetProperty( Actor::Property::POSITION, initialPosition );
+          mActor[count].SetProperty( Actor::Property::SIZE, Vector3(0.0f,0.0f,0.0f) );
+          mActor[count].SetProperty( Actor::Property::ORIENTATION, Quaternion( Quaternion( Radian( 0.0f ), Vector3::XAXIS ) ) );
           mShow.AnimateTo( Property( mActor[count], Actor::Property::POSITION ), Vector3( xpos+mSize.x*0.5f, ypos+mSize.y*0.5f, 0.0f), AlphaFunction::EASE_OUT_BACK, TimePeriod( delay, duration ) );
           mShow.AnimateTo( Property( mActor[count], Actor::Property::SIZE ), mSize, AlphaFunction::EASE_OUT_BACK, TimePeriod( delay, duration ) );
         }
         else
         {
-          mImageView[count].SetPosition( initialPosition );
-          mImageView[count].SetSize( Vector3(0.0f,0.0f,0.0f) );
-          mImageView[count].SetOrientation( Quaternion( Radian(0.0f),Vector3::XAXIS ) );
+          mImageView[count].SetProperty( Actor::Property::POSITION, initialPosition );
+          mImageView[count].SetProperty( Actor::Property::SIZE, Vector3(0.0f,0.0f,0.0f) );
+          mImageView[count].SetProperty( Actor::Property::ORIENTATION, Quaternion( Quaternion( Radian(0.0f), Vector3::XAXIS ) ) );
           mShow.AnimateTo( Property( mImageView[count], Actor::Property::POSITION ), Vector3( xpos+mSize.x*0.5f, ypos+mSize.y*0.5f, 0.0f ), AlphaFunction::EASE_OUT_BACK, TimePeriod( delay, duration ) );
           mShow.AnimateTo( Property( mImageView[count], Actor::Property::SIZE ), mSize, AlphaFunction::EASE_OUT_BACK, TimePeriod( delay, duration ) );
         }
@@ -384,12 +385,12 @@ public:
 
   void ScrollAnimation()
   {
-    Stage stage = Stage::GetCurrent();
-    Vector3 stageSize( stage.GetSize() );
+    Window window = mApplication.GetWindow();
+    Vector3 windowSize( window.GetSize() );
 
     mScroll = Animation::New( gDuration );
 
-    mScroll.AnimateBy( Property( mParent, Actor::Property::POSITION ), Vector3( -(gPageCount-1.)*stageSize.x,0.0f, 0.0f) );
+    mScroll.AnimateBy( Property( mParent, Actor::Property::POSITION ), Vector3( -(gPageCount-1.)*windowSize.x,0.0f, 0.0f) );
     mScroll.Play();
     mScroll.FinishedSignal().Connect( this, &PerfScroll::OnAnimationEnd );
   }
@@ -435,6 +436,17 @@ public:
     mHide.FinishedSignal().Connect( this, &PerfScroll::OnAnimationEnd );
   }
 
+  void OnKeyEvent( const KeyEvent& event )
+  {
+    if( event.GetState() == KeyEvent::DOWN )
+    {
+      if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
+      {
+        mApplication.Quit();
+      }
+    }
+  }
+
 private:
   Application&  mApplication;
 
@@ -452,15 +464,6 @@ private:
   Animation           mHide;
 };
 
-void RunTest( Application& application )
-{
-  PerfScroll test( application );
-
-  application.MainLoop();
-}
-
-// Entry point for Linux & Tizen applications
-//
 int DALI_EXPORT_API main( int argc, char **argv )
 {
   Application application = Application::New( &argc, &argv );
@@ -482,7 +485,8 @@ int DALI_EXPORT_API main( int argc, char **argv )
     }
   }
 
-  RunTest( application );
+  PerfScroll test( application );
+  application.MainLoop();
 
   return 0;
 }