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

📄 rpsappview.cpp

📁 基于symbian UIQ 的一款古老的飞机游戏。对入门学习很有帮助。
💻 CPP
字号:
// Copyright (c) Symbian Ltd 2008. All rights reserved.

// INCLUDE FILES
#include <coemain.h>
#include <eikenv.h>
#include "rpsAppView.h"
#include "common.hrh"
#include "rpsgamescreens.h"

// -----------------------------------------------------------------------------
// CRpsAppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CRpsAppView* CRpsAppView::NewL(MAppViewObserver& aObs, const TRect& aRect)
	{
	CRpsAppView* self = CRpsAppView::NewLC(aObs, aRect);
	CleanupStack::Pop( self );
	return self;
	}

// -----------------------------------------------------------------------------
// CRpsAppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CRpsAppView* CRpsAppView::NewLC(MAppViewObserver& aObs, const TRect& aRect)
	{
	CRpsAppView* self = new ( ELeave ) CRpsAppView(aObs);
	CleanupStack::PushL( self );
	self->ConstructL(aRect);
	return self;
	}

// -----------------------------------------------------------------------------
// CRpsAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CRpsAppView::ConstructL( const TRect& aRect )
	{
	// Create a window for this application view
	CreateWindowL();

	// Set the windows size
	SetRect( aRect );
	
	// Activate the window, which makes it ready to be drawn and starts the heartbeat
	ActivateL();
	}


// -----------------------------------------------------------------------------
// CRpsAppView::CRpsAppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CRpsAppView::CRpsAppView(MAppViewObserver& aObs): iObs(aObs)
	{
	// No implementation required
	}


// -----------------------------------------------------------------------------
// CRpsAppView::~CRpsAppView()
// Destructor.
// -----------------------------------------------------------------------------
CRpsAppView::~CRpsAppView()
	{
	}

// -----------------------------------------------------------------------------
// CRpsAppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CRpsAppView::SizeChanged()
	{  
	TRect rect(Rect());
	gScreenWidth = rect.Width();
	gScreenHeight = rect.Height();
	DrawNow();
	}

// --------------------------------------------------------------------------
// FocusChanged
// --------------------------------------------------------------------------
void CRpsAppView::FocusChanged(TDrawNow aDrawNow)
	{
	iObs.FocusChanged(IsFocused());
	
	if(aDrawNow)
		DrawNow();
	}


TKeyResponse CRpsAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
	{
	TKeyResponse response = EKeyWasConsumed;
	TUint input = 0x00000000;

// ----------------------------------------------------------------------------
//	Use during development only, to determine key code for different devices
//	TInt scanCode = aKeyEvent.iScanCode;
//	_LIT(KScanCode, "code: %d");
//	TBuf<20> formatBuf;
//	formatBuf.Format(KScanCode, scanCode);
//	CEikonEnv::Static()->InfoMsg(formatBuf);
// ----------------------------------------------------------------------------
	
	switch (aKeyEvent.iScanCode)
		{
		case EStdKeyDevice4: 	// Z8 and emulator
		case EStdKeyDevice1:	// M600i
			input = KControllerUp;
			break;
		case EStdKeyDevice5:	// Z8 and emulator
		case EStdKeyDevice2:	// M600i
			input = KControllerDown;
			break;
		case EStdKeyDevice8:	// Z8 and emulator 
		case EStdKeyDevice1B:   // M600i
			input = KControllerCentre;
			break;
		case 53:				// Z8
		case 72: 				// M600i
		case 141:				// emulator
			input = KKey5;
			break;
		default:
			response = EKeyWasNotConsumed;// Keypress was not handled
			break;
		}
	
	if (EEventKeyDown == aType)
		{
		iKeyState |= input; // set bitmask
		}
	else if (EEventKeyUp == aType)
		{
		iKeyState &= ~input; // clear bitmask
		}
	
	iObs.KeyEvent(iKeyState);
	
    return (response);
	}

// -----------------------------------------------------------------------------
// CRpsAppView::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
void CRpsAppView::Draw( const TRect& /*aRect*/ ) const
	{
	// Get the standard graphics context
	CWindowGc& gc = SystemGc();
	gc.Clear( Rect() );
	
	iObs.DrawGameScreen();
	}


// End of File

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -