Revert "[3.0] Removed 3D layer dependency of Model3dView and Mesh Visual."
[platform/core/uifw/dali-demo.git] / examples / mesh-visual / mesh-visual-example.cpp
index e8674c9..8376f61 100644 (file)
@@ -95,19 +95,25 @@ public:
     Stage stage = Stage::GetCurrent();
     stage.SetBackgroundColor( Vector4( 0.0, 0.5, 1.0, 1.0 ) );
 
-    //Set up root layer to receive touch gestures.
-    Layer rootLayer = stage.GetRootLayer();
-    rootLayer.RegisterProperty( "Tag", LAYER_TAG ); //Used to differentiate between different kinds of actor.
-    rootLayer.TouchSignal().Connect( this, &MeshVisualController::OnTouch );
+    //Set up layer to place objects on.
+    Layer baseLayer = Layer::New();
+    baseLayer.SetParentOrigin( ParentOrigin::CENTER );
+    baseLayer.SetAnchorPoint( AnchorPoint::CENTER );
+    baseLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+    baseLayer.SetBehavior( Layer::LAYER_2D ); //We use a 2D layer as this is closer to UI work than full 3D scene creation.
+    baseLayer.SetDepthTestDisabled( false ); //Enable depth testing, as otherwise the 2D layer would not do so.
+    baseLayer.RegisterProperty( "Tag", LAYER_TAG ); //Used to differentiate between different kinds of actor.
+    baseLayer.TouchedSignal().Connect( this, &MeshVisualController::OnTouch );
+    stage.Add( baseLayer );
 
     //Place models on the scene.
-    SetupModels( rootLayer );
+    SetupModels( baseLayer );
 
     //Place buttons on the scene.
-    SetupButtons( rootLayer );
+    SetupButtons( baseLayer );
 
     //Add a light to the scene.
-    SetupLight( rootLayer );
+    SetupLight( baseLayer );
 
     //Allow for exiting of the application via key presses.
     stage.KeyEventSignal().Connect( this, &MeshVisualController::OnKeyEvent );
@@ -123,7 +129,7 @@ public:
       mContainers[i].SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
       mContainers[i].RegisterProperty( "Tag", MODEL_TAG ); //Used to differentiate between different kinds of actor.
       mContainers[i].RegisterProperty( "Model", Property::Value( i ) ); //Used to index into the model.
-      mContainers[i].TouchSignal().Connect( this, &MeshVisualController::OnTouch );
+      mContainers[i].TouchedSignal().Connect( this, &MeshVisualController::OnTouch );
       layer.Add( mContainers[i] );
     }
 
@@ -278,7 +284,7 @@ public:
     SetLightImage();
 
     //Connect to touch signal for dragging.
-    mLightSource.TouchSignal().Connect( this, &MeshVisualController::OnTouch );
+    mLightSource.TouchedSignal().Connect( this, &MeshVisualController::OnTouch );
 
     //Place the light source on a layer above the base, so that it is rendered above everything else.
     Layer upperLayer = Layer::New();
@@ -390,11 +396,14 @@ public:
 
   //If the light source is touched, move it by dragging it.
   //If a model is touched, rotate it by panning around.
-  bool OnTouch( Actor actor, const TouchData& touch )
+  bool OnTouch( Actor actor, const TouchEvent& event )
   {
-    switch( touch.GetState( 0 ) )
+    //Get primary touch point.
+    const Dali::TouchPoint& point = event.GetPoint( 0 );
+
+    switch( point.state )
     {
-      case PointState::DOWN:
+      case TouchPoint::Down:
       {
         //Determine what was touched.
         actor.GetProperty( actor.GetPropertyIndex( "Tag" ) ).Get( mTag );
@@ -408,13 +417,13 @@ public:
           mModels[mSelectedModelIndex].rotationAnimation.Pause();
 
           //Store start points.
-          mPanStart = touch.GetScreenPosition( 0 );
+          mPanStart = point.screen;
           mRotationStart = mModels[mSelectedModelIndex].rotation;
         }
 
         break;
       }
-      case PointState::MOTION:
+      case TouchPoint::Motion:
       {
         //Switch on the kind of actor we're interacting with.
         switch( mTag )
@@ -422,7 +431,7 @@ public:
           case MODEL_TAG: //Rotate model
           {
             //Calculate displacement and corresponding rotation.
-            Vector2 displacement = touch.GetScreenPosition( 0 ) - mPanStart;
+            Vector2 displacement = point.screen - mPanStart;
             mModels[mSelectedModelIndex].rotation = Vector2( mRotationStart.x - displacement.y / Y_ROTATION_DISPLACEMENT_FACTOR,   // Y displacement rotates around X axis
                                                              mRotationStart.y + displacement.x / X_ROTATION_DISPLACEMENT_FACTOR ); // X displacement rotates around Y axis
             Quaternion rotation = Quaternion( Radian( mModels[mSelectedModelIndex].rotation.x ), Vector3::XAXIS) *
@@ -436,7 +445,7 @@ public:
           case LIGHT_TAG: //Drag light
           {
             //Set light source to new position and update the models accordingly.
-            mLightSource.SetPosition( Vector3( touch.GetScreenPosition( 0 ) ) );
+            mLightSource.SetPosition( Vector3( point.screen ) );
             UpdateLight();
 
             break;
@@ -445,8 +454,8 @@ public:
 
         break;
       }
-      case PointState::INTERRUPTED: //Same as finished.
-      case PointState::FINISHED:
+      case TouchPoint::Interrupted: //Same as finished.
+      case TouchPoint::Finished:
       {
         if( mTag == MODEL_TAG )
         {