public override void DrawOverride(Application application, ConsoleArea area)
 {
     foreach (Control control in Control.Items)
     {
         if (control.RenderArea.IsNotEmpty( ))
         {
             control.Draw(application, area.CreateSub(control.RenderArea.GetValueOrDefault( )));
         }
     }
 }
 /// <summary>
 ///     Draws all characters within the given playground
 /// </summary>
 public override void DrawOverride(Application application, ConsoleArea area)
 {
     for (int y = 0; y < Control.Height; y++)
     {
         for (int x = 0; x < Control.Width; x++)
         {
             area [x, y] = Control [x, y];
         }
     }
 }
        public SelectBox(string[] selections)
        {
            this.selections = selections;
            var recommendedHeight = selections.Length + 2;

            root            = new ConsoleArea(new Size(20, Math.Min(10, recommendedHeight)));
            root.Background = ConsoleColor.DarkBlue;
            root.Foreground = ConsoleColor.White;
            ConsoleBorder.Draw(root, root.Size.Width / 2, root.Size.Height / 2, root.Size.Width, root.Size.Height);
            Redraw();
        }
        /// <summary>
        ///     Draws the
        ///     <code>Button</code>
        ///     given in the Control-Property.
        /// </summary>
        /// <exception cref="InvalidOperationException">Is thrown if the Control-Property isn't set.</exception>
        /// <exception cref="InvalidOperationException">Is thrown if the CalculateBoundary-Method hasn't been called.</exception>
        public override void DrawOverride(Application application, ConsoleArea area)
        {
            if (Control is null)
            {
                return;
            }

            if (Control.ActualSize.IsEmpty)
            {
                return;
            }

            ConsoleColor foregroundColor = Control.ActualForegroundColor;
            ConsoleColor backgroundColor = Control.ActualBackgroundColor;

            area.Fill(backgroundColor);

            if (Control.ContentHeight == 1)
            {
                int startPosition = Control.ContentWidth - Control.Text.Length;
                startPosition = (startPosition + startPosition % 2) / 2;
                startPosition = Math.Max(startPosition, 0);

                for (int x = 0; x < Control.ContentWidth && x < Control.Text.Length; x++)
                {
                    area [x + startPosition, 0] = new ConsoleChar(
                        Control.Text [x],
                        foregroundColor,
                        backgroundColor);
                }
            }
            else
            {
                int startLine = (Control.ContentHeight - Control.Lines.Count) / 2;
                startLine = Math.Max(startLine, 0);

                for (int y = 0; y < Control.Lines.Count && y + startLine < Control.ContentHeight; y++)
                {
                    string currentLine = Control.Lines [y];

                    int startPosition = Control.ContentWidth - currentLine.Length;
                    startPosition = (startPosition + startPosition % 2) / 2;
                    startPosition = Math.Max(startPosition, 0);

                    for (int x = 0; x < Control.ContentWidth - 2 && x < currentLine.Length; x++)
                    {
                        area [x + startPosition, startLine + y] =
                            new ConsoleChar(currentLine [x], foregroundColor, backgroundColor);
                    }
                }
            }

            //Todo:
        }
        public RootWindow()
        {
            const int WIDTH       = 80;
            const int HEIGHT      = 30;
            var       defaultSize = new Size(WIDTH, HEIGHT);

            win            = new ConsoleArea(defaultSize);
            win.Background = ConsoleColor.DarkGray;
            win.Clear();
            driver = new AnsiDriver();
            screen = new ConsoleUpdater(driver, defaultSize);
        }
 /// <summary>
 /// Sets the specified console area with the given console color and clears the console.
 /// </summary>
 /// <param name="area">The area of the console.</param>
 /// <param name="color">The color to set the area as.</param>
 public static void SetConsoleColor(ConsoleArea area, ConsoleColor color)
 {
     if (area == ConsoleArea.Foreground)
     {
         Console.ForegroundColor = color;
         Console.Clear();
     }
     else if (area == ConsoleArea.Background)
     {
         Console.BackgroundColor = color;
         Console.Clear();
     }
 }
        public void Draw(ConsoleArea area)
        {
            Rectangle resultPosition = area.Position.Intersect(Buffer.Position);

            for (int y = resultPosition.Top; y <= resultPosition.Bottom; y++)
            {
                for (int x = resultPosition.Left; x <= resultPosition.Right; x++)
                {
                    Buffer [x, y] = area [x, y];
                }
            }

            Redraw( );
        }
Exemple #8
0
        /// <summary>
        ///     Draws the
        ///     <code>Label</code>
        ///     given in the Control-Property.
        /// </summary>
        /// <exception cref="InvalidOperationException">Is thrown if the Control-Property isn't set.</exception>
        /// <exception cref="InvalidOperationException">Is thrown if the CalculateBoundary-Method hasn't been called.</exception>
        public override void DrawOverride(Application application, ConsoleArea area)
        {
            area.Fill(Control.ActualBackgroundColor);

            switch (Control.HorizontalAlign)
            {
            default:
            case ContentHorizontalAlign.Stretch:
            case ContentHorizontalAlign.Left:
            {
                for (int x = 0; x < Control.ActualWidth && x < Control.Text.Length; x++)
                {
                    area [x, 0] = new ConsoleChar(
                        Control.Text [x],
                        Control.ActualForegroundColor,
                        Control.ActualBackgroundColor);
                }

                break;
            }

            case ContentHorizontalAlign.Center:
            {
                int startPosition = (Control.ActualWidth - Control.Text.Length) / 2;
                for (int x = 0; x < Control.ActualWidth && x < Control.Text.Length; x++)
                {
                    area [x + startPosition, 0] = new ConsoleChar(
                        Control.Text [x],
                        Control.ActualForegroundColor,
                        Control.ActualBackgroundColor);
                }

                break;
            }

            case ContentHorizontalAlign.Right:
            {
                for (int x = 0; x < Control.ActualWidth && x < Control.Text.Length; x++)
                {
                    area [Control.ActualWidth - Control.Text.Length + x, 0] =
                        new ConsoleChar(
                            Control.Text [x],
                            Control.ActualForegroundColor,
                            Control.ActualBackgroundColor);
                }

                break;
            }
            }
        }
        public override void DrawOverride(Application application, ConsoleArea area)
        {
            area.Fill(Control.ActualBackgroundColor);

            area [0, 0] = new ConsoleChar(
                '[',
                Control.ActualForegroundColor,
                Control.ActualBackgroundColor);
            area [1, 0] = new ConsoleChar(
                Control.CheckableChar.GetStateChar(Control.State),
                Control.ActualForegroundColor,
                Control.ActualBackgroundColor);
            area [2, 0] = new ConsoleChar(
                ']',
                Control.ActualForegroundColor,
                Control.ActualBackgroundColor);

            if (Control.ActualHeight == 1)
            {
                for (int x = 0; x < Control.ActualWidth - 4; x++)
                {
                    area [x + 3, 0] = new ConsoleChar(
                        Control.Text [x],
                        Control.ActualForegroundColor,
                        Control.ActualBackgroundColor);
                }
            }
            else
            {
                for (int x = 0; x < Control.ActualWidth - 4; x++)
                {
                    area [x + 3, 0] = new ConsoleChar(
                        Control.Text [x],
                        Control.ActualForegroundColor,
                        Control.ActualBackgroundColor);
                }

                for (int y = 1; y < Control.ActualWidth; y++)
                {
                    for (int x = 0; x < Control.ActualWidth; x++)
                    {
                        area [x, 0] = new ConsoleChar(
                            Control.Text [x],
                            Control.ActualForegroundColor,
                            Control.ActualBackgroundColor);
                    }
                }
            }
        }
        public override void DrawOverride(Application application, ConsoleArea area)
        {
            area.Fill(Control.ActualBackgroundColor);

            for (int y = 0; y < area.Size.Height && y < Control.AsciiArt.Height; y++)
            {
                for (int x = 0; x < area.Size.Width && x < Control.ActualText [y].Length; x++)
                {
                    area [x, y] = new ConsoleChar(
                        Control.ActualText [y] [x],
                        Control.ActualForegroundColor,
                        Control.ActualBackgroundColor);
                }
            }
        }
Exemple #11
0
        public override void DrawOverride(Application application, ConsoleArea area)
        {
            area.Fill(Control.ActualBackgroundColor);

            Control.Content? .Draw(application, area);

            Rectangle?focusedArea = application.FocusManager ? .FocusedControl ? .RenderArea;

            if (focusedArea.IsNotEmpty( ))
            {
                area.CreateSub(focusedArea.Value).InvertColor( );
            }

            application.Console.Draw(area);
        }
 /// <summary>
 /// Returns the current color of the specified console area.
 /// </summary>
 /// <param name="area">The area of the console.</param>
 /// <returns></returns>
 public static string GetConsoleColor(ConsoleArea area)
 {
     if (area == ConsoleArea.Foreground)
     {
         ConsoleColor color = Console.ForegroundColor;
         return(color.ToString());
     }
     else if (area == ConsoleArea.Background)
     {
         ConsoleColor color = Console.BackgroundColor;
         return(color.ToString());
     }
     else
     {
         return(null);
     }
 }
        /// <summary>
        ///     Draws the ProgressBar given in the Control-Property
        /// </summary>
        public override void DrawOverride(Application application, ConsoleArea area)
        {
            if (Control is null)
            {
                return;
            }

            if (Control.ActualSize.IsEmpty)
            {
                return;
            }

            ConsoleColor foregroundColor = Control.ActualForegroundColor;
            ConsoleColor backgroundColor = Control.ActualBackgroundColor;


            int barMaxWidth = Control.ActualWidth;
            int barXStart   = 0;
            int barHeight   = Control.ActualHeight;
            int barYStart   = 0;

            double valuePerCharacter = (Control.MaxValue - Control.MinValue) / ( double )barMaxWidth;

            for (int y = barYStart; y < barHeight; y++)
            {
                double currentValue = Control.Value / valuePerCharacter;

                for (int x = barXStart; x < barMaxWidth; x++)
                {
                    area [x, y] = new ConsoleChar(
                        Control.CharProvider.GetChar(currentValue),
                        foregroundColor,
                        backgroundColor);

                    currentValue--;
                }
            }
        }
Exemple #14
0
        /// <summary>
        /// Initialize the components that make up the window, including the window itself.
        /// </summary>
        private void Initialize()
        {
            Window = new Window(manager);
            Window.Init();
            Window.Text           = "Console";
            Window.Left           = windowFrame.X;
            Window.Top            = windowFrame.Y;
            Window.Width          = windowFrame.Width;
            Window.Height         = windowFrame.Height;
            Window.Alpha          = 200;
            Window.BorderVisible  = true;
            Window.CaptionVisible = false;
            Window.BackColor      = Color.Black;
            Window.Center();

            TextArea = new ConsoleArea(manager);
            TextArea.Init();
            TextArea.Text            = "";
            TextArea.Width           = windowFrame.Width - 15;
            TextArea.Height          = windowFrame.Height - 40;
            TextArea.Enabled         = true;
            TextArea.CanFocus        = false;
            TextArea.BackgroundColor = Color.Black;
            TextArea.TextColor       = Color.Green;
            TextArea.TextPosition    = ConsoleArea.TextOrigin.BOTTOM;
            TextArea.Parent          = Window;

            Input = new TextBox(manager);
            Input.Init();
            Input.Text      = "";
            Input.Color     = Color.Black;
            Input.TextColor = Color.Green;
            Input.Top       = TextArea.Top + TextArea.Height + 2;
            Input.Width     = windowFrame.Width - 15;
            Input.Height    = 20;
            Input.Enabled   = true;
            Input.Parent    = Window;
        }
        /// <summary>
        ///     Draws the TextBox given in the Control-Property
        /// </summary>
        public override void DrawOverride(Application application, ConsoleArea area)
        {
            ConsoleColor foregroundColor = Control.ActualForegroundColor;
            ConsoleColor backgroundColor = Control.ActualBackgroundColor;

            area.Fill(backgroundColor);

            int y = 0;

            for (int lineIndex = 0; lineIndex < Control.Lines.Count; lineIndex++)
            {
                string line       = Control.Lines [lineIndex];
                string renderLine = $"{line} ";
                int    x          = 0;

                for (int position = 0; position < renderLine.Length && y < Control.ContentHeight; position++)
                {
                    char t = renderLine [position];
                    area [x, y] = new ConsoleChar(t, foregroundColor, backgroundColor);

                    if (Control.CursorPosition.X == position &&
                        Control.CursorPosition.Y == lineIndex)
                    {
                        area [x, y] = area [x, y].InvertColor( );
                    }

                    x++;

                    if (x >= Control.ContentWidth)
                    {
                        x %= Control.ContentWidth;
                        y++;
                    }
                }

                y++;
            }
        }
Exemple #16
0
        public override void DrawOverride(Application application, ConsoleArea area)
        {
            if (string.IsNullOrEmpty(Control.Text))
            {
            }

            for (int y = 0; y < Control.ContentHeight && y * Control.ContentHeight < Control.Text.Length; y++)
            {
                for (int x = 0; x < Control.ContentWidth; x++)
                {
                    if (x + y * Control.ContentHeight < Control.Text.Length)
                    {
                        area [x, y] = new ConsoleChar(
                            Control.PasswordChar,
                            Control.ActualForegroundColor,
                            Control.ActualBackgroundColor);
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Exemple #17
0
		public static void Main (string[] args)
		{
			const int WIDTH = 80;
			const int HEIGHT = 30;
			var defaultSize = new Size (WIDTH, HEIGHT);
			var win = new ConsoleArea (defaultSize);
			//var driver = new ConsoleDriver ();
			var driver = new AnsiDriver ();
			var screen = new ConsoleUpdater (driver, defaultSize);
			var scrolly = new ConsoleScrollWindow (new Size (WIDTH - 2, 10));

			scrolly.Window.Background = ConsoleColor.DarkRed;

			win.Foreground = ConsoleColor.White;
			var input = new ConsoleInputField ();
			const int diff = 40;
			bool hide = false;

			for (var anim = 0; anim < 1000; ++anim)
			{
				win.Background = ConsoleColor.Blue;
				win.Clear ();
				var x = (int)(Math.Sin (anim / 10.0f) * diff + diff);

				win.Background = ConsoleColor.DarkBlue;
				win.Foreground = ConsoleColor.Yellow;
				var xStart = x / 3;
				var yStart = x / 8;
				var borderWidth = x / 3;
				var borderHeight = x / 5 + 1;
				ConsoleBorder.Draw (win, xStart, yStart, borderWidth, borderHeight);
				win.Background = ConsoleColor.DarkGreen;
				var p = new Position (xStart, yStart);
				var s = new Size (borderWidth - 2, borderHeight - 2);
				var rect = new Rectangle (p, s);
				win.Fill (rect);
				win.Background = ConsoleColor.Black;
				win.Foreground = ConsoleColor.Yellow;

				if (x > 40)
				{
					win.Background = ConsoleColor.Cyan;
				}
				else
				{
					win.Background = ConsoleColor.Red;
				}
				scrolly.AddString ("This is a test", true);
				win.Move (new Position (x, 10));
				win.AddString ("Hello world!");
				win.Background = ConsoleColor.DarkMagenta;
				win.Copy (scrolly.Window, new Position (40 - x / 6, 10 - x / 3));
				// ConsoleText.Draw (win, "THis is a field", 25, ConsoleText.TextAlign.Center);
				var info = driver.ReadKey ();
				var result = input.DoChar (info);

				if (result == InputResult.Enter)
				{
					hide = true;
				}
				else if (result == InputResult.Escape)
				{
					break;
				}
				win.Move (new Position (0, 15));

				if (!hide)
				{
					var adjustedCursorX = ConsoleText.Draw (win, input.Value, input.CursorX, 25, ConsoleText.TextAlign.Left);
					win.Move (new Position (adjustedCursorX, 15));
				}
				screen.Update (win);

				Task.Delay (10).Wait ();
			}
		}
 public override void DrawOverride(Application application, ConsoleArea area)
 {
     Control.Content? .Draw(application, area);
 }