Class CanvasGraphics
- Namespace
- SharpConsoleUI.Drawing
- Assembly
- SharpConsoleUI.dll
Drawing context that wraps a CharacterBuffer with local-coordinate translation. Used both for async painting (wrapping the internal canvas buffer at offset 0,0) and for event-driven painting (wrapping the window buffer with content-area offset). All drawing methods accept canvas-local coordinates and translate them automatically.
public sealed class CanvasGraphics
- Inheritance
-
CanvasGraphics
- Inherited Members
- Extension Methods
Properties
Height
Canvas content height in local coordinates.
public int Height { get; }
Property Value
Width
Canvas content width in local coordinates.
public int Width { get; }
Property Value
Methods
CheckerFill(int, int, int, int, char, char, Color, Color, Color)
Fills a rectangle with alternating characters in a checkerboard pattern.
public void CheckerFill(int x, int y, int width, int height, char ch1, char ch2, Color fg1, Color fg2, Color bg)
Parameters
xintThe X coordinate of the rectangle.
yintThe Y coordinate of the rectangle.
widthintThe width of the rectangle.
heightintThe height of the rectangle.
ch1charThe character for even cells.
ch2charThe character for odd cells.
fg1ColorThe foreground color for even cells.
fg2ColorThe foreground color for odd cells.
bgColorThe background color.
Clear(Color)
Clears the entire canvas area with the specified background color.
public void Clear(Color bg)
Parameters
bgColorThe background color to fill with.
Clear(char, Color, Color)
Clears the entire canvas area with the specified character and colors.
public void Clear(char ch, Color fg, Color bg)
Parameters
DrawArc(int, int, int, double, double, char, Color, Color)
Draws an arc (portion of a circle) using parametric sampling. Angles are in radians, measured counter-clockwise from the positive X axis.
public void DrawArc(int cx, int cy, int radius, double startAngle, double endAngle, char ch, Color fg, Color bg)
Parameters
cxintThe center X coordinate.
cyintThe center Y coordinate.
radiusintThe arc radius.
startAngledoubleThe starting angle in radians.
endAngledoubleThe ending angle in radians.
chcharThe character to draw with.
fgColorThe foreground color.
bgColorThe background color.
DrawBox(int, int, int, int, BoxChars, Color, Color)
Draws a box border using the specified box drawing characters.
public void DrawBox(int x, int y, int width, int height, BoxChars boxChars, Color fg, Color bg)
Parameters
xintThe X coordinate of the box's top-left corner.
yintThe Y coordinate of the box's top-left corner.
widthintThe width of the box.
heightintThe height of the box.
boxCharsBoxCharsThe box drawing character set.
fgColorThe foreground color.
bgColorThe background color.
DrawCircle(int, int, int, char, Color, Color)
Draws a circle outline using the midpoint circle algorithm.
public void DrawCircle(int cx, int cy, int radius, char ch, Color fg, Color bg)
Parameters
cxintThe center X coordinate.
cyintThe center Y coordinate.
radiusintThe circle radius.
chcharThe character to draw with.
fgColorThe foreground color.
bgColorThe background color.
DrawEllipse(int, int, int, int, char, Color, Color)
Draws an ellipse outline using the midpoint ellipse algorithm.
public void DrawEllipse(int cx, int cy, int rx, int ry, char ch, Color fg, Color bg)
Parameters
cxintThe center X coordinate.
cyintThe center Y coordinate.
rxintThe horizontal radius.
ryintThe vertical radius.
chcharThe character to draw with.
fgColorThe foreground color.
bgColorThe background color.
DrawHorizontalLine(int, int, int, char, Color, Color)
Draws a horizontal line starting at the given position.
public void DrawHorizontalLine(int x, int y, int length, char ch, Color fg, Color bg)
Parameters
xintThe starting X coordinate.
yintThe Y coordinate.
lengthintThe length of the line in characters.
chcharThe character to draw with.
fgColorThe foreground color.
bgColorThe background color.
DrawLine(int, int, int, int, char, Color, Color)
Draws a line between two points using Bresenham's algorithm.
public void DrawLine(int x0, int y0, int x1, int y1, char ch, Color fg, Color bg)
Parameters
x0intThe starting X coordinate.
y0intThe starting Y coordinate.
x1intThe ending X coordinate.
y1intThe ending Y coordinate.
chcharThe character to draw with.
fgColorThe foreground color.
bgColorThe background color.
DrawPolygon((int X, int Y)[], char, Color, Color)
Draws a polygon outline by connecting consecutive points with lines.
public void DrawPolygon((int X, int Y)[] points, char ch, Color fg, Color bg)
Parameters
points(int X, int Y)[]The polygon vertices in canvas-local coordinates.
chcharThe character to draw with.
fgColorThe foreground color.
bgColorThe background color.
DrawTriangle(int, int, int, int, int, int, char, Color, Color)
Draws a triangle outline by connecting three vertices with lines.
public void DrawTriangle(int x0, int y0, int x1, int y1, int x2, int y2, char ch, Color fg, Color bg)
Parameters
x0intFirst vertex X.
y0intFirst vertex Y.
x1intSecond vertex X.
y1intSecond vertex Y.
x2intThird vertex X.
y2intThird vertex Y.
chcharThe character to draw with.
fgColorThe foreground color.
bgColorThe background color.
DrawVerticalLine(int, int, int, char, Color, Color)
Draws a vertical line starting at the given position.
public void DrawVerticalLine(int x, int y, int length, char ch, Color fg, Color bg)
Parameters
xintThe X coordinate.
yintThe starting Y coordinate.
lengthintThe length of the line in characters.
chcharThe character to draw with.
fgColorThe foreground color.
bgColorThe background color.
FillCircle(int, int, int, char, Color, Color)
Draws a filled circle using the midpoint algorithm with horizontal scanlines.
public void FillCircle(int cx, int cy, int radius, char ch, Color fg, Color bg)
Parameters
cxintThe center X coordinate.
cyintThe center Y coordinate.
radiusintThe circle radius.
chcharThe fill character.
fgColorThe foreground color.
bgColorThe background color.
FillEllipse(int, int, int, int, char, Color, Color)
Draws a filled ellipse using the midpoint algorithm with horizontal scanlines.
public void FillEllipse(int cx, int cy, int rx, int ry, char ch, Color fg, Color bg)
Parameters
cxintThe center X coordinate.
cyintThe center Y coordinate.
rxintThe horizontal radius.
ryintThe vertical radius.
chcharThe fill character.
fgColorThe foreground color.
bgColorThe background color.
FillPolygon((int X, int Y)[], char, Color, Color)
Draws a filled polygon using scanline rasterization with the even-odd rule.
public void FillPolygon((int X, int Y)[] points, char ch, Color fg, Color bg)
Parameters
points(int X, int Y)[]The polygon vertices in canvas-local coordinates.
chcharThe fill character.
fgColorThe foreground color.
bgColorThe background color.
FillRect(int, int, int, int, Color)
Fills a rectangle at canvas-local coordinates with spaces and the specified background.
public void FillRect(int x, int y, int width, int height, Color bg)
Parameters
xintThe X coordinate of the rectangle's top-left corner.
yintThe Y coordinate of the rectangle's top-left corner.
widthintThe width of the rectangle.
heightintThe height of the rectangle.
bgColorThe background color.
FillRect(int, int, int, int, char, Color, Color)
Fills a rectangle at canvas-local coordinates with the specified character and colors.
public void FillRect(int x, int y, int width, int height, char ch, Color fg, Color bg)
Parameters
xintThe X coordinate of the rectangle's top-left corner.
yintThe Y coordinate of the rectangle's top-left corner.
widthintThe width of the rectangle.
heightintThe height of the rectangle.
chcharThe fill character.
fgColorThe foreground color.
bgColorThe background color.
FillTriangle(int, int, int, int, int, int, char, Color, Color)
Draws a filled triangle using scanline rasterization.
public void FillTriangle(int x0, int y0, int x1, int y1, int x2, int y2, char ch, Color fg, Color bg)
Parameters
x0intFirst vertex X.
y0intFirst vertex Y.
x1intSecond vertex X.
y1intSecond vertex Y.
x2intThird vertex X.
y2intThird vertex Y.
chcharThe fill character.
fgColorThe foreground color.
bgColorThe background color.
GetCell(int, int)
Gets the cell at the specified canvas-local position.
public Cell GetCell(int x, int y)
Parameters
Returns
- Cell
The cell at the specified position.
GradientFillHorizontal(int, int, int, int, char, Color, Color, Color)
Fills a rectangle with a horizontal foreground color gradient (left to right).
public void GradientFillHorizontal(int x, int y, int width, int height, char ch, Color fgStart, Color fgEnd, Color bg)
Parameters
xintThe X coordinate of the rectangle.
yintThe Y coordinate of the rectangle.
widthintThe width of the rectangle.
heightintThe height of the rectangle.
chcharThe fill character.
fgStartColorThe starting foreground color (left).
fgEndColorThe ending foreground color (right).
bgColorThe background color.
GradientFillRect(int, int, int, int, Color, Color, bool)
Fills a rectangle with a background color gradient.
public void GradientFillRect(int x, int y, int width, int height, Color bgStart, Color bgEnd, bool horizontal)
Parameters
xintThe X coordinate of the rectangle.
yintThe Y coordinate of the rectangle.
widthintThe width of the rectangle.
heightintThe height of the rectangle.
bgStartColorThe starting background color.
bgEndColorThe ending background color.
horizontalboolTrue for left-to-right gradient, false for top-to-bottom.
GradientFillVertical(int, int, int, int, char, Color, Color, Color)
Fills a rectangle with a vertical foreground color gradient (top to bottom).
public void GradientFillVertical(int x, int y, int width, int height, char ch, Color fgStart, Color fgEnd, Color bg)
Parameters
xintThe X coordinate of the rectangle.
yintThe Y coordinate of the rectangle.
widthintThe width of the rectangle.
heightintThe height of the rectangle.
chcharThe fill character.
fgStartColorThe starting foreground color (top).
fgEndColorThe ending foreground color (bottom).
bgColorThe background color.
PatternFill(int, int, int, int, string[], Color, Color)
Fills a rectangle with a repeating 2D character pattern.
public void PatternFill(int x, int y, int width, int height, string[] pattern, Color fg, Color bg)
Parameters
xintThe X coordinate of the rectangle.
yintThe Y coordinate of the rectangle.
widthintThe width of the rectangle.
heightintThe height of the rectangle.
patternstring[]The pattern rows to tile.
fgColorThe foreground color.
bgColorThe background color.
SetNarrowCell(int, int, char, Color, Color)
Sets a single cell at the specified canvas-local position.
public void SetNarrowCell(int x, int y, char ch, Color fg, Color bg)
Parameters
xintThe X coordinate in canvas-local space.
yintThe Y coordinate in canvas-local space.
chcharThe character to display.
fgColorThe foreground color.
bgColorThe background color.
StippleFill(int, int, int, int, double, Color, Color)
Fills a rectangle with a density-based stipple pattern. Density ranges from 0.0 (empty) to 1.0 (fully filled).
public void StippleFill(int x, int y, int width, int height, double density, Color fg, Color bg)
Parameters
xintThe X coordinate of the rectangle.
yintThe Y coordinate of the rectangle.
widthintThe width of the rectangle.
heightintThe height of the rectangle.
densitydoubleThe fill density from 0.0 to 1.0.
fgColorThe foreground color.
bgColorThe background color.
WriteString(int, int, string, Color, Color)
Writes a string at the specified canvas-local position.
public void WriteString(int x, int y, string text, Color fg, Color bg)
Parameters
xintThe X coordinate.
yintThe Y coordinate.
textstringThe text to write.
fgColorThe foreground color.
bgColorThe background color.
WriteStringCentered(int, string, Color, Color)
Writes horizontally centered text within the canvas at the specified Y position.
public void WriteStringCentered(int y, string text, Color fg, Color bg)
Parameters
yintThe Y coordinate in canvas-local space.
textstringThe text to center.
fgColorThe foreground color.
bgColorThe background color.
WriteStringInBox(int, int, int, int, string, BoxChars, Color, Color, Color, Color)
Draws a box border and writes centered text inside it.
public void WriteStringInBox(int x, int y, int width, int height, string text, BoxChars boxChars, Color fg, Color bg, Color boxFg, Color boxBg)
Parameters
xintThe X coordinate of the box.
yintThe Y coordinate of the box.
widthintThe width of the box.
heightintThe height of the box.
textstringThe text to center inside the box.
boxCharsBoxCharsThe box drawing character set.
fgColorThe text foreground color.
bgColorThe text background color.
boxFgColorThe box border foreground color.
boxBgColorThe box border background color.
WriteStringRight(int, string, Color, Color)
Writes right-aligned text within the canvas at the specified Y position.
public void WriteStringRight(int y, string text, Color fg, Color bg)
Parameters
yintThe Y coordinate in canvas-local space.
textstringThe text to right-align.
fgColorThe foreground color.
bgColorThe background color.
WriteWrappedText(int, int, int, string, Color, Color)
Writes word-wrapped text starting at the given position within the specified width.
public void WriteWrappedText(int x, int y, int width, string text, Color fg, Color bg)