Changes after TouchedSignal changes
[platform/core/uifw/dali-demo.git] / examples / metaball-explosion / metaball-explosion-example.cpp
index a7fdd82..92209c3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 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.
@@ -204,7 +204,7 @@ public:
    * Touch event handler to center metaballs at touch position
    * and start explosion animation on release
    */
-  bool OnTouch( Actor actor, const TouchData& touch );
+  bool OnTouch( Actor actor, const TouchEvent& touch );
 
   /**
    * Key event handler to quit application on escape or back key
@@ -218,7 +218,6 @@ private: // Data
 
   Texture           mBackgroundTexture;
   FrameBuffer       mMetaballFBO;
-  Texture           mMetaballFBOTexture;
 
   Actor             mMetaballRoot;
   MetaballInfo      mMetaballs[METABALL_NUMBER];
@@ -312,7 +311,6 @@ MetaballExplosionController::MetaballExplosionController( Application& applicati
   mScreenSize(),
   mBackgroundTexture(),
   mMetaballFBO(),
-  mMetaballFBOTexture(),
   mMetaballRoot(),
   mMetaballs(),
   mPositionIndex(),
@@ -339,15 +337,15 @@ MetaballExplosionController::~MetaballExplosionController()
 
 void MetaballExplosionController::Create( Application& app )
 {
-  Stage stage = Stage::GetCurrent();
+  Window window = app.GetWindow();
 
-  stage.KeyEventSignal().Connect( this, &MetaballExplosionController::OnKeyEvent );
+  window.KeyEventSignal().Connect( this, &MetaballExplosionController::OnKeyEvent );
 
-  mScreenSize = stage.GetSize();
+  mScreenSize = window.GetSize();
 
   mTimeMultiplier = 1.0f;
 
-  stage.SetBackgroundColor(Color::BLACK);
+  window.SetBackgroundColor(Color::BLACK);
 
   // Load background texture
   mBackgroundTexture = DemoHelper::LoadTexture( BACKGROUND_IMAGE );
@@ -366,7 +364,7 @@ void MetaballExplosionController::Create( Application& app )
   mTimerDispersion.TickSignal().Connect( this, &MetaballExplosionController::OnTimerDispersionTick );
 
   // Connect the callback to the touch signal on the mesh actor
-  stage.GetRootLayer().TouchSignal().Connect( this, &MetaballExplosionController::OnTouch );
+  window.GetRootLayer().TouchedSignal().Connect( this, &MetaballExplosionController::OnTouch );
 }
 
 Geometry MetaballExplosionController::CreateGeometry( bool aspectMappedTexture )
@@ -402,13 +400,13 @@ Geometry MetaballExplosionController::CreateGeometry( bool aspectMappedTexture )
   // Vertices
   Property::Map positionVertexFormat;
   positionVertexFormat["aPosition"] = Property::VECTOR2;
-  PropertyBuffer positionVertices = PropertyBuffer::New( positionVertexFormat );
+  VertexBuffer positionVertices = VertexBuffer::New( positionVertexFormat );
   positionVertices.SetData( vertices, numberOfVertices );
 
   // Textures
   Property::Map textureVertexFormat;
   textureVertexFormat["aTexture"] = Property::VECTOR2;
-  PropertyBuffer textureVertices = PropertyBuffer::New( textureVertexFormat );
+  VertexBuffer textureVertices = VertexBuffer::New( textureVertexFormat );
   textureVertices.SetData( textures, numberOfVertices );
 
   // Indices
@@ -445,9 +443,9 @@ void MetaballExplosionController::CreateMetaballActors()
     mMetaballs[i].radius = mMetaballs[i].initRadius = Random::Range(0.05f,0.07f);
 
     mMetaballs[i].actor = Actor::New( );
-    mMetaballs[i].actor.SetName( "Metaball" );
-    mMetaballs[i].actor.SetScale( 1.0f );
-    mMetaballs[i].actor.SetParentOrigin( ParentOrigin::CENTER );
+    mMetaballs[i].actor.SetProperty( Dali::Actor::Property::NAME, "Metaball" );
+    mMetaballs[i].actor.SetProperty( Actor::Property::SCALE, 1.0f );
+    mMetaballs[i].actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
     mMetaballs[i].actor.AddRenderer( renderer );
 
     mMetaballs[i].positionIndex = mMetaballs[i].actor.RegisterProperty( "uPositionMetaball", mMetaballs[i].position );
@@ -461,7 +459,7 @@ void MetaballExplosionController::CreateMetaballActors()
 
   // Root creation
   mMetaballRoot = Actor::New();
-  mMetaballRoot.SetParentOrigin( ParentOrigin::CENTER );
+  mMetaballRoot.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
   for( uint32_t i = 0; i < METABALL_NUMBER; i++ )
   {
     mMetaballRoot.Add( mMetaballs[i].actor );
@@ -472,18 +470,14 @@ void MetaballExplosionController::CreateMetaballActors()
 void MetaballExplosionController::CreateMetaballImage()
 {
   // Create an FBO and a render task to create to render the metaballs with a fragment shader
-  Stage stage = Stage::GetCurrent();
+  Window window = mApplication.GetWindow();
 
-  mMetaballFBO = FrameBuffer::New( mScreenSize.x, mScreenSize.y, FrameBuffer::Attachment::NONE );
-  mMetaballFBOTexture = Texture::New( Dali::TextureType::TEXTURE_2D,
-                                      Pixel::RGB888,
-                                      mScreenSize.x, mScreenSize.y );
-  mMetaballFBO.AttachColorTexture( mMetaballFBOTexture );
+  mMetaballFBO = FrameBuffer::New( mScreenSize.x, mScreenSize.y );
 
-  stage.Add(mMetaballRoot);
+  window.Add(mMetaballRoot);
 
   // Create the render task used to render the metaballs
-  RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
+  RenderTaskList taskList = window.GetRenderTaskList();
   RenderTask task = taskList.CreateTask();
   task.SetRefreshRate( RenderTask::REFRESH_ALWAYS );
   task.SetSourceActor( mMetaballRoot );
@@ -501,7 +495,7 @@ void MetaballExplosionController::CreateComposition()
   // Create new texture set
   auto textureSet = TextureSet::New();
   textureSet.SetTexture( 0u, mBackgroundTexture  );
-  textureSet.SetTexture( 1u, mMetaballFBOTexture );
+  textureSet.SetTexture( 1u, mMetaballFBO.GetColorTexture() );
 
   // Create geometry
   Geometry metaballGeom = CreateGeometry( false );
@@ -511,9 +505,9 @@ void MetaballExplosionController::CreateComposition()
 
   // Create actor
   mCompositionActor = Actor::New( );
-  mCompositionActor.SetParentOrigin(ParentOrigin::CENTER);
-  mCompositionActor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
-  mCompositionActor.SetSize(mScreenSize.x, mScreenSize.y);
+  mCompositionActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
+  mCompositionActor.SetProperty( Actor::Property::POSITION, Vector3(0.0f, 0.0f, 0.0f));
+  mCompositionActor.SetProperty( Actor::Property::SIZE, Vector2(mScreenSize.x, mScreenSize.y) );
   mCompositionActor.AddRenderer( mRenderer );
 
   Vector2 metaballCenter(0.0,0);
@@ -523,10 +517,10 @@ void MetaballExplosionController::CreateComposition()
 
   SetPositionToMetaballs( metaballCenter );
 
-  mCompositionActor.SetSize(mScreenSize.x, mScreenSize.y);
+  mCompositionActor.SetProperty( Actor::Property::SIZE, Vector2(mScreenSize.x, mScreenSize.y) );
 
-  Stage stage = Stage::GetCurrent();
-  stage.Add( mCompositionActor );
+  Window window = mApplication.GetWindow();
+  window.Add( mCompositionActor );
 }
 
 void MetaballExplosionController::CreateAnimations()
@@ -635,7 +629,7 @@ void MetaballExplosionController::SetPositionToMetaballs( const Vector2& metabal
   mCompositionActor.SetProperty( mPositionIndex, metaballCenter );
 }
 
-bool MetaballExplosionController::OnTouch( Actor actor, const TouchData& touch )
+bool MetaballExplosionController::OnTouch( Actor actor, const TouchEvent& touch )
 {
   float aspectR = mScreenSize.y / mScreenSize.x;
 
@@ -673,7 +667,7 @@ bool MetaballExplosionController::OnTouch( Actor actor, const TouchData& touch )
 
 void MetaballExplosionController::OnKeyEvent(const KeyEvent& event)
 {
-  if(event.state == KeyEvent::Down)
+  if(event.GetState() == KeyEvent::DOWN)
   {
     if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
     {