Using migrated Public Visual API
[platform/core/uifw/dali-demo.git] / examples / mesh-visual / mesh-visual-example.cpp
index e8674c9..682c243 100644 (file)
@@ -1,70 +1,71 @@
 #include <dali-toolkit/dali-toolkit.h>
-#include <dali/public-api/object/property-map.h>
 
 using namespace Dali;
 using namespace Dali::Toolkit;
 
 namespace
 {
-  //Keeps information about each model for access.
-  struct Model
-  {
-    Control control; // Control housing the mesh visual of the model.
-    Vector2 rotation; // Keeps track of rotation about x and y axis for manual rotation.
-    Animation rotationAnimation; // Automatically rotates when left alone.
-  };
+// Keeps information about each model for access.
+struct Model
+{
+  Control control; // Control housing the mesh visual of the model.
+  Vector2 rotation; // Keeps track of rotation about x and y axis for manual rotation.
+  Animation rotationAnimation; // Automatically rotates when left alone.
+};
 
-  //Files for meshes
-  const char * const MODEL_FILE_TABLE[] =
-  {
-      DEMO_MODEL_DIR "Dino.obj",
-      DEMO_MODEL_DIR "ToyRobot-Metal.obj",
-      DEMO_MODEL_DIR "Toyrobot-Plastic.obj"
-  };
+// Files for meshes
+const char * const MODEL_FILE_TABLE[] =
+{
+    DEMO_MODEL_DIR "Dino.obj",
+    DEMO_MODEL_DIR "ToyRobot-Metal.obj",
+    DEMO_MODEL_DIR "Toyrobot-Plastic.obj"
+};
 
-  const char * const MATERIAL_FILE_TABLE[] =
-  {
-      DEMO_MODEL_DIR "Dino.mtl",
-      DEMO_MODEL_DIR "ToyRobot-Metal.mtl",
-      DEMO_MODEL_DIR "Toyrobot-Plastic.mtl"
-  };
+const char * const MATERIAL_FILE_TABLE[] =
+{
+    DEMO_MODEL_DIR "Dino.mtl",
+    DEMO_MODEL_DIR "ToyRobot-Metal.mtl",
+    DEMO_MODEL_DIR "Toyrobot-Plastic.mtl"
+};
 
-  const char * const TEXTURES_PATH( DEMO_IMAGE_DIR "" );
+const char * const TEXTURES_PATH( DEMO_IMAGE_DIR "" );
 
-  //Possible shading modes.
-  MeshVisual::ShadingMode::Value SHADING_MODE_TABLE[] =
-  {
-    MeshVisual::ShadingMode::TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING,
-    MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING,
-    MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING
-  };
-
-  //Button labels.
-  const char * const PAUSE =  "  ||  ";
-  const char * const PLAY =   "  >  ";
-  const char * const FIXED =  "FIXED";
-  const char * const MANUAL = "MANUAL";
-  const char * const FRONT =  "FRONT";
-  const char * const BACK =   "BACK";
-
-  //Image urls for the light.
-  const char * const LIGHT_URL_FRONT = DEMO_IMAGE_DIR "light-icon-front.png";
-  const char * const LIGHT_URL_BACK =  DEMO_IMAGE_DIR "light-icon-back.png";
-
-  const float X_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
-  const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
-  const float MODEL_SCALE =                    0.75f;
-  const float LIGHT_SCALE =                    0.15f;
-  const float BUTTONS_OFFSET_BOTTOM =          0.08f;
-  const float BUTTONS_OFFSET_SIDE =            0.2f;
-  const int   NUM_MESHES =                     2;
-
-  //Used to identify actors.
-  const int MODEL_TAG = 0;
-  const int LIGHT_TAG = 1;
-  const int LAYER_TAG = 2;
-
-} //End namespace
+// Possible shading modes.
+MeshVisual::ShadingMode::Value SHADING_MODE_TABLE[] =
+{
+  MeshVisual::ShadingMode::TEXTURED_WITH_DETAILED_SPECULAR_LIGHTING,
+  MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING,
+  MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING
+};
+
+// Button labels.
+const char * const PAUSE =  "  ||  ";
+const char * const PLAY =   "  >  ";
+const char * const FIXED =  "FIXED";
+const char * const MANUAL = "MANUAL";
+const char * const FRONT =  "FRONT";
+const char * const BACK =   "BACK";
+
+// Image urls for the light.
+const char * const LIGHT_URL_FRONT = DEMO_IMAGE_DIR "light-icon-front.png";
+const char * const LIGHT_URL_BACK =  DEMO_IMAGE_DIR "light-icon-back.png";
+
+const float X_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
+const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.0f;
+const float MODEL_SCALE =                    0.75f;
+const float LIGHT_SCALE =                    0.15f;
+const float BUTTONS_OFFSET_BOTTOM =          0.08f;
+const float BUTTONS_OFFSET_SIDE =            0.2f;
+const int   NUM_MESHES =                     2;
+
+// Used to identify actors.
+const int MODEL_TAG = 0;
+const int LIGHT_TAG = 1;
+const int LAYER_TAG = 2;
+
+const Vector4 STAGE_COLOR( 211.0f / 255.0f, 211.0f / 255.0f, 211.0f / 255.0f, 1.0f ); ///< The color of the stage
+
+} // unnamed namespace
 
 class MeshVisualController : public ConnectionTracker
 {
@@ -93,7 +94,7 @@ public:
   {
     // Get a handle to the stage
     Stage stage = Stage::GetCurrent();
-    stage.SetBackgroundColor( Vector4( 0.0, 0.5, 1.0, 1.0 ) );
+    stage.SetBackgroundColor( STAGE_COLOR );
 
     //Set up root layer to receive touch gestures.
     Layer rootLayer = stage.GetRootLayer();
@@ -183,7 +184,7 @@ public:
     modelButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeModelClicked );
     modelButton.SetParentOrigin( ParentOrigin::TOP_CENTER );
     modelButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
-    modelButton.SetLabelText( "Model" );
+    modelButton.SetProperty( Toolkit::Button::Property::LABEL, "Model" );
     positionActorModel.Add( modelButton );
 
     //Create button for shading mode changing.
@@ -192,7 +193,7 @@ public:
     shadingModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeShadingModeClicked );
     shadingModeButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
     shadingModeButton.SetAnchorPoint( AnchorPoint::TOP_CENTER );
-    shadingModeButton.SetLabelText( "Shading Mode" );
+    shadingModeButton.SetProperty( Toolkit::Button::Property::LABEL, "Shading Mode" );
     positionActorModel.Add( shadingModeButton );
 
     //Text label title for changing model or shading mode.
@@ -209,7 +210,7 @@ public:
     pauseButton.ClickedSignal().Connect( this, &MeshVisualController::OnPauseClicked );
     pauseButton.SetParentOrigin( Vector3( 0.5, 1.0 - BUTTONS_OFFSET_BOTTOM, 0.5 ) );
     pauseButton.SetAnchorPoint( AnchorPoint::CENTER );
-    pauseButton.SetLabelText( PAUSE );
+    pauseButton.SetProperty( Toolkit::Button::Property::LABEL, PAUSE );
     layer.Add( pauseButton );
 
     //Actor for positioning light position buttons.
@@ -224,7 +225,7 @@ public:
     lightModeButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightModeClicked );
     lightModeButton.SetParentOrigin( ParentOrigin::TOP_CENTER );
     lightModeButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
-    lightModeButton.SetLabelText( FIXED );
+    lightModeButton.SetProperty( Toolkit::Button::Property::LABEL, FIXED );
     positionActorLight.Add( lightModeButton );
 
     //Create button for switching between front and back light position.
@@ -233,7 +234,7 @@ public:
     lightSideButton.ClickedSignal().Connect( this, &MeshVisualController::OnChangeLightSideClicked );
     lightSideButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
     lightSideButton.SetAnchorPoint( AnchorPoint::TOP_CENTER );
-    lightSideButton.SetLabelText( FRONT );
+    lightSideButton.SetProperty( Toolkit::Button::Property::LABEL, FRONT );
     positionActorLight.Add( lightSideButton );
 
     //Text label title for light position mode.
@@ -308,7 +309,7 @@ public:
     }
 
     Property::Map lightMap;
-    lightMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
+    lightMap.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
     lightMap.Insert( ImageVisual::Property::URL, imageUrl );
     mLightSource.SetProperty( Control::Property::BACKGROUND, Property::Value( lightMap ) );
   }
@@ -318,7 +319,10 @@ public:
   {
     //Create mesh property map
     Property::Map map;
-    map.Insert( Visual::Property::TYPE,  Visual::MESH );
+    map.Insert( Toolkit::Visual::Property::TYPE,  Visual::MESH );
+    map.Insert( Visual::Property::TRANSFORM,
+                Property::Map().Add( Visual::Transform::Property::ORIGIN, Align::CENTER )
+                               .Add( Visual::Transform::Property::ANCHOR_POINT, Align::CENTER ) );
     map.Insert( MeshVisual::Property::OBJECT_URL, MODEL_FILE_TABLE[mModelIndex] );
     map.Insert( MeshVisual::Property::MATERIAL_URL, MATERIAL_FILE_TABLE[mModelIndex] );
     map.Insert( MeshVisual::Property::TEXTURES_PATH, TEXTURES_PATH );
@@ -504,7 +508,7 @@ public:
         mModels[i].rotationAnimation.Pause();
       }
 
-      button.SetLabelText( PLAY );
+      button.SetProperty( Toolkit::Button::Property::LABEL, PLAY );
     }
     else //Unpause all animations again.
     {
@@ -513,7 +517,7 @@ public:
         mModels[i].rotationAnimation.Play();
       }
 
-      button.SetLabelText( PAUSE );
+      button.SetProperty( Toolkit::Button::Property::LABEL, PAUSE );
     }
 
     return true;
@@ -528,11 +532,11 @@ public:
 
     if( mLightFixed )
     {
-      button.SetLabelText( FIXED );
+      button.SetProperty( Toolkit::Button::Property::LABEL, FIXED );
     }
     else
     {
-      button.SetLabelText( MANUAL );
+      button.SetProperty( Toolkit::Button::Property::LABEL, MANUAL );
     }
 
     SetLightMode();
@@ -548,11 +552,11 @@ public:
 
     if( mLightFront )
     {
-      button.SetLabelText( FRONT );
+      button.SetProperty( Toolkit::Button::Property::LABEL, FRONT );
     }
     else
     {
-      button.SetLabelText( BACK );
+      button.SetProperty( Toolkit::Button::Property::LABEL, BACK );
     }
 
     //Change light image.