2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include <dali/integration-api/debug.h>
27 #include "shared/view.h"
31 using namespace Dali::Toolkit;
33 #define TOKEN_STRING(x) #x
37 std::string GetFileContents(const std::string& filename)
39 std::ifstream t(filename.c_str());
40 return std::string((std::istreambuf_iterator<char>(t)),
41 std::istreambuf_iterator<char>());
44 } // unnamed namespace
46 Launcher::Launcher( Dali::Application application, std::string layoutFileName, std::string scriptFileName )
47 : mApplication( application ),
48 mJSONFileName(layoutFileName ),
49 mJavaScriptFileName( scriptFileName )
51 mApplication.InitSignal().Connect( this, &Launcher::Create );
58 void Launcher::Create( Dali::Application& application )
60 TextLabel textActor = TextLabel::New( "JSON & JavaScript Launcher..." );
62 // Reposition the actor
63 textActor.SetParentOrigin( ParentOrigin::TOP_LEFT );
64 textActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
65 textActor.SetPosition( 20, 0 );
67 // Get a handle to the stage
68 Stage stage = Stage::GetCurrent();
70 // Display the actor on the stage
71 stage.Add( textActor );
73 // change the background color to purple
74 Stage::GetCurrent().SetBackgroundColor( Vector4(0.2,0.2,0.4,1.0) );
76 // Try loading a JSON file
77 if( !mJSONFileName.empty() )
79 mBuilder = Toolkit::Builder::New();
81 Property::Map defaultDirs;
82 defaultDirs[ TOKEN_STRING(DEMO_IMAGE_DIR) ] = DEMO_IMAGE_DIR;
83 defaultDirs[ TOKEN_STRING(DEMO_MODEL_DIR) ] = DEMO_MODEL_DIR;
84 defaultDirs[ TOKEN_STRING(DEMO_SCRIPT_DIR) ] = DEMO_SCRIPT_DIR;
85 mBuilder.AddConstants( defaultDirs );
87 std::string json_data(GetFileContents( mJSONFileName ));
88 mBuilder.LoadFromString(json_data);
89 mBuilder.AddActors( stage.GetRootLayer() );
92 // Try load a JavaScript file
93 if( !mJavaScriptFileName.empty() )
96 mScript = Toolkit::Script::New();
98 mScript.ExecuteFile( mJavaScriptFileName);
102 void Launcher::MainLoop()
104 mApplication.MainLoop();