Replace some Dali::Actor public APIs with new properties
[platform/core/uifw/dali-demo.git] / examples / builder / examples.cpp
index ba47e28..bcb3234 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 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,7 +25,6 @@
 #include <dali-toolkit/devel-api/builder/builder.h>
 #include <dali-toolkit/devel-api/builder/tree-node.h>
 #include <dali-toolkit/devel-api/builder/json-parser.h>
-#include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
 #include <dali-toolkit/devel-api/controls/popup/popup.h>
 #include <dali-toolkit/devel-api/controls/navigation-view/navigation-view.h>
 
@@ -43,6 +42,7 @@
 #include <cstring>
 
 #include <dali/integration-api/debug.h>
+#include <dali/devel-api/adaptor-framework/file-loader.h>
 #include "shared/view.h"
 
 #define TOKEN_STRING(x) #x
@@ -86,9 +86,14 @@ std::string ReplaceQuotes(const std::string &single_quoted)
 
 std::string GetFileContents(const std::string &fn)
 {
-  std::ifstream t(fn.c_str());
-  return std::string((std::istreambuf_iterator<char>(t)),
-                     std::istreambuf_iterator<char>());
+  std::streampos bufferSize = 0;
+  Dali::Vector<char> fileBuffer;
+  if( !Dali::FileLoader::ReadFile( fn, bufferSize, fileBuffer, FileLoader::FileType::BINARY ) )
+  {
+    return std::string();
+  }
+
+  return std::string( &fileBuffer[0], bufferSize );
 };
 
 typedef std::vector<std::string> FileList;
@@ -270,15 +275,15 @@ public:
 
     mItemView = ItemView::New(*this);
 
-    mItemView.SetParentOrigin(ParentOrigin::CENTER);
-    mItemView.SetAnchorPoint(AnchorPoint::CENTER);
+    mItemView.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
+    mItemView.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
     mLayout = DefaultItemLayout::New( DefaultItemLayout::LIST );
 
     mLayout->SetItemSize( Vector3( stage.GetSize().width, 50, 1 ) );
 
     mItemView.AddLayout( *mLayout );
 
-    mItemView.SetKeyboardFocusable( true );
+    mItemView.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
 
     mFiles.clear();
     FileList files;
@@ -406,7 +411,7 @@ public:
 
       RenderTask defaultTask = taskList.GetTask(0);
       defaultTask.SetSourceActor( stage.GetRootLayer() );
-      defaultTask.SetTargetFrameBuffer( FrameBufferImage() );
+      defaultTask.SetFrameBuffer( FrameBuffer() );
     }
 
     unsigned int numChildren = layer.GetChildCount();
@@ -445,11 +450,11 @@ public:
   {
     ReloadJsonFile( name, mBuilder, mBuilderLayer );
 
-    mBuilderLayer.SetParentOrigin(ParentOrigin::BOTTOM_CENTER);
-    mBuilderLayer.SetAnchorPoint(AnchorPoint::BOTTOM_CENTER);
-    Dali::Vector3 size = Stage::GetCurrent().GetRootLayer().GetCurrentSize();
+    mBuilderLayer.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_CENTER);
+    mBuilderLayer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_CENTER);
+    Dali::Vector3 size = Stage::GetCurrent().GetRootLayer().GetCurrentProperty< Vector3 >( Actor::Property::SIZE );
     size.y -= DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight;
-    mBuilderLayer.SetSize( size );
+    mBuilderLayer.SetProperty( Actor::Property::SIZE, size );
 
     mNavigationView.Push( mBuilderLayer );
   }
@@ -473,15 +478,15 @@ public:
 
     // Create an edit mode button. (left of toolbar)
     Toolkit::PushButton backButton = Toolkit::PushButton::New();
-    backButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, EDIT_IMAGE );
-    backButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, EDIT_IMAGE_SELECTED );
+    backButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EDIT_IMAGE );
+    backButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EDIT_IMAGE_SELECTED );
     backButton.ClickedSignal().Connect( this, &ExampleApp::OnBackButtonPressed);
-    backButton.SetLeaveRequired( true );
+    backButton.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
     mToolBar.AddControl( backButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING  );
 
     mNavigationView = Toolkit::NavigationView::New();
     mNavigationView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-    mNavigationView.SetAnchorPoint( AnchorPoint::TOP_LEFT);
+    mNavigationView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
 
     stage.Add( mNavigationView );
 
@@ -541,7 +546,7 @@ public:
    */
   void OnQuitOrBack()
   {
-    if ( mItemView.OnStage() )
+    if ( mItemView.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
     {
       mApp.Quit();
     }