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.

I'm careful to draw every pixel: I use DrawUtils::DrawBetween-Rects() to whiten the<br />

region between the rectangle to be drawn and the outside of the control. I then use the pen<br />

to draw a rectangle on the inside of the border. Then the rectangle is shrunk by a pixel and<br />

passed to the hello view's draw function.<br />

The fundamental point that this example does show is that you can implement drawing code<br />

that's completely independent of a control and completely independent of the screen device.<br />

15.1.3 Managing the Zoom Factor<br />

We have already claimed that a device map ultimately uses a real device.<br />

CExampleHelloControl shows how the zoom factor relates to the device. Here's the<br />

declaration of TZoomFactor in gdi.h:<br />

class TZoomFactor : public MGraphicsDeviceMap<br />

{<br />

public:<br />

IMPORT_C TZoomFactor();<br />

IMPORT_C ~TZoomFactor();<br />

inline TZoomFactor(const MGraphicsDeviceMap* aDevice);<br />

IMPORT_C TInt ZoomFactor() const;<br />

IMPORT_C void SetZoomFactor(TInt aZoomFactor);<br />

inline void SetGraphicsDeviceMap(const MGraphicsDeviceMap*<br />

aDevice);<br />

public:<br />

inline const MGraphicsDeviceMap* GraphicsDeviceMap() const;<br />

IMPORT_C void SetTwipToPixelMapping(const TSize& aSizeInPixels,<br />

const TSize& aSizeInTwips);<br />

IMPORT_C TInt HorizontalTwipsToPixels(TInt aTwipWidth) const;<br />

IMPORT_C TInt VerticalTwipsToPixels(TInt aTwipHeight) const;<br />

IMPORT_C TInt HorizontalPixelsToTwips(TInt aPixelWidth) const;<br />

IMPORT_C TInt VerticalPixelsToTwips(TInt aPixelHeight) const;<br />

IMPORT_C TInt GetNearestFontInTwips(CFont*& aFont,<br />

IMPORT_C void ReleaseFont(CFont* aFont);<br />

enum {EZoomOneToOne = 1000};<br />

private:<br />

TInt iZoomFactor;<br />

const MGraphicsDeviceMap* iDevice;<br />

};<br />

const TFontSpec& aFontSpec);<br />

TZoomFactor both implements MGraphicsDeviceMap's interface and uses a<br />

MGraphicsDeviceMap. TZoomFactor contains an integer, iZoomFactor, which is set to<br />

1000 to indicate a one-to-one zoom, and proportionately for any other zoom factor.

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

Saved successfully!

Ooh no, something went wrong!