Click or drag to resize
DrawingWindow Class

The DrawingWindow class provides a basic capability for creating drawings in a .NET environment using Windows Presentation Foundation (WPF) classes. It allows you to create drawings consisting of points, lines, squares, circles, and other geometric shapes in a window to save the drawings to a file. The class also includes facilities for text, color, pictures, and simple animation.

The coordinate system follows Windows convention, meaning that an x,y coordinate starts from the top-left corner, with the y axis oriented downward.

The API is modeled after the StdDraw class with necessary adaptation for the Windows environment.

A bare bone WPF client to support drawing and simple frame animation
Inheritance Hierarchy

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class DrawingWindow : Window

The DrawingWindow type exposes the following members.

Constructors
  NameDescription
Public methodDrawingWindow
Creates the WPF client
Top
Methods
  NameDescription
Public methodClear
Clears the screen to the default color (white).
Public methodClear(Color)
Clears the screen to the specified color.
Public methodDeleteVisual
Removes a visual from the canvas
Public methodDrawArc
Draws a circular arc of the specified radius, centered at (X, Y), from angle1 to angle2 (in degrees) clockwise. An angle of 0 would means an arc start at 3 o'clock
Public methodDrawCircle
Draws a circle of the specified radius, centered at (X, Y).
Public methodDrawCirle
Draws a circle of the specified radius, centered at (X, Y).
Public methodDrawEllipse(Double, Double, Double, Double)
Draws an ellipse with the specified semimajor and semiminor axes, centered at (X, Y).
Public methodDrawEllipse(DrawingVisual, Double, Double, Double, Double)
Draws an ellipse with the specified semimajor and semiminor axes, centered at (X, Y).
Public methodDrawFilledCircle(Double, Double, Double)
Draws a filled circle of the specified radius, centered at (X, Y).
Public methodDrawFilledCircle(DrawingVisual, Double, Double, Double)
Draws a filled circle of the specified radius, centered at (X, Y).
Public methodDrawFilledEllipse(Double, Double, Double, Double)
Draws a filled ellipse with the specified semimajor and semiminor axes, centered at (X, Y).
Public methodDrawFilledEllipse(DrawingVisual, Double, Double, Double, Double)
Draws a filled ellipse with the specified semimajor and semiminor axes, centered at (X, Y).
Public methodDrawFilledPolygon
Draws a filled polygon with the vertices (X0, Y0), (X1, Y1), ..., (XN-1, YN-1).
Public methodDrawFilledRectangle
Draws a filled rectangle of the specified size, centered at (X, Y).
Public methodDrawFilledSquare
Draws a filled square of the specified size, centered at (X, Y).
Public methodDrawLine(Double, Double, Double, Double)
Draws a line segment between (X0, Y0) and (X1, Y1).
Public methodDrawLine(DrawingVisual, Double, Double, Double, Double)
Draws a line segment between (X0, Y0) and (X1, Y1).
Public methodDrawPicture(Double, Double, String, Double, Double)
Loads and draws a picture centered at (X, Y) within the specified rectangle with sizes in desiredWidth and desiredHeight. The picture will be scaled to fit the rectangle
Public methodDrawPicture(Double, Double, String, Double, Double, Double)
Loads and draws a picture centered at (X, Y) within the specified rectangle with sizes in desiredWidth and desiredHeight. The picture will be scaled to fit the rectangle
Public methodDrawPoint
Draws a point centered at (X, Y). The point is a filled circle whose radius is equal to half the pen thickness.
Public methodDrawPolygon
Draws a polygon with the vertices (X0, Y0), (X1, Y1), ..., (XN-1, YN-1).
Public methodDrawRectangle
Draws a rectangle of the specified size, centered at (X, Y).
Public methodDrawSquare
Draws a square of the specified size, centered at (X, Y).
Public methodDrawText(Double, Double, String, Double, Boolean)
Draws a text using the current font starting at (X, Y) given the desired font size. The text is defaulted to flow from left to right can be specified to flow from right to left.
Public methodDrawText(Double, Double, String, Double, Double, Boolean)
Draws a text using the current font starting at (X, Y) given the desired font size. The text is defaulted to flow from left to right can be specified to flow from right to left.
Public methodGetCanvasSize
Returns the current canvas size
Public methodGetFont
Returns the curent font family
Public methodGetPenColor
Returns the current pen/solid brush color
Public methodGetPenThickness
Returns the current pen thickness (2 * radius), or the line width
Public methodSetCanvasSize
Resets the canvas size to default size
Public methodSetCanvasSize(Int32, Int32)
Sets the canvas (drawing area) to be Width-by-Height pixels. This also erases the current drawing and resets the coordinate system, pen radius, pen color, and font back to their default values. Ordinarly, this method is called once, at the very beginning of a program.
Public methodSetFont
Resets the text font to the default font
Public methodSetFont(FontFamily)
Changes the text font to the desired font family
Public methodSetPenColor
Resets the the current pen/solid brush color to default (black)
Public methodSetPenColor(Color)
Changes the the current pen/solid brush color to desired color using the Color type.
Public methodSetPenColor(Int32, Int32, Int32)
Changes the the current pen/solid brush color to desired color in RGB from
Public methodSetPenThickness
Sets the pen size to the default size (2 Dpi). The pen is circular, so that lines have rounded ends. When you draw a point, you get a circle.
Public methodSetPenThickness(Double)
Sets the pen size or line width to the desired size. The pen is circular, so that lines have rounded ends. When you draw a point, you get a circle.
Public methodSetPercentScale
If set, the input coordinate will be in the range 0.0 - 1.0. If an input coordinate is greater than 1, this setting will not take effect
Top
Remarks

For additional documentation, see Section 1.5 of Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.

See Also