×
Namespaces

Variants
Actions

如何直接在屏幕上绘制图片

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
翻译:
hoolee
最后由 hamishwillee 在 30 May 2013 编辑

在游戏开发中图片的绘制速度尤为重要,但是Symbian OS窗口框架并未为游戏提供全面的支持,我们需要直接访问屏幕缓存以便提供流畅的动画效果

需要的链接库:

LIBRARY  ws32.lib //RWsSession, CWsScreenDevice, RWindowGroup, CDirectScreenAccess
LIBRARY bitgdi.lib //CFbsBitGc


Display.h

#include <w32std.h> //RWsSession, CWsScreenDevice, RWindowGroup, CDirectScreenAccess
#include <bitstd.h> //CFbsBitGc
 
 
class CDisplay : public MDirectScreenAccess
{
public:
static CDisplay*NewL( RWsSession& pClient, CWsScreenDevice& pScreenDevice, RWindow& pWindow );
static CDisplay*NewLC( RWsSession& pClient, CWsScreenDevice& pScreenDevice, RWindow& pWindow );
~CDisplay();
 
inline CWsScreenDevice& GetScreenDevice()
{
return m_pScreenDevice;
}
 
inline RWindow& GetWindow()
{
return m_pWindow;
}
 
inline CFbsBitGc* GetScreenGc()
{
return m_pGc;
}
 
void Start();
void Stop();
void Update();
 
private:
CDisplay( RWsSession& pClient, CWsScreenDevice& pScreenDevice, RWindow& pWindow );
void ConstructL();
void Restart( RDirectScreenAccess::TTerminationReasons aReason );
void AbortNow( RDirectScreenAccess::TTerminationReasons aReason );
 
private:
CWsScreenDevice& m_pScreenDevice;
RWsSession& m_pClient;
RWindow& m_pWindow;
 
CDirectScreenAccess* m_pDirectScreenAccess;
RRegion* m_pRegion;
CFbsBitGc* m_pGc;
 
TBool m_bDrawing;
};


Display.cpp

#include "Display.h"
 
 
CDisplay* CDisplay::NewL( RWsSession& pClient, CWsScreenDevice& pScreenDevice, RWindow& pWindow )
{
CDisplay* self = NewLC( pClient, pScreenDevice, pWindow );
CleanupStack::Pop( self );
return self;
}
 
CDisplay* CDisplay::NewLC( RWsSession& pClient, CWsScreenDevice& pScreenDevice, RWindow& pWindow )
{
CDisplay* self = new ( ELeave ) CDisplay( pClient, pScreenDevice, pWindow );
CleanupStack::PushL( self );
self->ConstructL();
return self;
}
 
CDisplay::CDisplay( RWsSession& pClient, CWsScreenDevice& pScreenDevice, RWindow& pWindow ) :
m_pClient( pClient ),
m_pScreenDevice( pScreenDevice ),
m_pWindow( pWindow )
{
m_pDirectScreenAccess = NULL;
m_pRegion = NULL;
m_pGc = NULL;
 
m_bDrawing = EFalse;
}
 
CDisplay::~CDisplay()
{
delete m_pDirectScreenAccess;
}
 
void CDisplay::ConstructL()
{
m_pDirectScreenAccess = CDirectScreenAccess::NewL( m_pClient, m_pScreenDevice, m_pWindow, *this );
}
 
void CDisplay::Start()
{
if( !m_bDrawing )
{
TRAPD( dsaErr, m_pDirectScreenAccess->StartL() );
if( dsaErr == KErrNone )
{
m_pGc = m_pDirectScreenAccess->Gc();
m_pRegion = m_pDirectScreenAccess->DrawingRegion();
m_pGc->SetClippingRegion( m_pRegion );
m_bDrawing = ETrue;
}
}
}
 
void CDisplay::Stop()
{
if( m_bDrawing )
{
m_bDrawing = EFalse;
}
}
 
void CDisplay::Update()
{
m_pDirectScreenAccess->ScreenDevice()->Update();
}
 
void CDisplay::Restart( RDirectScreenAccess::TTerminationReasons /*aReason*/ )
{
Start();
}
 
void CDisplay::AbortNow( RDirectScreenAccess::TTerminationReasons /*aReason*/ )
{
m_pDirectScreenAccess->Cancel();
m_bDrawing = EFalse;
}
This page was last modified on 30 May 2013, at 07:37.
45 page views in the last 30 days.
×