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

📄 retroappview.cpp

📁 s60 二维动画教程 含源码及 s60 二维动画教程 含源码及
💻 CPP
字号:
////////////////////////////////////////////////////////////////////////
//
// RetroAppView.cpp
//
// Copyright (c) 2003 Nokia Mobile Phones Ltd.  All rights reserved.
//
////////////////////////////////////////////////////////////////////////

#include "RetroAppView.h"

#include <eikenv.h>

#include "ImageFactory.h"
#include "RetroEngine.h"

// Local Constants
_LIT (KImagesFilename,"\\System\\Apps\\RetroBlaster\\RetroBlaster.mbm");

/********************/
/*** Construction ***/
/********************/

CRetroAppView* CRetroAppView::NewL(const TRect& aRect)
    {
    CRetroAppView* self = CRetroAppView::NewLC(aRect);
    CleanupStack::Pop();
    return self;
    }

CRetroAppView* CRetroAppView::NewLC(const TRect& aRect)
    {
    CRetroAppView* self = new (ELeave) CRetroAppView;
    CleanupStack::PushL(self);
    self->ConstructL(aRect);
    return self;
    }

void CRetroAppView::ConstructL(const TRect& aRect)
    {
    // Create a window for this application view
    CreateWindowL();

    // Set the windows size
    SetRect(aRect);

	iImageFactory = CImageFactory::NewL(*iEikonEnv, KImagesFilename);  

	iEngine = CRetroEngine::NewL(iEikonEnv->WsSession(), *(CCoeEnv::Static()->ScreenDevice()), Window(), iKeyHandler, *iImageFactory, Rect().Size());
	
	// Activate the window, which makes it ready to be drawn
    ActivateL();

	iEngine->StartFirstGameL();
    }

CRetroAppView::CRetroAppView() :
	iKeyHandler()
    {
    }

/*******************/
/*** Destruction ***/
/*******************/

CRetroAppView::~CRetroAppView()
    {
	delete iImageFactory;
	delete iEngine;
    }

/***************************************************/
/*** Drawing function must just clear the screen ***/
/***************************************************/

void CRetroAppView::Draw(const TRect& /*aRect*/) const
    {
    // Clear the screen
    CWindowGc& gc = SystemGc();
    gc.Clear(Rect());
    }


/**************************/
/*** Handle Key Presses ***/
/**************************/
TKeyResponse CRetroAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
	{
	TKeyResponse returnKey = EKeyWasNotConsumed;

	// If the app switch key is pressed we need to stop drawing
	if(aType == EEventKey && aKeyEvent.iScanCode == EStdKeyApplication0)
		{
		StopGame();
		// we still want the key event to be passed on so don't consume the key
		}
	else if(aType == EEventKeyDown)
		{
		switch(aKeyEvent.iScanCode)
			{
			case EStdKeyLeftArrow:
				iKeyHandler.LeftPressed();
				returnKey = EKeyWasConsumed;
				break;
			case EStdKeyRightArrow:
				iKeyHandler.RightPressed();
				returnKey = EKeyWasConsumed;
				break;
			case EStdKeyDevice3:
				iKeyHandler.PressedFire();
				returnKey = EKeyWasConsumed;
				break;
		default:
			break;
			}
		}
	else if(aType == EEventKeyUp)
		{
		switch(aKeyEvent.iScanCode)
			{
			case EStdKeyLeftArrow:
				iKeyHandler.NoDirection();
				returnKey = EKeyWasConsumed;
				break;
			case EStdKeyRightArrow:
				iKeyHandler.NoDirection();
				returnKey = EKeyWasConsumed;
				break;
			case EStdKeyDevice3:
				iKeyHandler.FireReleased();
				returnKey = EKeyWasConsumed;
				break;
		default:
			break;
			}
		}

	return returnKey;

	}

/*************************************************/
/*** Starting and stopping the game            ***/
/*** Should be used for a user requested stop  ***/
/*** Also used to stop drawing if app switched ***/
/*************************************************/ 

void CRetroAppView::StartGameL()
	{
	iEngine->StartGameL();
	}

void CRetroAppView::StopGame()
	{
	iEngine->StopGame();
	}

/****************************************************/
/*** Determines whether the game has been stopped ***/
/****************************************************/ 
TBool CRetroAppView::IsPlaying()
	{
	return iEngine->Playing();
	}

⌨️ 快捷键说明

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