/// <summary>Draws a row of blocks of the specified color of specified length at the specified position</summary> /// <param name="RowColor"></param> /// <param name="Length"></param> /// <param name="LeftPos"></param> /// <param name="TopPos"></param> public static void Row(ConsoleColor RowColor, int Length, int LeftPos, int TopPos) { //If we get a position, move to that position. if (LeftPos != -1 && TopPos != -1) { if (!RenderUtils.SetPos(LeftPos, TopPos)) { return; } } //Save the current colors of the console ConsoleColor OldBG = Console.BackgroundColor; ConsoleColor OldFG = Console.ForegroundColor; //Set the color to the color this row will be RenderUtils.Color(RowColor, RowColor); //Draw the row for (int i = 0; i < Length; i++) { Console.Write(SpecialChars.BLOCK); } //Set the color back to whatever it was. RenderUtils.Color(OldBG, OldFG); }
/// <summary>renders a sprite at the specified cursor position</summary> /// <param name="sprite"></param> /// <param name="BackgroundColor"></param> /// <param name="ForegroundColor"></param> /// <param name="LeftPos"></param> /// <param name="TopPos"></param> public static void Sprite(string sprite, ConsoleColor BackgroundColor, ConsoleColor ForegroundColor, int LeftPos, int TopPos) { //If we get a position, move the cursor to that position if (LeftPos != -1 && TopPos != -1) { if (!RenderUtils.SetPos(LeftPos, TopPos)) { return; } } //Save the current colors of the console ConsoleColor OldBG = Console.BackgroundColor; ConsoleColor OldFG = Console.ForegroundColor; //Set the color to whatever the colors of the sprite will be RenderUtils.Color(BackgroundColor, ForegroundColor); //Write the sprite Console.Write(sprite); //Change back to the old colors. RenderUtils.Color(OldBG, OldFG); }
/// <summary>Draws text centered on the screen at the specified row, with the specified colors</summary> /// <param name="Text"></param> /// <param name="TopPos"></param> /// <param name="BG"></param> /// <param name="FG"></param> public static void CenterText(string Text, int TopPos, ConsoleColor BG, ConsoleColor FG) { //Find the position of this text where its centered. -1 so that it preffers left center rather than right center. int leftpos = (Console.WindowWidth - Text.Length - 1) / 2;; while (leftpos < 0) { Text.Substring(0, Text.Length - 1); leftpos = (Console.WindowWidth - Text.Length - 1) / 2;; if (leftpos < 0) { break; } Text.Substring(1, Text.Length - 1); leftpos = (Console.WindowWidth - Text.Length - 1) / 2;; } //Peacock Shake the text until it fits //Save the current console colors ConsoleColor OldBG = Console.BackgroundColor; ConsoleColor OldFG = Console.ForegroundColor; //set the color to the specified colors RenderUtils.Color(BG, FG); //Put the cursor in the right position and draw the centered text. if (!RenderUtils.SetPos(leftpos, TopPos)) { return; } Console.Write(Text); //Set the colors back to the old colors RenderUtils.Color(OldBG, OldFG); }