Ejemplo n.º 1
0
        public GraphicalApp()
        {
            _model = CharlieModel.LoadFromFile();
//      var accelGroup = new AccelGroup();

            var provider = new CssProvider();

            provider.LoadFromPath(GetResource("style.css"));
            StyleContext.AddProviderForScreen(Screen.Default, provider, 800);

            var window = new Window(WindowType.Toplevel)
            {
                DefaultWidth  = _model.WindowWidth,
                DefaultHeight = _model.WindowHeight,
                Title         = "",
                Role          = "Charlie",
                Resizable     = true
            };

            window.Move(_model.WindowX, _model.WindowY);
            window.SetIconFromFile(GetResource("logo.png"));
//      window.AddAccelGroup(accelGroup);

            window.Destroyed += (sender, args) => Quit();
            window.Show();

            _window      = window;
            window.Child = CreateRoot();
            window.Child.ShowAll();
        }
Ejemplo n.º 2
0
        public static CharlieModel LoadFromFile()
        {
            var model = new CharlieModel();

            if (!Directory.Exists(PrefenceDir) ||
                !File.Exists(PreferenceFile))
            {
                return(model);
            }

            var text = File.ReadAllText(PreferenceFile);
            var pref = JsonNet.Deserialize <Preferences>(text);

            model.WindowX      = pref.WindowX;
            model.WindowY      = pref.WindowY;
            model.WindowWidth  = pref.WindowWidth;
            model.WindowHeight = pref.WindowHeight;
            model.PreviousLoaded.Set(pref.PreviousLoadedSims);
            model.SimDelay          = pref.SimDelay;
            model.LogEveryIteration = pref.LogEveryIteration;
            model.RenderWidth       = pref.RenderWidth;
            model.RenderHeight      = pref.RenderHeight;

            return(model);
        }
Ejemplo n.º 3
0
        private void Quit()
        {
            if (_model.ActiveRun.Get() != null)
            {
                if (_model.ActiveRun.Get().Running)
                {
                    ShowMessageDialog("Please stop the simulation first");
                }

                _model.ActiveRun.Get().Stop();
                _model.ActiveRun.Get().End();
            }

            Application.Quit();
            CharlieModel.SaveToFile(_model);
        }
Ejemplo n.º 4
0
        public static void SaveToFile(CharlieModel model)
        {
            var pref = new Preferences
            {
                WindowX            = model.WindowX,
                WindowY            = model.WindowY,
                WindowHeight       = model.WindowHeight,
                WindowWidth        = model.WindowWidth,
                PreviousLoadedSims = model.PreviousLoaded.Get(),
                SimDelay           = model.SimDelay,
                LogEveryIteration  = model.LogEveryIteration,
                RenderHeight       = model.RenderHeight,
                RenderWidth        = model.RenderWidth
            };

            if (!Directory.Exists(PrefenceDir))
            {
                Directory.CreateDirectory(PrefenceDir);
            }

            File.WriteAllText(PreferenceFile, JsonNet.Serialize(pref));
        }