mirror of https://github.com/axmolengine/axmol.git
issue #439 ios and airplay midified.
This commit is contained in:
parent
1887417472
commit
48d57b88e2
|
@ -226,10 +226,8 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
|
|||
|
||||
s3eFile* pFile = s3eFileOpen(pszFileName, pszMode);
|
||||
|
||||
if (! pFile && getIsPopupNotify())
|
||||
{
|
||||
IwAssertMsg(GAME, pFile, ("Open file %s Failed. s3eFileError Code : %i", pszFileName, s3eFileGetError()));
|
||||
}
|
||||
|
||||
IwAssertMsg(GAME, pFile, ("Open file %s Failed. s3eFileError Code : %i", pszFileName, s3eFileGetError()));
|
||||
|
||||
int32 fileSize = s3eFileGetSize(pFile);
|
||||
*pSize=fileSize;
|
||||
|
@ -266,20 +264,5 @@ std::string& CCFileUtils::ccRemoveHDSuffixFromFile(std::string& path)
|
|||
return path;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Notification support when getFileData from a invalid file
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
static bool s_bPopupNotify = true;
|
||||
|
||||
void CCFileUtils::setIsPopupNotify(bool bNotify)
|
||||
{
|
||||
s_bPopupNotify = bNotify;
|
||||
}
|
||||
|
||||
bool CCFileUtils::getIsPopupNotify()
|
||||
{
|
||||
return s_bPopupNotify;
|
||||
}
|
||||
|
||||
NS_CC_END;
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include "CCImage.h"
|
||||
#include "CCCommon.h"
|
||||
#include "CCStdC.h"
|
||||
#include "CCFileUtils.h"
|
||||
#include "s3eFile.h"
|
||||
#include "IwImage.h"
|
||||
#include "IwUtil.h"
|
||||
|
@ -62,8 +61,52 @@ CCImage::~CCImage()
|
|||
bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/)
|
||||
{
|
||||
IW_CALLSTACK("UIImage::initWithImageFile");
|
||||
CCFileData data(CCFileUtils::fullPathFromRelativePath(strPath), "rb");
|
||||
return initWithImageData(data.getBuffer(), data.getSize(), eImgFmt);
|
||||
|
||||
bool bRet = false;
|
||||
FILE *fp = 0;
|
||||
unsigned char *buffer = NULL;
|
||||
do
|
||||
{
|
||||
// open file
|
||||
fp = fopen(strPath, "rb");
|
||||
CC_BREAK_IF(! fp);
|
||||
|
||||
// compute the length of file
|
||||
fseek(fp,0,SEEK_END);
|
||||
int size = ftell(fp);
|
||||
fseek(fp,0,SEEK_SET);
|
||||
|
||||
// allocate enough memory to save the data of file
|
||||
buffer = new unsigned char[size];
|
||||
CC_BREAK_IF(! buffer);
|
||||
|
||||
// read data
|
||||
size = fread(buffer, sizeof(unsigned char), size, fp);
|
||||
|
||||
if (kFmtJpg == eImgFmt)
|
||||
{
|
||||
bRet = _initWithJpgData(buffer, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
bRet = _initWithPngData(buffer, size);
|
||||
}
|
||||
} while (0);
|
||||
|
||||
CC_SAFE_DELETE_ARRAY(buffer);
|
||||
if (fp)
|
||||
{
|
||||
fclose(fp);
|
||||
}
|
||||
if (! bRet && CCImage::getIsPopupNotify())
|
||||
{
|
||||
std::string title = "cocos2d-x error!";
|
||||
std::string msg = "Load ";
|
||||
msg.append(strPath).append(" failed!");
|
||||
|
||||
IwError(("cocos2d-x error! Load %s failed", strPath));
|
||||
}
|
||||
return bRet;
|
||||
}
|
||||
|
||||
bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/* = eSrcFmtPng*/)
|
||||
|
@ -86,6 +129,16 @@ bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/*
|
|||
} while (0);
|
||||
return bRet;
|
||||
}
|
||||
static bool s_bPopupNotify = true;
|
||||
void CCImage::setIsPopupNotify(bool bNotify)
|
||||
{
|
||||
s_bPopupNotify = bNotify;
|
||||
}
|
||||
|
||||
bool CCImage::getIsPopupNotify()
|
||||
{
|
||||
return s_bPopupNotify;
|
||||
}
|
||||
|
||||
bool CCImage::_initWithJpgData(void * data, int nSize)
|
||||
{
|
||||
|
|
|
@ -336,7 +336,7 @@ public:
|
|||
}
|
||||
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
||||
{
|
||||
unsigned char * pBuffer = NULL;
|
||||
unsigned char * Buffer = NULL;
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -347,20 +347,12 @@ public:
|
|||
fseek(fp,0,SEEK_END);
|
||||
*pSize = ftell(fp);
|
||||
fseek(fp,0,SEEK_SET);
|
||||
pBuffer = new unsigned char[*pSize];
|
||||
*pSize = fread(pBuffer,sizeof(unsigned char), *pSize,fp);
|
||||
Buffer = new unsigned char[*pSize];
|
||||
*pSize = fread(Buffer,sizeof(unsigned char), *pSize,fp);
|
||||
fclose(fp);
|
||||
} while (0);
|
||||
|
||||
if (! pBuffer && getIsPopupNotify())
|
||||
{
|
||||
std::string title = "Notification";
|
||||
std::string msg = "Get data from file(";
|
||||
msg.append(pszFileName).append(") failed!");
|
||||
|
||||
CCMessageBox(msg.c_str(), title.c_str());
|
||||
}
|
||||
return pBuffer;
|
||||
return Buffer;
|
||||
}
|
||||
void CCFileUtils::setResource(const char* pszZipFileName, const char* pszResPath)
|
||||
{
|
||||
|
@ -370,18 +362,4 @@ public:
|
|||
{
|
||||
CCAssert(0, "Have not implement!");
|
||||
}
|
||||
|
||||
// notification support when getFileData from a invalid file
|
||||
static bool s_bPopupNotify = true;
|
||||
|
||||
void CCFileUtils::setIsPopupNotify(bool bNotify)
|
||||
{
|
||||
s_bPopupNotify = bNotify;
|
||||
}
|
||||
|
||||
bool CCFileUtils::getIsPopupNotify()
|
||||
{
|
||||
return s_bPopupNotify;
|
||||
}
|
||||
|
||||
}//namespace cocos2d
|
||||
|
|
|
@ -24,7 +24,6 @@ THE SOFTWARE.
|
|||
#include <Foundation/Foundation.h>
|
||||
#include <UIKit/UIKit.h>
|
||||
#include "CCImage.h"
|
||||
#include "CCFileUtils.h"
|
||||
#include <string>
|
||||
|
||||
typedef struct
|
||||
|
@ -449,6 +448,13 @@ static bool _initWithString(const char * pText, cocos2d::CCImage::ETextAlign eAl
|
|||
|
||||
NS_CC_BEGIN;
|
||||
|
||||
static bool s_bPopupNotify = true;
|
||||
|
||||
void CCMessageBox(const std::string& msg, const std::string& title)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CCImage::CCImage()
|
||||
: m_nWidth(0)
|
||||
, m_nHeight(0)
|
||||
|
@ -467,8 +473,30 @@ CCImage::~CCImage()
|
|||
|
||||
bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/)
|
||||
{
|
||||
CCFileData data(CCFileUtils::fullPathFromRelativePath(strPath), "rb");
|
||||
return initWithImageData(data.getBuffer(), data.getSize(), eImgFmt);
|
||||
bool bRet = false;
|
||||
tImageInfo info = {0};
|
||||
|
||||
switch (eImgFmt)
|
||||
{
|
||||
case kFmtPng:
|
||||
case kFmtJpg:
|
||||
bRet = _initWithFile(strPath, &info);
|
||||
break;
|
||||
default:
|
||||
// unsupported image type
|
||||
bRet = false;
|
||||
break;
|
||||
}
|
||||
if (bRet)
|
||||
{
|
||||
m_nHeight = (short)info.height;
|
||||
m_nWidth = (short)info.width;
|
||||
m_nBitsPerComponent = info.bitsPerComponent;
|
||||
m_bHasAlpha = info.hasAlpha;
|
||||
m_bPreMulti = info.isPremultipliedAlpha;
|
||||
m_pData = info.data;
|
||||
}
|
||||
return bRet;
|
||||
}
|
||||
|
||||
bool CCImage::initWithImageData(void * pData, int nDataLen, EImageFormat eFmt/* = eSrcFmtPng*/)
|
||||
|
@ -518,5 +546,15 @@ bool CCImage::initWithString(
|
|||
return true;
|
||||
}
|
||||
|
||||
void CCImage::setIsPopupNotify(bool bNotify)
|
||||
{
|
||||
s_bPopupNotify = bNotify;
|
||||
}
|
||||
|
||||
bool CCImage::getIsPopupNotify()
|
||||
{
|
||||
return s_bPopupNotify;
|
||||
}
|
||||
|
||||
NS_CC_END;
|
||||
|
||||
|
|
Loading…
Reference in New Issue