From b56fb7db7860ae90ee9457ba3506ddeb4274cd5d Mon Sep 17 00:00:00 2001 From: JFronny <33260128+JFronny@users.noreply.github.com> Date: Fri, 12 Jun 2020 15:21:58 +0200 Subject: [PATCH] Remove DiffDraw.FullDraw (merged with DiffDraw.Draw) --- CLITest/Program.cs | 2 +- Commandline/TUI/CenteredScreen.cs | 2 +- Commandline/TUI/DiffDraw.cs | 46 ++++--------------------------- 3 files changed, 8 insertions(+), 42 deletions(-) diff --git a/CLITest/Program.cs b/CLITest/Program.cs index 4dc782e..90f2728 100644 --- a/CLITest/Program.cs +++ b/CLITest/Program.cs @@ -20,7 +20,7 @@ namespace CLITest BackColor = ConsoleColor.DarkGreen }; screen.Controls.Add(btn1); - btn1.Click += (screen1, eventArgs) => { DiffDraw.FullDraw(true); }; + btn1.Click += (screen1, eventArgs) => { DiffDraw.Draw(true, true); }; Label lab1 = new Label("Meem") { Point = new Point(2, 1), diff --git a/Commandline/TUI/CenteredScreen.cs b/Commandline/TUI/CenteredScreen.cs index 5fdd8c5..62cd381 100644 --- a/Commandline/TUI/CenteredScreen.cs +++ b/Commandline/TUI/CenteredScreen.cs @@ -76,7 +76,7 @@ namespace CC_Functions.Commandline.TUI if (!initial) { Console.Clear(); - DiffDraw.FullDraw(Color); + DiffDraw.Draw(Color, true); } _resizing = false; } diff --git a/Commandline/TUI/DiffDraw.cs b/Commandline/TUI/DiffDraw.cs index 6c925d4..6ee50d7 100644 --- a/Commandline/TUI/DiffDraw.cs +++ b/Commandline/TUI/DiffDraw.cs @@ -26,49 +26,14 @@ namespace CC_Functions.Commandline.TUI /// Draws to the console /// /// Whether to use color - public static void Draw(bool color) + /// Whether to redraw the entire screen (should be done from time to time to prevent corruption) + public static void Draw(bool color, bool full = false) { Console.CursorTop = 0; Console.CursorLeft = 0; ConsoleColor fCol = Console.ForegroundColor; ConsoleColor bCol = Console.BackgroundColor; - int width = Width; - int height = Height; - for (int y = 0; y < height; y++) - { - for (int x = 0; x < width; x++) - { - Pixel tmp1 = Screen[y, x]; - if (tmp1 == _last[y, x]) continue; - if (color) - { - if (Console.ForegroundColor != tmp1.ForeColor) - Console.ForegroundColor = tmp1.ForeColor; - if (Console.BackgroundColor != tmp1.BackColor) - Console.BackgroundColor = tmp1.BackColor; - } - Console.CursorLeft = x; - Console.Write(tmp1); - } - Console.WriteLine(); - Console.CursorLeft = 0; - } - Console.ForegroundColor = fCol; - Console.BackgroundColor = bCol; - _last = Screen; - } - - /// - /// Redraws the entire screen (should be done from time to time to prevent corruption) - /// - /// Whether to use color - public static void FullDraw(bool color) - { - Console.CursorTop = 0; - Console.CursorLeft = 0; - ConsoleColor fcol = Console.ForegroundColor; - ConsoleColor bcol = Console.BackgroundColor; - Console.Clear(); + if (full) Console.Clear(); int width = Width; int height = Height; for (int y = 0; y < height; y++) @@ -76,6 +41,7 @@ namespace CC_Functions.Commandline.TUI for (int x = 0; x < width; x++) { Pixel? tmp1 = Screen[y, x]; + if (full && tmp1 == _last[y, x]) continue; if (tmp1 != null && color) { if (Console.ForegroundColor != tmp1.ForeColor) @@ -89,8 +55,8 @@ namespace CC_Functions.Commandline.TUI Console.WriteLine(); Console.CursorLeft = 0; } - Console.ForegroundColor = fcol; - Console.BackgroundColor = bcol; + Console.ForegroundColor = fCol; + Console.BackgroundColor = bCol; _last = Screen; }