public void DrawShadowRect(int x, int y, int width, int height, ConsoleColor backgroundColor) { DrawRect(x, y, width - 1, height - 1, backgroundColor); var narrowShadow = height < 3; var shadowRight = AsciiCodes.GetAsciiChar(220); var shadowBottom = AsciiCodes.GetAsciiChar(223); for (var i = y; i < (y + height); i++) { if (narrowShadow) { // most likely a button, or just a very narrow control // unfortunately, the only way to get a proper dropshadow for such // control is to use the half-size block ▄ // and this hides the text under it. var bg0 = this.GetBackground(x + width - 1, i); SetPixel(i == y ? shadowRight : shadowBottom, x + width - 1, i, ConsoleColor.Black, bg0); } else { var c0 = this.GetPixelChar(x + width - 1, i); var c1 = this.GetPixelChar(x + width, i); SetPixel(c0, x + width - 1, i, ConsoleColor.DarkGray, ConsoleColor.Black); SetPixel(c1, x + width, i, ConsoleColor.DarkGray, ConsoleColor.Black); } } for (var i = x + 1; i < (x + width - 1); i++) { if (narrowShadow) { var sampledBg = this.GetBackground(i, y + height - 1); SetPixel(shadowBottom, i, y + height - 1, ConsoleColor.Black, sampledBg); } else { var sampledChar = this.GetPixelChar(i, y + height - 1); SetPixel(sampledChar, i, y + height - 1, ConsoleColor.DarkGray, ConsoleColor.Black); } } }
/// <summary> /// Method to seed internal password with SecretKey from AppSettings:Application:SecretKey value in appsettings.json /// <br />https://www.random.org/cgi-bin/randbyte?nbytes=21&format=d /// </summary> /// <param name="secretKey">string</param> /// <exception cref="ArgumentNullException"></exception> /// <method>Seed(IConfiguration configuration)</method> public static void Seed(string secretKey) { if (string.IsNullOrEmpty(secretKey)) { throw new ArgumentNullException(nameof(secretKey)); } InternalPassword = AsciiCodes.STX; for (int x = 0; x < 15; x++) { if (x > 0) { InternalPassword += AsciiCodes.US; } foreach (string key in secretKey.Split(',').ToList()) { InternalPassword += AsciiCodes.ToString(int.Parse(key)); } } InternalPassword += AsciiCodes.EOT; }
public void DrawBorder( BorderThickness thickness, int x, int y, int width, int height, ConsoleColor borderTopColor, ConsoleColor borderRightColor, ConsoleColor borderBottomColor, ConsoleColor borderLeftColor, ConsoleColor backgroundColor) { var topBorder = AsciiCodes.GetBorderChars(thickness.Top); var leftBorder = AsciiCodes.GetBorderChars(thickness.Left); var rightBorder = AsciiCodes.GetBorderChars(thickness.Right); var botBorder = AsciiCodes.GetBorderChars(thickness.Bottom); // draw vertical lines for (var i = 0; i < height - 1; i++) { SetPixel(leftBorder[3], x, y + i + 1, borderLeftColor, backgroundColor); SetPixel(rightBorder[3], x + width, y + i + 1, borderRightColor, backgroundColor); } // draw top corners SetPixel(topBorder[0], x, y, borderTopColor, backgroundColor); SetPixel(topBorder[1], x + width, y, borderTopColor, backgroundColor); // draw horizontal lines for (var i = 0; i < width - 1; i++) { SetPixel(topBorder[2], x + i + 1, y, borderTopColor, backgroundColor); SetPixel(botBorder[2], x + i + 1, y + height, borderBottomColor, backgroundColor); } // draw bottom corners SetPixel(botBorder[4], x, y + height, borderBottomColor, backgroundColor); SetPixel(botBorder[5], x + width, y + height, borderBottomColor, backgroundColor); }