Legend

Class
Struct
Enum
Interface
Delegate
Constructor
Method
Property
Event
Field

Sealed class: RT.Util.Drawing.Canvas

Summary

Wraps a Graphics to provide a hopefully more convenient interface. The major bits of functionality are:

  • all coordinates in doubles or [Unrecognized cref attribute] structs;
  • support for the Y axis growing upwards;
  • functions targeted at drawing a 2d world onto a viewport of a specified size.

Common terms and abbreviations:

Screen Rectangular area that will be the final destination of the drawing.
Viewport The region, defined in terms of the world coordinates, that is viewable on the screen.
World coordinates Coordinates of the underlying "world" being represented.
Screen coordinates Coordinates on the screen, can be used to directly draw on the underlying Graphics.
WX, WY, WW, WH World X, Y, Width, Height, respectively
SX, SY, SW, SH Screen X, Y, Width, Height, respectively

Constructors

Creates an instance without initializing any of the required fields.
Canvas(Graphics graphics)
Creates an instance using the specified Graphics as the underlying drawing surface.
Canvas(Graphics graphics, Size screenSize)
Creates an instance using the specified graphics and screenSize. See Canvas.ScreenSize for more info.

Instance methods

void
Clear(Color color)
Fills the entire "screen" with the specified color.
void
DrawArc(Pen pen, PointD center, double radius, double startAngle, double sweepAngle)
Draws an arc using the specified pen.
void
DrawCircle(Pen pen, PointD center, double radius)
Draws a circle using the specified pen.
void
DrawCircle(Pen pen, double centerX, double centerY, double radius)
void
DrawLine(Pen pen, EdgeD segment)
Draws a straight line using the specified pen.
void
DrawLine(Pen pen, PointD pt1, PointD pt2)
void
DrawLine(Pen pen, double x1, double y1, double x2, double y2)
void
DrawPath(Pen pen, GraphicsPath path)
Draws a GraphicsPath using the specified pen.
void
DrawPie(Pen pen, PointD center, double radius, double startAngle, double sweepAngle)
Draws a "pie" using the specified pen. A pie is a circular arc whose endpoints are connected to the centre with straight lines.
void
DrawPie(Pen pen, double centerX, double centerY, double radius, double startAngle, double sweepAngle)
void
DrawRectangle(Pen pen, ref BoundingBoxD box)
Draws a rectangle using the specified pen. The bounding box defines the coordinates.
void
DrawRectangle(Pen pen, double xMin, double yMin, double width, double height)
Draws a rectangle using the specified pen. "xMin" and "yMin" specify the corner that has the smallest coordinates, so the resulting rectangle will be on coordinates xMin, yMin, xMin+width, yMin+height.
void
DrawText(string text, Brush brush, Font font, PointD center)
Draws text using the specified font and brush. The text's bounding box is centered on the specified point.
void
DrawText(string text, Brush brush, double centerX, double centerY)
Draws text using the default font and the specified brush. The text's bounding box is centered on the specified point.
void
DrawText(string text, Brush brush, Font font, double centerX, double centerY)
Draws text using the specified font and brush. The text's bounding box is centered on the specified point.
void
DrawText2(string text, Brush brush, double x, double y, Font font = null, TextAnchor anchor = TextAnchor.Center)
These members are not documented.
void
DrawTextOutline(string text, Pen pen, Font font, PointD center)
void
DrawTextOutline(string text, Pen pen, Font font, double centerX, double centerY)
void
DrawTextOutlineSim(string text, Brush brush, Font font, double shift, PointD center)
void
DrawTriangle(Pen pen, TriangleD triangle)
Draws a triangle using the specified pen.
void
DrawTriangle(Pen pen, PointD v1, PointD v2, PointD v3)
void
FillCircle(Brush brush, PointD center, double radius)
Fills a circle using the specified pen.
void
FillCircle(Brush brush, double centerX, double centerY, double radius)
void
FillPath(Brush brush, GraphicsPath path)
Fills a GraphicsPath using the specified brush.
void
FillRectangle(Brush brush, ref BoundingBoxD box)
Fills a rectangle using the specified brush. The bounding box defines the coordinates.
void
FillRectangle(Brush brush, double xMin, double yMin, double width, double height)
Fills a rectangle using the specified brush. "xMin" and "yMin" specify the corner that has the smallest coordinates, so the resulting rectangle will be on coordinates xMin, yMin, xMin+width, yMin+height.
void
FillTriangle(Brush brush, TriangleD triangle)
Fills a triangle using the specified brush.
void
FillTriangle(Brush brush, PointD v1, PointD v2, PointD v3)
GraphicsPath
MakeRoundedHorzVertPath(PointD position, double radius, IEnumerable<double> lengths)
This member is not documented.
void
MoveViewport(float sx, float sy, double wx, double wy)
Adjusts the offsets so that the world coordinate wx,wy is at the screen coordinate sx,sy. Does not modify the scaling.
void Resets the scaling and offset so that world coordinates correspond to screen pixels. Maintains the offsets so that all visible pixels have positive coordinates and one of the corners is 0,0.
void
SetViewport(double centerWX, double centerWY, double scale)
Sets the viewport so that the specified world coordinate is in the centre of the viewable screen, using the specified scaling factor.
void
SetViewport(double leftWX, double topWY, double rightWX, double bottomWY, bool maintainAspect)
Sets the scaling and offset so that the world coordinate "leftWX" corresponds to the leftmost coordinate on the screen, world "topWY" to the topmost screen coordinate, etc. If "maintainAspect" is "true", ensures that X and Y scaling is the same, by making one of the axes show more than implied by the arguments passed in.
void
SetViewport(double leftWX, double topWY, double rightWX, double bottomWY, double aspectXY)
These members are not documented.
void
SetViewportHeight(double worldHeight, float screenHeight, bool maintainAspect = false)
void
SetViewportHorz(double worldX, float screenX)
void
SetViewportHorz(double worldLeft, double worldRight)
void
SetViewportHorz(double worldLeft, double worldRight, float screenLeft, float screenRight, bool maintainAspect = false)
void
SetViewportVert(double worldY, float screenY)
void
SetViewportVert(double worldTop, double worldBottom)
void
SetViewportVert(double worldTop, double worldBottom, float screenTop, float screenBottom, bool maintainAspect = false)
void
SetViewportWidth(double worldWidth, float screenWidth, bool maintainAspect = false)
float
SH(double wh)
Converts world height into screen height. Screen height is measured in pixels.
PointFConverts a world point to a screen point.
float
SW(double ww)
Converts world width into screen width. Screen width is measured in pixels.
float
SX(double wx)
Converts world X coordinate into screen X. Screen X is zero at the leftmost pixel and Screen.Width at the rightmost pixel.
float
SY(double wy)
Converts world Y coordinate into screen Y. Screen Y is zero at the topmost pixel and Screen.Height at the bottommost pixel.
double
WH(float sh)
Converts screen height into world height. Screen height is measured in pixels.
PointD
WP(PointF sp)
Converts a screen point to a world point.
double
WW(float sw)
Converts screen width into world width. Screen width is measured in pixels.
double
WX(float sx)
Converts screen X coordinate into world X. Screen X is zero at the leftmost pixel and Screen.Width at the rightmost pixel.
double
WY(float sy)
Converts screen Y coordinate into world Y. Screen Y is zero at the topmost pixel and Screen.Height at the bottommost pixel.

Instance properties

doubleThese members are not documented.
float
float
double
double
double
double
double

Instance fields

CoordinateAxesDirectionSelects a coordinate axes mode.
FontThe font to be used by text drawing functions if no font is specified.
GraphicsThe underlying Graphics. All the actual drawing is done onto this instance.
Size Stores the screen size. "Screen" here refers to the final surface that this Canvas is destined for. The screen size is used for "set viewport" methods which do not take a screen location: they assume the relevant screen edge is meant instead.