Merge "Removing unused variables" into devel/master
[platform/core/uifw/dali-demo.git] / examples / item-view / item-view-example.cpp
index ccb74e2..e4aee2b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 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.
@@ -196,14 +196,14 @@ public:
    */
   void OnInit(Application& app)
   {
-    Stage stage = Dali::Stage::GetCurrent();
-    stage.KeyEventSignal().Connect(this, &ItemViewExample::OnKeyEvent);
-    stage.GetRootLayer().SetBehavior(Layer::LAYER_3D);
+    Window window = app.GetWindow();
+    window.KeyEventSignal().Connect(this, &ItemViewExample::OnKeyEvent);
+    window.GetRootLayer().SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D );
 
-    Vector2 stageSize = Stage::GetCurrent().GetSize();
+    Vector2 windowSize = window.GetSize();
 
     // Creates a default view with a default tool bar.
-    // The view is added to the stage.
+    // The view is added to the window.
 
     Layer contents = DemoHelper::CreateView( mApplication,
                                              mView,
@@ -232,55 +232,55 @@ public:
     mDeleteButton = Toolkit::PushButton::New();
     mDeleteButton.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_RIGHT);
     mDeleteButton.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
-    mDeleteButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
-    mDeleteButton.SetDrawMode( DrawMode::OVERLAY_2D );
+    mDeleteButton.SetProperty( Actor::Property::POSITION, Vector2( BUTTON_BORDER, BUTTON_BORDER ));
+    mDeleteButton.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D );
     mDeleteButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DELETE_IMAGE );
     mDeleteButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DELETE_IMAGE_SELECTED );
     mDeleteButton.SetProperty( Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE );
-    mDeleteButton.SetSize( Vector2( stageSize.width * 0.15f, stageSize.width * 0.15f ) );
+    mDeleteButton.SetProperty( Actor::Property::SIZE, Vector2( windowSize.width * 0.15f, windowSize.width * 0.15f ) );
     mDeleteButton.ClickedSignal().Connect( this, &ItemViewExample::OnDeleteButtonClicked);
     mDeleteButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
     mDeleteButton.SetProperty( Actor::Property::VISIBLE, false );
-    stage.Add( mDeleteButton );
+    window.Add( mDeleteButton );
 
     // Create an insert button (bottom right of screen)
     mInsertButton = Toolkit::PushButton::New();
     mInsertButton.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_RIGHT);
     mInsertButton.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
-    mInsertButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
-    mInsertButton.SetDrawMode( DrawMode::OVERLAY_2D );
+    mInsertButton.SetProperty( Actor::Property::POSITION, Vector2( BUTTON_BORDER, BUTTON_BORDER ));
+    mInsertButton.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D );
     mInsertButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, INSERT_IMAGE );
     mInsertButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, INSERT_IMAGE_SELECTED );
     mInsertButton.SetProperty( Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE );
-    mInsertButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
+    mInsertButton.SetProperty( Actor::Property::SIZE, Vector2( windowSize.width * 0.15f, windowSize.width * 0.15f ) );
     mInsertButton.ClickedSignal().Connect( this, &ItemViewExample::OnInsertButtonClicked);
     mInsertButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
     mInsertButton.SetProperty( Actor::Property::VISIBLE, false );
-    stage.Add( mInsertButton );
+    window.Add( mInsertButton );
 
     // Create an replace button (bottom right of screen)
     mReplaceButton = Toolkit::PushButton::New();
     mReplaceButton.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_RIGHT);
     mReplaceButton.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
-    mReplaceButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
-    mReplaceButton.SetDrawMode( DrawMode::OVERLAY_2D );
+    mReplaceButton.SetProperty( Actor::Property::POSITION, Vector2( BUTTON_BORDER, BUTTON_BORDER ));
+    mReplaceButton.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D );
     mReplaceButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, REPLACE_IMAGE );
     mReplaceButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, REPLACE_IMAGE_SELECTED );
     mReplaceButton.SetProperty( Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE );
-    mReplaceButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
+    mReplaceButton.SetProperty( Actor::Property::SIZE, Vector2( windowSize.width * 0.15f, windowSize.width * 0.15f ) );
     mReplaceButton.ClickedSignal().Connect( this, &ItemViewExample::OnReplaceButtonClicked);
     mReplaceButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
     mReplaceButton.SetProperty( Actor::Property::VISIBLE, false );
-    stage.Add( mReplaceButton );
+    window.Add( mReplaceButton );
 
     // Create the item view actor
     mItemView = ItemView::New(*this);
     mItemView.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
     mItemView.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
 
-    // Display item view on the stage
-    stage.Add( mItemView );
-    stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
+    // Display item view on the window
+    window.Add( mItemView );
+    window.GetRootLayer().SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D );
 
     // Create the layouts
     mSpiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
@@ -297,7 +297,7 @@ public:
 
     // Activate the spiral layout
     SetLayout( mCurrentLayout );
-    mItemView.SetKeyboardFocusable( true );
+    mItemView.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
     KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &ItemViewExample::OnKeyboardPreFocusChange );
 
     // Set the title and icon to the current layout
@@ -344,18 +344,18 @@ public:
    */
   void SetLayout( int layoutId )
   {
-    Stage stage = Dali::Stage::GetCurrent();
+    Window window = mApplication.GetWindow();
     switch( mCurrentLayout )
     {
       case SPIRAL_LAYOUT:
       case DEPTH_LAYOUT:
       {
-        stage.GetRootLayer().SetBehavior(Layer::LAYER_3D);
+        window.GetRootLayer().SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D );
         break;
       }
       case GRID_LAYOUT:
       {
-        stage.GetRootLayer().SetBehavior(Layer::LAYER_UI);
+        window.GetRootLayer().SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_UI );
         break;
       }
     }
@@ -363,18 +363,18 @@ public:
     // Set the new orientation to the layout
     mItemView.GetLayout(layoutId)->SetOrientation(static_cast<ControlOrientation::Type>(mOrientation / 90));
 
-    Vector2 stageSize = Stage::GetCurrent().GetSize();
+    Vector2 windowSize = window.GetSize();
 
     if(layoutId == DEPTH_LAYOUT)
     {
       // Set up the depth layout according to the new orientation
       if(Toolkit::IsVertical(mDepthLayout->GetOrientation()))
       {
-        mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionPortrait( stageSize.width ) );
+        mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionPortrait( windowSize.width ) );
       }
       else
       {
-        mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionLandscape( stageSize.height ) );
+        mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionLandscape( windowSize.height ) );
       }
     }
 
@@ -382,7 +382,7 @@ public:
     mItemView.SetAnchoring(layoutId == DEPTH_LAYOUT);
 
     // Activate the layout
-    mItemView.ActivateLayout( layoutId, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
+    mItemView.ActivateLayout( layoutId, Vector3(windowSize.x, windowSize.y, windowSize.x), 0.0f );
   }
 
   bool OnLayoutButtonClicked( Toolkit::Button button )
@@ -553,7 +553,7 @@ public:
     {
       case Gesture::Started:
       {
-        const Size& size = Stage::GetCurrent().GetSize();
+        const Size& size = mApplication.GetWindow().GetSize();
 
         ItemRange range( 0u, 0u );
         mItemView.GetItemsRange( range );
@@ -872,16 +872,16 @@ public: // From ItemFactory
     propertyMap.Insert(DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FILL);
     ImageView actor = ImageView::New();
     actor.SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap );
-    actor.SetZ( 0.0f );
-    actor.SetPosition( INITIAL_OFFSCREEN_POSITION );
+    actor.SetProperty( Actor::Property::POSITION_Z,  0.0f );
+    actor.SetProperty( Actor::Property::POSITION, INITIAL_OFFSCREEN_POSITION );
 
     // Add a border image child actor
     ImageView borderActor = ImageView::New();
     borderActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
     borderActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
     borderActor.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
-    borderActor.SetSizeModeFactor( Vector3( 2.0f * ITEM_BORDER_SIZE, 2.0f * ITEM_BORDER_SIZE, 0.0f ) );
-    borderActor.SetColorMode( USE_PARENT_COLOR );
+    borderActor.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 2.0f * ITEM_BORDER_SIZE, 2.0f * ITEM_BORDER_SIZE, 0.0f ) );
+    borderActor.SetProperty( Actor::Property::COLOR_MODE, USE_PARENT_COLOR );
 
     Property::Map borderProperty;
     borderProperty.Insert( Toolkit::Visual::Property::TYPE, Visual::BORDER );
@@ -892,20 +892,21 @@ public: // From ItemFactory
 
     actor.Add(borderActor);
 
-    actor.SetKeyboardFocusable( true );
+    actor.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
 
     Vector3 spiralItemSize;
-    static_cast<ItemLayout&>(*mSpiralLayout).GetItemSize( 0u, Vector3( Stage::GetCurrent().GetSize() ), spiralItemSize );
+    Vector2 windowSize = mApplication.GetWindow().GetSize();
+    static_cast<ItemLayout&>(*mSpiralLayout).GetItemSize( 0u, Vector3( windowSize ), spiralItemSize );
 
     // Add a checkbox child actor; invisible until edit-mode is enabled
     ImageView checkbox = ImageView::New();
     checkbox.SetProperty( Dali::Actor::Property::NAME, "CheckBox" );
-    checkbox.SetColorMode( USE_PARENT_COLOR );
+    checkbox.SetProperty( Actor::Property::COLOR_MODE, USE_PARENT_COLOR );
     checkbox.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT );
     checkbox.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT );
-    checkbox.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
-    checkbox.SetPosition( -SELECTION_BORDER_WIDTH, SELECTION_BORDER_WIDTH );
-    checkbox.SetZ( 0.1f );
+    checkbox.SetProperty( Actor::Property::SIZE, Vector2( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f ) );
+    checkbox.SetProperty( Actor::Property::POSITION, Vector2( -SELECTION_BORDER_WIDTH, SELECTION_BORDER_WIDTH ));
+    checkbox.SetProperty( Actor::Property::POSITION_Z,  0.1f );
 
     Property::Map solidColorProperty;
     solidColorProperty.Insert( Toolkit::Visual::Property::TYPE, Visual::COLOR );
@@ -922,11 +923,11 @@ public: // From ItemFactory
 
     ImageView tick = ImageView::New( SELECTED_IMAGE );
     tick.SetProperty( Dali::Actor::Property::NAME, "Tick" );
-    tick.SetColorMode( USE_PARENT_COLOR );
+    tick.SetProperty( Actor::Property::COLOR_MODE, USE_PARENT_COLOR );
     tick.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT );
     tick.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT );
-    tick.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
-    tick.SetZ( 0.2f );
+    tick.SetProperty( Actor::Property::SIZE, Vector2( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f ) );
+    tick.SetProperty( Actor::Property::POSITION_Z,  0.2f );
     tick.SetProperty( Actor::Property::VISIBLE, false );
     checkbox.Add( tick );
 
@@ -962,7 +963,7 @@ private:
    */
   void OnKeyEvent(const KeyEvent& event)
   {
-    if(event.state == KeyEvent::Down)
+    if(event.GetState() == KeyEvent::DOWN)
     {
       if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
       {