Size, Position, Color high level class added
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / examples / json-loader.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using System;
19 using System.Runtime.InteropServices;
20 using Dali;
21
22 namespace MyExampleApp
23 {
24   class Example
25   {
26     private Dali.Application _application;
27     private Builder _builder;
28     private string _jsonFileName;
29
30     public Example(Dali.Application application, string fileName)
31     {
32       _application = application;
33       _jsonFileName = fileName;
34       _application.Initialized += Initialize;
35     }
36
37     public void Initialize(object source, NUIApplicationInitEventArgs e)
38     {
39         if( _jsonFileName.Length == 0)
40         {
41           Console.WriteLine("Please specify JSON file to load");
42           return;
43         }
44
45         _builder = new Builder ();
46
47         Property.Map constants = new  Property.Map();
48
49         //  In dali-demo we have some JSON files that can be loaded, but they need 3 different macros defining.
50         // The JSON folder is typically installed into dali-env/opt/share/com.samsung.dali-demo/res:
51         //
52         //string demoDirectory = ".../dali-env/opt/share/com.samsung.dali-demo/res";
53         //constants.Insert( "DEMO_IMAGE_DIR" ,  new Property.Value( demoDirectory+"/images") );
54         //constants.Insert( "DEMO_MODEL_DIR" ,  new Property.Value( demoDirectory+"/models") );
55         //constants.Insert( "DEMO_SCRIPT_DIR",  new Property.Value( demoDirectory+"/scripts") );
56         constants.Insert( "CONFIG_SCRIPT_LOG_LEVEL",  new Property.Value( "Verbose") );
57
58          _builder.AddConstants( constants );
59
60
61         Stage stage = Stage.GetCurrent();
62         stage.BackgroundColor = Color.White;
63
64         _builder.LoadFromFile( _jsonFileName );
65
66         _builder.AddActors( stage.GetRootLayer() );
67
68     }
69
70
71     public void MainLoop()
72     {
73       _application.MainLoop ();
74     }
75
76     /// <summary>
77     /// The main entry point for the application.
78     /// </summary>
79     [STAThread]
80     static void Main(string[] args)
81     {
82       string fileName= "";
83
84       if( args.Length > 0)
85       {
86           fileName = args[0];
87       }
88
89       Console.WriteLine("arguments = " + args.Length);
90       Example example = new Example(Application.NewApplication(), fileName);
91       example.MainLoop ();
92     }
93   }
94 }