Further Setter/Getter public API removal from Dali::Actor
[platform/core/uifw/dali-demo.git] / examples / perf-scroll / perf-scroll.cpp
index bdf2195..503dcc5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
  */
 
 #include <dali-toolkit/dali-toolkit.h>
-#include <dali/devel-api/rendering/renderer.h>
-#include <dali/devel-api/rendering/sampler.h>
-#include <dali/public-api/common/dali-common.h>
-#include <dali/integration-api/resource-policies.h>
-#include <dali/integration-api/debug.h>
-#include <iostream>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
+#include "shared/utility.h"
 
 using namespace Dali;
 using namespace Dali::Toolkit;
@@ -184,29 +180,6 @@ const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
     }\n
 );
 
-
-Geometry& QuadMesh()
-{
-  static Geometry mesh;
-  if( !mesh )
-  {
-    PropertyBuffer vertexBuffer;
-    Property::Map vertexFormat;
-    vertexFormat["aPosition"] = Property::VECTOR2;
-    vertexFormat["aTexCoord"] = Property::VECTOR2;
-
-    //Create a vertex buffer for vertex positions and texture coordinates
-    vertexBuffer = PropertyBuffer::New( vertexFormat );
-    vertexBuffer.SetData( gQuadWithTexture, 4u );
-
-    //Create the geometry
-    mesh = Geometry::New();
-    mesh.AddVertexBuffer( vertexBuffer );
-    mesh.SetGeometryType( Geometry::TRIANGLE_STRIP );
-  }
-  return mesh;
-}
-
 bool gUseMesh(false);
 bool gNinePatch(false);
 unsigned int gRowsPerPage(15);
@@ -214,35 +187,18 @@ unsigned int gColumnsPerPage(15);
 unsigned int gPageCount(10);
 float gDuration(10.0f);
 
-Renderer CreateRenderer( unsigned int index )
+Renderer CreateRenderer( unsigned int index, Geometry geometry, Shader shader )
 {
-
-  int numImages = !gNinePatch ? NUM_IMAGES : NUM_NINEPATCH_IMAGES;
-  static Renderer* renderers = new Renderer[numImages];
-  if( !renderers[index] )
-  {
-    //Create the renderer
-    Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE );
-
-    const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index];
-    Image image = ResourceImage::New( imagePath );
-
-    TextureSet textureSet = TextureSet::New();
-    textureSet.SetImage( 0u, image );
-    renderers[index] = Renderer::New( QuadMesh(), shader );
-    renderers[index].SetTextures( textureSet );
-    renderers[index].SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
-  }
-  return renderers[index];
+  Renderer renderer = Renderer::New( geometry, shader );
+  const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index];
+  Texture texture = DemoHelper::LoadTexture( imagePath );
+  TextureSet textureSet = TextureSet::New();
+  textureSet.SetTexture( 0u, texture );
+  renderer.SetTextures( textureSet );
+  renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
+  return renderer;
 }
 
-Actor CreateMeshActor( unsigned int index)
-{
-  Renderer renderer = CreateRenderer( index );
-  Actor meshActor = Actor::New();
-  meshActor.AddRenderer( renderer );
-  return meshActor;
-}
 
 }
 // Test application to compare performance between ImageActor and ImageView
@@ -286,8 +242,11 @@ public:
     // Respond to a click anywhere on the stage
     stage.GetRootLayer().TouchSignal().Connect( this, &PerfScroll::OnTouch );
 
+    // Respond to key events
+    stage.KeyEventSignal().Connect( this, &PerfScroll::OnKeyEvent );
+
     mParent = Actor::New();
-    mParent.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+    mParent.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
     stage.Add(mParent);
 
     if( gUseMesh )
@@ -322,8 +281,14 @@ public:
 
     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] );
     }
@@ -331,18 +296,27 @@ public:
 
   void CreateMeshActors()
   {
-    Stage stage = Stage::GetCurrent();
+    unsigned int numImages = !gNinePatch ? NUM_IMAGES : NUM_NINEPATCH_IMAGES;
 
-    unsigned int actorCount( mRowsPerPage * mColumnsPerPage * mPageCount );
-    mActor.resize( actorCount );
+    //Create all the renderers
+    std::vector<Renderer> renderers( numImages );
+    Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE );
+    Geometry geometry = DemoHelper::CreateTexturedQuad();
+    for( unsigned int i(0); i<numImages; ++i )
+    {
+      renderers[i] = CreateRenderer( i, geometry, shader );
+    }
 
+    //Create the actors
+    Stage stage = Stage::GetCurrent();
+    unsigned int actorCount(mRowsPerPage*mColumnsPerPage * mPageCount);
+    mActor.resize(actorCount);
     for( size_t i(0); i<actorCount; ++i )
     {
-      size_t numImages = !gNinePatch ? NUM_IMAGES : NUM_NINEPATCH_IMAGES;
-      mActor[i] = CreateMeshActor( i % numImages );
-      mActor[i].SetSize(0.0f,0.0f,0.0f);
-
-      mParent.Add( mActor[i] );
+      mActor[i] = Actor::New();
+      mActor[i].AddRenderer( renderers[i % numImages] );
+      mActor[i].SetProperty( Actor::Property::SIZE, Vector3(0.0f,0.0f,0.0f) );
+      mParent.Add(mActor[i]);
     }
   }
 
@@ -388,24 +362,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 ) );
         }
@@ -469,6 +443,17 @@ public:
     mHide.FinishedSignal().Connect( this, &PerfScroll::OnAnimationEnd );
   }
 
+  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;
 
@@ -486,15 +471,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 );
@@ -516,7 +492,8 @@ int DALI_EXPORT_API main( int argc, char **argv )
     }
   }
 
-  RunTest( application );
+  PerfScroll test( application );
+  application.MainLoop();
 
   return 0;
 }