wxDC: wxObject

A wxDC is device context onto which graphics and text can be drawn. It is intended to represent a number of output devices in a generic way, so a canvas has a device context and a printer also has a device context. In this way, the same piece of code may write to a number of different devices, if the device context is used as a parameter.

To determine whether a device context is colour or monochrome, test the Colour Bool member variable. To override wxWindows monochrome graphics drawing behaviour, set this member to TRUE.

wxDC::wxDC

voidwxDC

voidwxDCwxCanvas *canvas

voidwxDCchar *driver, char *device, char *output, Bool interactive = TRUE

Constructor. The third form may be called with three NULLs to put up a default printer dialog in Windows or UNIX. The only supported printer type in UNIX is ``PostScript''; in Windows, specifying ``PostScript'' uses wxWindow's own Encapsulated PostScript driver, writing to a file only. Otherwise, device indicates the type of printer and output is an optional file for printing to. The driver parameter is currently unused. Use the Ok member to test whether the constructor was successful in creating a useable device context.

The following global variables are defined in wxWindows, edited by the user in the printer dialog and used by the PostScript driver. An application may wish to set them to appropriate default values.

wxDC::wxDC

voidwxDC

Destructor.

wxDC::Blit

BoolBlitfloat xdest, float ydest, float width, float height,
wxDC *source, float xsrc, float ysrc, int logical_func

Copy from a source DC to this DC, specifying the destination coordinates, size of area to copy, source DC, source coordinates, and logical function (see SetLogicalFunction). See CreateCompatibleDC for typical usage.

wxDC::Clear

voidClear

wxDC::CreateCompatibleDC

wxDC *CreateCompatibleDC

Creates and returns a device context compatible with this DC. A bitmap must be selected into the new DC before it may be used for anything. Typical usage is as follows:

  wxDC *temp_dc = dc.CreateCompatibleDC();
  temp_dc->SelectObject(test_bitmap);
  dc.Blit(250, 50, BITMAP_WIDTH, BITMAP_HEIGHT, temp_dc, 0, 0);
  delete temp_dc;

In future versions of wxWindows, this kind of DC will be used for drawing graphics in memory, then copying to visible windows.

wxDC::DestroyClippingRegion

voidDestroyClippingRegion

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

wxDC::DeviceToLogicalX

floatDeviceToLogicalXint x

Convert device X coordinate to logical coordinate, using the current mapping mode.

wxDC::DeviceToLogicalY

floatDeviceToLogicalYint y

Converts device Y coordinate to logical coordinate, using the current mapping mode.

wxDC::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.

wxDC::DrawIcon

voidDrawIconwxIcon *icon, float x, float y

Draw an icon on the display (does nothing if the device context is PostScript). This can be the simplest way of drawing bitmaps on a canvas. Icons and bitmaps in X are currently monochrome only.

wxDC::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.

wxDC::DrawLines

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

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

Draws 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.

wxDC::DrawPolygon

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

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

Draws 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.

wxDC::DrawPoint

voidDrawPointfloat x, float y

Draws a point using the current pen.

wxDC::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.

wxDC::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.

wxDC::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.

wxDC::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.

wxDC::EndDoc

voidEndDoc

Ends a document (only relevant when outputting to a printer).

wxDC::EndPage

voidEndPage

Ends a document page (only relevant when outputting to a printer).

wxDC::GetMapMode

intGetMapMode

Gets the mapping mode for the device context (see SetMapMode).

wxDC::LogicalToDeviceX

intLogicalToDeviceXfloat x

Converts logical X coordinate to device coordinate, using the current mapping mode.

wxDC::LogicalToDeviceY

intLogicalToDeviceYfloat y

Converts logical Y coordinate to device coordinate, using the current mapping mode.

wxDC::Ok

BoolOk

Returns TRUE if the DC is ok to use.

wxDC::SelectObject

voidSelectObjectwxBitmap *bitmap

Selects the given bitmap into the device context, to use as the memory bitmap. Drawing onto the DC is not yet allowed, but selecting the bitmap into a DC created by using CreateCompatibleDC allows you to then use Blit to copy the bitmap to a canvas. For this purpose, you may find DrawIcon easier to use instead, if your Windows bitmaps can be converted to icon format.

wxDC::SetBackground

voidSetBackgroundwxBrush *brush

Sets the current background brush for the DC. Do not delete the brush - it will be deleted automatically when the application terminates.

wxDC::SetClippingRegion

voidSetClippingRegionfloat x, float y, float width, float height

Sets the clipping region for the DC. 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.

wxDC::SetBrush

voidSetBrushwxBrush *brush

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

wxDC::SetFont

voidSetFontwxFont *font

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

wxDC::SetLogicalFunction

voidSetLogicalFunctionint function

Sets the current logical function for the DC. 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.

wxDC::SetMapMode

voidSetMapModeint int

The mapping mode of the device context defines the unit of measurement used to convert logical units to device units. Note that in X, text drawing isn't handled consistently with the mapping mode; a font is always specified in point size. However, setting the user scale (see SetUserScale) scales the text appropriately. In Windows, scaleable TrueType fonts are always used; in X, results depend on availability of fonts, but usually a reasonable match is found.

Note that the coordinate origin should ideally be selectable, but for now is always at the top left of the screen/printer.

Drawing to a Windows printer device context under UNIX uses the current mapping mode, but mapping mode is currently ignored for PostScript output.

The mapping mode can be one of the following:

wxDC::SetPen

voidSetPenwxPen *pen

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

wxDC::SetTextBackground

voidSetTextBackgroundwxColour *colour

Sets the current text background colour for the DC. Do not delete colour while selected for use by a DC.

wxDC::SetTextForeground

voidSetTextForegroundwxColour *colour

Sets the current text foreground colour for the DC. Do not delete colour while selected for use by a DC.

wxDC::SetUserScale

voidSetUserScalefloat x_scale, floaty_scale

Sets the user scaling factor, useful for applications which require `zooming'.

wxDC::StartDoc

BoolStartDocchar *message

Starts a document (only relevant when outputting to a printer). Message is a message to show whilst printing.

wxDC::StartPage

BoolStartPage

Starts a document page (only relevant when outputting to a printer).