// Copyright (c) 2004, Symbian Software Ltd. All rights reserved.
#include <coemain.h>
#include <gulutil.h>
#include <e32keys.h>
#include "FindTheBombAppView.h"
#include "FindTheBombAppUi.h"
#include "FindTheBomb.pan"
#include "findthebombdefs.h"
#include "findthebomb.mbg"
// Tile member functions
CFindTheBombTile::CFindTheBombTile()
{
}
CFindTheBombTile::~CFindTheBombTile()
{
}
void CFindTheBombTile::ConstructL(RWindow& aWindow)
{
SetContainerWindowL(aWindow);
// No call to ActivateL() as the window is activated by its container
}
void CFindTheBombTile::Draw(const TRect& /*aRect*/) const
{
CFbsBitmap* iSpriteImage;
CFbsBitmap* iSpriteMask;
TInt tileType;
tileType = iAppView->SquareStatus(this);
CWindowGc& gc = SystemGc();
TRect rect = Rect();
if (IsFocused())
{
gc.SetBrushColor(KRgbYellow);
}
gc.Clear(rect);
if (tileType!=ETileBlank)
{
TSize size;
size.SetSize(rect.iBr.iX- rect.iTl.iX, rect.iBr.iY - rect.iTl.iY);
rect.Shrink(size.iWidth/6,size.iHeight/6); // Shrink by about 15%
gc.SetPenStyle(CGraphicsContext::ESolidPen);
size.iWidth /=5; // Pen size set to just over 10% of the shape's size
size.iHeight /= 5;
gc.SetPenSize(size);
_LIT (KMultiBitmapFilename,"\\system\\apps\\findthebomb\\findthebomb.mbm");
switch (tileType)
{
case NumOfBomb :
{
iSpriteImage = iEikonEnv->CreateBitmapL(KMultiBitmapFilename,EMbmFindthebombPicover);
iSpriteMask = iEikonEnv->CreateBitmapL(KMultiBitmapFilename,EMbmFindthebombPicovermask);
}break;
case Bomb :
{
iSpriteImage = iEikonEnv->CreateBitmapL(KMultiBitmapFilename,EMbmFindthebombBomb);
iSpriteMask = iEikonEnv->CreateBitmapL(KMultiBitmapFilename,EMbmFindthebombBombmask);
}break;
case StartState:
{ iSpriteImage = iEikonEnv->CreateBitmapL(KMultiBitmapFilename,EMbmFindthebombStartpic);
iSpriteMask = iEikonEnv->CreateBitmapL(KMultiBitmapFilename,EMbmFindthebombStartpicmask);
}break;
case 1:
{
iSpriteImage = iEikonEnv->CreateBitmapL(KMultiBitmapFilename,EMbmFindthebombPic1);
iSpriteMask = iEikonEnv->CreateBitmapL(KMultiBitmapFilename,EMbmFindthebombPic1mask);
break;}
case 2:
{
iSpriteImage = iEikonEnv->CreateBitmapL(KMultiBitmapFilename,EMbmFindthebombPic2);
iSpriteMask = iEikonEnv->CreateBitmapL(KMultiBitmapFilename,EMbmFindthebombPic2mask);
break;}
case 3:
{
iSpriteImage = iEikonEnv->CreateBitmapL(KMultiBitmapFilename,EMbmFindthebombPic3);
iSpriteMask = iEikonEnv->CreateBitmapL(KMultiBitmapFilename,EMbmFindthebombPic3mask);
break;}
case 0:
{
break;
}
default:
{
iSpriteImage = iEikonEnv->CreateBitmapL(KMultiBitmapFilename,EMbmFindthebombPic4);
iSpriteMask = iEikonEnv->CreateBitmapL(KMultiBitmapFilename,EMbmFindthebombPic4mask);
break;}
}
if(tileType!=0)
{
if (IsFocused()&&tileType==StartState)
{
gc.SetBrushColor(KRgbYellow);
}
else
{
rect.iTl.iX-=2;
rect.iTl.iY-=2;
gc.BitBlt(rect.iTl,iSpriteImage);
gc.BitBltMasked(rect.iTl,iSpriteImage,rect,iSpriteMask,ETrue);
}
}
}
}
void CFindTheBombTile::SetOwnerAndObserver(CFindTheBombAppView* aControl)
{
iAppView = aControl;
SetObserver(aControl);
}
void CFindTheBombTile::TryHitL()
{
if (iAppView->TryHitSquareL(this))
{
DrawDeferred();
}
}
TKeyResponse CFindTheBombTile::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
TKeyResponse keyResponse = EKeyWasNotConsumed;
if (aType!=EEventKey)
{
return keyResponse;
}
switch (aKeyEvent.iCode)
{
case EKeyOK:
TryHitL();
keyResponse = EKeyWasConsumed;
DrawNow();
break;
default:
keyResponse = EKeyWasNotConsumed;
break;
}
return keyResponse;
}
TCoeInputCapabilities CFindTheBombTile::InputCapabilities() const
{
return TCoeInputCapabilities::ENavigation;
}
void CFindTheBombTile::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
if (aPointerEvent.iType == TPointerEvent::EButton1Down)
{
TryHitL();
}
}
void CFindTheBombTile::FocusChanged(TDrawNow aDrawNow)
{
DrawNow();
}
// App View member functions
#define KBorderWidth 10
#define KLineWidth ((KTilesPerRow > KTilesPerCol ? KTilesPerRow : KTilesPerCol) > 4 ? 2 : 4)
CFindTheBombAppView::CFindTheBombAppView()
{
}
CFindTheBombAppView::~CFindTheBombAppView()
{
for (TInt i=0; i<CountComponentControls(); i++)
{
delete iTiles[i];
}
iTiles.Close();
}
void CFindTheBombAppView::ConstructL(const TRect& aRect, MFindTheBombGameControl* aGameControl)
{
// Create a window for this application view
CreateWindowL();
iGameControl = aGameControl;
for (TInt i = 0; i < CountComponentControls(); i++)
{
User::LeaveIfError(iTiles.Append(CreateTileL()));
}
ComponentControl(0)->SetFocus(ETrue);
SetRect(aRect); // needs to be after tile creation - see SizeChanged()
;
// Activate the window, which makes it ready to be drawn
ActivateL();
}
CFindTheBombTile* CFindTheBombAppView::CreateTileL()
{
CFindTheBombTile * tile = new(ELeave) CFindTheBombTile;
CleanupStack::PushL(tile);
tile->ConstructL(Window());
CleanupStack::Pop(); // tile
tile->SetOwnerAndObserver(this);
return tile;
}
void CFindTheBombAppView::SizeChanged()
{
__ASSERT_DEBUG(iTiles[KNumberOfTiles-1], Panic(EFindTheBombNoTiles));
TSize controlSize = Rect().Size();
TSize tileSize;
tileSize.iWidth=2*((controlSize.iWidth-2*KBorderWidth-(KTilesPerRow-1)*KLineWidth)/(2*KTilesPerRow));
tileSize.iHeight=2*((controlSize.iHeight-2*KBorderWidth-(KTilesPerCol-1)*KLineWidth)/(2*KTilesPerCol));
iTileSide = tileSize.iWidth < tileSize.iHeight ? tileSize.iWidth :tileSize.iHeight;
TSize boardSize;
boardSize.iWidth = KTilesPerRow*iTileSide + (KTilesPerRow-1)*KLineWidth;
boardSize.iHeight = KTilesPerCol*iTileSide + (KTilesPerCol-1)*KLineWidth;
iBoardRect.iTl.iX = (controlSize.iWidth - boardSize.iWidth)/2;
iBoardRect.iTl.iY = (controlSize.iHeight - boardSize.iHeight)/2;
iBoardRect.iBr.iX = iBoardRect.iTl.iX + boardSize.iWidth;
iBoardRect.iBr.iY = iBoardRect.iTl.iY + boardSize.iHeight;
iBorderRect = iBoardRect;
iBorderRect.Grow(KBorderWidth,KBorderWidth);
for (TInt i=0; i<CountComponentControls(); i++)
{
TInt row = i / KTilesPerRow;
TInt col = i % KTilesPerRow;
TRect tileRect;
tileRect.iTl.iX = iBoardRect.iTl.iX + col * (iTileSide + KLineWidth);
tileRect.iTl.iY = iBoardRect.iTl.iY + row * (iTileSide + KLineWidth);
tileRect.iBr.iX = tileRect.iTl.iX + iTileSide;
tileRect.iBr.iY = tileRect.iTl.iY + iTileSide;
ComponentControl(i)->SetRect(tileRect);
}
}
void CFindTheBombAppView::ResetView()
{
MoveFocusTo(0);
DrawNow();
}
void CFindTheBombAppView::Draw(const TRect& /*aRect*/) const
{
CWindowGc& gc = SystemGc();
TRect rect = Rect();
// Draw outside the border
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.SetBrushColor(KRgbWhite);
DrawUtils::DrawBetweenRects(gc, rect, iBorderRect);
// Draw a border around the board
gc.SetBrushStyle(CGraphicsCo
aidebear
- 粉丝: 6
- 资源: 10
最新资源
- 动手学深度学习,沐神版配套代码,所有代码均可在jupyter中运行,内附有极为详尽的代码注释
- qaxbrowser-1.1.32574.52.exe (奇安信浏览器windows安装包)
- C#编写modbus tcp客户端读取modbus tcp服务器数据
- 某房地产瑞六补环境部分代码
- 基于Matlab实现无刷直流电机仿真(模型+说明文档).rar
- AllSort(直接插入排序,希尔排序,选择排序,堆排序,冒泡排序,快速排序,归并排序)
- 模拟qsort,改造冒泡排序使其能排序任意数据类型,即日常练习
- carsim+simulink联合仿真实现变道 包含路径规划算法+mpc轨迹跟踪算法 可选simulink版本和c++版本算法 可以适用于弯道道路,弯道车道保持,弯道变道 carsim内规划轨迹可视化
- 数组经典习题之顺序排序和二分查找和冒泡排序
- 永磁同步电机神经网络自抗扰控制,附带编程涉及到的公式文档,方便理解,模型顺利运行,效果好,位置电流双闭环采用二阶自抗扰控制,永磁同步电机三闭环控制,神经网络控制,自抗扰中状态扩张观测器与神经网络结合
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈