⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawing_helloview.cpp

📁 《SymbianOSC手机应用开发》源码
💻 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 + -