nui 0.2.32 manual merge, mapping to dali 1.2.32
[platform/core/csapi/tizenfx.git] / NUISamples / NUISamples / NUISamples.TizenTV / 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 Tizen.NUI;
21
22 namespace JsonLoaderTest
23 {
24   class Example : NUIApplication
25   {
26     private Builder _builder;
27     private string _jsonFileName;
28
29     public Example() : base()
30     {
31     }
32
33     public Example(string stylesheet) : base(stylesheet)
34     {
35        _jsonFileName = stylesheet;
36     }
37
38     public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
39     {
40     }
41
42     protected override void OnCreate()
43     {
44         base.OnCreate();
45         Initialize();
46     }
47
48     public void Initialize()
49     {
50         if( _jsonFileName.Length == 0)
51         {
52           Console.WriteLine("Please specify JSON file to load");
53           return;
54         }
55
56         _builder = new Builder ();
57
58         PropertyMap constants = new  PropertyMap();
59
60         //  In dali-demo we have some JSON files that can be loaded, but they need 3 different macros defining.
61         // The JSON folder is typically installed into dali-env/opt/share/com.samsung.dali-demo/res:
62         //
63         //string demoDirectory = ".../dali-env/opt/share/com.samsung.dali-demo/res";
64         //constants.Insert( "DEMO_IMAGE_DIR" ,  new PropertyValue( demoDirectory+"/images") );
65         //constants.Insert( "DEMO_MODEL_DIR" ,  new PropertyValue( demoDirectory+"/models") );
66         //constants.Insert( "DEMO_SCRIPT_DIR",  new PropertyValue( demoDirectory+"/scripts") );
67         constants.Insert( "CONFIG_SCRIPT_LOG_LEVEL",  new PropertyValue( "Verbose") );
68
69          _builder.AddConstants( constants );
70
71
72         Stage stage = Stage.Instance;
73         stage.BackgroundColor = Color.White;
74
75         _builder.LoadFromFile( _jsonFileName );
76
77         _builder.AddActors( stage.GetDefaultLayer() );
78
79     }
80
81     /// <summary>
82     /// The main entry point for the application.
83     /// </summary>
84     [STAThread]
85     static void _Main(string[] args)
86     {
87       string fileName= "";
88
89       if( args.Length > 0)
90       {
91           fileName = args[0];
92       }
93
94       Console.WriteLine("arguments = " + args.Length);
95       Example example = new Example(fileName);
96       example.Run(args);
97     }
98   }
99 }