mirror of https://github.com/axmolengine/axmol.git
Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into developEventTrigger
This commit is contained in:
commit
5acb556c74
6
AUTHORS
6
AUTHORS
|
@ -746,6 +746,12 @@ Developers:
|
|||
|
||||
ucchen
|
||||
Exposed the missing data structures of Spine to JS.
|
||||
|
||||
justmao945
|
||||
Corrected the definition of CMake variables.
|
||||
|
||||
maksqwe
|
||||
Fixed string size check in BitmapDC::utf8ToUtf16 on win32 and assert condition in TriggerMng.
|
||||
|
||||
Retired Core Developers:
|
||||
WenSheng Yang
|
||||
|
|
|
@ -6,6 +6,7 @@ cocos2d-x-3.0rc0 Feb.?? 2014
|
|||
[NEW] Using python to automatically generate script bindings codes.
|
||||
[NEW] Linux javascript bindings support.
|
||||
|
||||
[FIX] Supports 'setTimeout' and 'setInterval' in JSB.
|
||||
[FIX] Exposes the missing data structures of Spine to JS.
|
||||
[FIX] Node::setRotation() moves opposite when node has a physics body.
|
||||
[FIX] A string which only contains CJK characters can't make a line-break when it's needed.
|
||||
|
|
|
@ -1 +1 @@
|
|||
5bde2def1fece71a2464526c90939b9999ed05f3
|
||||
a7af0ccd05e86210026f7c72d6f5a7be8e17fe3d
|
|
@ -446,10 +446,23 @@ Image* RenderTexture::newImage(bool fliimage)
|
|||
break;
|
||||
}
|
||||
|
||||
this->begin();
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _FBO);
|
||||
|
||||
//TODO move this to configration, so we don't check it every time
|
||||
/* Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers.
|
||||
*/
|
||||
if (Configuration::getInstance()->checkForGLExtension("GL_QCOM"))
|
||||
{
|
||||
// -- bind a temporary texture so we can clear the render buffer without losing our texture
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _textureCopy->getName(), 0);
|
||||
CHECK_GL_ERROR_DEBUG();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture->getName(), 0);
|
||||
}
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glReadPixels(0,0,savedBufferWidth, savedBufferHeight,GL_RGBA,GL_UNSIGNED_BYTE, tempData);
|
||||
this->end();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _oldFBO);
|
||||
|
||||
if ( fliimage ) // -- flip is only required when saving image to file
|
||||
{
|
||||
|
|
|
@ -541,8 +541,9 @@ void SpriteBatchNode::removeSpriteFromAtlas(Sprite *sprite)
|
|||
{
|
||||
auto next = std::next(it);
|
||||
|
||||
Sprite *spr = nullptr;
|
||||
for(; next != _descendants.end(); ++next) {
|
||||
Sprite *spr = *next;
|
||||
spr = *next;
|
||||
spr->setAtlasIndex( spr->getAtlasIndex() - 1 );
|
||||
}
|
||||
|
||||
|
@ -649,10 +650,11 @@ SpriteBatchNode * SpriteBatchNode::addSpriteWithoutQuad(Sprite*child, int z, int
|
|||
child->setAtlasIndex(z);
|
||||
|
||||
// XXX: optimize with a binary search
|
||||
auto it = std::begin(_descendants);
|
||||
for(const auto &sprite: _descendants) {
|
||||
if(sprite->getAtlasIndex() >= z)
|
||||
std::next(it);
|
||||
auto it = _descendants.begin();
|
||||
for (; it != _descendants.end(); ++it)
|
||||
{
|
||||
if((*it)->getAtlasIndex() >= z)
|
||||
break;
|
||||
}
|
||||
|
||||
_descendants.insert(it, child);
|
||||
|
|
|
@ -753,7 +753,7 @@ bool Texture2D::initWithImage(Image *image, PixelFormat format)
|
|||
if (outTempData != nullptr && outTempData != tempData)
|
||||
{
|
||||
|
||||
delete [] outTempData;
|
||||
free(outTempData);
|
||||
}
|
||||
|
||||
// set the premultiplied tag
|
||||
|
@ -781,32 +781,32 @@ Texture2D::PixelFormat Texture2D::convertI8ToFormat(const unsigned char* data, s
|
|||
{
|
||||
case PixelFormat::RGBA8888:
|
||||
*outDataLen = dataLen*4;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertI8ToRGBA8888(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::RGB888:
|
||||
*outDataLen = dataLen*3;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertI8ToRGB888(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::RGB565:
|
||||
*outDataLen = dataLen*2;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertI8ToRGB565(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::AI88:
|
||||
*outDataLen = dataLen*2;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertI8ToAI88(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::RGBA4444:
|
||||
*outDataLen = dataLen*2;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertI8ToRGBA4444(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::RGB5A1:
|
||||
*outDataLen = dataLen*2;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertI8ToRGB5A1(data, dataLen, *outData);
|
||||
break;
|
||||
default:
|
||||
|
@ -830,37 +830,37 @@ Texture2D::PixelFormat Texture2D::convertAI88ToFormat(const unsigned char* data,
|
|||
{
|
||||
case PixelFormat::RGBA8888:
|
||||
*outDataLen = dataLen*2;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertAI88ToRGBA8888(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::RGB888:
|
||||
*outDataLen = dataLen/2*3;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertAI88ToRGB888(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::RGB565:
|
||||
*outDataLen = dataLen;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertAI88ToRGB565(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::A8:
|
||||
*outDataLen = dataLen/2;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertAI88ToA8(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::I8:
|
||||
*outDataLen = dataLen/2;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertAI88ToI8(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::RGBA4444:
|
||||
*outDataLen = dataLen;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertAI88ToRGBA4444(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::RGB5A1:
|
||||
*outDataLen = dataLen;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertAI88ToRGB5A1(data, dataLen, *outData);
|
||||
break;
|
||||
default:
|
||||
|
@ -885,32 +885,32 @@ Texture2D::PixelFormat Texture2D::convertRGB888ToFormat(const unsigned char* dat
|
|||
{
|
||||
case PixelFormat::RGBA8888:
|
||||
*outDataLen = dataLen/3*4;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertRGB888ToRGBA8888(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::RGB565:
|
||||
*outDataLen = dataLen/3*2;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertRGB888ToRGB565(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::I8:
|
||||
*outDataLen = dataLen/3;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertRGB888ToI8(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::AI88:
|
||||
*outDataLen = dataLen/3*2;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertRGB888ToAI88(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::RGBA4444:
|
||||
*outDataLen = dataLen/3*2;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertRGB888ToRGBA4444(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::RGB5A1:
|
||||
*outDataLen = dataLen;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertRGB888ToRGB5A1(data, dataLen, *outData);
|
||||
break;
|
||||
default:
|
||||
|
@ -934,37 +934,37 @@ Texture2D::PixelFormat Texture2D::convertRGBA8888ToFormat(const unsigned char* d
|
|||
{
|
||||
case PixelFormat::RGB888:
|
||||
*outDataLen = dataLen/4*3;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertRGBA8888ToRGB888(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::RGB565:
|
||||
*outDataLen = dataLen/2;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertRGBA8888ToRGB565(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::A8:
|
||||
*outDataLen = dataLen/4;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertRGBA8888ToA8(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::I8:
|
||||
*outDataLen = dataLen/4;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertRGBA8888ToI8(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::AI88:
|
||||
*outDataLen = dataLen/2;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertRGBA8888ToAI88(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::RGBA4444:
|
||||
*outDataLen = dataLen/2;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertRGBA8888ToRGBA4444(data, dataLen, *outData);
|
||||
break;
|
||||
case PixelFormat::RGB5A1:
|
||||
*outDataLen = dataLen/2;
|
||||
*outData = new unsigned char[*outDataLen];
|
||||
*outData = (unsigned char*)malloc(sizeof(unsigned char) * (*outDataLen));
|
||||
convertRGBA8888ToRGB5A1(data, dataLen, *outData);
|
||||
break;
|
||||
default:
|
||||
|
@ -1094,7 +1094,7 @@ bool Texture2D::initWithString(const char *text, const FontDefinition& textDefin
|
|||
|
||||
if (outTempData != nullptr && outTempData != outData.getBytes())
|
||||
{
|
||||
delete [] outTempData;
|
||||
free(outTempData);
|
||||
}
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
||||
_hasPremultipliedAlpha = true;
|
||||
|
|
|
@ -948,7 +948,7 @@ bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen)
|
|||
}
|
||||
png_read_image(png_ptr, row_pointers);
|
||||
|
||||
png_read_end(png_ptr, NULL);
|
||||
png_read_end(png_ptr, nullptr);
|
||||
|
||||
_preMulti = false;
|
||||
|
||||
|
@ -1094,7 +1094,7 @@ bool Image::initWithTiffData(const unsigned char * data, ssize_t dataLen)
|
|||
tiffMapProc,
|
||||
tiffUnmapProc);
|
||||
|
||||
CC_BREAK_IF(NULL == tif);
|
||||
CC_BREAK_IF(nullptr == tif);
|
||||
|
||||
uint32 w = 0, h = 0;
|
||||
uint16 bitsPerSample = 0, samplePerPixel = 0, planarConfig = 0;
|
||||
|
@ -1116,7 +1116,7 @@ bool Image::initWithTiffData(const unsigned char * data, ssize_t dataLen)
|
|||
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
|
||||
|
||||
uint32* raster = (uint32*) _TIFFmalloc(npixels * sizeof (uint32));
|
||||
if (raster != NULL)
|
||||
if (raster != nullptr)
|
||||
{
|
||||
if (TIFFReadRGBAImageOriented(tif, w, h, raster, ORIENTATION_TOPLEFT, 0))
|
||||
{
|
||||
|
@ -1851,7 +1851,7 @@ bool Image::initWithWebpData(const unsigned char * data, ssize_t dataLen)
|
|||
if (WebPDecode(static_cast<const uint8_t*>(data), dataLen, &config) != VP8_STATUS_OK)
|
||||
{
|
||||
free(_data);
|
||||
_data = NULL;
|
||||
_data = nullptr;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1941,21 +1941,21 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
|
|||
png_bytep *row_pointers;
|
||||
|
||||
fp = fopen(filePath.c_str(), "wb");
|
||||
CC_BREAK_IF(NULL == fp);
|
||||
CC_BREAK_IF(nullptr == fp);
|
||||
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
|
||||
|
||||
if (NULL == png_ptr)
|
||||
if (nullptr == png_ptr)
|
||||
{
|
||||
fclose(fp);
|
||||
break;
|
||||
}
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (NULL == info_ptr)
|
||||
if (nullptr == info_ptr)
|
||||
{
|
||||
fclose(fp);
|
||||
png_destroy_write_struct(&png_ptr, NULL);
|
||||
png_destroy_write_struct(&png_ptr, nullptr);
|
||||
break;
|
||||
}
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA && CC_TARGET_PLATFORM != CC_PLATFORM_NACL)
|
||||
|
@ -1987,14 +1987,14 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
|
|||
png_set_packing(png_ptr);
|
||||
|
||||
row_pointers = (png_bytep *)malloc(_height * sizeof(png_bytep));
|
||||
if(row_pointers == NULL)
|
||||
if(row_pointers == nullptr)
|
||||
{
|
||||
fclose(fp);
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
break;
|
||||
}
|
||||
|
||||
if (hasAlpha())
|
||||
if (!hasAlpha())
|
||||
{
|
||||
for (int i = 0; i < (int)_height; i++)
|
||||
{
|
||||
|
@ -2004,14 +2004,14 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
|
|||
png_write_image(png_ptr, row_pointers);
|
||||
|
||||
free(row_pointers);
|
||||
row_pointers = NULL;
|
||||
row_pointers = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isToRGB)
|
||||
{
|
||||
unsigned char *pTempData = static_cast<unsigned char*>(malloc(_width * _height * 3 * sizeof(unsigned char*)));
|
||||
if (NULL == pTempData)
|
||||
if (nullptr == pTempData)
|
||||
{
|
||||
fclose(fp);
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
|
@ -2036,7 +2036,7 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
|
|||
png_write_image(png_ptr, row_pointers);
|
||||
|
||||
free(row_pointers);
|
||||
row_pointers = NULL;
|
||||
row_pointers = nullptr;
|
||||
|
||||
if (pTempData != nullptr)
|
||||
{
|
||||
|
@ -2053,14 +2053,14 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
|
|||
png_write_image(png_ptr, row_pointers);
|
||||
|
||||
free(row_pointers);
|
||||
row_pointers = NULL;
|
||||
row_pointers = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
|
||||
png_free(png_ptr, palette);
|
||||
palette = NULL;
|
||||
palette = nullptr;
|
||||
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
|
||||
|
@ -2085,7 +2085,7 @@ bool Image::saveImageToJPG(const std::string& filePath)
|
|||
/* Now we can initialize the JPEG compression object. */
|
||||
jpeg_create_compress(&cinfo);
|
||||
|
||||
CC_BREAK_IF((outfile = fopen(filePath.c_str(), "wb")) == NULL);
|
||||
CC_BREAK_IF((outfile = fopen(filePath.c_str(), "wb")) == nullptr);
|
||||
|
||||
jpeg_stdio_dest(&cinfo, outfile);
|
||||
|
||||
|
@ -2103,7 +2103,7 @@ bool Image::saveImageToJPG(const std::string& filePath)
|
|||
if (hasAlpha())
|
||||
{
|
||||
unsigned char *pTempData = static_cast<unsigned char*>(malloc(_width * _height * 3 * sizeof(unsigned char)));
|
||||
if (NULL == pTempData)
|
||||
if (nullptr == pTempData)
|
||||
{
|
||||
jpeg_finish_compress(&cinfo);
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
|
|
|
@ -78,10 +78,6 @@ public:
|
|||
|
||||
~BitmapDC(void)
|
||||
{
|
||||
if (_data)
|
||||
{
|
||||
delete [] _data;
|
||||
}
|
||||
}
|
||||
|
||||
bool getBitmapFromJavaShadowStroke( const char *text,
|
||||
|
@ -115,11 +111,11 @@ public:
|
|||
// Do a full lookup for the font path using FileUtils in case the given font name is a relative path to a font file asset,
|
||||
// or the path has been mapped to a different location in the app package:
|
||||
std::string fullPathOrFontName = FileUtils::getInstance()->fullPathForFilename(pFontName);
|
||||
|
||||
// If the path name returned includes the 'assets' dir then that needs to be removed, because the android.content.Context
|
||||
// requires this portion of the path to be omitted for assets inside the app package.
|
||||
if (fullPathOrFontName.find("assets/") == 0)
|
||||
{
|
||||
|
||||
// If the path name returned includes the 'assets' dir then that needs to be removed, because the android.content.Context
|
||||
// requires this portion of the path to be omitted for assets inside the app package.
|
||||
if (fullPathOrFontName.find("assets/") == 0)
|
||||
{
|
||||
fullPathOrFontName = fullPathOrFontName.substr(strlen("assets/")); // Chop out the 'assets/' portion of the path.
|
||||
}
|
||||
|
||||
|
@ -163,7 +159,6 @@ public:
|
|||
int _width;
|
||||
int _height;
|
||||
unsigned char *_data;
|
||||
JNIEnv *env;
|
||||
};
|
||||
|
||||
static BitmapDC& sharedBitmapDC()
|
||||
|
@ -222,7 +217,7 @@ extern "C"
|
|||
cocos2d::BitmapDC& bitmapDC = cocos2d::sharedBitmapDC();
|
||||
bitmapDC._width = width;
|
||||
bitmapDC._height = height;
|
||||
bitmapDC._data = new unsigned char[size];
|
||||
bitmapDC._data = (unsigned char*)malloc(sizeof(unsigned char) * size);
|
||||
env->GetByteArrayRegion(pixels, 0, size, (jbyte*)bitmapDC._data);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -326,7 +326,7 @@ static bool _initWithString(const char * text, cocos2d::Device::TextAlign align,
|
|||
dim.height += shadowStrokePaddingY;
|
||||
|
||||
|
||||
unsigned char* data = new unsigned char[(int)(dim.width * dim.height * 4)];
|
||||
unsigned char* data = (unsigned char*)malloc(sizeof(unsigned char) * (int)(dim.width * dim.height * 4));
|
||||
memset(data, 0, (int)(dim.width * dim.height * 4));
|
||||
|
||||
// draw text
|
||||
|
@ -341,7 +341,7 @@ static bool _initWithString(const char * text, cocos2d::Device::TextAlign align,
|
|||
if (!context)
|
||||
{
|
||||
CGColorSpaceRelease(colorSpace);
|
||||
delete[] data;
|
||||
CC_SAFE_FREE(data);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -411,7 +411,7 @@ public:
|
|||
int txtHeight = iMaxLineHeight;
|
||||
iMaxLineHeight = MAX(iMaxLineHeight, nHeight);
|
||||
|
||||
_data = new unsigned char[iMaxLineWidth * iMaxLineHeight * 4];
|
||||
_data = (unsigned char*)malloc(sizeof(unsigned char) * (iMaxLineWidth * iMaxLineHeight * 4));
|
||||
memset(_data,0, iMaxLineWidth * iMaxLineHeight*4);
|
||||
|
||||
int iCurYCursor = computeLineStartY(face, eAlignMask, txtHeight, iMaxLineHeight);
|
||||
|
|
|
@ -112,24 +112,37 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
|
|||
font, NSFontAttributeName,
|
||||
paragraphStyle, NSParagraphStyleAttributeName, nil];
|
||||
|
||||
// linebreak
|
||||
// linebreak
|
||||
if (info->width > 0) {
|
||||
if ([string sizeWithAttributes:tokenAttributesDict].width > info->width) {
|
||||
NSMutableString *lineBreak = [[[NSMutableString alloc] init] autorelease];
|
||||
NSUInteger length = [string length];
|
||||
NSRange range = NSMakeRange(0, 1);
|
||||
NSUInteger width = 0;
|
||||
CGSize textSize;
|
||||
NSUInteger lastBreakLocation = 0;
|
||||
NSUInteger insertCount = 0;
|
||||
for (NSUInteger i = 0; i < length; i++) {
|
||||
range.location = i;
|
||||
NSString *character = [string substringWithRange:range];
|
||||
[lineBreak appendString:character];
|
||||
if ([@"!?.,-= " rangeOfString:character].location != NSNotFound) { lastBreakLocation = i; }
|
||||
width = [lineBreak sizeWithAttributes:tokenAttributesDict].width;
|
||||
if (width > info->width) {
|
||||
[lineBreak insertString:@"\r\n" atIndex:(lastBreakLocation > 0) ? lastBreakLocation : [lineBreak length] - 1];
|
||||
if ([@"!?.,-= " rangeOfString:character].location != NSNotFound) {
|
||||
lastBreakLocation = i + insertCount;
|
||||
}
|
||||
textSize = [lineBreak sizeWithAttributes:tokenAttributesDict];
|
||||
if(textSize.height > info->height)
|
||||
break;
|
||||
if (textSize.width > info->width) {
|
||||
if(lastBreakLocation > 0) {
|
||||
[lineBreak insertString:@"\r" atIndex:lastBreakLocation];
|
||||
lastBreakLocation = 0;
|
||||
}
|
||||
else {
|
||||
[lineBreak insertString:@"\r" atIndex:[lineBreak length] - 1];
|
||||
}
|
||||
insertCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
string = lineBreak;
|
||||
}
|
||||
}
|
||||
|
@ -194,7 +207,7 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
|
|||
|
||||
NSUInteger textureSize = POTWide*POTHigh*4;
|
||||
|
||||
unsigned char* dataNew = new unsigned char[textureSize];
|
||||
unsigned char* dataNew = (unsigned char*)malloc(sizeof(unsigned char) * textureSize);
|
||||
if (dataNew) {
|
||||
memcpy(dataNew, data, textureSize);
|
||||
// output params
|
||||
|
|
|
@ -95,22 +95,22 @@ public:
|
|||
removeCustomFont();
|
||||
}
|
||||
|
||||
wchar_t * utf8ToUtf16(std::string nString)
|
||||
wchar_t * utf8ToUtf16(const std::string& str)
|
||||
{
|
||||
wchar_t * pwszBuffer = NULL;
|
||||
do
|
||||
{
|
||||
if (nString.size() < 0)
|
||||
if (str.empty())
|
||||
{
|
||||
break;
|
||||
}
|
||||
// utf-8 to utf-16
|
||||
int nLen = nString.size();
|
||||
int nLen = str.size();
|
||||
int nBufLen = nLen + 1;
|
||||
pwszBuffer = new wchar_t[nBufLen];
|
||||
CC_BREAK_IF(! pwszBuffer);
|
||||
memset(pwszBuffer,0,nBufLen);
|
||||
nLen = MultiByteToWideChar(CP_UTF8, 0, nString.c_str(), nLen, pwszBuffer, nBufLen);
|
||||
nLen = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), nLen, pwszBuffer, nBufLen);
|
||||
pwszBuffer[nLen] = '\0';
|
||||
} while (0);
|
||||
return pwszBuffer;
|
||||
|
@ -412,7 +412,7 @@ Data Device::getTextureDataForText(const char * text,const FontDefinition& textD
|
|||
CC_BREAK_IF(! dc.drawText(text, size, align));
|
||||
|
||||
int dataLen = size.cx * size.cy * 4;
|
||||
unsigned char* dataBuf = new unsigned char[dataLen];
|
||||
unsigned char* dataBuf = (unsigned char*)malloc(sizeof(unsigned char) * dataLen);
|
||||
CC_BREAK_IF(! dataBuf);
|
||||
|
||||
struct
|
||||
|
|
|
@ -106,7 +106,7 @@ void TriggerMng::parse(const rapidjson::Value &root)
|
|||
|
||||
cocos2d::Vector<TriggerObj*>* TriggerMng::get(unsigned int event) const
|
||||
{
|
||||
CCAssert(event >= 0, "Argument must be larger than 0");
|
||||
CCASSERT(event != 0, "Argument must be larger than 0");
|
||||
|
||||
auto iter = _eventTriggers.find(event);
|
||||
if (iter == _eventTriggers.end())
|
||||
|
@ -129,7 +129,7 @@ TriggerObj* TriggerMng::getTriggerObj(unsigned int id) const
|
|||
bool TriggerMng::add(unsigned int event, TriggerObj *obj)
|
||||
{
|
||||
bool ret = false;
|
||||
CCAssert(obj != nullptr, "Argument must be non-nil");
|
||||
CCASSERT(obj != nullptr, "Argument must be non-nil");
|
||||
do
|
||||
{
|
||||
auto iterator = _eventTriggers.find(event);
|
||||
|
@ -170,7 +170,7 @@ void TriggerMng::removeAll(void)
|
|||
bool TriggerMng::remove(unsigned int event)
|
||||
{
|
||||
bool bRet = false;
|
||||
CCAssert(event >= 0, "event must be larger than 0");
|
||||
CCASSERT(event != 0, "event must be larger than 0");
|
||||
do
|
||||
{
|
||||
auto iterator = _eventTriggers.find(event);
|
||||
|
@ -194,8 +194,8 @@ bool TriggerMng::remove(unsigned int event)
|
|||
bool TriggerMng::remove(unsigned int event, TriggerObj *Obj)
|
||||
{
|
||||
bool bRet = false;
|
||||
CCAssert(event >= 0, "event must be larger than 0");
|
||||
CCAssert(Obj != 0, "TriggerObj must be not 0");
|
||||
CCASSERT(event != 0, "event must be larger than 0");
|
||||
CCASSERT(Obj != 0, "TriggerObj must be not 0");
|
||||
do
|
||||
{
|
||||
auto iterator = _eventTriggers.find(event);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
//
|
||||
|
||||
var cc = cc || {};
|
||||
var window = window || this;
|
||||
|
||||
cc.TARGET_PLATFORM = {
|
||||
WINDOWS:0,
|
||||
|
@ -821,3 +822,62 @@ cc.VisibleRect = {
|
|||
}
|
||||
};
|
||||
|
||||
var _windowTimeIntervalId = 0;
|
||||
var _windowTimeFunHash = {};
|
||||
var WindowTimeFun = cc.Class.extend({
|
||||
_code: null,
|
||||
_intervalId: 0,
|
||||
ctor: function (code) {
|
||||
this._intervalId = _windowTimeIntervalId++;
|
||||
this._code = code;
|
||||
},
|
||||
fun: function () {
|
||||
if (!this._code) return;
|
||||
var code = this._code;
|
||||
if (typeof code == "string") {
|
||||
Function(code)();
|
||||
}
|
||||
else if (typeof code == "function") {
|
||||
code();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* overwrite window's setTimeout
|
||||
@param {String|Function} code
|
||||
@param {number} delay
|
||||
@return {number}
|
||||
*/
|
||||
var setTimeout = function (code, delay) {
|
||||
var target = new WindowTimeFun(code);
|
||||
cc.Director.getInstance().getScheduler().scheduleCallbackForTarget(target, target.fun, delay / 1000, 0, 0, false);
|
||||
_windowTimeFunHash[target._intervalId] = target;
|
||||
return target._intervalId;
|
||||
};
|
||||
|
||||
/**
|
||||
* overwrite window's setInterval
|
||||
@param {String|Function} code
|
||||
@param {number} delay
|
||||
@return {number}
|
||||
*/
|
||||
var setInterval = function (code, delay) {
|
||||
var target = new WindowTimeFun(code);
|
||||
cc.Director.getInstance().getScheduler().scheduleCallbackForTarget(target, target.fun, delay / 1000, cc.REPEAT_FOREVER, 0, false);
|
||||
_windowTimeFunHash[target._intervalId] = target;
|
||||
return target._intervalId;
|
||||
};
|
||||
|
||||
/**
|
||||
* overwrite window's clearInterval
|
||||
@param {number} intervalId
|
||||
*/
|
||||
var clearInterval = function (intervalId) {
|
||||
var target = _windowTimeFunHash[intervalId];
|
||||
if (target) {
|
||||
cc.Director.getInstance().getScheduler().unscheduleCallbackForTarget(target, target.fun);
|
||||
delete _windowTimeFunHash[intervalId];
|
||||
}
|
||||
};
|
||||
var clearTimeout = clearInterval;
|
|
@ -18,8 +18,8 @@ endif(DEBUG_MODE)
|
|||
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
|
||||
|
||||
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-std=c99")
|
||||
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
|
||||
if(USE_CHIPMUNK)
|
||||
message("Using chipmunk ...")
|
||||
|
|
|
@ -143,14 +143,8 @@ void RenderTextureSave::saveImage(cocos2d::Object *sender)
|
|||
_target->saveToFile(png, Image::Format::PNG);
|
||||
_target->saveToFile(jpg, Image::Format::JPG);
|
||||
|
||||
|
||||
auto image = _target->newImage();
|
||||
|
||||
auto tex = Director::getInstance()->getTextureCache()->addImage(image, png);
|
||||
|
||||
CC_SAFE_DELETE(image);
|
||||
|
||||
auto sprite = Sprite::createWithTexture(tex);
|
||||
std::string fileName = FileUtils::getInstance()->getWritablePath() + jpg;
|
||||
auto sprite = Sprite::create(fileName);
|
||||
|
||||
sprite->setScale(0.3f);
|
||||
addChild(sprite);
|
||||
|
|
|
@ -423,7 +423,11 @@ void TMXOrthoTest4::removeSprite(float dt)
|
|||
auto s = layer->getLayerSize();
|
||||
|
||||
auto sprite = layer->getTileAt( Point(s.width-1,0) );
|
||||
auto sprite2 = layer->getTileAt(Point(s.width-1, s.height-1));
|
||||
layer->removeChild(sprite, true);
|
||||
auto sprite3 = layer->getTileAt(Point(2, s.height-1));
|
||||
layer->removeChild(sprite3, true);
|
||||
layer->removeChild(sprite2, true);
|
||||
}
|
||||
|
||||
std::string TMXOrthoTest4::title() const
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue