03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

virtual void DrawBitmap(const TRect& aDestRect,<br />

const CFbsBitmap* aSource,<br />

const TRect& aSourceRect) = 0;<br />

Use the same-size variant for high-performance blitting of GUI icons and the stretch-blit<br />

variants for device-independent view code supporting on-screen zooming or printing.<br />

Note<br />

See <strong>Chapter</strong> 15 for more on drawing bitmaps.<br />

Text<br />

You can draw text in the current font. Here are the functions for doing so:<br />

virtual void DrawText(const TDesC& aString,<br />

const TPoint& aPosition) = 0;<br />

virtual void DrawText(const TDesC& aString,<br />

const TRect& aBox,<br />

TInt aBaselineOffset,<br />

TTextAlign aHoriz = ELeft,<br />

TInt aLeftMrg = 0) = 0;<br />

The first (and apparently simpler) function uses the GC's justification settings, but you<br />

shouldn't call it yourself. Instead, use FORM if you need to handle properly laid out text. For<br />

general use, use the TRect variant that clips the text to the specified rectangle, and paints<br />

the rectangle background with the current brush.<br />

Important<br />

A graphics context has no default font and if you call a text-drawing<br />

function without a previous call to UseFont() in effect, you get a<br />

panic.<br />

The panic is particularly ugly when you're drawing to a CWindowGc because all windowdrawing<br />

functions are batched together and sent to the window to be executed later. The<br />

window server doesn't detect the absence of a UseFont() until the buffer is executed by<br />

which time there is no context information about where the panic occurred. Always<br />

remember to use DiscardFont() to discard the font after use and so avoid a memory<br />

leak.<br />

11.3 Drawing and Redrawing<br />

In a GUI program, all drawing is done to controls, which form all or part of a screen window<br />

as we saw with hellogui's CHelloGuiAppView::Draw():<br />

� The derived control class's Draw() function is called when drawing is required.<br />

� Draw() gets a graphics context using SystemGc().<br />

� It draws into the area defined by its Rect() function.<br />

But it's a bit more complicated than that. Your control must not only draw its content but<br />

must also redraw it when it changes, or when the system requires a redraw.<br />

System-initiated redraws occur when:<br />

� the window is first constructed;<br />

� the window, or part of it, is exposed after having been obscured by some other<br />

application or a dialog box.

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

Saved successfully!

Ooh no, something went wrong!