wxCanvas: wxWindow

A canvas is a subwindow onto which graphics and text can be drawn, and mouse and keyboard input can be intercepted. At present, panel items cannot be placed on a canvas.

To determine whether a canvas is colour or monochrome, test the canvas's device context colour Bool member variable.

wxCanvas::wxCanvas

voidwxCanvaswxFrame *parent, int x = -1, int y = -1, int width = -1, int height = -1,
int style = wxRETAINED

Constructor. The style parameter may be a combination (using the C++ logical `or' operator) of the following flags:

wxCanvas::wxCanvas

voidwxCanvas

Destructor.

wxCanvas::Clear

voidClear

Clears the canvas (fills it with the current background brush).

wxCanvas::DestroyClippingRegion

voidDestroyClippingRegion

Destroys the current clipping region so that none of the canvas is clipped.

wxCanvas::DrawEllipse

voidDrawEllipsefloat x, float y, float width, float height

Draws an ellipse contained in the rectangle with the given top left corner, and with the given size. The current pen is used for the outline and the current brush for filling the shape.

wxCanvas::DrawLine

voidDrawLinefloat x1, float y1, float x2, float y2

Draws a line from the first point to the second. The current pen is used for drawing the line.

wxCanvas::DrawLines

voidDrawLinesint n, wxPoint points[], float xoffset = 0, float yoffset = 0

voidDrawLineswxList *points, float xoffset = 0, float yoffset = 0

Draw lines using an array of points of size n, or list of pointers to points, adding the optional offset coordinate. The current pen is used for drawing the lines. The programmer is responsible for deleting the list of points.

wxCanvas::DrawPolygon

voidDrawPolygonint n, wxPoint points[], float xoffset = 0, float yoffset = 0

voidDrawPolygonwxList *points, float xoffset = 0, float yoffset = 0

Draw a filled polygon using an array of points of size n, or list of pointers to points, adding the optional offset coordinate. The current pen is used for drawing the outline, and the current brush for filling the shape. Using a transparent brush suppresses filling. The programmer is responsible for deleting the list of points.

Note that wxWindows does not close the first and last points automatically.

wxCanvas::DrawPoint

voidDrawPointfloat x, float y

Draws a point using the current pen.

wxCanvas::DrawRectangle

voidDrawRectanglefloat x, float y, float width, float height

Draws a rectangle with the given top left corner, and with the given size. The current pen is used for the outline and the current brush for filling the shape.

wxCanvas::DrawRoundedRectangle

voidDrawRoundedRectanglefloat x, float y, float width, float height, float radius = 20

Draws a rectangle with the given top left corner, and with the given size. The corners are quarter-circles using the given radius. The current pen is used for the outline and the current brush for filling the shape.

wxCanvas::DrawSpline

voidDrawSplinewxList *points

Draws a spline between all given control points, using the current pen. Doesn't delete the wxList and contents. The spline is drawn using a series of lines, using an algorithm taken from the X drawing program `XFIG'.

voidDrawSplinefloat x1, float y1, float x2, float y2, float x3, float y3

Draws a three-point spline using the current pen.

wxCanvas::DrawText

voidDrawTextchar *text, float x, float y

Draws a text string at the specified point, using the current text font, and the current text foreground and background colours.

wxCanvas::GetDC

wxDC *GetDC

Get a pointer to the canvas's device context. Note that the canvas's apparent device context may be temporarily replaced by the application using SetContext, so for example a printer context can be substituted and programs using the canvas's device context will really write to the printer. The canvas's real device context is unaffected by SetContext.

wxCanvas::ResetContext

voidResetContext

Reset a canvas's context set by SetContext.

wxCanvas::Scroll

voidScrollint x_pos, int y_pos

Scrolls a canvas so the view start is at the given point. The positions are in scroll units, not pixels, so to convert to pixels you will have to multiply by the number of pixels per scroll increment. If either parameter is -1, that position will be ignored (no change in that direction).

wxCanvas::SetBackground

voidSetBackgroundwxBrush *brush

Sets the current background brush for the canvas. The brush should not be deleted while being used by a canvas. All brushes are deleted automatically when the application terminates.

wxCanvas::SetClippingRegion

voidSetClippingRegionfloat x, float y, float width, float height

Sets the clipping region for the canvas. The clipping region is a rectangular area to which drawing is restricted. Possible uses for the clipping region are for clipping text or for speeding up canvas redraws when only a known area of the screen is damaged.

wxCanvas::SetContext

voidSetContextwxDC *dc

Set a substitute context for the canvas, so applications which think they're drawing to canvases can be fooled into drawing to the printer. Reset with ResetContext.

wxCanvas::SetBrush

voidSetBrushwxBrush *brush

Sets the current brush for the canvas. The brush is not copied, so you should not delete the brush unless the canvas pen has been set to another brush, or to NULL. Note that all pens and brushes are automatically deleted when the program is exited.

wxCanvas::SetFont

voidSetFontwxFont *font

Sets the current font for the canvas. The font is not copied, so you should not delete the font unless the canvas pen has been set to another font, or to NULL.

wxCanvas::SetLogicalFunction

voidSetLogicalFunctionint function

Sets the current logical function for the canvas. The possible values are:

The default is wxCOPY, which simply draws with the current colour. The others combine the current colour and the background using a logical operation. wxXOR is commonly used for drawing rubber bands or moving outlines, since drawing twice reverts to the original colour.

wxCanvas::SetPen

voidSetPenwxPen *pen

Sets the current pen for the canvas. The pen is not copied, so you should not delete the pen unless the canvas pen has been set to another pen, or to NULL. Note that all pens and brushes are automatically deleted when the program is exited.

wxCanvas::SetScrollbars

voidSetScrollbarsint horiz_pixels, int vert_pixels, int x_length, int y_length,
int x_page, int y_page

Sets up vertical and/or horizontal scrollbars. The first pair of parameters give the number of pixels per `scroll step', i.e. amount moved when the up or down scroll arrows are pressed. These may be 0 or less for no scrollbar. The second pair gives the length of scrollbar in scroll steps, which effectively sets the size of the `virtual canvas'. The third pair gives the number of scroll steps in a `page', i.e. amount moved when pressing above or below the scrollbar control, or using page up/page down (not yet implemented).

For example, the following gives a canvas horizontal and vertical scrollbars with 20 pixels per scroll step, a size of 50 steps (1000 pixels) in each direction, and 4 steps (80 pixels) to a page.

canvas->SetScrollbars(20, 20, 50, 50, 4, 4);

wxCanvas::SetTextBackground

voidSetTextBackgroundwxColour *colour

Sets the current text background colour for the canvas. Do not delete colour.

wxCanvas::SetTextForeground

voidSetTextForegroundwxColour *colour

Sets the current text foreground colour for the canvas. Do not delete colour.

wxCanvas::ViewStart

voidViewStartint *x, int * y

Get the position at which the visible portion of the canvas starts. If either of the scrollbars is not at the home position, x and/or y will be greater than zero. Combined with GetClientSize, the application can use this function to efficiently redraw only the visible portion of the canvas. The positions are in logical scroll units, not pixels, so to convert to pixels you will have to multiply by the number of pixels per scroll increment.