Table of Contents

Interface ICanvas

Namespace
SimulationFramework.Drawing
Assembly
SimulationFramework.dll

Enables the rendering shapes to a texture.

public interface ICanvas : IDisposable
Inherited Members

Properties

Height

Gets the height of the canvas, in pixels.

int Height { get; }

Property Value

int

State

The canvas's current state.

CanvasState State { get; }

Property Value

CanvasState

Target

The texture to which this canvas is drawing to.

ITexture Target { get; }

Property Value

ITexture

Width

Gets the width of the canvas, in pixels.

int Width { get; }

Property Value

int

Methods

Antialias(bool)

Sets whether the canvas should use antialiasing when rendering or not.

void Antialias(bool antialias)

Parameters

antialias bool

Clear(Color)

Clears the canvas.

void Clear(Color color)

Parameters

color Color

The color with which to clear the canvas.

Clip(Rectangle?)

Sets the clipping rectangle of the canvas.

void Clip(Rectangle? rectangle)

Parameters

rectangle Rectangle?

DrawArc(Rectangle, float, float, bool)

Draws a segment of an ellipse to the canvas to form an arc, using the current transform, clipping, and drawing settings.

void DrawArc(Rectangle bounds, float begin, float end, bool includeCenter)

Parameters

bounds Rectangle

The bounds of the ellipse.

begin float

The angle at which the ellipse segment begins.

end float

The angle at which the ellipse segment begins.

includeCenter bool

Whether the arc's endpoints include its center or just connect its endpoints.

DrawArc(Vector2, Vector2, float, float, bool, Alignment)

Draws a segment of an ellipse to the canvas to form an arc, using the current transform, clipping, and drawing settings.

void DrawArc(Vector2 position, Vector2 radii, float begin, float end, bool includeCenter, Alignment alignment = Alignment.Center)

Parameters

position Vector2

The position of the rectangle.

radii Vector2

The radii of the ellipse.

begin float

The angle at which the ellipse segment begins.

end float

The angle at which the ellipse segment begins.

includeCenter bool

Whether the arc's endpoints include its center or just connect its endpoints.

alignment Alignment

The point on the bounding-box of the ellipse to align to the provided position.

DrawArc(float, float, float, float, float, float, bool, Alignment)

Draws a segment of an ellipse to the canvas to form an arc, using the current transform, clipping, and drawing settings.

void DrawArc(float x, float y, float radiusX, float radiusY, float begin, float end, bool includeCenter, Alignment alignment = Alignment.Center)

Parameters

x float

The x-coordinate of the ellipse.

y float

The y-coordinate of the ellipse.

radiusX float

The radius of the ellipse on the x-axis.

radiusY float

The radius of the ellipse on the y-axis.

begin float

The angle at which the ellipse segment begins.

end float

The angle at which the ellipse segment begins.

includeCenter bool

Whether the arc's endpoints should connect to one other or to the center of the ellipse.

alignment Alignment

The point on the bounding-box of the ellipse to align to the provided position

DrawCircle(Circle)

Draws a circle to the canvas, using the current transform, clipping, and drawing settings.

void DrawCircle(Circle circle)

Parameters

circle Circle

The circle to draw.

DrawCircle(Vector2, float, Alignment)

Draws a circle to the canvas, using the current transform, clipping, and drawing settings.

void DrawCircle(Vector2 position, float radius, Alignment alignment = Alignment.Center)

Parameters

position Vector2

The position of the circle.

radius float

The radius of the circle on the x-axis.

alignment Alignment

The point on the bounding-box of the circle to align to the provided position.

DrawCircle(float, float, float, Alignment)

Draws a circle to the canvas, using the current transform, clipping, and drawing settings.

void DrawCircle(float x, float y, float radius, Alignment alignment = Alignment.Center)

Parameters

x float

The x-coordinate of the circle.

y float

The y-coordinate of the circle.

radius float

The radius of the circle on the x-axis.

alignment Alignment

The point on the bounding-box of the circle to align to the provided position.

DrawEllipse(Rectangle)

Draws an ellipse to the canvas, using the current transform, clipping, and drawing settings.

void DrawEllipse(Rectangle bounds)

Parameters

bounds Rectangle

The bounds into which the drawn ellipse should fit.

DrawEllipse(Vector2, Vector2, Alignment)

Draws an ellipse to the canvas, using the current transform, clipping, and drawing settings.

void DrawEllipse(Vector2 position, Vector2 radii, Alignment alignment = Alignment.Center)

Parameters

position Vector2

The position of the rectangle.

radii Vector2

The radii of the ellipse.

alignment Alignment

The point on the bounding-box of the ellipse to align to the provided position.

DrawEllipse(float, float, float, float, Alignment)

Draws an ellipse to the canvas, using the current transform, clipping, and drawing settings.

void DrawEllipse(float x, float y, float radiusX, float radiusY, Alignment alignment = Alignment.Center)

Parameters

x float

The x-coordinate of the ellipse.

y float

The y-coordinate of the ellipse.

radiusX float

The radius of the ellipse on the x-axis.

radiusY float

The radius of the ellipse on the y-axis.

alignment Alignment

The point on the bounding-box of the ellipse to align to the provided position

DrawLine(Vector2, Vector2)

Draws a line to the canvas, using the current transform, clipping, and drawing settings. To change the thickness of the line, see StrokeWidth(float).

void DrawLine(Vector2 p1, Vector2 p2)

Parameters

p1 Vector2

The first point of the line.

p2 Vector2

The second point of the line.

DrawLine(float, float, float, float)

Draws a line to the canvas, using the current transform, clipping, and drawing settings. To change the thickness of the line, see StrokeWidth(float).

void DrawLine(float x1, float y1, float x2, float y2)

Parameters

x1 float

The x-coordinate of the first point of the line.

y1 float

The y-coordinate of the first point of the line.

x2 float

The x-coordinate of the second point of the line.

y2 float

The y-coordinate of the second point of the line.

DrawPolygon(IEnumerable<Vector2>, bool)

Draws a polygon to the canvas, using the current transform, clipping, and drawing settings.

If the current DrawMode is Fill or Gradient, the first and last vertices are connected to create a closed polygon.

void DrawPolygon(IEnumerable<Vector2> polygon, bool close = true)

Parameters

polygon IEnumerable<Vector2>

The vertices of the polygon.

close bool

Whether the first and last vertices of the polygon should be treated as connected.

DrawPolygon(Vector2[], bool)

Draws a polygon to the canvas, using the current transform, clipping, and drawing settings.

If the current DrawMode is Fill or Gradient, the first and last vertices are connected to create a closed polygon.

void DrawPolygon(Vector2[] polygon, bool close = true)

Parameters

polygon Vector2[]

The vertices of the polygon.

close bool

Whether the first and last vertices of the polygon should be treated as connected.

DrawPolygon(ReadOnlySpan<Vector2>, bool)

Draws a polygon to the canvas, using the current transform, clipping, and drawing settings.

void DrawPolygon(ReadOnlySpan<Vector2> polygon, bool close = true)

Parameters

polygon ReadOnlySpan<Vector2>

The vertices of the polygon.

close bool

Whether the first and last vertices of the polygon should be treated as connected.

DrawRect(Rectangle)

Draws a rectangle to the canvas, using the current transform, clipping, and drawing settings.

void DrawRect(Rectangle rect)

Parameters

rect Rectangle

The rectangle to draw.

DrawRect(Vector2, Vector2, Alignment)

Draws a rectangle to the canvas, using the current transform, clipping, and drawing settings.

void DrawRect(Vector2 position, Vector2 size, Alignment alignment = Alignment.TopLeft)

Parameters

position Vector2

The position of the rectangle.

size Vector2

The size of the rectangle.

alignment Alignment

The point on the rectangle to align to the provided position.

DrawRect(float, float, float, float, Alignment)

Draws a rectangle to the canvas, using the current transform, clipping, and drawing settings.

void DrawRect(float x, float y, float width, float height, Alignment alignment = Alignment.TopLeft)

Parameters

x float

The X position of the rectangle.

y float

The Y position of the rectangle.

width float

The width of the rectangle.

height float

The height of the rectangle.

alignment Alignment

The point on the rectangle to align to the provided position.

DrawRoundedRect(Rectangle, float)

Draws a rounded rectangle to the canvas, using the current transform, clipping, and drawing settings.

void DrawRoundedRect(Rectangle rect, float radius)

Parameters

rect Rectangle

The position and size of rectangle.

radius float

The radius of the rounded corners of the rectangle.

DrawRoundedRect(Vector2, Vector2, float, Alignment)

Draws a rounded rectangle to the canvas, using the current transform, clipping, and drawing settings.

void DrawRoundedRect(Vector2 position, Vector2 size, float radius, Alignment alignment = Alignment.TopLeft)

Parameters

position Vector2

The position of the rectangle.

size Vector2

The size of the rectangle.

radius float

The radius of the rounded corners of the rectangle.

alignment Alignment

The point on the rectangle to align to the provided position.

DrawRoundedRect(float, float, float, float, float, Alignment)

Draws a rounded rectangle to the canvas, using the current transform, clipping, and drawing settings.

void DrawRoundedRect(float x, float y, float width, float height, float radius, Alignment alignment = Alignment.TopLeft)

Parameters

x float

The X position of the rectangle.

y float

The Y position of the rectangle.

width float

The width of the rectangle.

height float

The height of the rectangle.

radius float

The radius of the rounded corners of the rectangle.

alignment Alignment

The point on the rectangle to align to the provided position.

DrawText(ReadOnlySpan<char>, Vector2, Alignment, TextBounds)

Draws a set of text to the screen using the current font, transform, clipping, and drawing settings.

void DrawText(ReadOnlySpan<char> text, Vector2 position, Alignment alignment = Alignment.TopLeft, TextBounds origin = TextBounds.BestFit)

Parameters

text ReadOnlySpan<char>

The text to draw.

position Vector2

The position of the text.

alignment Alignment

The point on the text's bounding box to align to the provided position.

origin TextBounds

Determines the text's bounding box.

DrawText(ReadOnlySpan<char>, float, float, Alignment, TextBounds)

Draws a set of text to the screen using the current font, transform, clipping, and drawing settings.

void DrawText(ReadOnlySpan<char> text, float x, float y, Alignment alignment = Alignment.TopLeft, TextBounds origin = TextBounds.BestFit)

Parameters

text ReadOnlySpan<char>

The text to draw.

x float

The X position of the text.

y float

The Y position of the text.

alignment Alignment

The point on the text's bounding box to align to the provided position.

origin TextBounds

Determines the text's bounding box.

DrawText(string, Vector2, Alignment, TextBounds)

Draws a set of text to the screen using the current font, transform, clipping, and drawing settings.

void DrawText(string text, Vector2 position, Alignment alignment = Alignment.TopLeft, TextBounds origin = TextBounds.BestFit)

Parameters

text string

The text to draw.

position Vector2

The position of the text.

alignment Alignment

The point on the text's bounding box to align to the provided position.

origin TextBounds

Determines the text's bounding box.

DrawText(string, float, float, Alignment, TextBounds)

Draws a set of text to the screen using the current font, transform, clipping, and drawing settings.

void DrawText(string text, float x, float y, Alignment alignment = Alignment.TopLeft, TextBounds origin = TextBounds.BestFit)

Parameters

text string

The text to draw.

x float

The X position of the text.

y float

The Y position of the text.

alignment Alignment

The point on the text's bounding box to align to the provided position.

origin TextBounds

Determines the text's bounding box.

DrawTexture(ITexture, Alignment)

Draws a texture to the canvas at (0, 0), using the current transform and clipping settings.

void DrawTexture(ITexture texture, Alignment alignment = Alignment.TopLeft)

Parameters

texture ITexture

The texture to draw.

alignment Alignment

The point on the texture to align to (0, 0).

DrawTexture(ITexture, Rectangle)

Draws a texture to the canvas using the current transform and clipping settings.

void DrawTexture(ITexture texture, Rectangle destination)

Parameters

texture ITexture

The texture to draw.

destination Rectangle

The location to draw the texture.

DrawTexture(ITexture, Rectangle, Rectangle)

Draws a texture to the canvas, using the current transform and clipping settings.

void DrawTexture(ITexture texture, Rectangle source, Rectangle destination)

Parameters

texture ITexture

The texture to draw.

source Rectangle

The source bounds of the texture.

destination Rectangle

The destination bounds of the texture.

DrawTexture(ITexture, Vector2, Alignment)

Draws a texture to the canvas using the current transform and clipping settings.

void DrawTexture(ITexture texture, Vector2 position, Alignment alignment = Alignment.TopLeft)

Parameters

texture ITexture

The texture to draw.

position Vector2

The position of the texture's destination rectangle.

alignment Alignment

The point on the texture to align to the provided position.

DrawTexture(ITexture, Vector2, Vector2, Alignment)

Draws a texture to the canvas using the current transform and clipping settings.

void DrawTexture(ITexture texture, Vector2 position, Vector2 size, Alignment alignment = Alignment.TopLeft)

Parameters

texture ITexture

The texture to draw.

position Vector2

The position of the texture's destination rectangle.

size Vector2

The size of the texture's destination rectangle.

alignment Alignment

The point on the texture to align to the provided position.

DrawTexture(ITexture, float, float, Alignment)

Draws a texture to the canvas using the current transform and clipping settings.

void DrawTexture(ITexture texture, float x, float y, Alignment alignment = Alignment.TopLeft)

Parameters

texture ITexture

The texture to draw.

x float

The x-position of the texture.

y float

The y-position of the texture.

alignment Alignment

The point on the texture to align to the provided position.

DrawTexture(ITexture, float, float, float, float, Alignment)

Draws a texture to the canvas using the current transform and clipping settings.

void DrawTexture(ITexture texture, float x, float y, float width, float height, Alignment alignment = Alignment.TopLeft)

Parameters

texture ITexture

The texture to draw.

x float

The x-position of the texture.

y float

The y-position of the texture.

width float

The width of the texture destination.

height float

The height of the texture destination.

alignment Alignment

The point on the texture to align to the provided position.

Fill(Color)

Configures the canvas to fill shapes with the provided color.

Calling this method sets the current state's DrawMode to Fill, meaning that any shapes drawn after this call will be filled with the provided color.

void Fill(Color color)

Parameters

color Color

Fill(Gradient)

Configures the canvas to fill shapes using the provided gradient.

Calling this method sets the current state's DrawMode to Gradient, meaning that any shapes drawn after this call will be filled with the provided gradient.

void Fill(Gradient gradient)

Parameters

gradient Gradient

Fill(ITexture)

Fills any drawn shapes with the provided texture.

Calling this method sets the current state's DrawMode to Textured, meaning that any shapes drawn after this call will be filled with the provided texture.

void Fill(ITexture texture)

Parameters

texture ITexture

Fill(ITexture, Matrix3x2, TileMode, TileMode)

Fills any drawn shapes with the provided texture.

Calling this method sets the current state's DrawMode to Textured, meaning that any shapes drawn after this call will be filled with the provided texture.

void Fill(ITexture texture, Matrix3x2 transform, TileMode tileModeX = TileMode.Clamp, TileMode tileModeY = TileMode.Clamp)

Parameters

texture ITexture
transform Matrix3x2
tileModeX TileMode
tileModeY TileMode

Flush()

Waits for all drawing commands to finish executing.

void Flush()

Font(IFont)

Sets the font used for text rendering.

void Font(IFont font)

Parameters

font IFont

The font to use when drawing text.

Font(string)

Sets a font with the specified attributes as current (and loads it if it is not already loaded).

void Font(string name)

Parameters

name string

The name of the font to load.

FontSize(float)

Configures the size of the current font.

void FontSize(float size)

Parameters

size float

The size of the font.

FontStyle(FontStyle)

Configures the style of the current font.

void FontStyle(FontStyle style)

Parameters

style FontStyle

The style of the font.

MeasureText(ReadOnlySpan<char>, TextBounds)

Determines the size of the provided text based on the current font selection.

Vector2 MeasureText(ReadOnlySpan<char> text, TextBounds bounds = TextBounds.BestFit)

Parameters

text ReadOnlySpan<char>

The text to measure.

bounds TextBounds

Determines how the text's bounding box is calculated.

Returns

Vector2

The width and height of the provided text's bounds.

MeasureText(ReadOnlySpan<char>, float, out int, TextBounds)

Determines the size of the provided text based on the current font selection, stopping if the string's length exceeds a maximum.

Vector2 MeasureText(ReadOnlySpan<char> text, float maxLength, out int charsMeasured, TextBounds bounds = TextBounds.BestFit)

Parameters

text ReadOnlySpan<char>

The text to measure.

maxLength float

The maximum length of the string.

charsMeasured int

The number of characters measured before measuring stopped, or the length of text if the entire string was measured.

bounds TextBounds

Determines how the text's bounding box is calculated.

Returns

Vector2

The width and height of the provided text's bounds.

MeasureText(string, TextBounds)

Determines the size of the provided text based on the current font selection.

Vector2 MeasureText(string text, TextBounds bounds = TextBounds.BestFit)

Parameters

text string

The text to measure.

bounds TextBounds

Determines how the text's bounding box is calculated.

Returns

Vector2

The width and height of the provided text's bounds.

MeasureText(string, float, out int, TextBounds)

Determines the size of the provided text based on the current font selection, stopping if the string's length exceeds a maximum.

Vector2 MeasureText(string text, float maxLength, out int charsMeasured, TextBounds bounds = TextBounds.BestFit)

Parameters

text string

The text to measure.

maxLength float

The maximum length of the string.

charsMeasured int

The number of characters measured before measuring stopped, or the length of text if the entire string was measured.

bounds TextBounds

Determines how the text's bounding box is calculated.

Returns

Vector2

The width and height of the provided text's bounds.

PopState()

Pops a transformation matrix, clipping rectangle, and drawing state off the top of the stack.

void PopState()

PushState()

Pushes the current transformation matrix, clipping rectangle, and drawing state onto the stack.

void PushState()

ResetState()

Resets the transformation matrix, clipping rectangle, and drawing state to their defaults.

void ResetState()

Rotate(float)

Rotates the current transformation matrix center around the current translation by the provided angle.

void Rotate(float angle)

Parameters

angle float

The angle of the rotation, in radians.

Rotate(float, Vector2)

Rotates the current transformation matrix around the provided point by the provided angle.

void Rotate(float angle, Vector2 center)

Parameters

angle float

The angle of the rotation, in radians.

center Vector2

The point around which the rotation occurs.

Rotate(float, float, float)

Rotates the current transformation matrix around the provided point by the provided angle.

void Rotate(float angle, float centerX, float centerY)

Parameters

angle float

The angle of the rotation, in radians.

centerX float

The X coordinate of the point around which the rotation occurs.

centerY float

The Y coordinate of the point around which the rotation occurs.

Scale(Vector2)

Scales the current transformation matrix by the provided value.

void Scale(Vector2 scale)

Parameters

scale Vector2

The scales to transform the transformation matrix by on the X and Y axes.

Scale(float)

Scales the current transformation matrix by the provided value.

void Scale(float scale)

Parameters

scale float

The scale to transform the transformation matrix by.

Scale(float, float)

Scales the current transformation matrix by the provided values.

void Scale(float scaleX, float scaleY)

Parameters

scaleX float

The scale to transform the transformation matrix by on the x-axis.

scaleY float

The scale to transform the transformation matrix by on the y-axis.

SetTransform(Matrix3x2)

Sets the canvas' transformation matrix.

void SetTransform(Matrix3x2 transform)

Parameters

transform Matrix3x2

Stroke(Color)

Configures the canvas to outline shapes with the provided color.

Calling this method sets the current state's DrawMode to Stroke, meaning that any shapes drawn after this call will be outlined with the provided color.

void Stroke(Color color)

Parameters

color Color

StrokeWidth(float)

Sets the stroke width of the canvas.

void StrokeWidth(float width)

Parameters

width float

Transform(Matrix3x2)

Composes the provided transformation with the canvas' current transform.

void Transform(Matrix3x2 transformation)

Parameters

transformation Matrix3x2

Translate(Vector2)

Translates the current transformation matrix by the provided translation.

void Translate(Vector2 translation)

Parameters

translation Vector2

The value of the translation.

Translate(float, float)

Translates the current transformation matrix by the provided translation.

void Translate(float x, float y)

Parameters

x float

The X value of the translation.

y float

The Y value of the translation.