Revert "Updates following rename of PropertyBuffer"
[platform/core/uifw/dali-demo.git] / examples / ray-marching / ray-marching-example.cpp
index 4a924a6..0660bec 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.
@@ -20,6 +20,8 @@
 #include "shared/view.h"
 #include "shared/utility.h"
 #include <stdio.h>
+#include <dali/integration-api/debug.h>
+#include <dali/devel-api/adaptor-framework/file-stream.h>
 
 using namespace Dali;
 using Dali::Toolkit::TextLabel;
@@ -41,20 +43,31 @@ bool LoadShaderCode( const char* path, const char* filename, std::vector<char>&
 {
   std::string fullpath( path );
   fullpath += filename;
-  FILE* f = fopen( fullpath.c_str(), "rb" );
-  if( !f )
+
+  Dali::FileStream fileStream( fullpath, Dali::FileStream::READ | Dali::FileStream::BINARY );
+  FILE* file = fileStream.GetFile();
+  if( !file )
   {
     return false;
   }
-  fseek( f, 0, SEEK_END );
-  size_t size = ftell( f );
-  fseek( f, 0, SEEK_SET );
-  output.resize( size + 1 );
-  std::fill( output.begin(), output.end(), 0 );
-  ssize_t result = fread( output.data(), size, 1, f );
-  fclose( f );
-
-  return ( result >= 0 );
+
+  bool retValue = false;
+  if( !fseek( file, 0, SEEK_END ) )
+  {
+    long int size = ftell( file );
+
+    if( ( size != -1L ) &&
+        ( ! fseek( file, 0, SEEK_SET ) ) )
+    {
+      output.resize( size + 1 );
+      std::fill( output.begin(), output.end(), 0 );
+      ssize_t result = fread( output.data(), size, 1, file );
+
+      retValue = ( result >= 0 );
+    }
+  }
+
+  return retValue;
 }
 
 /**
@@ -69,9 +82,13 @@ Shader LoadShaders( const std::string& shaderName )
   std::string shaderFSH( shaderName );
   shaderVSH += ".vsh";
   shaderFSH += ".fsh";
-  LoadShaderCode( DEMO_SHADER_DIR, shaderVSH.c_str(), bufV );
-  LoadShaderCode( DEMO_SHADER_DIR, shaderFSH.c_str(), bufF );
-  Shader shader = Shader::New( bufV.data(), bufF.data() );
+
+  Shader shader;
+  if( LoadShaderCode( DEMO_SHADER_DIR, shaderVSH.c_str(), bufV ) &&
+      LoadShaderCode( DEMO_SHADER_DIR, shaderFSH.c_str(), bufF ) )
+  {
+    shader = Shader::New( bufV.data(), bufF.data() );
+  }
   return shader;
 }
 
@@ -96,20 +113,17 @@ 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();
+    // Get a handle to the window
+    Window window = application.GetWindow();
 
-    stage.GetRootLayer().TouchSignal().Connect( this, &RayMarchingExample::OnTouch );
+    window.GetRootLayer().TouchSignal().Connect( this, &RayMarchingExample::OnTouch );
 
-    stage.KeyEventSignal().Connect(this, &RayMarchingExample::OnKeyEvent);
+    window.KeyEventSignal().Connect(this, &RayMarchingExample::OnKeyEvent);
 
-    stage.SetBackgroundColor( Color::YELLOW );
-
-    // Hide the indicator bar
-    application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
+    window.SetBackgroundColor( Color::YELLOW );
 
     // Creates a default view with a default tool bar.
-    // The view is added to the stage.
+    // The view is added to the window.
     mContentLayer = DemoHelper::CreateView( application,
                                             mView,
                                             mToolBar,
@@ -123,7 +137,7 @@ public:
     AddContentLayer();
 
   }
-  bool OnTouch( Actor actor, const TouchData& touch )
+  bool OnTouch( Actor actor, const TouchEvent& touch )
   {
     // quit the application
     mApplication.Quit();
@@ -189,7 +203,7 @@ public:
 
   void AddContentLayer()
   {
-    Stage stage = Stage::GetCurrent();
+    Window window = mApplication.GetWindow();
 
      //Create all the renderers
     Renderer renderer = CreateQuadRenderer();
@@ -197,8 +211,8 @@ public:
     Actor actor = Actor::New();
     actor.AddRenderer( renderer );
 
-    actor.SetAnchorPoint( Dali::AnchorPoint::CENTER );
-    actor.SetParentOrigin( Dali::ParentOrigin::CENTER );
+    actor.SetProperty( Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER );
+    actor.SetProperty( Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER );
     actor.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
 
     mContentLayer.Add( actor );
@@ -211,20 +225,10 @@ private:
   ToolBar mToolBar;
 };
 
-void RunTest( Application& application )
-{
-  RayMarchingExample test( application );
-
-  application.MainLoop();
-}
-
-// Entry point for Linux & Tizen applications
-//
 int DALI_EXPORT_API main( int argc, char **argv )
 {
   Application application = Application::New( &argc, &argv );
-
-  RunTest( application );
-
+  RayMarchingExample test( application );
+  application.MainLoop();
   return 0;
 }