?? drawing_helloview.cpp
字號:
// Drawing_HelloView.cpp
// ----------------------------
//
// Copyright (c) 2002 Symbian Ltd. All rights reserved.
//
////////////////////////////////////////////////////////////////////////
//
// Source file for the implementation of the
// application CExampleHelloView class
//
////////////////////////////////////////////////////////////////////////
#include "Drawing.h"
CExampleHelloView* CExampleHelloView::NewL()
{
CExampleHelloView* self=new(ELeave) CExampleHelloView;
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop();
return self;
}
void CExampleHelloView::ConstructL()
{
SetFullRedraw(ETrue);
// draw some text
}
CExampleHelloView::~CExampleHelloView()
{
delete iText;
}
// settings
void CExampleHelloView::SetTextL(const TDesC& aText)
{
HBufC* text=aText.AllocL();
delete iText;
iText=text;
}
void CExampleHelloView::SetFullRedraw(TBool aFullRedraw)
{
iFullRedraw=aFullRedraw;
}
// draws "Hello World" and box in the given rectangle.
void CExampleHelloView::DrawInRect(const MGraphicsDeviceMap& aMap,CGraphicsContext& aGc, const TRect& aDeviceRect, CFont* aFont) const
{
//Draw text
if (iFullRedraw)
{
aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
aGc.SetBrushColor(KRgbWhite);
}
else
{
aGc.SetBrushStyle(CGraphicsContext::ENullBrush); //Note that ENullBrush is the default
} //value, so this line makes no
//difference in this application
//(as iFullRedraw does not change
//between function calls).
aGc.SetPenStyle(CGraphicsContext::ESolidPen);
aGc.SetPenColor(KRgbBlack);
aGc.UseFont(aFont);
TInt baseline=aDeviceRect.Height()/2 + aFont->AscentInPixels()/2;
aGc.DrawText(*iText, aDeviceRect, baseline, CGraphicsContext::ECenter);
aGc.DiscardFont();
//Draw a box:
//Allocates a device-independent size for the box to be drawn around the text.
TSize boxInTwips(1440,288); // 1" x 1/5" surrounding box
//Converts twips to pixels, using iZoomFactor, to get a box of 1" x 1/5"
TSize boxInPixels;
boxInPixels.iWidth=aMap.HorizontalTwipsToPixels(boxInTwips.iWidth);
boxInPixels.iHeight=aMap.VerticalTwipsToPixels(boxInTwips.iHeight);
// draws the box
TRect box( //this creates a TRect using boxInPixels
TPoint(
aDeviceRect.Center().iX - boxInPixels.iWidth/2,
aDeviceRect.Center().iY - boxInPixels.iHeight/2
),
boxInPixels);
aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
aGc.SetClippingRect(aDeviceRect);
aGc.SetPenColor(KRgbDarkGray);
aGc.DrawRect(box);
box.Grow(1,1);
aGc.SetPenColor(KRgbBlack);
aGc.DrawRect(box); //this makes the box 2 pixels thick
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -