?? drawing_hellocontrol.cpp
字號:
// Drawing_HelloControl.cpp
// ----------------------------
//
// Copyright (c) 2002 - 2007 Symbian Software Ltd. All rights reserved.
//
////////////////////////////////////////////////////////////////////////
//
// Source file for the implementation of the
// application CExampleHelloControl class
//
////////////////////////////////////////////////////////////////////////
#include "Drawing.h"
#include <GulUtil.h>
CExampleHelloControl* CExampleHelloControl::NewL(const CCoeControl& aContainer)
{
CExampleHelloControl* self=new(ELeave) CExampleHelloControl;
CleanupStack::PushL(self);
self->ConstructL(aContainer);
CleanupStack::Pop();
return self;
}
void CExampleHelloControl::ConstructL(const CCoeControl& aContainer)
{
SetContainerWindowL(aContainer);
iView=CExampleHelloView::NewL();
iText=iEikonEnv->AllocReadResourceL(R_EXAMPLE_TEXT_HELLO_WORLD);
iView->SetTextL(*iText);
iZoomFactor.SetGraphicsDeviceMap(iCoeEnv->ScreenDevice());
SetZoomAndDeviceDependentFontL(1000);
ActivateL();
}
TInt CExampleHelloControl::GetZoom() const
{
return iZoomFactor.ZoomFactor();
}
//
// Called on class construction and as a result of zooming in or out.
// As well as setting the zoom factor, the function allocates a device-dependent
// font for the "Hello World" text.
// This is an appropriate location for the font allocation as it is expected to
// change when the user zooms in or out.
// The font allocation could also be performed in Draw() or CExampleHelloControl::DrawL(), which
// is called by Draw(). However, Draw() is not a leave function and it implements a
// virtual function in the parent class and cannot be altered. Therefore, in order to
// be able to allocate a font a trap harness would have to be used, resulting in a call
// from Draw() something like the following, with the font allocation taking place in
// DrawL(): TRAPD(err, iView -> DrawL(iZoomFactor, gc, rect));
// Using a trap here is undesirable practice (although it would allow all the
// device-independent code to be contained in the CExampleHelloView class).
//
void CExampleHelloControl::SetZoomAndDeviceDependentFontL(TInt aZoomFactor)
{
iZoomFactor.SetZoomFactor(aZoomFactor);
//Allocate a device dependent font for drawing.
iZoomFactor.ReleaseFont(iFont);
iFont=NULL; // This is in case the function leaves with the LeaveIfError() below.
// In this case iFont would still have the old value when the class
// destructor is called, and in the destructor the zoom factor will
// attempt to release the same font again, causing the application
// to crash.
_LIT(fontName, "SwissA");
TFontSpec fontSpec(fontName, 240); // font size is 12 point
fontSpec.iFontStyle=TFontStyle(EPostureUpright, EStrokeWeightBold, EPrintPosNormal);
User::LeaveIfError(iZoomFactor.GetNearestFontInTwips(iFont, fontSpec));
}
void CExampleHelloControl::SetZoomInL()
{
TInt zoom=GetZoom();
zoom=
zoom < 500 ? 500 :
zoom < 1000 ? 1000 :
zoom < 1500 ? 1500 :
zoom < 2000 ? 2000 :
500;//if you keep zooming in the font and rectangle size becomes small again.
SetZoomAndDeviceDependentFontL(zoom);
}
void CExampleHelloControl::SetZoomOutL()
{
TInt zoom=GetZoom();
zoom=
zoom > 2000 ? 2000 :
zoom > 1500 ? 1500 :
zoom > 1000 ? 1000 :
zoom > 500 ? 500 :
2000;//if you keep zooming out the font and rectangle size becomes large again.
SetZoomAndDeviceDependentFontL(zoom);
}
void CExampleHelloControl::SetFullRedraw(TBool aFullRedraw)
{
iView->SetFullRedraw(aFullRedraw);
}
CExampleHelloControl::~CExampleHelloControl()
{
delete iText;
delete iView;
iZoomFactor.ReleaseFont(iFont); //releases the last font to be used
}
//
// Draws a rectangle in a corner of the screen with a white border, then calls
// DrawInRect() to fill the rectangle
//
void CExampleHelloControl::Draw(const TRect& /*aRect*/) const
{
CWindowGc& gc=SystemGc();
TRect rect=Rect();
rect.Shrink(10,10);
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.SetBrushColor(KRgbWhite);
DrawUtils::DrawBetweenRects(gc, Rect(), rect);
gc.SetPenStyle(CGraphicsContext::ESolidPen);
gc.SetPenColor(KRgbBlack);
gc.SetBrushStyle(CGraphicsContext::ENullBrush);
gc.DrawRect(rect);
rect.Shrink(1,1);
iView->DrawInRect(iZoomFactor, gc, rect, iFont);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -