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

📄 icebloxxview.cpp

📁 Source code (C++) of the Icebloxx game for Symbian OS UIQ3.x
💻 CPP
字号:
#include "icebloxxview.h"
#include "icebloxxappui.h"
#include "spritecollection.h"
#include "IceBloxx.hrh"
#include <eikenv.h>
#include <eikappui.h>
#include <string.h>
#include <gdi.h>
#include <quartzkeys.h>
#include <icebloxx.rsg>

#include "icebloxx.h"
#ifdef UIQ3
#include <qikcommand.h>
#include <QikFullscreenFloatingMenu.h>
const CFont& CIceBloxxView::ScreenFont(const TCoeFont& aFont) const
{
	return CQikViewBase::ScreenFont(aFont);
}

// from CQikViewBase
void CIceBloxxView::ViewConstructL() {
	ViewConstructFromResourceL(R_ICQBLOXX_UI_CONFIGURATIONS);
	CQikFullscreenFloatingMenu* floatingMenu = CQikFullscreenFloatingMenu::NewL(*this);
    floatingMenu->SetUniqueHandle(EIceBloxxFloatingMenu);
	// The control array will take ownership of the floating menu.
    AddControlLC(floatingMenu);
   
    CQikCommandManager::Static(*iEikonEnv).AddCustomOperatorL(*this, *floatingMenu);
    CleanupStack::Pop(floatingMenu);

}

// from MQikCommandHandler
void CIceBloxxView::HandleCommandL(CQikCommand& aCommand)
{
	if(aCommand.Id()>=EStartNewGame && aCommand.Id()<ELastCommand)
	{
		iEikonEnv->EikAppUi()->HandleCommandL(aCommand.Id());
	}
	else
	{
		CQikViewBase::HandleCommandL(aCommand);
	}
}

void CIceBloxxView::UpdateCommandsL(TInt aCoins, TInt aSpeed, TInt aStrength)
{
	CQikCommandManager& comMan = CQikCommandManager::Static();
	TInt selItem = 0;
	switch(aCoins)
	{
	case 3:
		selItem = E3Coins;
		break;
	case 4:
		selItem = E4Coins;
		break;
	case 5:
		selItem = E5Coins;
		break;
	case 6:
		selItem = E6Coins;
		break;
	case 7:
		selItem = E7Coins;
		break;
	case 8:
		selItem = E8Coins;
		break;
	default:
		selItem = -1;
		break;
	}
	
	if(selItem != -1)
	{
		for(TInt loop = E3Coins;loop<=E8Coins;loop++)
		{
			comMan.SetChecked(*this, loop, selItem == loop);
		}
	}
	
	switch(aSpeed)
	{
	case 6:
		selItem = ENormalSpeed;
		break;
	case 9:
		selItem = EFastSpeed;
		break;
	case 12:
		selItem = ERoadRunnerSpeed;
		break;
	default:
		selItem = -1;
		break;
	}
	
	if(selItem != -1)
	{
		for(TInt loop = ENormalSpeed;loop<=ERoadRunnerSpeed;loop++)
		{
			comMan.SetChecked(*this, loop, selItem == loop);
		}
	}
	
	switch(aStrength)
	{
	case 6:
		selItem = EWeakStrength;
		break;
	case 12:
		selItem = ENormalStrength;
		break;
	case 18:
		selItem = EStrongStrength;
		break;
	case 24:
		selItem = ESuperStrength;
		break;
	default:
		selItem = -1;
		break;
	}
	
	if(selItem != -1)
	{
		for(TInt loop = EWeakStrength;loop<=ESuperStrength;loop++)
		{
			comMan.SetChecked(*this, loop, selItem == loop);
		}
	}
	
}


CIceBloxxView::CIceBloxxView(CQikAppUi& aAppUI):CQikViewBase(aAppUI, KNullViewId)
#else
CIceBloxxView::CIceBloxxView()
#endif
{
}

void CIceBloxxView::SetIceBloxxGame(Icebloxx* aGame)
{
	iGame = aGame;
}


CIceBloxxView::~CIceBloxxView()
{
}

void CIceBloxxView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
	
	if(aPointerEvent.iType == TPointerEvent::EButton1Down)
	{
		QMouseEvent event;
#ifdef UIQ3
		event.iX = (aPointerEvent.iPosition.iX);
#else
		event.iX = (aPointerEvent.iPosition.iX*15)/13;
#endif
		event.iY = aPointerEvent.iPosition.iY;
		iGame->Field().mousePressEvent(&event);
	}
}

TKeyResponse CIceBloxxView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{

	if(aType ==EEventKeyUp)
	{
		QKeyEvent event;
		event.iKey = -1;
		switch(aKeyEvent.iScanCode)
		{
		case EStdQuartzKeyTwoWayUp:
		case EStdQuartzKeyFourWayUp:
		case EStdKeyUpArrow:
		case EStdKeyNkp2:
			event.iKey = Key_Up;
				break;
		case EStdQuartzKeyTwoWayDown:
		case EStdQuartzKeyFourWayDown:
		case EStdKeyDownArrow:
		case EStdKeyNkp8:
			event.iKey = Key_Down;
			break;
		case EStdKeyLeftArrow:
		case EStdQuartzKeyFourWayLeft:
		case EStdKeyNkp4:
			event.iKey = Key_Left;
			break;
		
		case EStdKeyRightArrow:
		case EStdQuartzKeyFourWayRight:
		case EStdKeyNkp6:
			event.iKey = Key_Right;
			break;

		case EStdQuartzKeyConfirm:
		case EStdKeySpace:
	 // Special support for jogdial in for SE phones
		case EStdKeyDevice1B:
		case EStdKeyNkp5:
			event.iKey = 32;
			break;
		default:
			break;
		}

		if(event.key()!=-1)
		{
			iGame->Field().keyReleaseEvent(&event);
		}
	}

	if(aType == EEventKeyDown)
	{		QKeyEvent event;
		event.iKey = -1;
		switch(aKeyEvent.iScanCode)
		{
		case EStdQuartzKeyTwoWayUp:
		case EStdQuartzKeyFourWayUp:
		case EStdKeyUpArrow:
		case EStdKeyNkp2:
			event.iKey = Key_Up;
				break;
		case EStdQuartzKeyTwoWayDown:
		case EStdQuartzKeyFourWayDown:
		case EStdKeyDownArrow:
		case EStdKeyNkp8:
			event.iKey = Key_Down;
			break;
		case EStdKeyLeftArrow:
		case EStdQuartzKeyFourWayLeft:
		case EStdKeyNkp4:
			event.iKey = Key_Left;
			break;
		
		case EStdKeyRightArrow:
		case EStdQuartzKeyFourWayRight:
		case EStdKeyNkp6:
			event.iKey = Key_Right;
			break;

		case EStdQuartzKeyConfirm:
		case EStdKeySpace:
		case EStdKeyNkp5:
			event.iKey = 32;
			break;
		default:
			break;
		}
		if(event.key()!=-1)
		{
			iGame->Field().keyPressEvent(&event);
		}
	}

	return EKeyWasNotConsumed;
}


void CIceBloxxView::BlitImage(QPixmap* aPixmap)
{
	ActivateGc();
	CWindowGc& gc=SystemGc();
	gc.BitBlt(TPoint(0,0),aPixmap,TRect(TPoint(0,0),aPixmap->SizeInPixels()));
	DeactivateGc();
}
void CIceBloxxView::ConstructL()
{
	CreateWindowL();
#ifdef UIQ3
	BaseConstructL();
	PreemptViewConstructionL();
	TQikViewMode viewmode;
	viewmode.SetFullscreen();
	SetViewModeL(viewmode);
	SetRect(iEikonEnv->ScreenDevice()->SizeInPixels());
#else
	SetRect(iEikonEnv->EikAppUi()->ClientRect());

#endif
	ActivateL();
}

void CIceBloxxView::Draw(const TRect& aRect) const
{
#ifndef UIQ3
	CWindowGc& gc = SystemGc();
	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
	gc.SetPenStyle(CGraphicsContext::ENullPen);
	gc.SetBrushColor(KRgbBlack);
	gc.DrawRect(aRect);
#endif
}

void CIceBloxxView::ViewDeactivated()
{
#ifdef UIQ3
	CQikViewBase::ViewDeactivated();
#endif

	iGame->Field().hideEvent();
	MakeVisible(EFalse);
}
void CIceBloxxView::ViewActivatedL(const TVwsViewId& aPrevViewId,TUid aCustomMessageId,const TDesC8& aCustomMessage)
{
#ifdef UIQ3
	CQikViewBase::ViewActivatedL(aPrevViewId, aCustomMessageId, aCustomMessage);
#endif
	MakeVisible(ETrue);
	iGame->Field().showEvent();
}

TVwsViewId CIceBloxxView::ViewId() const
{
	TVwsViewId viewId(TUid::Uid(KICEBLOXUID),TUid::Uid(0x12341234));
	return viewId;
}


QPainter::QPainter(CBitmapContext* aGc):iGc(aGc)
{
	iEikEnv=CEikonEnv::Static();
	iView = static_cast<CIceBloxxAppUi*>(iEikEnv->EikAppUi())->GameView();
}
QPainter::~QPainter()
{
}
void QPainter::drawPixmap(TInt aX,TInt aY,QPixmap* aBitmap)
{
	iGc->BitBlt(TPoint(aX,aY),aBitmap,TRect(TPoint(0,0),aBitmap->SizeInPixels()));
}

void QPainter::drawPixmapMask(TInt aX,TInt aY,QPixmap* aBitmap,QPixmap* aMask)
{
	iGc->SetBrushStyle(CGraphicsContext::ENullBrush);
	iGc->BitBltMasked(TPoint(aX,aY),aBitmap,TRect(TPoint(0,0),aBitmap->SizeInPixels()),aMask,ETrue);
}

void QPainter::fillRect(TInt aX,TInt aY,TInt aWidth,TInt aHeight,QColor aColor)
{
	iGc->SetBrushColor(aColor.Color());
	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
	iGc->SetPenStyle(CGraphicsContext::ENullPen);
	iGc->DrawRect(TRect(TPoint(aX,aY),TSize(aWidth,aHeight)));
}
void QPainter::drawText(TInt aX,TInt aY,TInt aWidth,TInt aHeight,TInt aAlign,const char* aString)
{
	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
	iGc->SetPenStyle(CGraphicsContext::ESolidPen);
#ifdef UIQ3
	TCoeFont font(12,TCoeFont::EPlain);
	const CFont* usedFont = &iView->ScreenFont(font);
#else
	const usedFont = iEikEnv->NormalFont();
#endif
	iGc->UseFont(usedFont);

	TPtrC8 str((const unsigned char*)aString,strlen(aString));
	HBufC* buf = HBufC::NewLC(str.Length());
	buf->Des().Copy(str);
//	iGc->DrawText(*buf,TRect(TPoint(aX,aY),TSize(aWidth,aHeight)),0);
	if(aAlign &AlignVCenter)
	{
		aY+=(aHeight/2-usedFont->HeightInPixels()/2);
	}
	else if(aAlign & AlignBottom)
	{
		aY+=(aHeight-usedFont->HeightInPixels());
	}

	if(aAlign & AlignHCenter)
	{
		aX+=(aWidth/2-usedFont->TextWidthInPixels(*buf)/2);
	}
	else if(aAlign & AlignRight)
	{
		aX+=(aWidth-usedFont->TextWidthInPixels(*buf));
	}

	iGc->DrawText(*buf,TPoint(aX,aY+usedFont->AscentInPixels()));
	CleanupStack::PopAndDestroy(buf);
	iGc->DiscardFont();
}
void QPainter::drawLine(TInt aX,TInt aY,TInt aX2,TInt aY2)
{
	iGc->SetBrushStyle(CGraphicsContext::ENullBrush);
	iGc->SetPenStyle(CGraphicsContext::ESolidPen);
	iGc->DrawLine(TPoint(aX,aY),TPoint(aX2,aY2));
}

void QPainter::setPen(QColor aColor)
{
	iGc->SetPenColor(aColor.Color());
}

QColor::QColor(TInt r,TInt g,TInt b)
{
	iR=r;
	iG=g;
	iB=b;
}

TRgb QColor::Color()
{
	return TRgb(iR,iG,iB);
}

QPixmap::QPixmap(RWsSession &aWs):CWsBitmap(aWs)
{
}

⌨️ 快捷键说明

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