?? retroappview.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 + -