Remove ResourceImage usage from demos
[platform/core/uifw/dali-demo.git] / examples / metaball-refrac / metaball-refrac-example.cpp
index 46bf2b0..ce43545 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <cstdio>
 #include <string>
+#include "shared/utility.h"
 
 using namespace Dali;
 using namespace Dali::Toolkit;
@@ -164,7 +165,7 @@ public:
   ~MetaballRefracController();
 
   void Create( Application& app );
-  bool OnTouch( Actor actor, const TouchEvent& touch );
+  bool OnTouch( Actor actor, const TouchData& touch );
   void OnKeyEvent(const KeyEvent& event);
 
   void SetGravity(const Vector2 & gravity);
@@ -270,7 +271,7 @@ void MetaballRefracController::Create( Application& app )
   stage.SetBackgroundColor(Color::BLACK);
 
   //Set background image for the view
-  mBackImage = ResourceImage::New( BACKGROUND_IMAGE );
+  mBackImage = DemoHelper::LoadImage( BACKGROUND_IMAGE );
 
   mGravity = Vector2(GRAVITY_X,GRAVITY_Y);
   mGravityVar = Vector2(0,0);
@@ -283,7 +284,7 @@ void MetaballRefracController::Create( Application& app )
   CreateAnimations();
 
   // Connect the callback to the touch signal on the mesh actor
-  stage.GetRootLayer().TouchedSignal().Connect( this, &MetaballRefracController::OnTouch );
+  stage.GetRootLayer().TouchSignal().Connect( this, &MetaballRefracController::OnTouch );
 }
 
 /**
@@ -322,8 +323,6 @@ Geometry MetaballRefracController::CreateGeometry()
     { Vector3(0.0f, 0.0f, 1.0f) }
   };
 
-  int indices[] = { 0, 3, 1, 0, 2, 3 };
-
   unsigned int numberOfVertices = sizeof(vertices)/sizeof(VertexPosition);
 
   //Vertices
@@ -345,11 +344,7 @@ Geometry MetaballRefracController::CreateGeometry()
   normalVertices.SetData( normals, numberOfVertices );
 
   //Indices
-  Property::Map indicesVertexFormat;
-  indicesVertexFormat["aIndices"] = Property::INTEGER;
-  PropertyBuffer indicesToVertices = PropertyBuffer::New( indicesVertexFormat );
-  indicesToVertices.SetData( indices, 6 );
-
+  unsigned short indices[] = { 0, 3, 1, 0, 2, 3 };
 
   // Create the geometry object
   Geometry texturedQuadGeometry = Geometry::New();
@@ -357,7 +352,7 @@ Geometry MetaballRefracController::CreateGeometry()
   texturedQuadGeometry.AddVertexBuffer( textureVertices );
   texturedQuadGeometry.AddVertexBuffer( normalVertices );
 
-  texturedQuadGeometry.SetIndexBuffer ( indicesToVertices );
+  texturedQuadGeometry.SetIndexBuffer ( &indices[0], 6 );
 
   return texturedQuadGeometry;
 }
@@ -398,8 +393,6 @@ Geometry MetaballRefracController::CreateGeometryComposition()
     { Vector3(0.0f, 0.0f, 1.0f) }
   };
 
-  int indices[] = { 0, 3, 1, 0, 2, 3 };
-
   unsigned int numberOfVertices = sizeof(vertices)/sizeof(VertexPosition);
 
   //Vertices
@@ -421,10 +414,7 @@ Geometry MetaballRefracController::CreateGeometryComposition()
   normalVertices.SetData( normals, numberOfVertices );
 
   //Indices
-  Property::Map indicesVertexFormat;
-  indicesVertexFormat["aIndices"] = Property::INTEGER;
-  PropertyBuffer indicesToVertices = PropertyBuffer::New( indicesVertexFormat );
-  indicesToVertices.SetData( indices, 6 );
+  unsigned short indices[] = { 0, 3, 1, 0, 2, 3 };
 
   // Create the geometry object
   Geometry texturedQuadGeometry = Geometry::New();
@@ -432,7 +422,7 @@ Geometry MetaballRefracController::CreateGeometryComposition()
   texturedQuadGeometry.AddVertexBuffer( textureVertices );
   texturedQuadGeometry.AddVertexBuffer( normalVertices );
 
-  texturedQuadGeometry.SetIndexBuffer ( indicesToVertices );
+  texturedQuadGeometry.SetIndexBuffer ( &indices[0], sizeof( indices )/ sizeof( indices[0] ) );
 
   return texturedQuadGeometry;
 }
@@ -450,8 +440,11 @@ void MetaballRefracController::CreateMetaballActors()
   Shader shader = Shader::New( METABALL_VERTEX_SHADER, METABALL_FRAG_SHADER );
   Geometry metaballGeom = CreateGeometry();
   Renderer renderer = Renderer::New( metaballGeom, shader );
-  renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::ON );
-  renderer.SetBlendFunc(BlendingFactor::ONE, BlendingFactor::ONE, BlendingFactor::ONE, BlendingFactor::ONE);
+  renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
+  renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB,    BlendFactor::ONE );
+  renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB,   BlendFactor::ONE );
+  renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA,  BlendFactor::ONE );
+  renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE  );
 
   //Each metaball has a different radius
   mMetaballs[0].radius = mMetaballs[0].initRadius = 0.0145f;
@@ -767,13 +760,12 @@ void MetaballRefracController::SetPositionToMetaballs(Vector2 & metaballCenter)
   }
 }
 
-bool MetaballRefracController::OnTouch( Actor actor, const TouchEvent& touch )
+bool MetaballRefracController::OnTouch( Actor actor, const TouchData& touch )
 {
-  const TouchPoint &point = touch.GetPoint(0);
   float aspectR = mScreenSize.y / mScreenSize.x;
-  switch(point.state)
+  switch( touch.GetState( 0 ) )
   {
-    case TouchPoint::Down:
+    case PointState::DOWN:
     {
       StopAfterClickAnimations();
       for (int i = 0 ; i < METABALL_NUMBER ; i++)
@@ -784,17 +776,18 @@ bool MetaballRefracController::OnTouch( Actor actor, const TouchEvent& touch )
       //We draw with the refraction-composition shader
       mRendererRefraction.SetTextures(mTextureSetRefraction);
       mRendererRefraction.SetShader( mShaderRefraction );
-      mCurrentTouchPosition = point.screen;
+      mCurrentTouchPosition = touch.GetScreenPosition( 0 );
 
       //we use the click position for the metaballs
-      Vector2 metaballCenter = Vector2((point.screen.x / mScreenSize.x) - 0.5, (aspectR * (mScreenSize.y - point.screen.y) / mScreenSize.y) - 0.5) * 2.0;
+      Vector2 metaballCenter = Vector2((mCurrentTouchPosition.x / mScreenSize.x) - 0.5, (aspectR * (mScreenSize.y - mCurrentTouchPosition.y) / mScreenSize.y) - 0.5) * 2.0;
       SetPositionToMetaballs(metaballCenter);
       break;
     }
-    case TouchPoint::Motion:
+    case PointState::MOTION:
     {
-      Vector2 displacement = point.screen - mCurrentTouchPosition;
-      mCurrentTouchPosition = point.screen;
+      Vector2 screen = touch.GetScreenPosition( 0 );
+      Vector2 displacement = screen - mCurrentTouchPosition;
+      mCurrentTouchPosition = screen;
 
       mMetaballPosVariationTo.x += (displacement.x / mScreenSize.x) * 2.2;
       mMetaballPosVariationTo.y += (- displacement.y / mScreenSize.y) * 2.2;
@@ -811,13 +804,13 @@ bool MetaballRefracController::OnTouch( Actor actor, const TouchEvent& touch )
       mPositionVarAnimation[1].Play();
 
       //we use the click position for the metaballs
-      Vector2 metaballCenter = Vector2((point.screen.x / mScreenSize.x) - 0.5, (aspectR * (mScreenSize.y - point.screen.y) / mScreenSize.y) - 0.5) * 2.0;
+      Vector2 metaballCenter = Vector2((screen.x / mScreenSize.x) - 0.5, (aspectR * (mScreenSize.y - screen.y) / mScreenSize.y) - 0.5) * 2.0;
       SetPositionToMetaballs(metaballCenter);
       break;
     }
-    case TouchPoint::Up:
-    case TouchPoint::Leave:
-    case TouchPoint::Interrupted:
+    case PointState::UP:
+    case PointState::LEAVE:
+    case PointState::INTERRUPTED:
     {
       //Stop click animations
       StopClickAnimations();