Esempio n. 1
0
        public void LoadContent(GraphicsDevice device, GraphicsDeviceManager deviceManager,
                                SpriteFont font, Effect bgEffect)
        {
            Check.ArgumentNotNull(deviceManager, nameof(deviceManager), "Cannot instantiate the console without graphics device manager.");
            Check.ArgumentNotNull(font, nameof(font), "Cannot instantiate the console without a font.");

            GraphicsDevice         = device;
            _graphicsDeviceManager = deviceManager;
            _defaultFont           = font;
            if (Font == null)
            {
                Font = _defaultFont;
            }

            SpriteBatch = new SpriteBatch(GraphicsDevice);

            _graphicsDeviceManager.PreparingDeviceSettings += OnPreparingDeviceChanged;
            WhiteTexture = new Texture2D(GraphicsDevice, 2, 2, false, SurfaceFormat.Color);
            WhiteTexture.SetData(new[] { Color.White, Color.White, Color.White, Color.White });
            _loaded = true;

            MeasureFontSize();
            SetWindowWidthAndHeight();

            ConsoleInput.LoadContent(this);
            ConsoleOutput.LoadContent(this);
            BgRenderer.LoadContent(this, bgEffect);
        }
Esempio n. 2
0
        public void Dispose()
        {
            _graphicsDeviceManager.PreparingDeviceSettings -= OnPreparingDeviceChanged;

            SpriteBatch?.Dispose();
            WhiteTexture?.Dispose();
            BgRenderer.Dispose();
        }
Esempio n. 3
0
        private void SetSettings(ConsoleSettings settings)
        {
            BackgroundColor            = settings.BackgroundColor;
            FontColor                  = settings.FontColor;
            HeightRatio                = settings.HeightRatio;
            OpenCloseTransitionSeconds = settings.TimeToToggleOpenClose;
            Padding               = settings.Padding;
            BottomBorderColor     = settings.BottomBorderColor;
            BottomBorderThickness = settings.BottomBorderThickness;
            TabSymbol             = settings.TabSymbol;

            BgRenderer.SetDefaults(settings);
            ConsoleInput.SetDefaults(settings);
            ConsoleOutput.SetDefaults(settings);
        }
Esempio n. 4
0
 public void Draw()
 {
     switch (State)
     {
     case ConsoleState.Closing:
     case ConsoleState.Opening:
     case ConsoleState.Open:
         SpriteBatch.Begin();
         // Draw background.
         if (BgRenderer.Texture != null)
         {
             BgRenderer.Draw();
         }
         else
         {
             SpriteBatch.Draw(
                 WhiteTexture,
                 WindowArea,
                 new RectangleF(
                     0,
                     0,
                     WindowArea.Width,
                     WindowArea.Height),
                 BackgroundColor);
         }
         // Draw bottom border if enabled (thickness larger than zero).
         if (BottomBorderThickness > 0)
         {
             SpriteBatch.Draw(
                 WhiteTexture,
                 new RectangleF(0, WindowArea.Bottom, WindowArea.Width, BottomBorderThickness),
                 BottomBorderColor);
         }
         // Draw output and input strings.
         ConsoleOutput.Draw();
         ConsoleInput.Draw();
         SpriteBatch.End();
         break;
     }
 }