/// <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: }
/// <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); } } }
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> /// 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++; } }
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 (); } }