Changes after TouchedSignal changes
[platform/core/uifw/dali-demo.git] / examples / metaball-refrac / metaball-refrac-example.cpp
index 8d1def8..021a2ac 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.
@@ -196,7 +196,7 @@ public:
   /**
    * Touch handler, start the grow animation and creates additional metaballs
    */
-  bool OnTouch( Actor actor, const TouchData& touch );
+  bool OnTouch( Actor actor, const TouchEvent& touch );
 
   /**
    * Key event callback to quit the application on escape or back key
@@ -210,7 +210,6 @@ private: // Data
 
   Texture           mBackgroundTexture;
   FrameBuffer       mMetaballFBO;
-  Texture           mMetaballFBOTexture;
 
   Actor             mMetaballRoot;
   MetaballInfo      mMetaballs[METABALL_NUMBER];
@@ -319,13 +318,13 @@ MetaballRefracController::~MetaballRefracController()
 
 void MetaballRefracController::Create( Application& app )
 {
-  Stage stage = Stage::GetCurrent();
+  Window window = app.GetWindow();
 
-  stage.KeyEventSignal().Connect( this, &MetaballRefracController::OnKeyEvent );
+  window.KeyEventSignal().Connect( this, &MetaballRefracController::OnKeyEvent );
 
-  mScreenSize = stage.GetSize();
+  mScreenSize = window.GetSize();
 
-  stage.SetBackgroundColor(Color::BLACK);
+  window.SetBackgroundColor(Color::BLACK);
 
   // Load background texture
   mBackgroundTexture = DemoHelper::LoadTexture( BACKGROUND_IMAGE );
@@ -339,7 +338,7 @@ void MetaballRefracController::Create( Application& app )
   CreateAnimations();
 
   // Connect the callback to the touch signal on the mesh actor
-  stage.GetRootLayer().TouchSignal().Connect( this, &MetaballRefracController::OnTouch );
+  window.GetRootLayer().TouchedSignal().Connect( this, &MetaballRefracController::OnTouch );
 }
 
 Geometry MetaballRefracController::CreateGeometry( bool aspectMappedTexture )
@@ -375,13 +374,13 @@ Geometry MetaballRefracController::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
@@ -423,9 +422,9 @@ void MetaballRefracController::CreateMetaballActors()
     mMetaballs[i].position = Vector2(0.0f, 0.0f);
 
     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 );
@@ -440,7 +439,7 @@ void MetaballRefracController::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 );
@@ -450,17 +449,13 @@ void MetaballRefracController::CreateMetaballActors()
 void MetaballRefracController::CreateMetaballImage()
 {
   // Create an FBO and a render task to create to render the metaballs with a fragment shader
-  Stage stage = Stage::GetCurrent();
-  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 );
+  Window window = mApplication.GetWindow();
+  mMetaballFBO = FrameBuffer::New( mScreenSize.x, mScreenSize.y );
 
-  stage.Add(mMetaballRoot);
+  window.Add(mMetaballRoot);
 
   //Creation of 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 );
@@ -478,7 +473,7 @@ void MetaballRefracController::CreateComposition()
   // Create new texture set
   mTextureSetRefraction = TextureSet::New();
   mTextureSetRefraction.SetTexture( 0u, mBackgroundTexture  );
-  mTextureSetRefraction.SetTexture( 1u, mMetaballFBOTexture );
+  mTextureSetRefraction.SetTexture( 1u, mMetaballFBO.GetColorTexture() );
 
   // Create normal shader
   mShaderNormal = Shader::New( METABALL_VERTEX_SHADER, FRAG_SHADER );
@@ -489,9 +484,9 @@ void MetaballRefracController::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) );
 
   // Create geometry
   Geometry metaballGeometry = CreateGeometry( false );
@@ -499,8 +494,8 @@ void MetaballRefracController::CreateComposition()
   mRendererRefraction.SetTextures( mTextureSetNormal );
   mCompositionActor.AddRenderer( mRendererRefraction );
 
-  Stage stage = Stage::GetCurrent();
-  stage.Add( mCompositionActor );
+  Window window = mApplication.GetWindow();
+  window.Add( mCompositionActor );
 }
 
 void MetaballRefracController::CreateAnimations()
@@ -685,7 +680,7 @@ void MetaballRefracController::SetPositionToMetaballs( const Vector2& metaballCe
   }
 }
 
-bool MetaballRefracController::OnTouch( Actor actor, const TouchData& touch )
+bool MetaballRefracController::OnTouch( Actor actor, const TouchEvent& touch )
 {
   const float aspect = mScreenSize.y / mScreenSize.x;
   switch( touch.GetState( 0 ) )
@@ -764,7 +759,7 @@ bool MetaballRefracController::OnTouch( Actor actor, const TouchData& touch )
 
 void MetaballRefracController::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) )
     {