s60testappui.cpp

来自「基于symbian s60 2nd的俄罗斯方块(注意:只能在2nd环境中工作)」· C++ 代码 · 共 106 行

CPP
106
字号
#include <avkon.hrh>
#include <aknnotewrappers.h>
#include <eikmenup.h> 

#include "S60Test.pan"
#include "S60TestDocument.h"
#include "S60TestAppUi.h"
#include "S60TestAppView.h"
#include "S60Test.hrh"
#include "Step6.rsg"

void CS60TestAppUi::ConstructL()
{
  BaseConstructL();

  iEngine=CS60TestEngine::NewL(iDoc);
  iAppView=CS60TestAppView::NewL(ClientRect(), iDoc, iEngine);
  AddToStackL(iAppView);
}

CS60TestAppUi::CS60TestAppUi(CS60TestDocument *aDoc)
:iEngine(NULL)
{
  iDoc=aDoc;
}

CS60TestAppUi::~CS60TestAppUi()
{
  if (iAppView)
  {
    RemoveFromStack(iAppView);
    delete iAppView;
    iAppView = NULL;
  }
  delete iEngine;
}

void CS60TestAppUi::UpdateBoard()
{
  iAppView->DrawDeferred();
}

void CS60TestAppUi::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane *aMenuPane)
{
  if (aResourceId==R_S60TEST_MENU)
  {
    if (iEngine->iPauseRef>0)
      aMenuPane->SetItemTextL(ES60TestPause, R_MENU_UNPAUSE_TITLE);
      else aMenuPane->SetItemTextL(ES60TestPause, R_MENU_PAUSE_TITLE);
  }
}

// handle any menu commands
void CS60TestAppUi::HandleCommandL(TInt aCommand)
{
  switch(aCommand)
  {
    case EEikCmdExit:
    case EAknSoftkeyExit:
      Exit();
      break;

    case ES60TestNewGame:
      iDoc->Reset();
      iEngine->Reset();
      UpdateBoard();
      break;

    case ES60TestPause:
      if (iEngine->iPauseRef>0) iEngine->Unpause();
        else iEngine->Pause();
      break;

    default:
      Panic(ES60TestBasicUi);
      break;
  }
}

TKeyResponse CS60TestAppUi::HandleKeyEventL(const TKeyEvent &aKeyEvent,
    TEventCode aType)
{
  if (aType==EEventKey)
  {
    if (aKeyEvent.iCode==EKeyUpArrow)
      iEngine->KeyRotate(1);

    if (aKeyEvent.iCode==EKeyDownArrow)
      iEngine->KeyDrop();

    if (aKeyEvent.iCode==EKeyLeftArrow)
      iEngine->KeyLeft();

    if (aKeyEvent.iCode==EKeyRightArrow)
      iEngine->KeyRight();

    if (aKeyEvent.iCode=='1')
      iEngine->KeyRotate(-1);

    if (aKeyEvent.iCode=='0' || aKeyEvent.iCode=='3')
      iEngine->KeyRotate(1);
  }
  return EKeyWasNotConsumed;
}

⌨️ 快捷键说明

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