예제 #1
0
        /// <summary>
        /// Constructs a new viewport with the given width/height.
        /// </summary>
        /// <param name="routine">Routine to view.</param>
        /// <param name="width">Viewport width.</param>
        /// <param name="height">Viewport height.</param>
        public RoutineViewport(IRoutine routine, int width, int height)
        {
            _routine = routine;

            // Validate that routines defined views the way we expect
            if (_routine.Views.Count == 0)
            {
                throw new Exception($"{_routine.GetType().Name} defines 0 views.");
            }

            for (int i = 1; i < _routine.Views.Count; i++)
            {
                var curView  = _routine.Views[i].view;
                var prevView = _routine.Views[i - 1].view;

                if (curView.Width != prevView.Width || curView.Height != prevView.Height)
                {
                    throw new Exception($"{_routine.GetType().Name} defines views that are not the same size.");
                }
            }

            // Initialize initial views
            _viewIndex = 0;
            (CurrentViewName, CurrentView) = _routine.Views[_viewIndex];

            // Initialize initial viewport
            CurrentViewport = new Viewport <char>(CurrentView, (0, 0, width, height));
            CurrentViewport.SetViewArea(
                CurrentViewport.ViewArea.WithCenter((CurrentView.Width / 2, CurrentView.Height / 2)));
        }
예제 #2
0
        /// <summary>
        /// Advance to next view for routine.
        /// </summary>
        public void NextView()
        {
            var oldView = CurrentView;

            // Update index and views
            _viewIndex = MathHelpers.WrapAround(_viewIndex + 1, _routine.Views.Count);
            (CurrentViewName, CurrentView) = _routine.Views[_viewIndex];

            // Validate the size hasn't changed
            if (oldView.Width != CurrentView.Width || oldView.Height != CurrentView.Height)
            {
                throw new Exception($"{_routine.GetType().Name} defines views that are not the same size.");
            }

            // Create new viewport based on new view.
            CurrentViewport = new Viewport <char>(CurrentView, CurrentViewport.ViewArea);
        }
예제 #3
0
 public RoutineViewModel(IRoutine routine)
 {
     _routine        = routine;
     RoutineTypeName = routine.GetType().Name;
     DisplayName     = routine.DisplayName;
     Description     = routine.Description;
     RequiredBuild   = routine.BuildRequirements;
     Author          = routine.Author;
     Version         = routine.Version;
     Class           = routine.Class;
     Url             = routine.Url;
     BuildControl(routine);
 }