/** * Draws the aHotKeys text into the graphics context aGc, in the rectangle aRect. By defalut the * text is right aligned. */ EXPORT_C void LafMenuPane::DrawHotKeyText(const MLafEnv& aLafEnv, const CCoeControl& /*aMenuPane*/, CWindowGc& aGc, const TRect& aRect, const TDesC& aHotKeysText, const TItemAttributes& aItemAttributes) { aGc.UseFont(AnnotationFont(aLafEnv)); // Left alignment aGc.DrawText(aHotKeysText, aRect, aItemAttributes.iBaseLine, CGraphicsContext::ELeft,KLafSpaceBetweenTextAndHotkey); aGc.UseFont(NormalFont(aLafEnv)); }
/** * Prepares the graphics context aGc for drawing the items by setting the pen and brush. */ EXPORT_C void LafMenuPane::PrepareGcForDrawingItems(const MLafEnv& aLafEnv, const CCoeControl& aMenuPane, CWindowGc& aGc) { const CFont* font = NormalFont(aLafEnv); aGc.UseFont(font); aGc.SetPenColor(aLafEnv.ControlColor(EColorMenuPaneText, aMenuPane)); aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); aGc.SetBrushColor(aLafEnv.ControlColor(EColorMenuPaneBackground, aMenuPane)); }
/** Writes the text "aText" on the control.\n Sets the font,pen colour,brush style used for writing the text.\n Draws the text uisng Draw Text function of Graphics context.\n */ void CCtlBase::WriteName( CWindowGc& aGc, const TDesC& aText ) const { TRect rect = Rect() ; rect.Shrink( 3, 3 ) ; aGc.UseFont( iFont ) ; TInt ascent = ( rect.iBr.iY - rect.iTl.iY-iFont->HeightInPixels() ) / 2 + iFont->AscentInPixels() ; aGc.SetPenColor( KRgbBlack ) ; aGc.SetBrushStyle( CGraphicsContext::ESolidBrush ) ; aGc.DrawText( aText, rect, ascent, CGraphicsContext::ECenter ) ; }
void CZXingBarcodeReaderAppView::DrawTexts(CWindowGc& gc) const { if (iTitle.Length()>0) { TRect rect(Rect()); gc.SetPenColor(KRgbWhite); gc.UseFont(iTitleFont); gc.DrawText(iTitle, rect, rect.Height()/10, CGraphicsContext::ECenter ); gc.DiscardFont(); } }
/** * Draws the left adornment to the graphics context aGc, in the rectangle aRect. The menu pane * flags determines the type of adornment to be drawn. */ EXPORT_C void LafMenuPane::DrawLeftAdornment(const MLafEnv& aLafEnv, const CCoeControl& /*aMenuPane*/, CWindowGc& aGc, const TRect& aRect, const TItemAttributes& aItemAttributes) { // Brush the background of the rect. aGc.SetPenStyle(CGraphicsContext::ENullPen); aGc.DrawRect(aRect); aGc.SetPenStyle(CGraphicsContext::ESolidPen); const TInt itemFlags = aItemAttributes.iFlags; if (itemFlags&EEikMenuItemSymbolOn) { if (itemFlags&EEikMenuItemCheckBox) { TRect rect = aRect; rect.iTl.iY += aItemAttributes.iBaseLine; TBuf<1> buf; buf.Append(TChar(ESymFontTick)); aGc.UseFont(SymbolFont(aLafEnv)); aGc.SetPenStyle(CGraphicsContext::ESolidPen); // as the tick is big, ignore KPreLeftAdornment and steal 1 pixels from left. aGc.DrawText(buf,TPoint(rect.iTl.iX-1, rect.iTl.iY)); aGc.UseFont(NormalFont(aLafEnv)); } else if (itemFlags&KLafMenuItemRadio) { TUid bmpUid(TUid::Uid(KLafUidEikonOptiVal)); const CFbsBitmap* bitmap = aLafEnv.Bitmap(bmpUid); TSize bitsize = bitmap->SizeInPixels(); TRect butRect(TPoint(0,0), TPoint(bitsize.iWidth,bitsize.iHeight)); TInt yoffset = (aRect.Size().iHeight - bitsize.iHeight) / 2; TInt xoffset = KLafPreLeftAdornmentSpace; TPoint offset(xoffset,yoffset); if (aItemAttributes.iHighlightType == SLafMenuPane::EDrawHighlight) { bmpUid=TUid::Uid(KLafUidEikonOptihVal); bitmap = aLafEnv.Bitmap(bmpUid); } bmpUid=TUid::Uid(KLafUidEikonOptimVal); const CFbsBitmap* mask = aLafEnv.Bitmap(bmpUid); aGc.BitBltMasked((aRect.iTl+offset), bitmap, butRect, mask,ETrue); } } }
/** * Draws the cascade symbol into the graphics context aGc, in the rectangle aRect and sets * the pen color depending on whether the menu item is dimmed or focused. */ EXPORT_C void LafMenuPane::DrawRightAdornment(const MLafEnv& aLafEnv, const CCoeControl& /*aMenuPane*/, CWindowGc& aGc, const TRect& aRect, const TItemAttributes& aItemAttributes) { const TInt cascadeSize=Min(KLafRightAdornmentSpace,aItemAttributes.iHeight); // Brush the background of the rect. aGc.SetPenStyle(CGraphicsContext::ENullPen); aGc.DrawRect(aRect); aGc.SetPenStyle(CGraphicsContext::ESolidPen); if (aItemAttributes.iInternalFlags&EMenuIsRightAdornment) { //Sort out rect for cascade symbol TRect cascadeRect=TRect(TPoint(aRect.iBr.iX-cascadeSize-PostRightAdornmentSpace(),aItemAttributes.iHPosition), TSize(cascadeSize,aItemAttributes.iHeight)); cascadeRect.iTl.iY+=((aItemAttributes.iHeight-cascadeSize)/2); cascadeRect.iBr.iY-=((aItemAttributes.iHeight-cascadeSize)/2); TBuf<1> cascade; cascade.Append(TChar(ESymFontMenuCascade)); aGc.UseFont(SymbolFont(aLafEnv)); aGc.DrawText(cascade,cascadeRect,cascadeRect.Height(),CGraphicsContext::ERight); aGc.UseFont(NormalFont(aLafEnv)); } }
TInt LoadsOfText(TInt aOwningGroup) { RWsSession ws; ws.Connect(); CWsScreenDevice *device=new(ELeave) CWsScreenDevice(ws); device->Construct(); RWindowGroup group(ws); group.Construct(ENullWsHandle); group.SetOwningWindowGroup(aOwningGroup); TSize scrSize(device->SizeInPixels()); // RWindow window(ws); window.Construct(group,ENullWsHandle); window.SetExtent(TPoint(), scrSize); window.Activate(); // CWindowGc *gc; device->CreateContext(gc); window.BeginRedraw(); gc->Activate(window); gc->Clear(); window.EndRedraw(); TFontSpec fspec(KTestFontTypefaceName,200); CFbsFont *font; User::LeaveIfError(device->GetNearestFontToDesignHeightInTwips((CFont *&)font, fspec)); gc->UseFont(font); TBuf<100> loadsatext(_L("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890zyxwvutsrqponmlkjihgfedcba")); TInt ascent=font->AscentInPixels(); TInt fheight=font->HeightInPixels(); for(TInt nTimes=0;nTimes<10;nTimes++) { TPoint pos; // for(pos.iY=ascent;pos.iY<scrSize.iHeight;pos.iY+=font->HeightInPixels()) // gc->DrawText(loadsatext,pos); for(pos.iY=0;pos.iY<scrSize.iHeight;pos.iY+=fheight) gc->DrawText(loadsatext,TRect(pos,TPoint(scrSize.iWidth,pos.iY+fheight)),ascent); gc->Clear(); } gc->Deactivate(); // ws.Flush(); delete gc; device->ReleaseFont(font); window.Close(); group.Close(); delete device; ws.Close(); return(KErrNone); }
void CSpaceInvadersAppView::DrawQuitCommand(CWindowGc& aGc) const { TRgb pencolor = TRgb(255,255,255); aGc.SetPenColor(pencolor); _LIT(KQuitText, "Quit"); TBufC<4> quitText; TPtr quitPtr = quitText.Des(); quitPtr.Append(KQuitText); const CFont* menuFont = AknLayoutUtils::FontFromId(EAknLogicalFontPrimarySmallFont, NULL); aGc.UseFont(menuFont); TInt textLength = menuFont->TextWidthInPixels(quitPtr); TInt textHeight = menuFont->HeightInPixels(); TPoint textpoint(Rect().Width() - ( textLength + 10 ), Rect().Height() - textHeight); aGc.DrawText(quitPtr, textpoint); }
void CSpaceInvadersAppView::DrawPoints(CWindowGc& aGc) const { TRgb pencolor = TRgb(255,255,255); aGc.SetPenColor(pencolor); _LIT(KPointsText, "Points: "); TBufC<15> pointsText; TPtr pointsPtr = pointsText.Des(); pointsPtr.Append(KPointsText); pointsPtr.AppendNum(iHolder->ActivePoints()); const CFont* menuFont = AknLayoutUtils::FontFromId(EAknLogicalFontPrimarySmallFont, NULL); aGc.UseFont(menuFont); TInt textLength = menuFont->TextWidthInPixels(pointsPtr); TInt textHeight = menuFont->HeightInPixels(); TPoint textpoint(Rect().Width() / 2 - textLength / 2, textHeight); aGc.DrawText(pointsPtr, textpoint); }
/****************************************************************************\ | 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 CTraceContainer::PieDrawer(CWindowGc& aGc, TPoint aLeftTop, TInt aSize, TInt aProsentages, const TBool& aReverceColor) const { TBuf<50> Buffer; Buffer.Num(aProsentages); Buffer.Append(_L("%")); aGc.SetPenColor(KRgbBlack); if(aReverceColor) aGc.SetBrushColor(KRgbGreen); else aGc.SetBrushColor(KRgbRed); aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); aGc.DrawEllipse(TRect(aLeftTop.iX,aLeftTop.iY,aLeftTop.iX + aSize,aLeftTop.iY + aSize)); if(aProsentages < 0) { Buffer.Copy(_L("N/A")); if(aReverceColor) aGc.SetBrushColor(KRgbGreen); else aGc.SetBrushColor(KRgbRed); } else { TInt HelpPie = 0; if(aReverceColor) aGc.SetBrushColor(KRgbRed); else aGc.SetBrushColor(KRgbGreen); TInt Angle =((aProsentages * 360) / 100); if(Angle == 360) { aGc.DrawPie(TRect(aLeftTop.iX,aLeftTop.iY,aLeftTop.iX + aSize,aLeftTop.iY + aSize),aLeftTop,aLeftTop); } else if(Angle == 45) { aGc.DrawPie(TRect(aLeftTop.iX,aLeftTop.iY,aLeftTop.iX + aSize,aLeftTop.iY + aSize),TPoint(aLeftTop.iX + (aSize/2),aLeftTop.iY),TPoint(aLeftTop.iX,aLeftTop.iY)); } else if(Angle == 135) { aGc.DrawPie(TRect(aLeftTop.iX,aLeftTop.iY,aLeftTop.iX + aSize,aLeftTop.iY + aSize),TPoint(aLeftTop.iX + (aSize/2),aLeftTop.iY),TPoint(aLeftTop.iX,aLeftTop.iY + aSize)); } else if(Angle == 225) { aGc.DrawPie(TRect(aLeftTop.iX,aLeftTop.iY,aLeftTop.iX + aSize,aLeftTop.iY + aSize),TPoint(aLeftTop.iX + (aSize/2),aLeftTop.iY),TPoint(aLeftTop.iX + aSize,aLeftTop.iY + aSize)); } else if(Angle == 315) { aGc.DrawPie(TRect(aLeftTop.iX,aLeftTop.iY,aLeftTop.iX + aSize,aLeftTop.iY + aSize),TPoint(aLeftTop.iX + (aSize/2),aLeftTop.iY),TPoint(aLeftTop.iX + aSize,aLeftTop.iY)); } else if(Angle > 45 && Angle < 135) { HelpPie = ((((Angle - 45) * aSize) / 90) + aLeftTop.iY); aGc.DrawPie(TRect(aLeftTop.iX,aLeftTop.iY,aLeftTop.iX + aSize,aLeftTop.iY + aSize),TPoint(aLeftTop.iX + (aSize/2),aLeftTop.iY),TPoint(aLeftTop.iX,HelpPie)); } else if(Angle > 135 && Angle < 225) { HelpPie = ((((Angle - 135) * aSize) / 90) + aLeftTop.iX); aGc.DrawPie(TRect(aLeftTop.iX,aLeftTop.iY,aLeftTop.iX + aSize,aLeftTop.iY + aSize),TPoint(aLeftTop.iX + (aSize/2),aLeftTop.iY),TPoint(HelpPie,aLeftTop.iY + aSize)); } else if(Angle > 225 && Angle < 315) { HelpPie = (((aLeftTop.iY + aSize) - ((Angle - 225) * aSize) / 90)); aGc.DrawPie(TRect(aLeftTop.iX,aLeftTop.iY,aLeftTop.iX + aSize,aLeftTop.iY + aSize),TPoint(aLeftTop.iX + (aSize/2),aLeftTop.iY),TPoint(aLeftTop.iX + aSize,HelpPie)); } else if(Angle > 0 && Angle < 45) { HelpPie = (((aLeftTop.iX + (aSize/2)) - ((Angle) * (aSize/2)) / 45)); aGc.DrawPie(TRect(aLeftTop.iX,aLeftTop.iY,aLeftTop.iX + aSize,aLeftTop.iY + aSize),TPoint(aLeftTop.iX + (aSize/2),aLeftTop.iY),TPoint(HelpPie,aLeftTop.iY)); } else if(Angle > 315 && Angle < 360) { HelpPie = (((aLeftTop.iX + aSize) - ((Angle - 315) * (aSize/2)) / 45)); aGc.DrawPie(TRect(aLeftTop.iX,aLeftTop.iY,aLeftTop.iX + aSize,aLeftTop.iY + aSize),TPoint(aLeftTop.iX + (aSize/2),aLeftTop.iY),TPoint(HelpPie,aLeftTop.iY)); } if(aReverceColor) { if(Angle > 180) aGc.SetBrushColor(KRgbGreen); else aGc.SetBrushColor(KRgbRed); } else { if(Angle > 180) aGc.SetBrushColor(KRgbRed); else aGc.SetBrushColor(KRgbGreen); } } const CFont* MuFonr = AknLayoutUtils::FontFromId(EAknLogicalFontSecondaryFont); TInt TextHeight= MuFonr->HeightInPixels(); TInt TextWidth = MuFonr->TextWidthInPixels(Buffer); TInt StartX = (aLeftTop.iX + ((aSize - TextWidth) / 2)); TInt StartY = (aLeftTop.iY + ((aSize - TextHeight) / 2)); aGc.UseFont(MuFonr); aGc.SetPenColor(KRgbBlack); aGc.SetBrushStyle(CGraphicsContext::ENullBrush); aGc.DrawText(Buffer,TRect(StartX,StartY,StartX + TextWidth,StartY + TextHeight),MuFonr->AscentInPixels(), CGraphicsContext::ELeft, 0); aGc.SetBrushStyle(CGraphicsContext::ENullBrush); }
/* ----------------------------------------------------------------------- ----------------------------------------------------------------------- */ void CTraceContainer::DrawMemory(const TRect& aRect, CWindowGc& gc) const { if(iMaskImg) { if(iMaskImg->Bitmap() && iMaskImg->Mask()) { if(iMaskImg->Bitmap()->Handle() && iMaskImg->Mask()->Handle()) { TSize ButtonSiz(iMaskImg->Bitmap()->SizeInPixels()); gc.DrawBitmapMasked(aRect,iMaskImg->Bitmap(),TRect(0,0,ButtonSiz.iWidth,ButtonSiz.iHeight),iMaskImg->Mask(),EFalse); } } } gc.SetPenColor(KRgbBlack); gc.DrawLine(aRect.iTl,TPoint(aRect.iTl.iX,aRect.iBr.iY)); gc.DrawLine(aRect.iTl,TPoint(aRect.iBr.iX,aRect.iTl.iY)); gc.DrawLine(aRect.iBr,TPoint(aRect.iTl.iX,aRect.iBr.iY)); gc.DrawLine(aRect.iBr,TPoint(aRect.iBr.iX,aRect.iTl.iY)); gc.SetPenColor(KRgbRed); TInt Prosentages(0); TBuf<100> FreeBuffer(_L("Free: ")); TBuf<100> TotalBuffer(_L("Total: ")); if(iArray.Count()) { if(iArray[iArray.Count() - 1]) { FreeBuffer.AppendNum(iArray[iArray.Count() - 1]->iMemory,EDecimal); TotalBuffer.AppendNum(iTotalRamInBytes,EDecimal); Prosentages = ((iArray[iArray.Count() - 1]->iMemory * 100) / iTotalRamInBytes); } } TInt SizPie = (aRect.Height() / 3); PieDrawer(gc,aRect.iTl,SizPie,Prosentages,EFalse); const CFont* MuFonr = AknLayoutUtils::FontFromId(EAknLogicalFontSecondaryFont); TInt TextHeight= MuFonr->HeightInPixels(); TInt StartX = (aRect.iTl.iX + SizPie); TInt StartY = (aRect.iTl.iY + 2); gc.SetPenColor(KRgbBlack); gc.UseFont(MuFonr); gc.DrawText(FreeBuffer,TRect(StartX,StartY,aRect.iBr.iX,StartY + TextHeight),MuFonr->AscentInPixels(), CGraphicsContext::ELeft, 0); gc.DrawText(TotalBuffer,TRect(StartX,(StartY + TextHeight),aRect.iBr.iX,(StartY + (TextHeight * 2))),MuFonr->AscentInPixels(), CGraphicsContext::ELeft, 0); gc.SetPenColor(KRgbRed); StartX = 0; if(iArray.Count() > aRect.Width()) { StartX = (iArray.Count() - aRect.Width()); } TPoint MePoint1(aRect.iTl.iX,aRect.iBr.iY); TPoint MePoint2(aRect.iTl); TInt Valll(0); for(TInt i = StartX; i < iArray.Count(); i++) { if(iArray[i] && iTotalRamInBytes > 0) { Valll = ((aRect.Height() * iArray[i]->iMemory) / iTotalRamInBytes); } MePoint2.iY = (aRect.iBr.iY - Valll); if(StartX != 1) { gc.DrawLine(MePoint1,MePoint2); } MePoint1 = MePoint2; MePoint2.iX = MePoint2.iX + 1; } }