📄 testdoublebufferappview.cpp
字号:
/*
============================================================================
Name : TestDoubleBufferAppView.cpp
Author :
Copyright : Your copyright notice
Description : Application view implementation
============================================================================
*/
// INCLUDE FILES
#include <coemain.h>
#include <EIKENV.h>
#include "TestDoubleBufferAppView.h"
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CTestDoubleBufferAppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CTestDoubleBufferAppView* CTestDoubleBufferAppView::NewL(const TRect& aRect)
{
CTestDoubleBufferAppView* self = CTestDoubleBufferAppView::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
// -----------------------------------------------------------------------------
// CTestDoubleBufferAppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CTestDoubleBufferAppView* CTestDoubleBufferAppView::NewLC(const TRect& aRect)
{
CTestDoubleBufferAppView* self = new ( ELeave ) CTestDoubleBufferAppView;
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
// -----------------------------------------------------------------------------
// CTestDoubleBufferAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CTestDoubleBufferAppView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();
// Set the windows size
SetRect(aRect);
InitDoubleBufferL();
// Activate the window, which makes it ready to be drawn
ActivateL();
}
/**
* 初始化双缓冲区
*/
void CTestDoubleBufferAppView::InitDoubleBufferL()
{
iBufBmp = new(ELeave)CWsBitmap(CEikonEnv::Static()->WsSession());
CleanupStack::PushL(iBufBmp);
User::LeaveIfError(iBufBmp->Create(Rect().Size(), CEikonEnv::Static()->ScreenDevice()->DisplayMode()));
iBufDevice = CFbsBitmapDevice::NewL(iBufBmp);
CleanupStack::PushL(iBufDevice);
User::LeaveIfError(iBufDevice->CreateBitmapContext(iBufGc));
CleanupStack::Pop(2); // iDevice, iBufBmp
}
// -----------------------------------------------------------------------------
// CTestDoubleBufferAppView::CTestDoubleBufferAppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CTestDoubleBufferAppView::CTestDoubleBufferAppView()
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CTestDoubleBufferAppView::~CTestDoubleBufferAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CTestDoubleBufferAppView::~CTestDoubleBufferAppView()
{
// No implementation required
if (iBufBmp)
{
delete iBufBmp;
iBufBmp = NULL;
}
if (iBufDevice)
{
delete iBufDevice;
iBufDevice = NULL;
}
if (iBufGc)
{
delete iBufGc;
iBufGc = NULL;
}
}
/**
* 测试在缓冲区上绘制
*/
void CTestDoubleBufferAppView::DoTestDraw()
{
iBufGc->Clear(Rect());
// 在buffer里画方块,而不是在屏幕上
for (int i=0; i<100; i+=2)
{
iBufGc->DrawRect(TRect(TPoint(i, i), TSize(50, 50)));
}
}
/**
* View的重绘事件
*/
void CTestDoubleBufferAppView::Draw(const TRect& /*aRect*/) const
{
// 以下代码忽略
// // Get the standard graphics context
// CWindowGc& gc = SystemGc();
//
// // Gets the control's extent
// TRect drawRect(Rect());
//
// // Clears the screen
// gc.Clear(drawRect);
SystemGc().BitBlt(TPoint(0, 0), iBufBmp);
}
// -----------------------------------------------------------------------------
// CTestDoubleBufferAppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CTestDoubleBufferAppView::SizeChanged()
{
DrawNow();
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -