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.

TInt baseline=aDeviceRect.Height()/2 + font-<br />

>AscentInPixels()/2;<br />

}<br />

aGc.DrawText(*iText, aDeviceRect, baseline,<br />

CGraphicsContext::ECenter);<br />

aGc.DiscardFont();<br />

//Draw a surrounding box<br />

This uses the version of DrawText() that specifies a rectangle and guarantees that<br />

drawing will be clipped within that rectangle.<br />

However, the DrawText() function will only white out the background before drawing, if<br />

iFullRedraw is set. When it is set, the brush setting is solid and white, which will cause the<br />

background to be whited; when it is not set, there is effectively no brush and the text is<br />

drawn straight over whatever was there before. This is the reason for the messy display in<br />

the upper rectangle in the screen shot of our application. In a real program, the whiting out of<br />

the background would not be conditional.<br />

15.1.2 Using the View<br />

CExampleHelloControl has a CExampleHelloView, which it uses for drawing its<br />

model. Here's CExampleHelloControl::Draw():<br />

void CExampleHelloControl::Draw(const TRect& /*aRect*/) const<br />

{<br />

CWindowGc& gc = SystemGc();//CWindowGc is derived from<br />

CGraphicsContext<br />

TRect rect = Rect();<br />

rect.Shrink(10,10);<br />

gc.SetPenStyle(CGraphicsContext::ENullPen);<br />

gc.SetBrushStyle(CGraphicsContext::ESolidBrush);<br />

gc.SetBrushColor(KRgbWhite);<br />

DrawUtils::DrawBetweenRects(gc, Rect(), rect);//whitens the<br />

border<br />

gc.SetPenStyle(CGraphicsContext::ESolidPen);<br />

gc.SetPenColor(KRgbBlack);<br />

gc.SetBrushStyle(CGraphicsContext::ENullBrush);<br />

gc.DrawRect(rect);<br />

rect.Shrink(1,1);<br />

iView->DrawInRect(iZoomFactor, gc, rect, iFont);<br />

}<br />

First, CExampleHelloControl draws a surrounding 10-pixel border. This code is<br />

guaranteed to be on the screen, and the 10-pixel border is chosen independently of the<br />

zoom state (as it would look silly if the border were to scale to honor the zoom state).

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

Saved successfully!

Ooh no, something went wrong!