/*
- * Copyright (c) 2014 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.
//
//------------------------------------------------------------------------------
-#include <dali/dali.h>
#include <dali-toolkit/dali-toolkit.h>
#include <dali-toolkit/devel-api/builder/builder.h>
#include <dali-toolkit/devel-api/builder/tree-node.h>
+#include <dali/dali.h>
+#include <dali/devel-api/adaptor-framework/file-loader.h>
+#include <fstream>
#include <iostream>
#include <map>
-#include <string>
-#include <fstream>
#include <streambuf>
+#include <string>
-#include "sys/stat.h"
#include <ctime>
+#include "sys/stat.h"
#include <dali/integration-api/debug.h>
namespace
{
-
-std::string JSON_BROKEN(" \
+std::string JSON_BROKEN(
+ " \
{ \
'stage': \
[ \
} \
");
-std::string ReplaceQuotes(const std::string &single_quoted)
+std::string ReplaceQuotes(const std::string& single_quoted)
{
std::string s(single_quoted);
return s;
}
-} // anon namespace
-
+} // namespace
//------------------------------------------------------------------------------
//
public:
FileWatcher(void);
~FileWatcher(void);
- explicit FileWatcher(const std::string &fn): mLastTime(0) { SetFilename(fn) ; };
+ explicit FileWatcher(const std::string& fn)
+ : mLastTime(0)
+ {
+ SetFilename(fn);
+ };
- void SetFilename(const std::string &fn);
+ void SetFilename(const std::string& fn);
std::string GetFilename();
- bool FileHasChanged(void);
- std::string GetFileContents(void) { return GetFileContents(mstringPath) ; };
+ bool FileHasChanged(void);
+ std::string GetFileContents(void)
+ {
+ return GetFileContents(mstringPath);
+ };
private:
// compiler does
std::time_t mLastTime;
std::string mstringPath;
- std::string GetFileContents(const std::string &fn)
+ std::string GetFileContents(const std::string& filename)
{
- 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(filename, bufferSize, fileBuffer, FileLoader::FileType::BINARY))
+ {
+ return std::string();
+ }
+
+ return std::string(&fileBuffer[0], bufferSize);
};
};
-FileWatcher::FileWatcher(void) : mLastTime(0)
+FileWatcher::FileWatcher(void)
+: mLastTime(0)
{
}
{
}
-void FileWatcher::SetFilename(const std::string &fn)
+void FileWatcher::SetFilename(const std::string& fn)
{
mstringPath = fn;
}
return mstringPath;
}
-
//------------------------------------------------------------------------------
//
//
class ExampleApp : public ConnectionTracker
{
public:
- ExampleApp(Application &app) : mApp(app)
+ ExampleApp(Application& app)
+ : mApp(app)
{
app.InitSignal().Connect(this, &ExampleApp::Create);
-
}
- ~ExampleApp() {}
+ ~ExampleApp()
+ {
+ }
public:
- void SetJSONFilename(std::string const &fn) { fw.SetFilename(fn) ; };
+ void SetJSONFilename(std::string const& fn)
+ {
+ fw.SetFilename(fn);
+ };
void Create(Application& app)
{
- mTimer = Timer::New( 500 ); // ms
- mTimer.TickSignal().Connect( this, &ExampleApp::OnTimer);
+ mTimer = Timer::New(500); // ms
+ mTimer.TickSignal().Connect(this, &ExampleApp::OnTimer);
mTimer.Start();
// Connect to key events in order to exit
- Stage::GetCurrent().KeyEventSignal().Connect(this, &ExampleApp::OnKeyEvent);
+ app.GetWindow().KeyEventSignal().Connect(this, &ExampleApp::OnKeyEvent);
}
private:
Application& mApp;
- Layer mRootLayer;
+ Layer mRootLayer;
FileWatcher fw;
- Timer mTimer;
+ Timer mTimer;
void ReloadJsonFile(Builder& builder, Layer& layer)
{
- Stage stage = Stage::GetCurrent();
+ Window window = mApp.GetWindow();
+ window.SetBackgroundColor(Color::WHITE);
builder = Builder::New();
- builder.QuitSignal().Connect( this, &ExampleApp::OnBuilderQuit );
+ builder.QuitSignal().Connect(this, &ExampleApp::OnBuilderQuit);
Property::Map defaultDirs;
- defaultDirs[ TOKEN_STRING(DALI_IMAGE_DIR) ] = DALI_IMAGE_DIR;
- defaultDirs[ TOKEN_STRING(DALI_MODEL_DIR) ] = DALI_MODEL_DIR;
- defaultDirs[ TOKEN_STRING(DALI_SCRIPT_DIR) ] = DALI_SCRIPT_DIR;
+ defaultDirs[TOKEN_STRING(DEMO_IMAGE_DIR)] = DEMO_IMAGE_DIR;
+ defaultDirs[TOKEN_STRING(DEMO_MODEL_DIR)] = DEMO_MODEL_DIR;
+ defaultDirs[TOKEN_STRING(DEMO_SCRIPT_DIR)] = DEMO_SCRIPT_DIR;
- builder.AddConstants( defaultDirs );
+ builder.AddConstants(defaultDirs);
if(!layer)
{
layer = Layer::New();
- layer.SetParentOrigin(ParentOrigin::CENTER);
- layer.SetAnchorPoint(AnchorPoint::CENTER);
- layer.SetSize( stage.GetRootLayer().GetCurrentSize() );
- stage.GetRootLayer().Add(layer);
+ layer.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+ layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+ layer.SetProperty(Actor::Property::SIZE, window.GetRootLayer().GetCurrentProperty<Vector3>(Actor::Property::SIZE));
+ window.GetRootLayer().Add(layer);
// render tasks may have been setup last load so remove them
- RenderTaskList taskList = stage.GetRenderTaskList();
- if( taskList.GetTaskCount() > 1 )
+ RenderTaskList taskList = window.GetRenderTaskList();
+ if(taskList.GetTaskCount() > 1)
{
typedef std::vector<RenderTask> Collection;
- typedef Collection::iterator ColIter;
- Collection tasks;
+ typedef Collection::iterator ColIter;
+ Collection tasks;
for(unsigned int i = 1; i < taskList.GetTaskCount(); ++i)
{
- tasks.push_back( taskList.GetTask(i) );
+ tasks.push_back(taskList.GetTask(i));
}
for(ColIter iter = tasks.begin(); iter != tasks.end(); ++iter)
}
RenderTask defaultTask = taskList.GetTask(0);
- defaultTask.SetSourceActor( stage.GetRootLayer() );
- defaultTask.SetTargetFrameBuffer( FrameBufferImage() );
+ defaultTask.SetSourceActor(window.GetRootLayer());
+ defaultTask.SetFrameBuffer(FrameBuffer());
}
}
unsigned int numChildren = layer.GetChildCount();
- for(unsigned int i=0; i<numChildren; ++i)
+ for(unsigned int i = 0; i < numChildren; ++i)
{
- layer.Remove( layer.GetChildAt(0) );
+ layer.Remove(layer.GetChildAt(0));
}
std::string data(fw.GetFileContents());
builder.LoadFromString(ReplaceQuotes(JSON_BROKEN));
}
- builder.AddActors( layer );
-
+ builder.AddActors(layer);
}
-
bool OnTimer(void)
{
if(fw.FileHasChanged())
{
- ReloadJsonFile( mBuilder, mRootLayer );
+ ReloadJsonFile(mBuilder, mRootLayer);
}
return true;
}
// Process Key events to Quit on back-key
- void OnKeyEvent( const KeyEvent& event )
+ 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 ) )
+ if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
{
mApp.Quit();
}
//
//
//------------------------------------------------------------------------------
-int main(int argc, char **argv)
+int DALI_EXPORT_API main(int argc, char** argv)
{
- Application dali_app = Application::New(&argc, &argv);
-
- ExampleApp app(dali_app);
-
+ Application dali_app = Application::New(&argc, &argv, DEMO_THEME_PATH);
+ ExampleApp app(dali_app);
if(argc > 1)
{