Use Window instead of Stage
[platform/core/uifw/dali-demo.git] / examples / line-mesh / line-mesh-example.cpp
index a56f1b5..ff3aace 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 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.
@@ -16,8 +16,9 @@
  */
 
 // EXTERNAL INCLUDES
-#include <dali/public-api/rendering/renderer.h>
+#include <dali/devel-api/actors/actor-devel.h>
 #include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/controls/table-view/table-view.h>
 
 // INTERNAL INCLUDES
 #include "shared/view.h"
@@ -119,7 +120,19 @@ public:
    * @param[in] application The application instance
    */
   ExampleController( Application& application )
-  : mApplication( application )
+  : mApplication( application ),
+    mWindowSize(),
+    mShader(),
+    mGeometry(),
+    mRenderer(),
+    mMeshActor(),
+    mButtons(),
+    mMinusButton(),
+    mPlusButton(),
+    mIndicesCountLabel(),
+    mPrimitiveType( Geometry::LINES ),
+    mCurrentIndexCount( 0 ),
+    mMaxIndexCount( 0 )
   {
     // Connect to the Application's Init signal
     mApplication.InitSignal().Connect( this, &ExampleController::Create );
@@ -139,7 +152,7 @@ public:
    */
   void Create( Application& application )
   {
-    Stage stage = Stage::GetCurrent();
+    Window window = application.GetWindow();
 
     // initial settings
     mPrimitiveType = Geometry::LINES;
@@ -148,16 +161,13 @@ public:
 
     CreateRadioButtons();
 
-    stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent);
+    window.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent);
 
-    mStageSize = stage.GetSize();
+    mWindowSize = window.GetSize();
 
     Initialise();
 
-    // Hide the indicator bar
-    application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
-
-    stage.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));
+    window.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));
   }
 
   /**
@@ -165,12 +175,12 @@ public:
    */
   void Initialise()
   {
-    Stage stage = Stage::GetCurrent();
+    Window window = mApplication.GetWindow();
 
     // destroy mesh actor and its resources if already exists
     if( mMeshActor )
     {
-      stage.Remove( mMeshActor );
+      window.Remove( mMeshActor );
       mMeshActor.Reset();
     }
 
@@ -183,15 +193,16 @@ public:
 
     mMeshActor = Actor::New();
     mMeshActor.AddRenderer( mRenderer );
-    mMeshActor.SetSize(200, 200);
+    mMeshActor.SetProperty( Actor::Property::SIZE, Vector2(200, 200) );
+    mMeshActor.SetProperty( DevelActor::Property::UPDATE_SIZE_HINT, Vector2(400, 400) );
 
     Property::Index morphAmountIndex = mMeshActor.RegisterProperty( "uMorphAmount", 0.0f );
 
     mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, 0 );
 
-    mMeshActor.SetParentOrigin( ParentOrigin::CENTER );
-    mMeshActor.SetAnchorPoint( AnchorPoint::CENTER );
-    stage.Add( mMeshActor );
+    mMeshActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+    mMeshActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+    window.Add( mMeshActor );
 
     Animation  animation = Animation::New(5);
     KeyFrames keyFrames = KeyFrames::New();
@@ -208,16 +219,16 @@ public:
    */
   void CreateRadioButtons()
   {
-    Stage stage = Stage::GetCurrent();
+    Window window = mApplication.GetWindow();
 
     Toolkit::TableView modeSelectTableView = Toolkit::TableView::New( 4, 1 );
-    modeSelectTableView.SetParentOrigin( ParentOrigin::TOP_LEFT );
-    modeSelectTableView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+    modeSelectTableView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+    modeSelectTableView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
     modeSelectTableView.SetFitHeight( 0 );
     modeSelectTableView.SetFitHeight( 1 );
     modeSelectTableView.SetFitHeight( 2 );
     modeSelectTableView.SetCellPadding( Vector2( 6.0f, 0.0f ) );
-    modeSelectTableView.SetScale( Vector3( 0.8f, 0.8f, 0.8f ));
+    modeSelectTableView.SetProperty( Actor::Property::SCALE, Vector3( 0.8f, 0.8f, 0.8f ));
 
     const char* labels[] =
     {
@@ -228,16 +239,18 @@ public:
 
     for( int i = 0; i < 3; ++i )
     {
-      Property::Map labelMap;
-      labelMap[ "text" ]      = labels[i];
-      labelMap[ "textColor" ] = Vector4( 0.8f, 0.8f, 0.8f, 1.0f );
-
       Dali::Toolkit::RadioButton radio = Dali::Toolkit::RadioButton::New();
 
-      radio.SetProperty( Dali::Toolkit::Button::Property::LABEL, labelMap );
-      radio.SetParentOrigin( ParentOrigin::TOP_LEFT );
-      radio.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-      radio.SetSelected( i == 0 );
+      radio.SetProperty( Toolkit::Button::Property::LABEL,
+                                 Property::Map()
+                                  .Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
+                                  .Add( Toolkit::TextVisual::Property::TEXT, labels[i] )
+                                  .Add( Toolkit::TextVisual::Property::TEXT_COLOR, Vector4( 0.8f, 0.8f, 0.8f, 1.0f ) )
+                               );
+
+      radio.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+      radio.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+      radio.SetProperty( Toolkit::Button::Property::SELECTED, i == 0 );
       radio.PressedSignal().Connect( this, &ExampleController::OnButtonPressed );
       mButtons[i] = radio;
       modeSelectTableView.AddChild( radio, Toolkit::TableView::CellPosition( i,  0 ) );
@@ -245,28 +258,28 @@ public:
 
     Toolkit::TableView elementCountTableView = Toolkit::TableView::New( 1, 3 );
     elementCountTableView.SetCellPadding( Vector2( 6.0f, 0.0f ) );
-    elementCountTableView.SetParentOrigin( ParentOrigin::BOTTOM_LEFT );
-    elementCountTableView.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT );
+    elementCountTableView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT );
+    elementCountTableView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT );
     elementCountTableView.SetFitHeight( 0 );
     elementCountTableView.SetFitWidth( 0 );
     elementCountTableView.SetFitWidth( 1 );
     elementCountTableView.SetFitWidth( 2 );
     mMinusButton = Toolkit::PushButton::New();
-    mMinusButton.SetLabelText( "<<" );
-    mMinusButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
-    mMinusButton.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
+    mMinusButton.SetProperty( Toolkit::Button::Property::LABEL, "<<" );
+    mMinusButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+    mMinusButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT );
 
     Toolkit::PushButton mPlusButton = Toolkit::PushButton::New();
-    mPlusButton.SetLabelText( ">>" );
-    mPlusButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
-    mPlusButton.SetAnchorPoint( AnchorPoint::CENTER_RIGHT );
+    mPlusButton.SetProperty( Toolkit::Button::Property::LABEL, ">>" );
+    mPlusButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+    mPlusButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_RIGHT );
 
     mMinusButton.ClickedSignal().Connect( this, &ExampleController::OnButtonClicked );
     mPlusButton.ClickedSignal().Connect( this, &ExampleController::OnButtonClicked );
 
     mIndicesCountLabel = Toolkit::TextLabel::New();
-    mIndicesCountLabel.SetParentOrigin( ParentOrigin::CENTER );
-    mIndicesCountLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+    mIndicesCountLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+    mIndicesCountLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
 
     std::stringstream str;
     str << mCurrentIndexCount;
@@ -280,8 +293,8 @@ public:
     elementCountTableView.AddChild( mIndicesCountLabel, Toolkit::TableView::CellPosition( 0,  1 ) );
     elementCountTableView.AddChild( mPlusButton, Toolkit::TableView::CellPosition( 0,  2 ) );
 
-    stage.Add(modeSelectTableView);
-    stage.Add(elementCountTableView);
+    window.Add(modeSelectTableView);
+    window.Add(elementCountTableView);
   }
 
   /**
@@ -363,7 +376,7 @@ public:
 private:
 
   Application&  mApplication;                             ///< Application instance
-  Vector3 mStageSize;                                     ///< The size of the stage
+  Vector3 mWindowSize;                                     ///< The size of the window
 
   Shader   mShader;
   Geometry mGeometry;
@@ -378,20 +391,10 @@ private:
   int      mMaxIndexCount;
 };
 
-void RunTest( Application& application )
-{
-  ExampleController test( application );
-
-  application.MainLoop();
-}
-
-// Entry point for Linux & SLP applications
-//
 int DALI_EXPORT_API main( int argc, char **argv )
 {
   Application application = Application::New( &argc, &argv );
-
-  RunTest( application );
-
+  ExampleController test( application );
+  application.MainLoop();
   return 0;
 }