public static void SetBColor(ProColor color, bool perma = true) { Write("\x1b[48;2;" + color.r + ";" + color.g + ";" + color.b + "m"); if (perma) { currentBColor = color; } }
public static void DrawBox( int x, int y, int w, int h, string title = null, string caption = null, BorderStyle borderStyle = BorderStyle.SingleDefault, bool useCustomColors = false, ProColor cBorder = null, ProColor cBkg = null, ProColor cTitle = null, ProColor cCaption = null, bool opaque = true, float bkgColorFactor = 1f ) { if (w < 2 || h < 2) { return; } int bs = (int)borderStyle; if (!useCustomColors || cBorder == null) { cBorder = currentFColor; } if (!useCustomColors || cBkg == null) { cBkg = currentBColor; } if (!useCustomColors || cTitle == null) { cTitle = currentFColor; } if (!useCustomColors || cCaption == null) { cCaption = currentFColor; } Print(borderElements[bs, 2] + borderElements[bs, 0].Repeat(w - 2) + borderElements[bs, 3], x, y, cBorder, cBorder, cBkg, cBkg, opaque, bkgColorFactor); for (int i = 0; i < h - 2; i++) { if (bkgColorFactor < 1f) { Print(borderElements[bs, 1] + " ".Repeat(w - 2) + borderElements[bs, 1], x, y + 1 + i, cBorder, cBorder, cBkg, cBkg, opaque, bkgColorFactor); } else { Print(borderElements[bs, 1], x, y + 1 + i, cBorder, cBorder, cBkg, cBkg, opaque, bkgColorFactor); Print(borderElements[bs, 1], x + w - 1, y + 1 + i, cBorder, cBorder, cBkg, cBkg, opaque, bkgColorFactor); } } Print(borderElements[bs, 4] + borderElements[bs, 0].Repeat(w - 2) + borderElements[bs, 5], x, y + h - 1, cBorder, cBorder, cBkg, cBkg, opaque, bkgColorFactor); if (title != null) { title = borderElements[bs, 6] + title + borderElements[bs, 7]; int cx = x + (w - title.Length) / 2; Print(title, cx, y, cTitle, cTitle, cBkg, cBkg, opaque, bkgColorFactor); } if (caption != null) { int cx = x + (w - caption.Length) / 2; int cy = y + h / 2; Print(caption, cx, cy, cCaption, cCaption, cBkg, cBkg, opaque, bkgColorFactor); } }
public static void ClearScreen(ProColor color) { background = new ProColor[WindowWidth, WindowHeight, 2]; SetBColor(color); for (int y = 0; y < WindowHeight; y++) { Write(" ".Repeat(WindowWidth)); for (int x = 0; x < WindowWidth; x++) { background[x, y, 0] = color; background[x, y, 1] = color; } } metalTexts.Clear(); }
public void DrawArrow(bool visible, ProColor color, bool opaque, float bkgColorFactor) { if (opaque) { SetFColor(color, false); SetCursorPosition(x + 2, y + contentMarginTop + (currentItem - firstVisibleItem) * itemSpacing); Write("»"); SetCursorPosition(x + w - 3, y + contentMarginTop + (currentItem - firstVisibleItem) * itemSpacing); Write("«"); ResetColors(); } else { Print(visible ? "»" : " ", x + 2, y + contentMarginTop + (currentItem - firstVisibleItem) * itemSpacing, color, color, opaque, bkgColorFactor); Print(visible ? "«" : " ", x + w - 3, y + contentMarginTop + (currentItem - firstVisibleItem) * itemSpacing, color, color, opaque, bkgColorFactor); } }
public static void Print(string caption, int col, int row, ProColor cForeStart, ProColor cForeEnd, ProColor cBackStart, ProColor cBackEnd, bool opaque = true, float bkgColorFactor = 1f) { int cl = CursorLeft; int ct = CursorTop; int[,,] colors = new int[2, 2, 3] { { { cForeStart.r, cForeStart.g, cForeStart.b }, { cForeEnd.r, cForeEnd.g, cForeEnd.b } }, { { cBackStart.r, cBackStart.g, cBackStart.b }, { cBackEnd.r, cBackEnd.g, cBackEnd.b } } }; int[,] colorDelta = new int[2, 3]; for (int i = 0; i < 2; i++) { for (int c = 0; c < 3; c++) { colorDelta[i, c] = colors[i, 1, c] - colors[i, 0, c]; } } int x = col == -1 ? (WindowWidth - caption.Length) / 2 : col; int y = row == -1 ? WindowHeight / 2 : row; SetCursorPosition(x, y); for (int i = 0; i < caption.Length; i++) { float f = (float)i / caption.Length; SetFColor(new ProColor { r = cForeStart.r + (int)(f * colorDelta[0, 0]), g = cForeStart.g + (int)(f * colorDelta[0, 1]), b = cForeStart.b + (int)(f * colorDelta[0, 2]) }, false); if (opaque) { SetBColor(new ProColor { r = cBackStart.r + (int)(f * colorDelta[1, 0]), g = cBackStart.g + (int)(f * colorDelta[1, 1]), b = cBackStart.b + (int)(f * colorDelta[1, 2]) }, false); } else { SetBColor(background[x + i, y, 0] * bkgColorFactor, false); } Write(caption[i]); } ResetColors(); SetCursorPosition(cl, ct); }
public static void DrawImage(Image image, int col, int row, ImageResolutionScale scale = ImageResolutionScale.Double, bool ignoreError = false, float alpha = -1f, bool draw = true) { if (image == null) { return; } if (image.Width % 2 != 0 || image.Height % 2 != 0) { DrawBox(col, row, (3 - (int)scale) * image.Width, image.Height / (int)scale, null, "Unable to render image.", BorderStyle.DoubleDefault, true, cWhite, cBlack, cWhite, cWhite); return; } Bitmap img = new Bitmap(image); for (int i = 0; i < img.Width; i++) { for (int j = 0; j < img.Height; j += (int)scale) { try { SetCursorPosition(col + i * (3 - (int)scale), row + j / (int)scale); } catch (ArgumentOutOfRangeException) { if (ignoreError) { continue; } else { return; } } int cl = CursorLeft; // caching is more efficient than multiple CursorXXX calls int ct = CursorTop; Color pixel = img.GetPixel(i, j); ProColor bColor = new ProColor { r = pixel.R, g = pixel.G, b = pixel.B, a = pixel.A }; if (alpha != -1f) { float a = bColor.a / 255f * alpha; float ainv = 1 - a; bColor = new ProColor { r = (int)(bColor.r * a + background[cl, ct, 0].r * ainv), g = (int)(bColor.g * a + background[cl, ct, 0].g * ainv), b = (int)(bColor.b * a + background[cl, ct, 0].b * ainv) }; } if (draw) { SetBColor(bColor, false); } if (scale == ImageResolutionScale.Double) { pixel = img.GetPixel(i, j + 1); ProColor fColor = new ProColor { r = pixel.R, g = pixel.G, b = pixel.B, a = pixel.A }; float a = fColor.a / 255f * alpha; float ainv = 1 - a; if (alpha != -1f) { fColor = new ProColor { r = (int)(fColor.r * a + background[cl, ct, 1].r * ainv), g = (int)(fColor.g * a + background[cl, ct, 1].g * ainv), b = (int)(fColor.b * a + background[cl, ct, 1].b * ainv) }; } if (draw) { SetFColor(fColor, false); Write("▄"); } background[cl, ct, 0] = bColor; background[cl, ct, 1] = fColor; background[cl, ct, 0].e = 2; // dual "pixel" mode } else { if (draw) { Write(" "); } background[cl, ct, 0] = bColor; background[cl, ct, 0].e = 0; // normal mode background[cl + 1, ct, 0] = bColor; background[cl + 1, ct, 0].e = 0; } } } if (draw) { ResetColors(); SetCursorPosition(0, 0); } }
public static void Print(string caption, int col, int row, ProColor cForeStart, ProColor cForeEnd, bool opaque = true, float bkgColorFactor = 1f) { Print(caption, col, row, cForeStart, cForeEnd, currentBColor, currentBColor, opaque, bkgColorFactor); }