//Background drawing function void CTestRectGc::Draw(CWindowGc& aGc, const CCoeControl& aControl, const TRect& aRect) const { if (iBmpBackground) { TPoint a = PositionRelativeToScreen(); TPoint b = aControl.PositionRelativeToScreen(); //The source rect of the background is the relationship between this control and the control being drawn (child) //plus the subrect (aRect) to be drawn. TRect SourceRect(b-a+aRect.iTl, aRect.Size()); aGc.SetDrawMode(CGraphicsContext::EDrawModePEN); aGc.BitBlt(aRect.iTl, iBmpBackground, SourceRect); aGc.SetDrawMode(CGraphicsContext::EDrawModePEN); } else { TRect rc; aGc.SetClippingRect(aRect); aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); aGc.SetBrushColor(iBrushColor); aGc.SetBrushStyle(iBrushStyle); aGc.DrawRect(rc); aGc.CancelClippingRect(); } }
/****************************************************************************\ | Function: CNumberedWindow::Draw | Purpose: Redraws the contents of CNumberedWindow within a given | rectangle. CNumberedWindow displays a number in the window. | Input: aRect Rectangle that needs redrawing | Output: None \****************************************************************************/ void CNumberedWindow::Draw(const TRect& aRect) { const TBufC<1> strings[5] = { *&KString1, *&KString2, *&KString3, *&KString4, *&KString5 }; CWindowGc* gc = SystemGc(); // get a graphics context gc->SetClippingRect(aRect); // clip outside the redraw area gc->Clear(aRect); // clear the redraw area TSize size = iWindow.Size(); TInt height = size.iHeight; // Need window height to calculate vertical text offset TInt ascent = Font()->AscentInPixels(); TInt descent = Font()->DescentInPixels(); TInt offset = (height + (ascent + descent)) / 2; // Calculate vertical text offset gc->SetPenColor(TRgb(0, 0, 0)); // Set pen to black gc->UseFont(Font()); gc->DrawText(strings[iNumber], TRect(TPoint(0, 0), size), offset, CGraphicsContext::ECenter); gc->DiscardFont(); }
void CMainWindow::Draw(const TRect& aRect) { CWindowGc* gc = SystemGc(); // get a gc gc->SetClippingRect(aRect); // clip outside this rect gc->Clear(aRect); // clear }