// draws a string starting from right of string public static void StringRight(Coord pos, string s, Color.Foreground fg = DEFAULT_FG, Color.Background bg = DEFAULT_BG) { pos.x -= s.Length; /// draws from right of string drawQueue += () => { /// adds draw call to queue _drawString(pos, s, fg, bg); }; }
private const Color.Background BORDER_BG = Color.Background.Black; /// border background // ## PUBLIC METHODS ## // Updates the Renderer and prepares it to be used for the frame public static void Update() { Console.CursorVisible = false; /// prevents users from seeing cursor drawing _UpdateSize(); // Initializes array of rows buffer = new char[Height][]; fgColorbuffer = new Color.Foreground[Height][]; bgColorbuffer = new Color.Background[Height][]; for (int row = 0; row < buffer.Length; row++) { // Initializes each row buffer[row] = new char[Width]; fgColorbuffer[row] = new Color.Foreground[Width]; bgColorbuffer[row] = new Color.Background[Width]; // sets defualt values to each position for (int column = 0; column < buffer[row].Length; column++) { buffer[row][column] = ' '; fgColorbuffer[row][column] = Color.Foreground.Red; bgColorbuffer[row][column] = Color.Background.Black; } } }
// sets the forground color at given position public static void SetColor(int x, int y, Color.Foreground fgColor) { if (fgColor == Color.Foreground.None) { return; /// doesn't set color if none is provided } fgColorbuffer[y][x] = fgColor; }
// ## PRIVATE UTITLITY METHODS ## // Things to make drawing easier // draws a string with left formatting at the given position private static void _drawString(Coord pos, string s, Color.Foreground fg, Color.Background bg) { // Exits if y is out of range if (!(0 <= pos.y && pos.y < ConsoleRenderer.Height)) { return; } int x = pos.x; foreach (char c in s) { if (ConsoleRenderer.Width <= x) { break; } ConsoleRenderer.SetChar(x, pos.y, c); ConsoleRenderer.SetColor(x, pos.y, fg); ConsoleRenderer.SetColor(x, pos.y, bg); x++; } }
public Spit(char c, Color.Foreground fgColor, Color.Background bgColor) { this.character = c; this.foregroundColor = fgColor; this.backgroundColor = bgColor; }
public Spit(char c, Color.Background bgColor, Color.Foreground fgColor) : this(c, fgColor, bgColor) { }
public Spit(char c, Color.Foreground fgColor) : this(c, fgColor, DEFAULT_BG) { }
// ## PUBLIC DRAW METHODS ## // These add draw calls to the UI queue // draws a string starting from left of string public static void StringLeft(Coord pos, string s, Color.Foreground fg = DEFAULT_FG, Color.Background bg = DEFAULT_BG) { drawQueue += () => { /// adds draw call to queue _drawString(pos, s, fg, bg); }; }