Exemplo n.º 1
0
        private void UserSettingsOnPropertyChanged(object sender, PropertyChangedEventArgs args)
        {
            if (Automaton == null)
            {
                return;
            }

            PauseIteration();

            switch (args.PropertyName)
            {
            case nameof(Settings.Width):
            case nameof(Settings.Height):
                ImplementNewSize();
                break;

            case nameof(Settings.KnownLifePreset):
                CellLifeService.LifePreset = KnownLifePresets.GetKnownLifePreset(Settings.KnownLifePreset);
                break;

            case nameof(Settings.InitialAutomatonType):
                if (Settings.InitialAutomatonType != InitialAutomatonType.Previous)
                {
                    Automaton.Clear();
                    AutomatonSetPoints(InitialAutomaton());
                }
                break;

            case nameof(Settings.IterationDelay):
                _iterateTimer.Interval = TimeSpan.FromMilliseconds(Settings.IterationDelay);
                break;
            }

            ContinueIteration();
        }
Exemplo n.º 2
0
        private static void OnKnownLifePresetPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            var lifePresetControl = dependencyObject as LifePresetControl;

            if (lifePresetControl != null)
            {
                lifePresetControl.LifePreset = KnownLifePresets.GetKnownLifePreset((KnownLifePreset)dependencyPropertyChangedEventArgs.NewValue);
            }
        }
Exemplo n.º 3
0
        public AutomatonViewModel(
            ICellLifeService cellLifeService,
            ISettings settings,
            IChartRepository chartRepository,
            ICommandProvider automatonCommandProvider,
            ILogger logger)
        {
            settings.ThrowIfNull(nameof(settings));
            Settings = settings;

            chartRepository.ThrowIfNull(nameof(chartRepository));
            _chartRepository = chartRepository;

            automatonCommandProvider.ThrowIfNull(nameof(automatonCommandProvider));

            logger.ThrowIfNull(nameof(logger));
            _logger = logger;

            cellLifeService.ThrowIfNull(nameof(cellLifeService));
            CellLifeService            = cellLifeService;
            CellLifeService.LifePreset = KnownLifePresets.GetKnownLifePreset(Settings.KnownLifePreset);

            _resizeTimer = new DispatcherTimer
            {
                Interval = TimeSpan.FromMilliseconds(100),
            };
            _resizeTimer.Tick += ResizeTimerTick;

            _iterateTimer = new DispatcherTimer
            {
                Interval = TimeSpan.FromMilliseconds(Settings.IterationDelay),
            };
            _iterateTimer.Tick += IterateTimerTick;
            _logger.Log("AutomatonViewModel constructor is completed");

            Application.Current.MainWindow.Closing += new CancelEventHandler(MainWindow_Closing);

            // create commands
            IterateCommand = new DelegateCommand(Iterate, () => CanIterate)
            {
                IsActive = IsActive
            };
            StartIteratingCommand = new DelegateCommand(StartTimer, () => CanStartIterating)
            {
                IsActive = IsActive
            };
            StopIteratingCommand = new DelegateCommand(StopTimer, () => CanStopIterating)
            {
                IsActive = IsActive
            };
            RestartCommand = new DelegateCommand(SetInitialAutomaton, () => CanRestart)
            {
                IsActive = IsActive
            };

            automatonCommandProvider.IterateCommand.RegisterCommand(IterateCommand);
            automatonCommandProvider.StartIteratingCommand.RegisterCommand(StartIteratingCommand);
            automatonCommandProvider.StopIteratingCommand.RegisterCommand(StopIteratingCommand);
            automatonCommandProvider.RestartCommand.RegisterCommand(RestartCommand);

            SetAutomatonCommandProviderMode(AutomatonCommandProviderMode.None);
        }
Exemplo n.º 4
0
 public LifePresetControl()
 {
     InitializeComponent();
     LifePreset = KnownLifePresets.GetKnownLifePreset(KnownLifePreset);
 }