rpsappview.cpp

来自「roids60 game symbian os application deve」· C++ 代码 · 共 150 行

CPP
150
字号
// Copyright (c) Symbian Ltd 2008. All rights reserved.

// INCLUDE FILES
#include <coemain.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();

	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;

	switch (aKeyEvent.iScanCode)
		{
		case EStdKeyUpArrow: 	
			input = KControllerUp;
			break;
		case EStdKeyDownArrow: 
			input = KControllerDown;
			break;
		case EStdKeyDevice3:  
			input = KControllerCentre;
			break;
		case '5': 
			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 + =
减小字号Ctrl + -
显示快捷键?