03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Nevertheless, CExampleHelloControl contains part of the size- and target-independent code:<br />

it allocates the size and device-dependent font with which to do the drawing, using an<br />

independent font specification. The reason for this is explained later.<br />

The role of each of the GDI classes is summarized below:<br />

Class Description<br />

CGraphicsContext The abstract base class created by a graphics device,<br />

CGraphicsDevice. Contains the main drawing functions.<br />

Provides the 'context' in which you are drawing to the<br />

associated device in the sense that it holds the pen and brush<br />

settings (e.g. color, line styles) and font settings (e.g. bold,<br />

underline, italic) for drawing, and also the clipping region(the<br />

visible drawing area). These can all be updated while drawing.<br />

Deals with pixels of device-dependent size and uses fonts with<br />

device-dependent size and representation. The sizes and<br />

fonts to be passed to CGraphicsContext functions therefore<br />

need to be converted from size-independent units to sizedependent<br />

units beforehand. This is done by an<br />

MGraphicsDeviceMap derived class. This may be a<br />

TZoomFactor or the CGraphicsDevice.<br />

Note that the CGraphicsContext class was described in more<br />

detail in <strong>Chapter</strong> 11 and its handling of colors and bitmaps is<br />

described later in this chapter.<br />

MGraphicsDeviceMap The abstract base class for both graphic devices and zoom<br />

factors.<br />

Defines the size-dependent functions in a graphics device.<br />

These functions convert between pixels and twips and perform<br />

font allocation and release. Font allocation involves finding the<br />

font supported by the device that is the closest to a deviceindependent<br />

font specification.<br />

CGraphicsDevice The abstract base class for all graphics devices that<br />

represents the medium being drawn to.<br />

Manufactures a graphics context suitable for drawing to itself<br />

(using CreateContext()), which takes into account the<br />

attributes of the device, such as the size and display mode.<br />

Allocates (and releases) fonts suitable for drawing to itself and<br />

converts between twips and pixels.<br />

Important graphic devices are CScreenDevice,<br />

CBitmapDevice and CPrinterDevice. (Bitmap<br />

applications are discussed later in the chapter.)<br />

TZoomFactor Defines a zoom factor and implements the<br />

MGraphicsDeviceMap interface. Allocates and releases<br />

device-dependent fonts and converts between twips and<br />

pixels.<br />

Facilitates zooming, because it allows the size of the graphic<br />

to become independent of the target size.This class is<br />

recursive, because a TZoomFactor object can use an<br />

MGraphicsDeviceMap, which could be a TZoomFactor<br />

itself, as illustrated below. This allows a zoom factor object to

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!