Class Canvas
Represents a drawing surface.
Inherited Members
Namespace: Cosmos.System.Graphics
Assembly: Cosmos.System2.dll
Syntax
public abstract class Canvas
Constructors
| Improve this Doc View SourceCanvas()
Initializes a new instance of the Canvas class.
Declaration
public Canvas()
Canvas(Mode)
Initializes a new instance of the Canvas class.
Declaration
public Canvas(Mode mode)
Parameters
Type | Name | Description |
---|---|---|
Mode | mode |
Properties
| Improve this Doc View SourceAvailableModes
The available graphics modes.
Declaration
public abstract List<Mode> AvailableModes { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.List<Mode> |
DefaultGraphicsMode
The default graphics mode.
Declaration
public abstract Mode DefaultGraphicsMode { get; }
Property Value
Type | Description |
---|---|
Mode |
Mode
The currently used display mode.
Declaration
public abstract Mode Mode { get; set; }
Property Value
Type | Description |
---|---|
Mode |
Methods
| Improve this Doc View SourceAlphaBlend(Color, Color, Byte)
Blends between color from
and to
,
using the given alpha
value.
Declaration
public static Color AlphaBlend(Color to, Color from, byte alpha)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color | to | The background color. |
System.Drawing.Color | from | The foreground color. |
System.Byte | alpha | The alpha value. |
Returns
Type | Description |
---|---|
System.Drawing.Color |
CheckIfModeIsValid(Mode)
Checks if the given video mode is valid.
Declaration
protected bool CheckIfModeIsValid(Mode mode)
Parameters
Type | Name | Description |
---|---|---|
Mode | mode | The target video mode. |
Returns
Type | Description |
---|---|
System.Boolean |
Clear()
Clears the canvas with the default color.
Declaration
public void Clear()
Clear(Color)
Clears the entire canvas with the specified color.
Declaration
public virtual void Clear(Color color)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color | color | The color to clear the screen with. |
Clear(Int32)
Clears the entire canvas with the specified color.
Declaration
public abstract void Clear(int color)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | color | The ARGB color to clear the screen with. |
CroppedDrawImage(Image, Int32, Int32, Int32, Int32, Boolean)
Draws the given image at the specified coordinates, cropping the image to fit within the maximum width and height.
Declaration
public virtual void CroppedDrawImage(Image image, int x, int y, int maxWidth, int maxHeight, bool preventOffBoundPixels = true)
Parameters
Type | Name | Description |
---|---|---|
Image | image | The image to draw. |
System.Int32 | x | The X coordinate where the image will be drawn. |
System.Int32 | y | The Y coordinate where the image will be drawn. |
System.Int32 | maxWidth | The maximum width to display the image. If the image exceeds this width, it will be cropped. |
System.Int32 | maxHeight | The maximum height to display the image. If the image exceeds this height, it will be cropped. |
System.Boolean | preventOffBoundPixels | Prevents drawing outside the bounds of the canvas. |
Disable()
Disables the canvas.
Declaration
public abstract void Disable()
Display()
Updates the screen to display the underlying frame-buffer. Call this method in order to synchronize the screen with the canvas.
Declaration
public abstract void Display()
DrawArc(Int32, Int32, Int32, Int32, Color, Int32, Int32)
Draws an arc.
Declaration
public virtual void DrawArc(int x, int y, int width, int height, Color color, int startAngle = 0, int endAngle = 360)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | The starting X coordinate. |
System.Int32 | y | The ending X coordinate. |
System.Int32 | width | The width of the arc. |
System.Int32 | height | The height of the arc. |
System.Drawing.Color | color | The color of the arc. |
System.Int32 | startAngle | The starting angle of the arc, in degrees. |
System.Int32 | endAngle | The ending angle of the arc, in degrees. |
DrawArray(Color[], Int32, Int32, Int32, Int32)
Draws an array of pixels to the canvas, starting at the given coordinates, using the given width.
Declaration
public virtual void DrawArray(Color[] colors, int x, int y, int width, int height)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color[] | colors | The pixels to draw. |
System.Int32 | x | The X coordinate. |
System.Int32 | y | The Y coordinate. |
System.Int32 | width | The width of the drawn bitmap. |
System.Int32 | height | This parameter is unused. |
DrawArray(Int32[], Int32, Int32, Int32, Int32)
Draws an array of pixels to the canvas, starting at the given coordinates, using the given width.
Declaration
public virtual void DrawArray(int[] colors, int x, int y, int width, int height)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | colors | The pixels to draw. |
System.Int32 | x | The X coordinate. |
System.Int32 | y | The Y coordinate. |
System.Int32 | width | The width of the drawn bitmap. |
System.Int32 | height | The height of the drawn bitmap. |
DrawArray(Int32[], Int32, Int32, Int32, Int32, Int32)
Draws an array of pixels to the canvas, starting at the given coordinates, using the given width.
Declaration
public virtual void DrawArray(int[] colors, int x, int y, int width, int height, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | colors | The pixels to draw. |
System.Int32 | x | The X coordinate. |
System.Int32 | y | The Y coordinate. |
System.Int32 | width | The width of the drawn bitmap. |
System.Int32 | height | The height of the drawn bitmap. |
System.Int32 | startIndex | int[] colors tarting position |
DrawChar(Char, Font, Color, Int32, Int32)
Draws a single character using the given bitmap font.
Declaration
public virtual void DrawChar(char c, Font font, Color color, int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Char | c | The character to draw. |
Font | font | The bitmap font to use. |
System.Drawing.Color | color | The color to write the string with. |
System.Int32 | x | The origin X coordinate. |
System.Int32 | y | The origin Y coordinate. |
DrawCircle(Color, Int32, Int32, Int32)
Draws a circle at the given coordinates with the given radius.
Declaration
public virtual void DrawCircle(Color color, int xCenter, int yCenter, int radius)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color | color | The color to draw with. |
System.Int32 | xCenter | The X center coordinate. |
System.Int32 | yCenter | The Y center coordinate. |
System.Int32 | radius | The radius of the circle to draw. |
DrawEllipse(Color, Int32, Int32, Int32, Int32)
Draws an ellipse.
Declaration
public virtual void DrawEllipse(Color color, int xCenter, int yCenter, int xR, int yR)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color | color | The color to draw with. |
System.Int32 | xCenter | The X center coordinate. |
System.Int32 | yCenter | The Y center coordinate. |
System.Int32 | xR | The X radius. |
System.Int32 | yR | The Y radius. |
DrawFilledCircle(Color, Int32, Int32, Int32)
Draws a filled circle at the given coordinates with the given radius.
Declaration
public virtual void DrawFilledCircle(Color color, int x0, int y0, int radius)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color | color | The color to draw with. |
System.Int32 | x0 | The X center coordinate. |
System.Int32 | y0 | The Y center coordinate. |
System.Int32 | radius | The radius of the circle to draw. |
DrawFilledEllipse(Color, Int32, Int32, Int32, Int32)
Draws a filled ellipse.
Declaration
public virtual void DrawFilledEllipse(Color color, int xCenter, int yCenter, int yR, int xR)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color | color | The color to draw with. |
System.Int32 | xCenter | The X center coordinate. |
System.Int32 | yCenter | The Y center coordinate. |
System.Int32 | yR | The Y radius. |
System.Int32 | xR | The X radius. |
DrawFilledRectangle(Color, Int32, Int32, Int32, Int32, Boolean)
Draws a filled rectangle.
Declaration
public virtual void DrawFilledRectangle(Color color, int xStart, int yStart, int width, int height, bool preventOffBoundPixels = true)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color | color | The color to draw the rectangle with. |
System.Int32 | xStart | The starting point X coordinate. |
System.Int32 | yStart | The starting point Y coordinate. |
System.Int32 | width | The width of the rectangle. |
System.Int32 | height | The height of the rectangle. |
System.Boolean | preventOffBoundPixels |
DrawImage(Image, Int32, Int32, Boolean)
Draws the given image at the specified coordinates.
Declaration
public virtual void DrawImage(Image image, int x, int y, bool preventOffBoundPixels = true)
Parameters
Type | Name | Description |
---|---|---|
Image | image | The image to draw. |
System.Int32 | x | The origin X coordinate. |
System.Int32 | y | The origin Y coordinate. |
System.Boolean | preventOffBoundPixels | Prevents drawing outside the bounds of the canvas. |
DrawImage(Image, Int32, Int32, Int32, Int32, Boolean)
Draws a bitmap, applying scaling to the given image.
Declaration
public virtual void DrawImage(Image image, int x, int y, int w, int h, bool preventOffBoundPixels = true)
Parameters
Type | Name | Description |
---|---|---|
Image | image | The image to draw. |
System.Int32 | x | The X coordinate. |
System.Int32 | y | The Y coordinate. |
System.Int32 | w | The desired width to scale the image to before drawing. |
System.Int32 | h | The desired height to scale the image to before drawing |
System.Boolean | preventOffBoundPixels | Prevents drawing outside the bounds of the canvas. |
DrawImageAlpha(Image, Int32, Int32, Boolean)
Draws an image with alpha blending.
Declaration
public void DrawImageAlpha(Image image, int x, int y, bool preventOffBoundPixels = true)
Parameters
Type | Name | Description |
---|---|---|
Image | image | The image to draw. |
System.Int32 | x | The X coordinate. |
System.Int32 | y | The Y coordinate. |
System.Boolean | preventOffBoundPixels | Prevents drawing outside the bounds of the canvas. |
DrawLine(Color, Int32, Int32, Int32, Int32)
Draws a line between the given points.
Declaration
public virtual void DrawLine(Color color, int x1, int y1, int x2, int y2)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color | color | The color to draw the line with. |
System.Int32 | x1 | The starting point X coordinate. |
System.Int32 | y1 | The starting point Y coordinate. |
System.Int32 | x2 | The end point X coordinate. |
System.Int32 | y2 | The end point Y coordinate. |
DrawPoint(Color, Int32, Int32)
Sets the pixel at the given coordinates to the specified color
.
Declaration
public abstract void DrawPoint(Color color, int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color | color | The color to draw with. |
System.Int32 | x | The X coordinate. |
System.Int32 | y | The Y coordinate. |
DrawPoint(Int32, Int32, Int32)
Sets the pixel at the given coordinates to the specified color
. without ToArgb()
Declaration
public abstract void DrawPoint(int color, int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | color | The color to draw with (raw argb). |
System.Int32 | x | The X coordinate. |
System.Int32 | y | The Y coordinate. |
DrawPoint(UInt32, Int32, Int32)
Sets the pixel at the given coordinates to the specified color
, without unnecessary color operations.
Declaration
public abstract void DrawPoint(uint color, int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | color | The color to draw with (raw argb). |
System.Int32 | x | The X coordinate. |
System.Int32 | y | The Y coordinate. |
DrawPolygon(Color, Point[])
Draws a polygon.
Declaration
public virtual void DrawPolygon(Color color, params Point[] points)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color | color | The color to draw with. |
System.Drawing.Point[] | points | The vertices of the polygon. |
DrawRectangle(Color, Int32, Int32, Int32, Int32)
Draws a rectangle.
Declaration
public virtual void DrawRectangle(Color color, int x, int y, int width, int height)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color | color | The color to draw with. |
System.Int32 | x | The X coordinate. |
System.Int32 | y | The Y coordinate. |
System.Int32 | width | The width of the rectangle. |
System.Int32 | height | The height of the rectangle. |
DrawSquare(Color, Int32, Int32, Int32)
Draws a square.
Declaration
public virtual void DrawSquare(Color color, int x, int y, int size)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color | color | The color to draw with. |
System.Int32 | x | The X coordinate. |
System.Int32 | y | The Y coordinate. |
System.Int32 | size | The size of the square. |
DrawString(String, Font, Color, Int32, Int32)
Draws a string using the given bitmap font.
Declaration
public virtual void DrawString(string str, Font font, Color color, int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string to draw. |
Font | font | The bitmap font to use. |
System.Drawing.Color | color | The color to write the string with. |
System.Int32 | x | The origin X coordinate. |
System.Int32 | y | The origin Y coordinate. |
DrawTriangle(Color, Int32, Int32, Int32, Int32, Int32, Int32)
Draws a triangle.
Declaration
public virtual void DrawTriangle(Color color, int v1x, int v1y, int v2x, int v2y, int v3x, int v3y)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.Color | color | The color to draw with. |
System.Int32 | v1x | The first points X coordinate. |
System.Int32 | v1y | The first points Y coordinate. |
System.Int32 | v2x | The second points X coordinate. |
System.Int32 | v2y | The second points Y coordinate. |
System.Int32 | v3x | The third points X coordinate. |
System.Int32 | v3y | The third points Y coordinate. |
GetImage(Int32, Int32, Int32, Int32)
Creates a bitmap by copying a portion of your canvas from the specified coordinates and dimensions.
Declaration
public virtual Bitmap GetImage(int x, int y, int width, int height)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | The starting X coordinate of the region to copy. |
System.Int32 | y | The starting Y coordinate of the region to copy. |
System.Int32 | width | The width of the region to copy. |
System.Int32 | height | The height of the region to copy. |
Returns
Type | Description |
---|---|
Bitmap | A new Bitmap containing the copied region. |
GetPointColor(Int32, Int32)
Gets the color of the pixel at the given coordinates.
Declaration
public abstract Color GetPointColor(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | The X coordinate. |
System.Int32 | y | The Y coordinate. |
Returns
Type | Description |
---|---|
System.Drawing.Color |
GetRawPointColor(Int32, Int32)
Gets the color of the pixel at the given coordinates in ARGB.
Declaration
public abstract int GetRawPointColor(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | The X coordinate. |
System.Int32 | y | The Y coordinate. |
Returns
Type | Description |
---|---|
System.Int32 |
Name()
The name of the Canvas implementation.
Declaration
public abstract string Name()
Returns
Type | Description |
---|---|
System.String |
ThrowIfCoordNotValid(Int32, Int32)
Validates that the given coordinates are in-range of the canvas, and throws an exception if the coordinates are out-of-bounds.
Declaration
protected void ThrowIfCoordNotValid(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | The X coordinate. |
System.Int32 | y | The Y coordinate. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown if the coordinates are invalid. |
ThrowIfModeIsNotValid(Mode)
Validates the given video mode, and throws an exception if the given value is invalid.
Declaration
protected void ThrowIfModeIsNotValid(Mode mode)
Parameters
Type | Name | Description |
---|---|---|
Mode | mode |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown if the mode is not supported. |
TrimLine(ref Int32, ref Int32, ref Int32, ref Int32)
Declaration
protected void TrimLine(ref int x1, ref int y1, ref int x2, ref int y2)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x1 | |
System.Int32 | y1 | |
System.Int32 | x2 | |
System.Int32 | y2 |