📄 sourcemapinfo.cpp
字号:
/*
============================================================================
Name : SourceMapInfo.cpp
Author :
Version : 1.0
Copyright : Your copyright notice
Description : CSourceMapInfo implementation
============================================================================
*/
#include "map/SourceMapInfo.h"
#include "Common.h"
#include <eikenv.h>
CSourceMapInfo::CSourceMapInfo(RFs& aFs, CImageHelper& aImgHelper) :
iImgHelper(aImgHelper), iFs(aFs)
{
// No implementation required
}
CSourceMapInfo::~CSourceMapInfo()
{
delete iMapImage;
iMapImage = NULL;
delete iMaskMapImage;
iMaskMapImage = NULL;
iMapItems.Reset();
}
CSourceMapInfo* CSourceMapInfo::NewLC(RFs& aFs, CImageHelper& aImgHelper)
{
CSourceMapInfo* self = new (ELeave)CSourceMapInfo(aFs, aImgHelper);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
CSourceMapInfo* CSourceMapInfo::NewL(RFs& aFs, CImageHelper& aImgHelper)
{
CSourceMapInfo* self=CSourceMapInfo::NewLC(aFs, aImgHelper);
CleanupStack::Pop(); // self;
return self;
}
void CSourceMapInfo::LoadSourceMapL(const TInt aIndex)
{
// 将以前的内容清空
delete iMapImage;
iMapImage = NULL;
delete iMaskMapImage;
iMaskMapImage = NULL;
iMapItems.Reset();
iIndex = aIndex - 1;
// 创建两个图像对象
iMapImage = new (ELeave)CFbsBitmap;
iMaskMapImage = new (ELeave)CFbsBitmap;
// 首先创建文件名
TFileName imgFileName(KSourcePath);
imgFileName.AppendNum(aIndex);
imgFileName.Append(KMapImageExt);
// 调用伪同步方法获取图像文件
iImgHelper.LoadPngImageL(imgFileName, *iMapImage, *iMaskMapImage);
// 读取地图信息
ReadInfosFromFileL(aIndex);
}
/**
* 从文件读取源图信息
*/
void CSourceMapInfo::ReadInfosFromFileL(TInt aIndex)
{
RFile file;
CleanupClosePushL(file);
// 创建信息文件名
TFileName infoFileName(KSourcePath);
infoFileName.AppendNum(aIndex);
infoFileName.Append(KMapInfoExt);
// 打开文件
User::LeaveIfError(file.Open(iFs, infoFileName, EFileRead));
CleanupStack::Pop(&file);
// 读取文件大小并构造描述符
TInt fileSize;
User::LeaveIfError(file.Size(fileSize));
HBufC8* fileContent = HBufC8::NewLC(fileSize);
TPtr8 ptr = fileContent->Des();
User::LeaveIfError(file.Read(ptr));
// 项个数 = 长度 / 4
TInt itemsCount = fileSize / 4;
for (TInt n = 0; n < itemsCount; n++)
{
TSourceMapItemInfo itemInfo;
itemInfo.ParseL(ptr, n);
// 如果四个值都>0
if (itemInfo.iStartX > 0 && itemInfo.iStartY > 0 && itemInfo.iEndX > 0 && itemInfo.iEndY > 0)
{
itemInfo.iStartX--;
itemInfo.iStartY--;
itemInfo.iEndX--;
itemInfo.iEndY--;
iMapItems.Append(itemInfo);
}
}
CleanupStack::PopAndDestroy(fileContent);
file.Close();
}
void CSourceMapInfo::ConstructL()
{
}
const CFbsBitmap& CSourceMapInfo::GetMapImage() const
{
return *iMapImage;
}
const CFbsBitmap& CSourceMapInfo::GetMaskMapImage() const
{
return *iMaskMapImage;
}
const RArray<TSourceMapItemInfo>& CSourceMapInfo::GetMapItems() const
{
return iMapItems;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -