The Bitmaps API and Printing API provide concrete implementations of the abstract drawing interfaces defined in this API, for screens and printers respectively. The Window Server Client Side API extends the Bitmaps API's classes in turn for drawing in windows (the normal case). For some applications, this polymorphism can be important, as it allows shared code for screen drawing and printing.
Most drawing takes place within a control, as defined in the UI Control Framework. That API provides support functions for using graphics contexts.
The API has five key concepts: basic geometry classes, graphics
device (CGraphicsDevice
), graphics context (CGraphicsContext
), colour (TRgb
), and units conversion (TPoint
, TSize
and MGraphicsDeviceMap
) and zooming (TZoomFactor
).
Point: a pair of (x,y) co-ordinates. It is provided by
TPoint
.
Size: a width and height. It is provided by
TSize
.
Rectangle: described by the co-ordinates of its top-left and
bottom-right corners, or by its top-left hand corner and its size. It is
provided by TRect
.
Region: defines an area made up a collection of rectangles. They
are handled by a family of classes derived from TRegion
.
A graphics device represents the medium being drawn to. It is the provider of graphics contexts through which drawing is done.
The base class for graphics devices is
CGraphicsDevice
. Concrete devices implement derived
classes.
A graphics context provides a large number of drawing operations, with some state settings defining how the drawing is performed. The settings are:
a pen, for drawing shape outlines and text, with colour, line size and style settings
a brush, for filling areas, with colour, style and origin settings
for text, a current font and a justification mode
a drawing mode: controls how colours drawn interact with the screen colour
a co-ordinate origin, typically the top left corner of the screen
an internal drawing position, for relative drawing operations
Operations include drawing shapes (points, lines, polylines, arcs, rectangles, polygons, ellipses, rounded rectangles and pie slices), text, and bitmaps.
The base class for graphics contexts is
CGraphicsContext
. Concrete devices provide derived classes that
can provide additional operations suitable to the device.
A colour is specified by a 24-bit colour value. The system then
maps these values into device-level values. The colour class is
TRgb
.
Graphics code can be written in a device-independent way by
handling lengths/positions using twips (1/1440th inch), and only converting
into pixels when actually drawing. Graphic devices implement a twips/pixels
mapping interface for this conversion. The interface is defined by
MGraphicsDeviceMap
.
You might want drawing code to draw at different possible levels
of magnification (zoom). In that case, the mapping is performed by a
TZoomFactor
, which also implements
MGraphicsDeviceMap
.