Revert "Revert "KeyEvent class pimpling""
[platform/core/uifw/dali-demo.git] / examples / model3d-view / model3d-view-example.cpp
index fc056b5..c02d526 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 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.
@@ -25,20 +25,20 @@ namespace
 const int MODEL_NUMBER(3);
 
 const char * const MODEL_FILE[] = {
-    DALI_MODEL_DIR "Dino.obj",
-    DALI_MODEL_DIR "ToyRobot-Metal.obj",
-    DALI_MODEL_DIR "Toyrobot-Plastic.obj"
+    DEMO_MODEL_DIR "Dino.obj",
+    DEMO_MODEL_DIR "ToyRobot-Metal.obj",
+    DEMO_MODEL_DIR "Toyrobot-Plastic.obj"
 };
 
 const char * const MATERIAL_FILE[] = {
-    DALI_MODEL_DIR "Dino.mtl",
-    DALI_MODEL_DIR "ToyRobot-Metal.mtl",
-    DALI_MODEL_DIR "Toyrobot-Plastic.mtl"
+    DEMO_MODEL_DIR "Dino.mtl",
+    DEMO_MODEL_DIR "ToyRobot-Metal.mtl",
+    DEMO_MODEL_DIR "Toyrobot-Plastic.mtl"
 };
 
-const char * const IMAGE_PATH( DALI_IMAGE_DIR "" );
+const char * const IMAGE_PATH( DEMO_IMAGE_DIR "" );
 
-const char * BACKGROUND_IMAGE( DALI_IMAGE_DIR "background-1.jpg");
+const char * BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-1.jpg");
 
 }
 
@@ -57,7 +57,16 @@ class Model3dViewController : public ConnectionTracker
 public:
 
   Model3dViewController( Application& application )
-  : mApplication( application )
+  : mApplication( application ),
+    mModelCounter( 0 ),
+    mModel3dView(),
+    mButtonLayer(),
+    mTapDetector(),
+    mIlluminationShader( Model3dView::DIFFUSE ),
+    mRotationAnimation(),
+    mLightAnimation(),
+    mPlaying( false ),
+    mScaled( false )
   {
     // Connect to the Application's Init signal
     mApplication.InitSignal().Connect( this, &Model3dViewController::Create );
@@ -71,71 +80,62 @@ public:
   // The Init signal is received once (only) during the Application lifetime
   void Create( Application& application )
   {
-    // Get a handle to the stage
-    Stage stage = Stage::GetCurrent();
-    Vector2 screenSize = stage.GetSize();
+    // Get a handle to the window
+    Window window = application.GetWindow();
+    Vector2 screenSize = window.GetSize();
 
     //Add background
-    Image imageBackground = ResourceImage::New( BACKGROUND_IMAGE );
-    Toolkit::ImageView backView = Toolkit::ImageView::New(imageBackground);
-    backView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-    stage.Add(backView);
-
-    //Add 3D model control
-    m3DLayer = Layer::New();
-    stage.GetRootLayer().Add(m3DLayer);
-
-    //3D models require 3D based rendering method, so it can use depth buffer, etc.
-    m3DLayer.SetBehavior(Layer::LAYER_3D);
-    m3DLayer.SetParentOrigin( ParentOrigin::CENTER );
-    m3DLayer.SetAnchorPoint( AnchorPoint::CENTER );
+    Toolkit::ImageView backView = Toolkit::ImageView::New( BACKGROUND_IMAGE );
+    backView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+    backView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+    window.Add( backView );
 
     mModelCounter = 0;
 
     mModel3dView = Model3dView::New( MODEL_FILE[0], MATERIAL_FILE[0], IMAGE_PATH );
-    mModel3dView.SetParentOrigin( ParentOrigin::CENTER );
-    mModel3dView.SetAnchorPoint( AnchorPoint::CENTER );
-    mModel3dView.SetName( "model3dViewControl" );
+    mModel3dView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+    mModel3dView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+    mModel3dView.SetProperty( Dali::Actor::Property::NAME, "model3dViewControl" );
     mModel3dView.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
-    mModel3dView.SetSize(screenSize);
+    mModel3dView.SetProperty( Actor::Property::SIZE, screenSize);
 
     mModel3dView.SetProperty(Model3dView::Property::LIGHT_POSITION, Vector3(5,10.,0));
 
-    m3DLayer.Add( mModel3dView );
+    backView.Add( mModel3dView );
 
     mIlluminationShader = Model3dView::IlluminationType(mModel3dView.GetProperty<int>(Model3dView::Property::ILLUMINATION_TYPE));
 
     mButtonLayer = Layer::New();
     mButtonLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-    mButtonLayer.SetParentOrigin( ParentOrigin::CENTER );
-    mButtonLayer.SetAnchorPoint( AnchorPoint::CENTER );
-    stage.GetRootLayer().Add(mButtonLayer);
+    mButtonLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+    mButtonLayer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+    window.Add(mButtonLayer);
 
     // Create button for model changing
     Toolkit::PushButton editButton = Toolkit::PushButton::New();
     editButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
     editButton.ClickedSignal().Connect( this, &Model3dViewController::OnChangeModelClicked);
-    editButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
-    editButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-    editButton.SetLabelText( "Change Model" );
+    editButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+    editButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+    editButton.SetProperty( Toolkit::Button::Property::LABEL, "Change Model" );
     mButtonLayer.Add( editButton  );
 
     // Create button for shader changing
     editButton = Toolkit::PushButton::New();
     editButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
     editButton.ClickedSignal().Connect( this, &Model3dViewController::OnChangeLightingClicked);
-    editButton.SetParentOrigin( ParentOrigin::TOP_RIGHT );
-    editButton.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
-    editButton.SetLabelText( "Change Shader" );
+    editButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT );
+    editButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT );
+    editButton.SetProperty( Toolkit::Button::Property::LABEL, "Change Shader" );
     mButtonLayer.Add( editButton  );
 
     // Create button for pause/resume animation
     editButton = Toolkit::PushButton::New();
     editButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
     editButton.ClickedSignal().Connect( this, &Model3dViewController::OnPauseAnimationsClicked);
-    editButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
-    editButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
-    editButton.SetLabelText( "Pause Animations" );
+    editButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER );
+    editButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER );
+    editButton.SetProperty( Toolkit::Button::Property::LABEL, "Pause Animations" );
     mButtonLayer.Add( editButton  );
 
     //Create animations
@@ -153,8 +153,8 @@ public:
     mPlaying = true;
     mScaled = false;
 
-    // Respond to a click anywhere on the stage
-    stage.KeyEventSignal().Connect(this, &Model3dViewController::OnKeyEvent);
+    // Respond to a click anywhere on the window
+    window.KeyEventSignal().Connect(this, &Model3dViewController::OnKeyEvent);
 
     //Create a tap gesture detector for zoom
     mTapDetector = TapGestureDetector::New( 2 );
@@ -170,14 +170,14 @@ public:
   {
     if (mScaled)
     {
-      mModel3dView.SetScale(1.0);
-      mModel3dView.SetPosition(0,0,0);
+      mModel3dView.SetProperty( Actor::Property::SCALE, 1.0f );
+      mModel3dView.SetProperty( Actor::Property::POSITION, Vector3( 0, 0, 0 ) );
       mScaled = false;
     }
     else
     {
-      Stage stage = Stage::GetCurrent();
-      Vector2 screenSize = stage.GetSize();
+      Window window = mApplication.GetWindow();
+      Vector2 screenSize = window.GetSize();
 
       Vector2 position;
       position.x = tap.screenPoint.x - screenSize.x * 0.5;
@@ -185,8 +185,8 @@ public:
 
       float size = 2.5;
 
-      mModel3dView.SetScale(size);
-      mModel3dView.SetPosition(-position.x * size,-position.y * size, 0);
+      mModel3dView.SetProperty( Actor::Property::SCALE, size );
+      mModel3dView.SetProperty( Actor::Property::POSITION, Vector3( -position.x * size, -position.y * size, 0 ) );
       mScaled = true;
     }
   }
@@ -199,8 +199,6 @@ public:
     mModelCounter = (mModelCounter + 1) % MODEL_NUMBER;
     mModel3dView.SetProperty(Model3dView::Property::GEOMETRY_URL, MODEL_FILE[mModelCounter]);
     mModel3dView.SetProperty(Model3dView::Property::MATERIAL_URL, MATERIAL_FILE[mModelCounter]);
-    mModel3dView.SetProperty(Model3dView::Property::IMAGES_URL, IMAGE_PATH);
-
     return true;
   }
 
@@ -264,7 +262,7 @@ public:
    */
   void 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) )
       {
@@ -284,7 +282,6 @@ private:
   int mModelCounter;
   Model3dView mModel3dView;
 
-  Layer m3DLayer;
   Layer mButtonLayer;
   TapGestureDetector mTapDetector;
 
@@ -297,20 +294,10 @@ private:
   bool mScaled;
 };
 
-void RunTest( Application& application )
+int DALI_EXPORT_API main( int argc, char **argv )
 {
+  Application application = Application::New( &argc, &argv );
   Model3dViewController test( application );
-
   application.MainLoop();
-}
-
-// Entry point for Linux & Tizen applications
-//
-int main( int argc, char **argv )
-{
-  Application application = Application::New( &argc, &argv );
-
-  RunTest( application );
-
   return 0;
 }