Merge pull request #13387 from WenhaiLin/v3-replace-tab-withSpaces

Replace tab with spaces
This commit is contained in:
子龙山人 2015-08-17 11:29:03 +08:00
commit 8e01326cfa
26 changed files with 425 additions and 430 deletions

View File

@ -244,18 +244,18 @@ void GLView::setScissorInPoints(float x , float y , float w , float h)
bool GLView::isScissorEnabled()
{
return (GL_FALSE == glIsEnabled(GL_SCISSOR_TEST)) ? false : true;
return (GL_FALSE == glIsEnabled(GL_SCISSOR_TEST)) ? false : true;
}
Rect GLView::getScissorRect() const
{
GLfloat params[4];
glGetFloatv(GL_SCISSOR_BOX, params);
float x = (params[0] - _viewPortRect.origin.x) / _scaleX;
float y = (params[1] - _viewPortRect.origin.y) / _scaleY;
float w = params[2] / _scaleX;
float h = params[3] / _scaleY;
return Rect(x, y, w, h);
GLfloat params[4];
glGetFloatv(GL_SCISSOR_BOX, params);
float x = (params[0] - _viewPortRect.origin.x) / _scaleX;
float y = (params[1] - _viewPortRect.origin.y) / _scaleY;
float w = params[2] / _scaleX;
float h = params[3] / _scaleY;
return Rect(x, y, w, h);
}
void GLView::setViewName(const std::string& viewname )
@ -296,7 +296,7 @@ void GLView::handleTouchesBegin(int num, intptr_t ids[], float xs[], float ys[])
}
Touch* touch = g_touches[unusedIndex] = new (std::nothrow) Touch();
touch->setTouchInfo(unusedIndex, (x - _viewPortRect.origin.x) / _scaleX,
touch->setTouchInfo(unusedIndex, (x - _viewPortRect.origin.x) / _scaleX,
(y - _viewPortRect.origin.y) / _scaleY);
CCLOGINFO("x = %f y = %f", touch->getLocationInView().x, touch->getLocationInView().y);
@ -341,8 +341,8 @@ void GLView::handleTouchesMove(int num, intptr_t ids[], float xs[], float ys[])
Touch* touch = g_touches[iter->second];
if (touch)
{
touch->setTouchInfo(iter->second, (x - _viewPortRect.origin.x) / _scaleX,
(y - _viewPortRect.origin.y) / _scaleY);
touch->setTouchInfo(iter->second, (x - _viewPortRect.origin.x) / _scaleX,
(y - _viewPortRect.origin.y) / _scaleY);
touchEvent._touches.push_back(touch);
}
@ -390,8 +390,8 @@ void GLView::handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num
if (touch)
{
CCLOGINFO("Ending touches with id: %d, x=%f, y=%f", id, x, y);
touch->setTouchInfo(iter->second, (x - _viewPortRect.origin.x) / _scaleX,
(y - _viewPortRect.origin.y) / _scaleY);
touch->setTouchInfo(iter->second, (x - _viewPortRect.origin.x) / _scaleX,
(y - _viewPortRect.origin.y) / _scaleY);
touchEvent._touches.push_back(touch);

View File

@ -120,7 +120,7 @@ namespace
enum class PVR3TextureFlag
{
PremultipliedAlpha = (1<<1) // has premultiplied alpha
PremultipliedAlpha = (1<<1) // has premultiplied alpha
};
static const char gPVRTexIdentifier[5] = "PVR!";
@ -195,18 +195,18 @@ namespace
static const _pixel2_formathash::value_type v2_pixel_formathash_value[] =
{
_pixel2_formathash::value_type(PVR2TexturePixelFormat::BGRA8888, Texture2D::PixelFormat::BGRA8888),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA8888, Texture2D::PixelFormat::RGBA8888),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA4444, Texture2D::PixelFormat::RGBA4444),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA5551, Texture2D::PixelFormat::RGB5A1),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGB565, Texture2D::PixelFormat::RGB565),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGB888, Texture2D::PixelFormat::RGB888),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::A8, Texture2D::PixelFormat::A8),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::I8, Texture2D::PixelFormat::I8),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::AI88, Texture2D::PixelFormat::AI88),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::BGRA8888, Texture2D::PixelFormat::BGRA8888),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA8888, Texture2D::PixelFormat::RGBA8888),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA4444, Texture2D::PixelFormat::RGBA4444),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA5551, Texture2D::PixelFormat::RGB5A1),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGB565, Texture2D::PixelFormat::RGB565),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::RGB888, Texture2D::PixelFormat::RGB888),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::A8, Texture2D::PixelFormat::A8),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::I8, Texture2D::PixelFormat::I8),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::AI88, Texture2D::PixelFormat::AI88),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::PVRTC2BPP_RGBA, Texture2D::PixelFormat::PVRTC2A),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::PVRTC4BPP_RGBA, Texture2D::PixelFormat::PVRTC4A),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::PVRTC2BPP_RGBA, Texture2D::PixelFormat::PVRTC2A),
_pixel2_formathash::value_type(PVR2TexturePixelFormat::PVRTC4BPP_RGBA, Texture2D::PixelFormat::PVRTC4A),
};
static const int PVR2_MAX_TABLE_ELEMENTS = sizeof(v2_pixel_formathash_value) / sizeof(v2_pixel_formathash_value[0]);
@ -216,22 +216,22 @@ namespace
typedef const std::map<PVR3TexturePixelFormat, Texture2D::PixelFormat> _pixel3_formathash;
static _pixel3_formathash::value_type v3_pixel_formathash_value[] =
{
_pixel3_formathash::value_type(PVR3TexturePixelFormat::BGRA8888, Texture2D::PixelFormat::BGRA8888),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA8888, Texture2D::PixelFormat::RGBA8888),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA4444, Texture2D::PixelFormat::RGBA4444),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA5551, Texture2D::PixelFormat::RGB5A1),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGB565, Texture2D::PixelFormat::RGB565),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGB888, Texture2D::PixelFormat::RGB888),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::A8, Texture2D::PixelFormat::A8),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::L8, Texture2D::PixelFormat::I8),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::LA88, Texture2D::PixelFormat::AI88),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::BGRA8888, Texture2D::PixelFormat::BGRA8888),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA8888, Texture2D::PixelFormat::RGBA8888),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA4444, Texture2D::PixelFormat::RGBA4444),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA5551, Texture2D::PixelFormat::RGB5A1),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGB565, Texture2D::PixelFormat::RGB565),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::RGB888, Texture2D::PixelFormat::RGB888),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::A8, Texture2D::PixelFormat::A8),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::L8, Texture2D::PixelFormat::I8),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::LA88, Texture2D::PixelFormat::AI88),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC2BPP_RGB, Texture2D::PixelFormat::PVRTC2),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC2BPP_RGBA, Texture2D::PixelFormat::PVRTC2A),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC4BPP_RGB, Texture2D::PixelFormat::PVRTC4),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC4BPP_RGBA, Texture2D::PixelFormat::PVRTC4A),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC2BPP_RGB, Texture2D::PixelFormat::PVRTC2),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC2BPP_RGBA, Texture2D::PixelFormat::PVRTC2A),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC4BPP_RGB, Texture2D::PixelFormat::PVRTC4),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC4BPP_RGBA, Texture2D::PixelFormat::PVRTC4A),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::ETC1, Texture2D::PixelFormat::ETC),
_pixel3_formathash::value_type(PVR3TexturePixelFormat::ETC1, Texture2D::PixelFormat::ETC),
};
static const int PVR3_MAX_TABLE_ELEMENTS = sizeof(v3_pixel_formathash_value) / sizeof(v3_pixel_formathash_value[0]);
@ -771,8 +771,8 @@ namespace
#if CC_USE_JPEG
struct MyErrorMgr
{
struct jpeg_error_mgr pub; /* "public" fields */
jmp_buf setjmp_buffer; /* for return to caller */
struct jpeg_error_mgr pub; /* "public" fields */
jmp_buf setjmp_buffer; /* for return to caller */
};
typedef struct MyErrorMgr * MyErrorPtr;
@ -859,42 +859,42 @@ bool Image::decodeWithWIC(const unsigned char *data, ssize_t dataLen)
bool Image::encodeWithWIC(const std::string& filePath, bool isToRGB, GUID containerFormat)
{
// Save formats supported by WIC
WICPixelFormatGUID targetFormat = isToRGB ? GUID_WICPixelFormat24bppBGR : GUID_WICPixelFormat32bppBGRA;
unsigned char *pSaveData = nullptr;
int saveLen = _dataLen;
int bpp = 4;
// Save formats supported by WIC
WICPixelFormatGUID targetFormat = isToRGB ? GUID_WICPixelFormat24bppBGR : GUID_WICPixelFormat32bppBGRA;
unsigned char *pSaveData = nullptr;
int saveLen = _dataLen;
int bpp = 4;
if (targetFormat == GUID_WICPixelFormat24bppBGR && _renderFormat == Texture2D::PixelFormat::RGBA8888)
{
bpp = 3;
saveLen = _width * _height * bpp;
pSaveData = new unsigned char[saveLen];
int indL = 0, indR = 0;
if (targetFormat == GUID_WICPixelFormat24bppBGR && _renderFormat == Texture2D::PixelFormat::RGBA8888)
{
bpp = 3;
saveLen = _width * _height * bpp;
pSaveData = new unsigned char[saveLen];
int indL = 0, indR = 0;
while (indL < saveLen && indR < _dataLen)
{
memcpy(&pSaveData[indL], &_data[indR], 3);
indL += 3;
indR += 4;
}
}
else
{
pSaveData = new unsigned char[saveLen];
memcpy(pSaveData, _data, saveLen);
}
while (indL < saveLen && indR < _dataLen)
{
memcpy(&pSaveData[indL], &_data[indR], 3);
indL += 3;
indR += 4;
}
}
else
{
pSaveData = new unsigned char[saveLen];
memcpy(pSaveData, _data, saveLen);
}
for (int ind = 2; ind < saveLen; ind += bpp) {
std::swap(pSaveData[ind - 2], pSaveData[ind]);
}
for (int ind = 2; ind < saveLen; ind += bpp) {
std::swap(pSaveData[ind - 2], pSaveData[ind]);
}
bool bRet = false;
WICImageLoader img;
bRet = img.encodeImageData(filePath, pSaveData, saveLen, targetFormat, _width, _height, containerFormat);
bool bRet = false;
WICImageLoader img;
bRet = img.encodeImageData(filePath, pSaveData, saveLen, targetFormat, _width, _height, containerFormat);
delete[] pSaveData;
return bRet;
delete[] pSaveData;
return bRet;
}
@ -908,10 +908,10 @@ bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen)
/* these are standard libjpeg structures for reading(decompression) */
struct jpeg_decompress_struct cinfo;
/* We use our private extension JPEG error handler.
* Note that this struct must live as long as the main JPEG parameter
* struct, to avoid dangling-pointer problems.
*/
struct MyErrorMgr jerr;
* Note that this struct must live as long as the main JPEG parameter
* struct, to avoid dangling-pointer problems.
*/
struct MyErrorMgr jerr;
/* libjpeg data structure for storing one row, that is, scanline of an image */
JSAMPROW row_pointer[1] = {0};
unsigned long location = 0;
@ -920,17 +920,17 @@ bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen)
do
{
/* We set up the normal JPEG error routines, then override error_exit. */
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = myErrorExit;
/* Establish the setjmp return context for MyErrorExit to use. */
if (setjmp(jerr.setjmp_buffer))
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = myErrorExit;
/* Establish the setjmp return context for MyErrorExit to use. */
if (setjmp(jerr.setjmp_buffer))
{
/* If we get here, the JPEG code has signaled an error.
* We need to clean up the JPEG object, close the input file, and return.
*/
jpeg_destroy_decompress(&cinfo);
break;
}
/* If we get here, the JPEG code has signaled an error.
* We need to clean up the JPEG object, close the input file, and return.
*/
jpeg_destroy_decompress(&cinfo);
break;
}
/* setup decompression process and source, then read JPEG header */
jpeg_create_decompress( &cinfo );
@ -978,12 +978,12 @@ bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen)
jpeg_read_scanlines(&cinfo, row_pointer, 1);
}
/* When read image file with broken data, jpeg_finish_decompress() may cause error.
* Besides, jpeg_destroy_decompress() shall deallocate and release all memory associated
* with the decompression object.
* So it doesn't need to call jpeg_finish_decompress().
*/
//jpeg_finish_decompress( &cinfo );
/* When read image file with broken data, jpeg_finish_decompress() may cause error.
* Besides, jpeg_destroy_decompress() shall deallocate and release all memory associated
* with the decompression object.
* So it doesn't need to call jpeg_finish_decompress().
*/
//jpeg_finish_decompress( &cinfo );
jpeg_destroy_decompress( &cinfo );
/* wrap up decompression, destroy objects, free pointers and close open files */
ret = true;
@ -1533,20 +1533,20 @@ bool Image::initWithPVRv3Data(const unsigned char * data, ssize_t dataLen)
{
if (static_cast<size_t>(dataLen) < sizeof(PVRv3TexHeader))
{
return false;
}
const PVRv3TexHeader *header = static_cast<const PVRv3TexHeader *>(static_cast<const void*>(data));
// validate version
if (CC_SWAP_INT32_BIG_TO_HOST(header->version) != 0x50565203)
return false;
}
const PVRv3TexHeader *header = static_cast<const PVRv3TexHeader *>(static_cast<const void*>(data));
// validate version
if (CC_SWAP_INT32_BIG_TO_HOST(header->version) != 0x50565203)
{
CCLOG("cocos2d: WARNING: pvr file version mismatch");
return false;
}
// parse pixel format
PVR3TexturePixelFormat pixelFormat = static_cast<PVR3TexturePixelFormat>(header->pixelFormat);
CCLOG("cocos2d: WARNING: pvr file version mismatch");
return false;
}
// parse pixel format
PVR3TexturePixelFormat pixelFormat = static_cast<PVR3TexturePixelFormat>(header->pixelFormat);
if (!testFormatForPvr3TCSupport(pixelFormat))
{
@ -1576,7 +1576,7 @@ bool Image::initWithPVRv3Data(const unsigned char * data, ssize_t dataLen)
int bpp = it->second.bpp;
// flags
int flags = CC_SWAP_INT32_LITTLE_TO_HOST(header->flags);
int flags = CC_SWAP_INT32_LITTLE_TO_HOST(header->flags);
// PVRv3 specifies premultiply alpha in a flag -- should always respect this in PVRv3 files
if (flags & (unsigned int)PVR3TextureFlag::PremultipliedAlpha)
@ -1584,24 +1584,24 @@ bool Image::initWithPVRv3Data(const unsigned char * data, ssize_t dataLen)
_hasPremultipliedAlpha = true;
}
// sizing
int width = CC_SWAP_INT32_LITTLE_TO_HOST(header->width);
int height = CC_SWAP_INT32_LITTLE_TO_HOST(header->height);
_width = width;
_height = height;
int dataOffset = 0, dataSize = 0;
int blockSize = 0, widthBlocks = 0, heightBlocks = 0;
// sizing
int width = CC_SWAP_INT32_LITTLE_TO_HOST(header->width);
int height = CC_SWAP_INT32_LITTLE_TO_HOST(header->height);
_width = width;
_height = height;
int dataOffset = 0, dataSize = 0;
int blockSize = 0, widthBlocks = 0, heightBlocks = 0;
_dataLen = dataLen - (sizeof(PVRv3TexHeader) + header->metadataLength);
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
memcpy(_data, static_cast<const unsigned char*>(data) + sizeof(PVRv3TexHeader) + header->metadataLength, _dataLen);
_numberOfMipmaps = header->numberOfMipmaps;
CCAssert(_numberOfMipmaps < MIPMAP_MAX, "Image: Maximum number of mimpaps reached. Increate the CC_MIPMAP_MAX value");
for (int i = 0; i < _numberOfMipmaps; i++)
_numberOfMipmaps = header->numberOfMipmaps;
CCAssert(_numberOfMipmaps < MIPMAP_MAX, "Image: Maximum number of mimpaps reached. Increate the CC_MIPMAP_MAX value");
for (int i = 0; i < _numberOfMipmaps; i++)
{
switch ((PVR3TexturePixelFormat)pixelFormat)
switch ((PVR3TexturePixelFormat)pixelFormat)
{
case PVR3TexturePixelFormat::PVRTC2BPP_RGB :
case PVR3TexturePixelFormat::PVRTC2BPP_RGBA :
@ -1662,43 +1662,43 @@ bool Image::initWithPVRv3Data(const unsigned char * data, ssize_t dataLen)
widthBlocks = width;
heightBlocks = height;
break;
}
}
// Clamp to minimum number of blocks
if (widthBlocks < 2)
// Clamp to minimum number of blocks
if (widthBlocks < 2)
{
widthBlocks = 2;
widthBlocks = 2;
}
if (heightBlocks < 2)
if (heightBlocks < 2)
{
heightBlocks = 2;
heightBlocks = 2;
}
dataSize = widthBlocks * heightBlocks * ((blockSize * bpp) / 8);
auto packetLength = _dataLen - dataOffset;
packetLength = packetLength > dataSize ? dataSize : packetLength;
if(!_unpack)
{
_mipmaps[i].address = _data + dataOffset;
_mipmaps[i].len = static_cast<int>(packetLength);
}
dataOffset += packetLength;
CCAssert(dataOffset <= _dataLen, "CCTexurePVR: Invalid lenght");
width = MAX(width >> 1, 1);
height = MAX(height >> 1, 1);
}
dataSize = widthBlocks * heightBlocks * ((blockSize * bpp) / 8);
auto packetLength = _dataLen - dataOffset;
packetLength = packetLength > dataSize ? dataSize : packetLength;
if(!_unpack)
{
_mipmaps[i].address = _data + dataOffset;
_mipmaps[i].len = static_cast<int>(packetLength);
}
dataOffset += packetLength;
CCAssert(dataOffset <= _dataLen, "CCTexurePVR: Invalid lenght");
width = MAX(width >> 1, 1);
height = MAX(height >> 1, 1);
}
if (_unpack)
{
_data = _mipmaps[0].address;
_dataLen = _mipmaps[0].len;
}
return true;
return true;
}
bool Image::initWithETCData(const unsigned char * data, ssize_t dataLen)
@ -2107,13 +2107,13 @@ bool Image::initWithPVRData(const unsigned char * data, ssize_t dataLen)
bool Image::initWithWebpData(const unsigned char * data, ssize_t dataLen)
{
#if CC_USE_WEBP
bool ret = false;
bool ret = false;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
CCLOG("WEBP image format not supported on WinRT or WP8");
#else
do
{
do
{
WebPDecoderConfig config;
if (WebPInitDecoderConfig(&config) == 0) break;
if (WebPGetFeatures(static_cast<const uint8_t*>(data), dataLen, &config.input) != VP8_STATUS_OK) break;
@ -2143,9 +2143,9 @@ bool Image::initWithWebpData(const unsigned char * data, ssize_t dataLen)
}
ret = true;
} while (0);
} while (0);
#endif // (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
return ret;
return ret;
#else
CCLOG("webp is not enabled, please enable it in ccConfig.h");
return false;

View File

@ -155,8 +155,8 @@ public:
protected:
#if defined(CC_USE_WIC)
bool encodeWithWIC(const std::string& filePath, bool isToRGB, GUID containerFormat);
bool decodeWithWIC(const unsigned char *data, ssize_t dataLen);
bool encodeWithWIC(const std::string& filePath, bool isToRGB, GUID containerFormat);
bool decodeWithWIC(const unsigned char *data, ssize_t dataLen);
#endif
bool initWithJpgData(const unsigned char * data, ssize_t dataLen);
bool initWithPngData(const unsigned char * data, ssize_t dataLen);

View File

@ -131,7 +131,7 @@ THE SOFTWARE.
// WinRT (Windows 8.1 Store/Phone App)
#if defined(WINRT)
#undef CC_TARGET_PLATFORM
#define CC_TARGET_PLATFORM CC_PLATFORM_WINRT
#define CC_TARGET_PLATFORM CC_PLATFORM_WINRT
#endif
//////////////////////////////////////////////////////////////////////////

View File

@ -108,7 +108,7 @@ CC_DEPRECATED_ATTRIBUTE static __TYPE__* node() \
#define NS_CC_BEGIN namespace cocos2d {
#define NS_CC_END }
#define USING_NS_CC using namespace cocos2d
#define NS_CC ::cocos2d
#define NS_CC ::cocos2d
#else
#define NS_CC_BEGIN
#define NS_CC_END
@ -258,7 +258,7 @@ public: virtual void set##funName(varType var) \
* This should be used in the private: declarations for a class
*/
#if defined(__GNUC__) && ((__GNUC__ >= 5) || ((__GNUG__ == 4) && (__GNUC_MINOR__ >= 4))) \
|| (defined(__clang__) && (__clang_major__ >= 3)) || (_MSC_VER >= 1800)
|| (defined(__clang__) && (__clang_major__ >= 3)) || (_MSC_VER >= 1800)
#define CC_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName &) = delete; \
TypeName &operator =(const TypeName &) = delete;

View File

@ -35,56 +35,56 @@ NS_CC_BEGIN
class XmlSaxHander : public tinyxml2::XMLVisitor
{
public:
XmlSaxHander():_ccsaxParserImp(0){};
virtual bool VisitEnter( const tinyxml2::XMLElement& element, const tinyxml2::XMLAttribute* firstAttribute );
virtual bool VisitExit( const tinyxml2::XMLElement& element );
virtual bool Visit( const tinyxml2::XMLText& text );
virtual bool Visit( const tinyxml2::XMLUnknown&){ return true; }
XmlSaxHander():_ccsaxParserImp(0){};
virtual bool VisitEnter( const tinyxml2::XMLElement& element, const tinyxml2::XMLAttribute* firstAttribute );
virtual bool VisitExit( const tinyxml2::XMLElement& element );
virtual bool Visit( const tinyxml2::XMLText& text );
virtual bool Visit( const tinyxml2::XMLUnknown&){ return true; }
void setSAXParserImp(SAXParser* parser)
{
_ccsaxParserImp = parser;
}
void setSAXParserImp(SAXParser* parser)
{
_ccsaxParserImp = parser;
}
private:
SAXParser *_ccsaxParserImp;
SAXParser *_ccsaxParserImp;
};
bool XmlSaxHander::VisitEnter( const tinyxml2::XMLElement& element, const tinyxml2::XMLAttribute* firstAttribute )
{
//log(" VisitEnter %s",element.Value());
//log(" VisitEnter %s",element.Value());
std::vector<const char*> attsVector;
for( const tinyxml2::XMLAttribute* attrib = firstAttribute; attrib; attrib = attrib->Next() )
{
//log("%s", attrib->Name());
attsVector.push_back(attrib->Name());
//log("%s",attrib->Value());
attsVector.push_back(attrib->Value());
}
std::vector<const char*> attsVector;
for( const tinyxml2::XMLAttribute* attrib = firstAttribute; attrib; attrib = attrib->Next() )
{
//log("%s", attrib->Name());
attsVector.push_back(attrib->Name());
//log("%s",attrib->Value());
attsVector.push_back(attrib->Value());
}
// nullptr is used in c++11
//attsVector.push_back(nullptr);
//attsVector.push_back(nullptr);
attsVector.push_back(nullptr);
SAXParser::startElement(_ccsaxParserImp, (const CC_XML_CHAR *)element.Value(), (const CC_XML_CHAR **)(&attsVector[0]));
return true;
SAXParser::startElement(_ccsaxParserImp, (const CC_XML_CHAR *)element.Value(), (const CC_XML_CHAR **)(&attsVector[0]));
return true;
}
bool XmlSaxHander::VisitExit( const tinyxml2::XMLElement& element )
{
//log("VisitExit %s",element.Value());
//log("VisitExit %s",element.Value());
SAXParser::endElement(_ccsaxParserImp, (const CC_XML_CHAR *)element.Value());
return true;
SAXParser::endElement(_ccsaxParserImp, (const CC_XML_CHAR *)element.Value());
return true;
}
bool XmlSaxHander::Visit( const tinyxml2::XMLText& text )
{
//log("Visit %s",text.Value());
SAXParser::textHandler(_ccsaxParserImp, (const CC_XML_CHAR *)text.Value(), static_cast<int>(strlen(text.Value())));
return true;
//log("Visit %s",text.Value());
SAXParser::textHandler(_ccsaxParserImp, (const CC_XML_CHAR *)text.Value(), static_cast<int>(strlen(text.Value())));
return true;
}
SAXParser::SAXParser()
@ -105,12 +105,12 @@ bool SAXParser::init(const char *encoding)
bool SAXParser::parse(const char* xmlData, size_t dataLength)
{
tinyxml2::XMLDocument tinyDoc;
tinyDoc.Parse(xmlData, dataLength);
XmlSaxHander printer;
printer.setSAXParserImp(this);
return tinyDoc.Accept( &printer );
tinyxml2::XMLDocument tinyDoc;
tinyDoc.Parse(xmlData, dataLength);
XmlSaxHander printer;
printer.setSAXParserImp(this);
return tinyDoc.Accept( &printer );
}
bool SAXParser::parse(const std::string& filename)

View File

@ -91,12 +91,12 @@ public:
*/
virtual bool openURL(const std::string &url);
/**
@brief This function will be called when the application screen size is changed.
@param new width
@param new height
*/
virtual void applicationScreenSizeChanged(int newWidth, int newHeight);
/**
@brief This function will be called when the application screen size is changed.
@param new width
@param new height
*/
virtual void applicationScreenSizeChanged(int newWidth, int newHeight);
protected:
static Application * sm_pSharedApplication;

View File

@ -48,56 +48,56 @@ EnhanceAPI::~EnhanceAPI()
int EnhanceAPI::setResolutionPercent(int n)
{
JniMethodInfo t;
int ret = -1;
int ret = -1;
if(JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setResolutionPercent", "(I)I"))
{
ret = t.env->CallStaticIntMethod(t.classID, t.methodID, n);
}
return ret;
return ret;
}
int EnhanceAPI::setFPS(int fps)
{
JniMethodInfo t;
int ret = -1;
int ret = -1;
if(JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setFPS", "(I)I"))
{
ret = t.env->CallStaticIntMethod(t.classID, t.methodID, fps);
}
return ret;
return ret;
}
int EnhanceAPI::fastLoading(int sec)
{
JniMethodInfo t;
int ret = -1;
int ret = -1;
if(JniHelper::getStaticMethodInfo(t, CLASS_NAME, "fastLoading", "(I)I"))
{
ret = t.env->CallStaticIntMethod(t.classID, t.methodID, sec);
}
return ret;
return ret;
}
int EnhanceAPI::getTemperature()
{
JniMethodInfo t;
int ret = -1;
int ret = -1;
if(JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getTemperature", "()I"))
{
ret = t.env->CallStaticIntMethod(t.classID, t.methodID);
}
return ret;
return ret;
}
int EnhanceAPI::setLowPowerMode(bool enable)
{
JniMethodInfo t;
int ret = -1;
int ret = -1;
if(JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setLowPowerMode", "(Z)I"))
{
ret = t.env->CallStaticIntMethod(t.classID, t.methodID, enable);
}
return ret;
return ret;
}
NS_CC_END

View File

@ -54,7 +54,7 @@ public:
*/
static int setResolutionPercent(int percent);
/**
/**
*@brief The function is used to set FPS level.
*@Warn The input fps level(0-99) corresponds to game fps value(0-60).
* FPS level 99 means game FPS value 60.

View File

@ -56,7 +56,7 @@ public:
virtual ~FileUtilsAndroid();
static void setassetmanager(AAssetManager* a);
static AAssetManager* getAssetManager() { return assetmanager; }
static AAssetManager* getAssetManager() { return assetmanager; }
/* override funtions */
bool init();

View File

@ -29,15 +29,15 @@ THE SOFTWARE.
#include "platform/CCPlatformConfig.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#define glClearDepth glClearDepthf
#define glDeleteVertexArrays glDeleteVertexArraysOES
#define glGenVertexArrays glGenVertexArraysOES
#define glBindVertexArray glBindVertexArrayOES
#define glMapBuffer glMapBufferOES
#define glUnmapBuffer glUnmapBufferOES
#define glClearDepth glClearDepthf
#define glDeleteVertexArrays glDeleteVertexArraysOES
#define glGenVertexArrays glGenVertexArraysOES
#define glBindVertexArray glBindVertexArrayOES
#define glMapBuffer glMapBufferOES
#define glUnmapBuffer glUnmapBufferOES
#define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
#define GL_WRITE_ONLY GL_WRITE_ONLY_OES
#define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
#define GL_WRITE_ONLY GL_WRITE_ONLY_OES
// GL_GLEXT_PROTOTYPES isn't defined in glplatform.h on android ndk r7
// we manually define it here

View File

@ -93,12 +93,12 @@ public:
*/
virtual bool openURL(const std::string &url);
/**
@brief This function will be called when the application screen size is changed.
@param new width
@param new height
*/
virtual void applicationScreenSizeChanged(int newWidth, int newHeight);
/**
@brief This function will be called when the application screen size is changed.
@param new width
@param new height
*/
virtual void applicationScreenSizeChanged(int newWidth, int newHeight);
protected:
static Application * sm_pSharedApplication;

View File

@ -147,13 +147,13 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
originalRect_ = self.frame;
self.keyboardShowNotification = nil;
if ([self respondsToSelector:@selector(setContentScaleFactor:)])
{
self.contentScaleFactor = [[UIScreen mainScreen] scale];
}
}
if ([self respondsToSelector:@selector(setContentScaleFactor:)])
{
self.contentScaleFactor = [[UIScreen mainScreen] scale];
}
}
return self;
}
@ -349,25 +349,25 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
- (CGPoint) convertPointFromViewToSurface:(CGPoint)point
{
CGRect bounds = [self bounds];
CGPoint ret;
ret.x = (point.x - bounds.origin.x) / bounds.size.width * size_.width;
ret.y = (point.y - bounds.origin.y) / bounds.size.height * size_.height;
return ret;
CGPoint ret;
ret.x = (point.x - bounds.origin.x) / bounds.size.width * size_.width;
ret.y = (point.y - bounds.origin.y) / bounds.size.height * size_.height;
return ret;
}
- (CGRect) convertRectFromViewToSurface:(CGRect)rect
{
CGRect bounds = [self bounds];
CGRect ret;
ret.origin.x = (rect.origin.x - bounds.origin.x) / bounds.size.width * size_.width;
ret.origin.y = (rect.origin.y - bounds.origin.y) / bounds.size.height * size_.height;
ret.size.width = rect.size.width / bounds.size.width * size_.width;
ret.size.height = rect.size.height / bounds.size.height * size_.height;
CGRect ret;
ret.origin.x = (rect.origin.x - bounds.origin.x) / bounds.size.width * size_.width;
ret.origin.y = (rect.origin.y - bounds.origin.y) / bounds.size.height * size_.height;
ret.size.width = rect.size.width / bounds.size.width * size_.width;
ret.size.height = rect.size.height / bounds.size.height * size_.height;
return ret;
return ret;
}
@ -775,7 +775,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
float scaleX = glview->getScaleX();
float scaleY = glview->getScaleY();
float scaleY = glview->getScaleY();
@ -847,16 +847,16 @@ UIInterfaceOrientation getFixedOrientation(UIInterfaceOrientation statusBarOrien
-(void) doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)dis
{
[UIView beginAnimations:nil context:nullptr];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:duration];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:duration];
[UIView setAnimationBeginsFromCurrentState:YES];
//NSLog(@"[animation] dis = %f, scale = %f \n", dis, cocos2d::GLView::getInstance()->getScaleY());
if (dis < 0.0f) dis = 0.0f;
auto glview = cocos2d::Director::getInstance()->getOpenGLView();
dis *= glview->getScaleY();
dis *= glview->getScaleY();
dis /= self.contentScaleFactor;
@ -882,7 +882,7 @@ UIInterfaceOrientation getFixedOrientation(UIInterfaceOrientation statusBarOrien
break;
}
[UIView commitAnimations];
[UIView commitAnimations];
}

View File

@ -162,8 +162,8 @@
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer_);
if (depthFormat_ == GL_DEPTH24_STENCIL8_OES) {
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthBuffer_);
}
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthBuffer_);
}
// bind color buffer
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer_);
@ -256,4 +256,3 @@
@end
#endif // CC_PLATFORM_IOS

View File

@ -29,15 +29,15 @@ THE SOFTWARE.
#include "platform/CCPlatformConfig.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
#define glClearDepth glClearDepthf
#define glDeleteVertexArrays glDeleteVertexArraysOES
#define glGenVertexArrays glGenVertexArraysOES
#define glBindVertexArray glBindVertexArrayOES
#define glMapBuffer glMapBufferOES
#define glUnmapBuffer glUnmapBufferOES
#define glClearDepth glClearDepthf
#define glDeleteVertexArrays glDeleteVertexArraysOES
#define glGenVertexArrays glGenVertexArraysOES
#define glBindVertexArray glBindVertexArrayOES
#define glMapBuffer glMapBufferOES
#define glUnmapBuffer glUnmapBufferOES
#define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
#define GL_WRITE_ONLY GL_WRITE_ONLY_OES
#define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
#define GL_WRITE_ONLY GL_WRITE_ONLY_OES
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>

View File

@ -42,37 +42,37 @@ public:
/**
* @js ctor
*/
Application();
Application();
/**
* @js NA
* @lua NA
*/
virtual ~Application();
virtual ~Application();
/**
@brief Callback by Director for limit FPS.
@param interval The time, which expressed in second in second, between current frame and next.
*/
void setAnimationInterval(float interval);
/**
@brief Callback by Director for limit FPS.
@param interval The time, which expressed in second in second, between current frame and next.
*/
void setAnimationInterval(float interval);
/**
@brief Run the message loop.
*/
int run();
/**
@brief Run the message loop.
*/
int run();
/**
@brief Get current applicaiton instance.
@return Current application instance pointer.
*/
static Application* getInstance();
/**
@brief Get current applicaiton instance.
@return Current application instance pointer.
*/
static Application* getInstance();
/** @deprecated Use getInstance() instead */
CC_DEPRECATED_ATTRIBUTE static Application* sharedApplication();
/* override functions */
virtual LanguageType getCurrentLanguage();
/* override functions */
virtual LanguageType getCurrentLanguage();
/**
/**
@brief Get current language iso 639-1 code
@return Current language iso 639-1 code
*/
@ -86,13 +86,13 @@ public:
virtual bool openURL(const std::string &url);
/**
/**
* Sets the Resource root path.
* @deprecated Please use FileUtils::getInstance()->setSearchPaths() instead.
*/
CC_DEPRECATED_ATTRIBUTE void setResourceRootPath(const std::string& rootResDir);
/**
/**
* Gets the Resource root path.
* @deprecated Please use FileUtils::getInstance()->getSearchPaths() instead.
*/
@ -106,7 +106,7 @@ protected:
long _animationInterval; //micro second
std::string _resourceRootPath;
static Application * sm_pSharedApplication;
static Application * sm_pSharedApplication;
};
NS_CC_END

View File

@ -30,7 +30,7 @@ THE SOFTWARE.
#include "GL/glew.h"
#define CC_GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8
#define CC_GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_LINUX

View File

@ -47,26 +47,26 @@ public:
* @lua NA
*/
virtual ~Application();
/**
@brief Callback by Director for limit FPS.
@brief Callback by Director for limit FPS.
@param interval The time, which expressed in second in second, between current frame and next.
*/
virtual void setAnimationInterval(float interval);
/**
@brief Get status bar rectangle in GLView window.
@brief Get status bar rectangle in GLView window.
*/
/**
@brief Run the message loop.
@brief Run the message loop.
* @js NA
* @lua NA
*/
int run();
/**
@brief Get current applicaiton instance.
@brief Get current applicaiton instance.
@return Current application instance pointer.
*/
static Application* getInstance();
@ -79,13 +79,13 @@ public:
@return Current language config
*/
virtual LanguageType getCurrentLanguage();
/**
@brief Get current language iso 639-1 code
@return Current language iso 639-1 code
*/
virtual const char * getCurrentLanguageCode();
/**
@brief Get target platform
*/
@ -126,4 +126,4 @@ NS_CC_END
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_MAC
#endif // end of __CC_APPLICATION_MAC_H__;
#endif // end of __CC_APPLICATION_MAC_H__;

View File

@ -47,21 +47,20 @@ void MessageBox(const char * msg, const char * title)
NSString * tmpTitle = (title) ? [NSString stringWithUTF8String : title] : nil;
NSString * tmpMsg = (msg) ? [NSString stringWithUTF8String : msg] : nil;
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:tmpMsg];
[alert setInformativeText:tmpTitle];
[alert setAlertStyle:NSWarningAlertStyle];
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:tmpMsg];
[alert setInformativeText:tmpTitle];
[alert setAlertStyle:NSWarningAlertStyle];
auto glview = Director::getInstance()->getOpenGLView();
id window = glview->getCocoaWindow();
[alert beginSheetModalForWindow:window
modalDelegate:[window delegate]
didEndSelector:nil
contextInfo:nil];
[alert beginSheetModalForWindow:window
modalDelegate:[window delegate]
didEndSelector:nil
contextInfo:nil];
}
NS_CC_END
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_MAC

View File

@ -40,7 +40,7 @@ int Device::getDPI()
NSDictionary *description = [screen deviceDescription];
NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue];
CGSize displayPhysicalSize = CGDisplayScreenSize([[description objectForKey:@"NSScreenNumber"] unsignedIntValue]);
return ((displayPixelSize.width / displayPhysicalSize.width) * 25.4f);
}
@ -58,81 +58,81 @@ typedef struct
{
int height;
int width;
bool hasAlpha;
bool isPremultipliedAlpha;
unsigned char* data;
bool hasAlpha;
bool isPremultipliedAlpha;
unsigned char* data;
} tImageInfo;
static bool _initWithString(const char * text, Device::TextAlign align, const char * fontName, int size, tImageInfo* info, const Color3B* fontColor, int fontAlpha)
{
bool ret = false;
CCASSERT(text, "Invalid pText");
CCASSERT(info, "Invalid pInfo");
do {
NSString * string = [NSString stringWithUTF8String:text];
CCASSERT(text, "Invalid pText");
CCASSERT(info, "Invalid pInfo");
do {
NSString * string = [NSString stringWithUTF8String:text];
NSString * fntName = [NSString stringWithUTF8String:fontName];
fntName = [[fntName lastPathComponent] stringByDeletingPathExtension];
// font
NSFont *font = [[NSFontManager sharedFontManager]
// font
NSFont *font = [[NSFontManager sharedFontManager]
fontWithFamily:fntName
traits:NSUnboldFontMask | NSUnitalicFontMask
traits:NSUnboldFontMask | NSUnitalicFontMask
weight:0
size:size];
if (font == nil) {
font = [[NSFontManager sharedFontManager]
fontWithFamily:@"Arial"
traits:NSUnboldFontMask | NSUnitalicFontMask
weight:0
size:size];
}
CC_BREAK_IF(!font);
// color
NSColor* foregroundColor;
if (font == nil) {
font = [[NSFontManager sharedFontManager]
fontWithFamily:@"Arial"
traits:NSUnboldFontMask | NSUnitalicFontMask
weight:0
size:size];
}
CC_BREAK_IF(!font);
// color
NSColor* foregroundColor;
if (fontColor) {
foregroundColor = [NSColor colorWithDeviceRed:fontColor->r/255.0 green:fontColor->g/255.0 blue:fontColor->b/255.0 alpha:fontAlpha/255.0];
} else {
foregroundColor = [NSColor whiteColor];
}
// alignment, linebreak
unsigned horiFlag = (int)align & 0x0f;
unsigned vertFlag = ((int)align >> 4) & 0x0f;
NSTextAlignment textAlign = (2 == horiFlag) ? NSRightTextAlignment
} else {
foregroundColor = [NSColor whiteColor];
}
// alignment, linebreak
unsigned horiFlag = (int)align & 0x0f;
unsigned vertFlag = ((int)align >> 4) & 0x0f;
NSTextAlignment textAlign = (2 == horiFlag) ? NSRightTextAlignment
: (3 == horiFlag) ? NSCenterTextAlignment
: NSLeftTextAlignment;
NSMutableParagraphStyle *paragraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
[paragraphStyle setParagraphStyle:[NSParagraphStyle defaultParagraphStyle]];
[paragraphStyle setLineBreakMode:NSLineBreakByCharWrapping];
[paragraphStyle setAlignment:textAlign];
// attribute
NSDictionary* tokenAttributesDict = [NSDictionary dictionaryWithObjectsAndKeys:
foregroundColor,NSForegroundColorAttributeName,
font, NSFontAttributeName,
paragraphStyle, NSParagraphStyleAttributeName, nil];
NSMutableParagraphStyle *paragraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
[paragraphStyle setParagraphStyle:[NSParagraphStyle defaultParagraphStyle]];
[paragraphStyle setLineBreakMode:NSLineBreakByCharWrapping];
[paragraphStyle setAlignment:textAlign];
// attribute
NSDictionary* tokenAttributesDict = [NSDictionary dictionaryWithObjectsAndKeys:
foregroundColor,NSForegroundColorAttributeName,
font, NSFontAttributeName,
paragraphStyle, NSParagraphStyleAttributeName, nil];
// 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);
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);
NSSize textSize;
NSUInteger lastBreakLocation = 0;
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) {
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 + insertCount;
}
textSize = [lineBreak sizeWithAttributes:tokenAttributesDict];
@ -147,21 +147,21 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
[lineBreak insertString:@"\r" atIndex:[lineBreak length] - 1];
}
insertCount += 1;
}
}
}
}
string = lineBreak;
}
}
string = lineBreak;
}
}
NSAttributedString *stringWithAttributes =[[[NSAttributedString alloc] initWithString:string
NSAttributedString *stringWithAttributes =[[[NSAttributedString alloc] initWithString:string
attributes:tokenAttributesDict] autorelease];
NSSize realDimensions = [stringWithAttributes size];
// Mac crashes if the width or height is 0
CC_BREAK_IF(realDimensions.width <= 0 || realDimensions.height <= 0);
NSSize realDimensions = [stringWithAttributes size];
// Mac crashes if the width or height is 0
CC_BREAK_IF(realDimensions.width <= 0 || realDimensions.height <= 0);
CGSize dimensions = CGSizeMake(info->width, info->height);
CGSize dimensions = CGSizeMake(info->width, info->height);
if(dimensions.width <= 0.f) {
dimensions.width = realDimensions.width;
}
@ -172,15 +172,15 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
NSInteger POTWide = dimensions.width;
NSInteger POTHigh = dimensions.height;
unsigned char* data = nullptr;
//Alignment
CGFloat xPadding = 0;
switch (textAlign) {
case NSLeftTextAlignment: xPadding = 0; break;
case NSCenterTextAlignment: xPadding = (dimensions.width-realDimensions.width)/2.0f; break;
case NSRightTextAlignment: xPadding = dimensions.width-realDimensions.width; break;
default: break;
}
//Alignment
CGFloat xPadding = 0;
switch (textAlign) {
case NSLeftTextAlignment: xPadding = 0; break;
case NSCenterTextAlignment: xPadding = (dimensions.width-realDimensions.width)/2.0f; break;
case NSRightTextAlignment: xPadding = dimensions.width-realDimensions.width; break;
default: break;
}
CGFloat yPadding = 0.f;
switch (vertFlag) {
@ -192,43 +192,43 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
case 3: yPadding = (dimensions.height - realDimensions.height) / 2.0f; break;
default: break;
}
NSRect textRect = NSMakeRect(xPadding, POTHigh - dimensions.height + yPadding, realDimensions.width, realDimensions.height);
//Disable antialias
[[NSGraphicsContext currentContext] setShouldAntialias:NO];
NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(POTWide, POTHigh)];
[image lockFocus];
NSRect textRect = NSMakeRect(xPadding, POTHigh - dimensions.height + yPadding, realDimensions.width, realDimensions.height);
//Disable antialias
[[NSGraphicsContext currentContext] setShouldAntialias:NO];
NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(POTWide, POTHigh)];
[image lockFocus];
// patch for mac retina display and lableTTF
[[NSAffineTransform transform] set];
//[stringWithAttributes drawAtPoint:NSMakePoint(xPadding, offsetY)]; // draw at offset position
[stringWithAttributes drawInRect:textRect];
//[stringWithAttributes drawInRect:textRect withAttributes:tokenAttributesDict];
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect (0.0f, 0.0f, POTWide, POTHigh)];
[image unlockFocus];
data = (unsigned char*) [bitmap bitmapData]; //Use the same buffer to improve the performance.
NSUInteger textureSize = POTWide*POTHigh*4;
unsigned char* dataNew = (unsigned char*)malloc(sizeof(unsigned char) * textureSize);
if (dataNew) {
memcpy(dataNew, data, textureSize);
// output params
info->width = static_cast<int>(POTWide);
info->height = static_cast<int>(POTHigh);
info->data = dataNew;
info->hasAlpha = true;
info->isPremultipliedAlpha = true;
ret = true;
}
[bitmap release];
[image release];
} while (0);
//[stringWithAttributes drawAtPoint:NSMakePoint(xPadding, offsetY)]; // draw at offset position
[stringWithAttributes drawInRect:textRect];
//[stringWithAttributes drawInRect:textRect withAttributes:tokenAttributesDict];
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect (0.0f, 0.0f, POTWide, POTHigh)];
[image unlockFocus];
data = (unsigned char*) [bitmap bitmapData]; //Use the same buffer to improve the performance.
NSUInteger textureSize = POTWide*POTHigh*4;
unsigned char* dataNew = (unsigned char*)malloc(sizeof(unsigned char) * textureSize);
if (dataNew) {
memcpy(dataNew, data, textureSize);
// output params
info->width = static_cast<int>(POTWide);
info->height = static_cast<int>(POTHigh);
info->data = dataNew;
info->hasAlpha = true;
info->isPremultipliedAlpha = true;
ret = true;
}
[bitmap release];
[image release];
} while (0);
return ret;
}

View File

@ -204,12 +204,12 @@ LanguageType Application::getCurrentLanguage()
const char * Application::getCurrentLanguageCode()
{
LANGID lid = GetUserDefaultUILanguage();
const LCID locale_id = MAKELCID(lid, SORT_DEFAULT);
static char code[3] = { 0 };
GetLocaleInfoA(locale_id, LOCALE_SISO639LANGNAME, code, sizeof(code));
code[2] = '\0';
return code;
LANGID lid = GetUserDefaultUILanguage();
const LCID locale_id = MAKELCID(lid, SORT_DEFAULT);
static char code[3] = { 0 };
GetLocaleInfoA(locale_id, LOCALE_SISO639LANGNAME, code, sizeof(code));
code[2] = '\0';
return code;
}
Application::Platform Application::getTargetPlatform()

View File

@ -68,7 +68,7 @@ public:
virtual void setAnimationInterval(float interval);
virtual LanguageType getCurrentLanguage();
virtual const char * getCurrentLanguageCode();
virtual const char * getCurrentLanguageCode();
/**
@brief Get target platform

View File

@ -48,14 +48,14 @@ void LuaLog(const char *pszMsg)
OutputDebugStringW(widebuff);
OutputDebugStringA("\n");
bufflen = WideCharToMultiByte(CP_ACP, 0, widebuff, -1, nullptr, 0, nullptr, nullptr);
char* buff = new char[bufflen + 1];
memset(buff, 0, sizeof(char) * (bufflen + 1));
WideCharToMultiByte(CP_ACP, 0, widebuff, -1, buff, bufflen, nullptr, nullptr);
puts(buff);
bufflen = WideCharToMultiByte(CP_ACP, 0, widebuff, -1, nullptr, 0, nullptr, nullptr);
char* buff = new char[bufflen + 1];
memset(buff, 0, sizeof(char) * (bufflen + 1));
WideCharToMultiByte(CP_ACP, 0, widebuff, -1, buff, bufflen, nullptr, nullptr);
puts(buff);
delete[] widebuff;
delete[] buff;
delete[] widebuff;
delete[] buff;
}
NS_CC_END

View File

@ -31,7 +31,7 @@ THE SOFTWARE.
#include "GL/glew.h"
#define CC_GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8
#define CC_GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32

View File

@ -151,8 +151,5 @@ void Cocos2dRenderer::QueueBackButtonEvent()
void Cocos2dRenderer::QueueKeyboardEvent(WinRTKeyboardEventType type, Windows::UI::Core::KeyEventArgs^ args)
{
GLViewImpl::sharedOpenGLView()->QueueWinRTKeyboardEvent(type, args);
GLViewImpl::sharedOpenGLView()->QueueWinRTKeyboardEvent(type, args);
}

View File

@ -34,9 +34,9 @@ namespace cocos2d
Windows::UI::Core::CoreDispatcher^ dispathcer, Windows::UI::Xaml::Controls::Panel^ panel);
~Cocos2dRenderer();
void Draw(GLsizei width, GLsizei height, float dpi, Windows::Graphics::Display::DisplayOrientations orientation);
void QueuePointerEvent(PointerEventType type, Windows::UI::Core::PointerEventArgs^ args);
void QueueKeyboardEvent(WinRTKeyboardEventType type, Windows::UI::Core::KeyEventArgs^ args);
void QueueBackButtonEvent();
void QueuePointerEvent(PointerEventType type, Windows::UI::Core::PointerEventArgs^ args);
void QueueKeyboardEvent(WinRTKeyboardEventType type, Windows::UI::Core::KeyEventArgs^ args);
void QueueBackButtonEvent();
void Pause();
void Resume();
void DeviceLost();
@ -54,4 +54,4 @@ namespace cocos2d
Platform::Agile<Windows::UI::Xaml::Controls::Panel> m_panel;
Windows::Graphics::Display::DisplayOrientations m_orientation;
};
}
}