mirror of https://github.com/axmolengine/axmol.git
Merge branch 'newest' into master_base
This commit is contained in:
commit
cfa42fa8a1
|
@ -69,31 +69,45 @@ const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const
|
||||||
|
|
||||||
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
||||||
{
|
{
|
||||||
unsigned char * pBuffer = NULL;
|
unsigned char * pData = 0;
|
||||||
|
string fullPath;
|
||||||
|
|
||||||
do
|
if ((! pszFileName) || (! pszMode))
|
||||||
{
|
{
|
||||||
// read the file from hardware
|
return 0;
|
||||||
FILE *fp = fopen(pszFileName, pszMode);
|
}
|
||||||
CC_BREAK_IF(!fp);
|
|
||||||
|
|
||||||
fseek(fp,0,SEEK_END);
|
fullPath = fullPathFromRelativePath(pszFileName);
|
||||||
*pSize = ftell(fp);
|
|
||||||
fseek(fp,0,SEEK_SET);
|
|
||||||
pBuffer = new unsigned char[*pSize];
|
|
||||||
*pSize = fread(pBuffer,sizeof(unsigned char), *pSize,fp);
|
|
||||||
fclose(fp);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
if (! pBuffer && getIsPopupNotify())
|
do
|
||||||
{
|
{
|
||||||
std::string title = "Notification";
|
// read rrom other path than user set it
|
||||||
std::string msg = "Get data from file(";
|
FILE *fp = fopen(fullPath.c_str(), pszMode);
|
||||||
msg.append(pszFileName).append(") failed!");
|
CC_BREAK_IF(!fp);
|
||||||
|
|
||||||
CCMessageBox(msg.c_str(), title.c_str());
|
unsigned long size;
|
||||||
}
|
fseek(fp,0,SEEK_END);
|
||||||
return pBuffer;
|
size = ftell(fp);
|
||||||
|
fseek(fp,0,SEEK_SET);
|
||||||
|
pData = new unsigned char[size];
|
||||||
|
size = fread(pData,sizeof(unsigned char), size,fp);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
if (pSize)
|
||||||
|
{
|
||||||
|
*pSize = size;
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
if (! pData && getIsPopupNotify())
|
||||||
|
{
|
||||||
|
std::string title = "Notification";
|
||||||
|
std::string msg = "Get data from file(";
|
||||||
|
msg.append(fullPath.c_str()).append(") failed!");
|
||||||
|
CCMessageBox(msg.c_str(), title.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
return pData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCFileUtils::setResource(const char* pszZipFileName)
|
void CCFileUtils::setResource(const char* pszZipFileName)
|
||||||
|
|
|
@ -43,11 +43,12 @@ public:
|
||||||
CC_SAFE_DELETE(m_pCanvas);
|
CC_SAFE_DELETE(m_pCanvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool drawText(const char * pszText, CCSize& dimensions, CCImage::ETextAlign alignment, const char * fontName = NULL, int fontSize = 0)
|
bool drawText(const char * pszText, Dimension& dimensions, CCImage::ETextAlign alignment, const char * fontName = NULL, int fontSize = 0)
|
||||||
{
|
{
|
||||||
bool nRet = false;
|
bool nRet = false;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
CC_BREAK_IF(pszText == NULL || strlen(pszText) <= 0);
|
||||||
// text
|
// text
|
||||||
Osp::Base::String strText(pszText);
|
Osp::Base::String strText(pszText);
|
||||||
// Set a font to the TextElement
|
// Set a font to the TextElement
|
||||||
|
@ -55,7 +56,7 @@ public:
|
||||||
font.Construct(FONT_STYLE_PLAIN, fontSize);
|
font.Construct(FONT_STYLE_PLAIN, fontSize);
|
||||||
|
|
||||||
// calculate text size
|
// calculate text size
|
||||||
if (CCSize::CCSizeEqualToSize(dimensions, CCSizeZero))
|
if (dimensions.width <= 0)
|
||||||
{
|
{
|
||||||
Dimension dim;
|
Dimension dim;
|
||||||
font.GetTextExtent(strText, strText.GetLength(), dim);
|
font.GetTextExtent(strText, strText.GetLength(), dim);
|
||||||
|
@ -63,16 +64,11 @@ public:
|
||||||
dimensions.height = dim.height;
|
dimensions.height = dim.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
CC_SAFE_DELETE(m_pCanvas);
|
CC_BREAK_IF(dimensions.width <= 0);
|
||||||
|
|
||||||
CC_BREAK_IF(dimensions.width <= 0 || dimensions.height <= 0);
|
|
||||||
|
|
||||||
m_pCanvas = new Canvas();
|
|
||||||
m_pCanvas->Construct(Rectangle(0, 0, dimensions.width, dimensions.height));
|
|
||||||
|
|
||||||
// Create an EnrichedText
|
// Create an EnrichedText
|
||||||
m_pEnrichedText = new EnrichedText();
|
m_pEnrichedText = new EnrichedText();
|
||||||
m_pEnrichedText->Construct(Dimension(dimensions.width, dimensions.height));
|
m_pEnrichedText->Construct(Dimension(dimensions.width, 10));
|
||||||
|
|
||||||
switch (alignment)
|
switch (alignment)
|
||||||
{
|
{
|
||||||
|
@ -130,6 +126,13 @@ public:
|
||||||
// Add the TextElement to the EnrichedText
|
// Add the TextElement to the EnrichedText
|
||||||
m_pEnrichedText->Add(*pTextElement);
|
m_pEnrichedText->Add(*pTextElement);
|
||||||
|
|
||||||
|
m_pEnrichedText->Refresh();
|
||||||
|
dimensions.height = m_pEnrichedText->GetTotalLineHeight();
|
||||||
|
m_pEnrichedText->SetSize(dimensions.width, dimensions.height);
|
||||||
|
|
||||||
|
CC_SAFE_DELETE(m_pCanvas);
|
||||||
|
m_pCanvas = new Canvas();
|
||||||
|
m_pCanvas->Construct(Rectangle(0, 0, dimensions.width, dimensions.height));
|
||||||
m_pCanvas->DrawText(Point(0, 0), *m_pEnrichedText);
|
m_pCanvas->DrawText(Point(0, 0), *m_pEnrichedText);
|
||||||
|
|
||||||
m_pEnrichedText->RemoveAllTextElements(true);
|
m_pEnrichedText->RemoveAllTextElements(true);
|
||||||
|
@ -169,7 +172,7 @@ bool CCImage::initWithString(
|
||||||
|
|
||||||
BitmapDC& dc = sharedBitmapDC();
|
BitmapDC& dc = sharedBitmapDC();
|
||||||
|
|
||||||
CCSize size(nWidth, nHeight);
|
Dimension size(nWidth, nHeight);
|
||||||
|
|
||||||
bRet = dc.drawText(pText, size, eAlignMask, pFontName, nSize);
|
bRet = dc.drawText(pText, size, eAlignMask, pFontName, nSize);
|
||||||
|
|
||||||
|
@ -186,23 +189,13 @@ bool CCImage::initWithString(
|
||||||
CC_BREAK_IF(!m_pData);
|
CC_BREAK_IF(!m_pData);
|
||||||
memcpy(m_pData, bufferInfo.pPixels, nLen);
|
memcpy(m_pData, bufferInfo.pPixels, nLen);
|
||||||
|
|
||||||
if (bufferInfo.bitsPerPixel == 32)
|
int iBytesPerPixel = bufferInfo.bitsPerPixel/8;
|
||||||
{
|
|
||||||
if (bufferInfo.width * 4 != bufferInfo.pitch)
|
|
||||||
{
|
|
||||||
m_nWidth = bufferInfo.pitch / 4;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_nWidth = bufferInfo.width;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_nHeight = bufferInfo.height;
|
|
||||||
|
|
||||||
|
m_nWidth = bufferInfo.pitch / iBytesPerPixel;
|
||||||
|
m_nHeight = bufferInfo.height;
|
||||||
m_bHasAlpha = true;
|
m_bHasAlpha = true;
|
||||||
m_bPreMulti = false;
|
m_bPreMulti = false;
|
||||||
m_nBitsPerComponent = bufferInfo.bitsPerPixel / 4;
|
m_nBitsPerComponent = 8;
|
||||||
dc.m_pCanvas->Unlock();
|
dc.m_pCanvas->Unlock();
|
||||||
|
|
||||||
bRet = true;
|
bRet = true;
|
||||||
|
|
Loading…
Reference in New Issue