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
State
The canvas's current state.
CanvasState State { get; }
Property Value
Target
The texture to which this canvas is drawing to.
ITexture Target { get; }
Property Value
Width
Gets the width of the canvas, in pixels.
int Width { get; }
Property Value
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
ColorThe 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
RectangleThe bounds of the ellipse.
begin
floatThe angle at which the ellipse segment begins.
end
floatThe angle at which the ellipse segment begins.
includeCenter
boolWhether 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
Vector2The position of the rectangle.
radii
Vector2The radii of the ellipse.
begin
floatThe angle at which the ellipse segment begins.
end
floatThe angle at which the ellipse segment begins.
includeCenter
boolWhether the arc's endpoints include its center or just connect its endpoints.
alignment
AlignmentThe 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
floatThe x-coordinate of the ellipse.
y
floatThe y-coordinate of the ellipse.
radiusX
floatThe radius of the ellipse on the x-axis.
radiusY
floatThe radius of the ellipse on the y-axis.
begin
floatThe angle at which the ellipse segment begins.
end
floatThe angle at which the ellipse segment begins.
includeCenter
boolWhether the arc's endpoints should connect to one other or to the center of the ellipse.
alignment
AlignmentThe 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
CircleThe 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
Vector2The position of the circle.
radius
floatThe radius of the circle on the x-axis.
alignment
AlignmentThe 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
floatThe x-coordinate of the circle.
y
floatThe y-coordinate of the circle.
radius
floatThe radius of the circle on the x-axis.
alignment
AlignmentThe 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
RectangleThe 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
Vector2The position of the rectangle.
radii
Vector2The radii of the ellipse.
alignment
AlignmentThe 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
floatThe x-coordinate of the ellipse.
y
floatThe y-coordinate of the ellipse.
radiusX
floatThe radius of the ellipse on the x-axis.
radiusY
floatThe radius of the ellipse on the y-axis.
alignment
AlignmentThe 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
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
floatThe x-coordinate of the first point of the line.
y1
floatThe y-coordinate of the first point of the line.
x2
floatThe x-coordinate of the second point of the line.
y2
floatThe 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
boolWhether 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
boolWhether 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
boolWhether 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
RectangleThe 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
Vector2The position of the rectangle.
size
Vector2The size of the rectangle.
alignment
AlignmentThe 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
floatThe X position of the rectangle.
y
floatThe Y position of the rectangle.
width
floatThe width of the rectangle.
height
floatThe height of the rectangle.
alignment
AlignmentThe 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
RectangleThe position and size of rectangle.
radius
floatThe 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
Vector2The position of the rectangle.
size
Vector2The size of the rectangle.
radius
floatThe radius of the rounded corners of the rectangle.
alignment
AlignmentThe 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
floatThe X position of the rectangle.
y
floatThe Y position of the rectangle.
width
floatThe width of the rectangle.
height
floatThe height of the rectangle.
radius
floatThe radius of the rounded corners of the rectangle.
alignment
AlignmentThe 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
Vector2The position of the text.
alignment
AlignmentThe point on the text's bounding box to align to the provided position.
origin
TextBoundsDetermines 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
floatThe X position of the text.
y
floatThe Y position of the text.
alignment
AlignmentThe point on the text's bounding box to align to the provided position.
origin
TextBoundsDetermines 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
stringThe text to draw.
position
Vector2The position of the text.
alignment
AlignmentThe point on the text's bounding box to align to the provided position.
origin
TextBoundsDetermines 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
stringThe text to draw.
x
floatThe X position of the text.
y
floatThe Y position of the text.
alignment
AlignmentThe point on the text's bounding box to align to the provided position.
origin
TextBoundsDetermines 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
ITextureThe texture to draw.
alignment
AlignmentThe 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
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
ITextureThe texture to draw.
source
RectangleThe source bounds of the texture.
destination
RectangleThe 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
ITextureThe texture to draw.
position
Vector2The position of the texture's destination rectangle.
alignment
AlignmentThe 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
ITextureThe texture to draw.
position
Vector2The position of the texture's destination rectangle.
size
Vector2The size of the texture's destination rectangle.
alignment
AlignmentThe 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
ITextureThe texture to draw.
x
floatThe x-position of the texture.
y
floatThe y-position of the texture.
alignment
AlignmentThe 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
ITextureThe texture to draw.
x
floatThe x-position of the texture.
y
floatThe y-position of the texture.
width
floatThe width of the texture destination.
height
floatThe height of the texture destination.
alignment
AlignmentThe 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
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
IFontThe 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
stringThe name of the font to load.
FontSize(float)
Configures the size of the current font.
void FontSize(float size)
Parameters
size
floatThe size of the font.
FontStyle(FontStyle)
Configures the style of the current font.
void FontStyle(FontStyle style)
Parameters
style
FontStyleThe 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
TextBoundsDetermines 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
floatThe maximum length of the string.
charsMeasured
intThe number of characters measured before measuring stopped, or the length of
text
if the entire string was measured.bounds
TextBoundsDetermines 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
stringThe text to measure.
bounds
TextBoundsDetermines 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
stringThe text to measure.
maxLength
floatThe maximum length of the string.
charsMeasured
intThe number of characters measured before measuring stopped, or the length of
text
if the entire string was measured.bounds
TextBoundsDetermines 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
floatThe 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
floatThe angle of the rotation, in radians.
center
Vector2The 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
floatThe angle of the rotation, in radians.
centerX
floatThe X coordinate of the point around which the rotation occurs.
centerY
floatThe 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
Vector2The 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
floatThe 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
floatThe scale to transform the transformation matrix by on the x-axis.
scaleY
floatThe 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
Vector2The value of the translation.
Translate(float, float)
Translates the current transformation matrix by the provided translation.
void Translate(float x, float y)