From 15e3a6b1cf601f9c30fa240c8bea0c360ac35383 Mon Sep 17 00:00:00 2001 From: dumganhar Date: Wed, 23 Nov 2011 18:40:36 +0800 Subject: [PATCH] update CCFileUtils_bada.cpp and CCImage_bada.cpp --- cocos2dx/platform/bada/CCFileUtils_bada.cpp | 56 +++++++++++++-------- cocos2dx/platform/bada/CCImage_bada.cpp | 41 +++++++-------- 2 files changed, 52 insertions(+), 45 deletions(-) diff --git a/cocos2dx/platform/bada/CCFileUtils_bada.cpp b/cocos2dx/platform/bada/CCFileUtils_bada.cpp index 739e3b659b..a8fbfc5d89 100644 --- a/cocos2dx/platform/bada/CCFileUtils_bada.cpp +++ b/cocos2dx/platform/bada/CCFileUtils_bada.cpp @@ -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 * pBuffer = NULL; + unsigned char * pData = 0; + string fullPath; - do - { - // read the file from hardware - FILE *fp = fopen(pszFileName, pszMode); - CC_BREAK_IF(!fp); + if ((! pszFileName) || (! pszMode)) + { + return 0; + } - 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); - fclose(fp); - } while (0); + fullPath = fullPathFromRelativePath(pszFileName); - if (! pBuffer && getIsPopupNotify()) - { - std::string title = "Notification"; - std::string msg = "Get data from file("; - msg.append(pszFileName).append(") failed!"); + do + { + // read rrom other path than user set it + FILE *fp = fopen(fullPath.c_str(), pszMode); + CC_BREAK_IF(!fp); - CCMessageBox(msg.c_str(), title.c_str()); - } - return pBuffer; + unsigned long size; + fseek(fp,0,SEEK_END); + 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) diff --git a/cocos2dx/platform/bada/CCImage_bada.cpp b/cocos2dx/platform/bada/CCImage_bada.cpp index dcdc9b874c..12460d1e93 100644 --- a/cocos2dx/platform/bada/CCImage_bada.cpp +++ b/cocos2dx/platform/bada/CCImage_bada.cpp @@ -43,11 +43,12 @@ public: 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; do { + CC_BREAK_IF(pszText == NULL || strlen(pszText) <= 0); // text Osp::Base::String strText(pszText); // Set a font to the TextElement @@ -55,7 +56,7 @@ public: font.Construct(FONT_STYLE_PLAIN, fontSize); // calculate text size - if (CCSize::CCSizeEqualToSize(dimensions, CCSizeZero)) + if (dimensions.width <= 0) { Dimension dim; font.GetTextExtent(strText, strText.GetLength(), dim); @@ -63,16 +64,11 @@ public: dimensions.height = dim.height; } - CC_SAFE_DELETE(m_pCanvas); - - CC_BREAK_IF(dimensions.width <= 0 || dimensions.height <= 0); - - m_pCanvas = new Canvas(); - m_pCanvas->Construct(Rectangle(0, 0, dimensions.width, dimensions.height)); + CC_BREAK_IF(dimensions.width <= 0); // Create an EnrichedText m_pEnrichedText = new EnrichedText(); - m_pEnrichedText->Construct(Dimension(dimensions.width, dimensions.height)); + m_pEnrichedText->Construct(Dimension(dimensions.width, 10)); switch (alignment) { @@ -130,6 +126,13 @@ public: // Add the TextElement to the EnrichedText 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_pEnrichedText->RemoveAllTextElements(true); @@ -169,7 +172,7 @@ bool CCImage::initWithString( BitmapDC& dc = sharedBitmapDC(); - CCSize size(nWidth, nHeight); + Dimension size(nWidth, nHeight); bRet = dc.drawText(pText, size, eAlignMask, pFontName, nSize); @@ -186,23 +189,13 @@ bool CCImage::initWithString( CC_BREAK_IF(!m_pData); memcpy(m_pData, bufferInfo.pPixels, nLen); - if (bufferInfo.bitsPerPixel == 32) - { - if (bufferInfo.width * 4 != bufferInfo.pitch) - { - m_nWidth = bufferInfo.pitch / 4; - } - else - { - m_nWidth = bufferInfo.width; - } - } - - m_nHeight = bufferInfo.height; + int iBytesPerPixel = bufferInfo.bitsPerPixel/8; + m_nWidth = bufferInfo.pitch / iBytesPerPixel; + m_nHeight = bufferInfo.height; m_bHasAlpha = true; m_bPreMulti = false; - m_nBitsPerComponent = bufferInfo.bitsPerPixel / 4; + m_nBitsPerComponent = 8; dc.m_pCanvas->Unlock(); bRet = true;