From 81fda225970eeac0981aa783b3f2e21ca7ba51d2 Mon Sep 17 00:00:00 2001 From: johnangel Date: Thu, 13 Sep 2012 19:13:38 +0200 Subject: [PATCH 01/64] OpenGL access violation fix --- cocos2dx/platform/win32/CCEGLView.cpp | 91 +++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 13 deletions(-) diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index aead83fd60..b21ae220d4 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -40,7 +40,7 @@ static void SetupPixelFormat(HDC hDC) int pixelFormat; PIXELFORMATDESCRIPTOR pfd = - { + { sizeof(PIXELFORMATDESCRIPTOR), // size 1, // version PFD_SUPPORT_OPENGL | // OpenGL window @@ -65,6 +65,68 @@ static void SetupPixelFormat(HDC hDC) SetPixelFormat(hDC, pixelFormat, &pfd); } +void glew_dynamic_binding() +{ + const char *gl_extensions = (const char*)glGetString(GL_EXTENSIONS); + + /* If the current opengl driver don't have framebuffers methods, + * Check if an extension exist + */ + if (glGenFramebuffers == NULL) + { + CCLog("OpenGL: glGenFramebuffers is NULL, try to detect an extension\n"); + if (strstr(gl_extensions, "ARB_framebuffer_object")) + { + CCLog("OpenGL: ARB_framebuffer_object is supported\n"); + + glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) wglGetProcAddress("glIsRenderbuffer"); + glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) wglGetProcAddress("glBindRenderbuffer"); + glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) wglGetProcAddress("glDeleteRenderbuffers"); + glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) wglGetProcAddress("glGenRenderbuffers"); + glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) wglGetProcAddress("glRenderbufferStorage"); + glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) wglGetProcAddress("glGetRenderbufferParameteriv"); + glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC) wglGetProcAddress("glIsFramebuffer"); + glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) wglGetProcAddress("glBindFramebuffer"); + glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) wglGetProcAddress("glDeleteFramebuffers"); + glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) wglGetProcAddress("glGenFramebuffers"); + glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) wglGetProcAddress("glCheckFramebufferStatus"); + glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC) wglGetProcAddress("glFramebufferTexture1D"); + glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) wglGetProcAddress("glFramebufferTexture2D"); + glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC) wglGetProcAddress("glFramebufferTexture3D"); + glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) wglGetProcAddress("glFramebufferRenderbuffer"); + glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) wglGetProcAddress("glGetFramebufferAttachmentParameteriv"); + glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) wglGetProcAddress("glGenerateMipmap"); + } + else + if (strstr(gl_extensions, "EXT_framebuffer_object")) + { + CCLog("GL: EXT_framebuffer_object is supported\n"); + glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) wglGetProcAddress("glIsRenderbufferEXT"); + glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) wglGetProcAddress("glBindRenderbufferEXT"); + glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) wglGetProcAddress("glDeleteRenderbuffersEXT"); + glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) wglGetProcAddress("glGenRenderbuffersEXT"); + glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) wglGetProcAddress("glRenderbufferStorageEXT"); + glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) wglGetProcAddress("glGetRenderbufferParameterivEXT"); + glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC) wglGetProcAddress("glIsFramebufferEXT"); + glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) wglGetProcAddress("glBindFramebufferEXT"); + glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) wglGetProcAddress("glDeleteFramebuffersEXT"); + glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) wglGetProcAddress("glGenFramebuffersEXT"); + glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) wglGetProcAddress("glCheckFramebufferStatusEXT"); + glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC) wglGetProcAddress("glFramebufferTexture1DEXT"); + glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) wglGetProcAddress("glFramebufferTexture2DEXT"); + glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC) wglGetProcAddress("glFramebufferTexture3DEXT"); + glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) wglGetProcAddress("glFramebufferRenderbufferEXT"); + glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) wglGetProcAddress("glGetFramebufferAttachmentParameterivEXT"); + glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) wglGetProcAddress("glGenerateMipmapEXT"); + } + else + { + CCLog("OpenGL: No framebuffers extension is supported\n"); + CCLog("OpenGL: Any call to Fbo will crash!\n"); + } + } +} + ////////////////////////////////////////////////////////////////////////// // impliment CCEGLView ////////////////////////////////////////////////////////////////////////// @@ -119,14 +181,14 @@ bool CCEGLView::initGL() if ( atof((const char*)glVersion) < 1.5 ) { char strComplain[256] = {0}; - sprintf(strComplain, - "Your OpenGL version is %s, but Cocos2d-x requires OpenGL 1.5 or higher on Windows. Please upgrade the driver of your video card", + sprintf(strComplain, + "Your OpenGL version is %s, but Cocos2d-x requires OpenGL 1.5 or higher on Windows. Please upgrade the driver of your video card", glVersion); CCMessageBox(strComplain, "OpenGL version tooooooooooold"); } GLenum GlewInitResult = glewInit(); - if (GLEW_OK != GlewInitResult) + if (GLEW_OK != GlewInitResult) { fprintf(stderr,"ERROR: %s\n",glewGetErrorString(GlewInitResult)); return false; @@ -136,7 +198,7 @@ bool CCEGLView::initGL() { CCLog("Ready for GLSL"); } - else + else { CCLog("Not totally ready :("); } @@ -149,6 +211,9 @@ bool CCEGLView::initGL() { CCLog("OpenGL 2.0 not supported"); } + + glew_dynamic_binding(); + return true; } @@ -165,7 +230,7 @@ void CCEGLView::destroyGL() bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) { bool bRet = false; - do + do { CC_BREAK_IF(m_hWnd); @@ -173,7 +238,7 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) WNDCLASS wc; // Windows Class Structure // Redraw On Size, And Own DC For Window. - wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; + wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = _WindowProc; // WndProc Handles Messages wc.cbClsExtra = 0; // No Extra Window Data wc.cbWndExtra = 0; // No Extra Window Data @@ -181,10 +246,10 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); // Load The Default Icon wc.hCursor = LoadCursor( NULL, IDC_ARROW ); // Load The Arrow Pointer wc.hbrBackground = NULL; // No Background Required For GL - wc.lpszMenuName = m_menu; // + wc.lpszMenuName = m_menu; // wc.lpszClassName = kWindowClassName; // Set The Class Name - CC_BREAK_IF(! RegisterClass(&wc) && 1410 != GetLastError()); + CC_BREAK_IF(! RegisterClass(&wc) && 1410 != GetLastError()); // center window position RECT rcDesktop; @@ -213,7 +278,7 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) bRet = initGL(); CC_BREAK_IF(!bRet); - + s_pMainWindow = this; bRet = true; } while (0); @@ -357,7 +422,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) default: if (m_wndproc) { - + m_wndproc(message, wParam, lParam, &bProcessed); if (bProcessed) break; } @@ -463,7 +528,7 @@ void CCEGLView::resize(int width, int height) kWindowClassName, frameSize.width, frameSize.height, 1.0f / m_windowTouchScaleX); SetWindowText(m_hWnd, buff); } - + AdjustWindowRectEx(&rcClient, GetWindowLong(m_hWnd, GWL_STYLE), false, GetWindowLong(m_hWnd, GWL_EXSTYLE)); // change width and height @@ -517,7 +582,7 @@ bool CCEGLView::setContentScaleFactor(float contentScaleFactor) CCEGLViewProtocol::setContentScaleFactor(contentScaleFactor); resize((int)(m_obScreenSize.width * contentScaleFactor), (int)(m_obScreenSize.height * contentScaleFactor)); centerWindow(); - + return true; } From 6396089b161da9666b95a8d459956fa5dc6978e4 Mon Sep 17 00:00:00 2001 From: johnangel Date: Thu, 13 Sep 2012 19:18:43 +0200 Subject: [PATCH 02/64] Revert "OpenGL access violation fix" This reverts commit 81fda225970eeac0981aa783b3f2e21ca7ba51d2. --- cocos2dx/platform/win32/CCEGLView.cpp | 91 ++++----------------------- 1 file changed, 13 insertions(+), 78 deletions(-) diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index b21ae220d4..aead83fd60 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -40,7 +40,7 @@ static void SetupPixelFormat(HDC hDC) int pixelFormat; PIXELFORMATDESCRIPTOR pfd = - { + { sizeof(PIXELFORMATDESCRIPTOR), // size 1, // version PFD_SUPPORT_OPENGL | // OpenGL window @@ -65,68 +65,6 @@ static void SetupPixelFormat(HDC hDC) SetPixelFormat(hDC, pixelFormat, &pfd); } -void glew_dynamic_binding() -{ - const char *gl_extensions = (const char*)glGetString(GL_EXTENSIONS); - - /* If the current opengl driver don't have framebuffers methods, - * Check if an extension exist - */ - if (glGenFramebuffers == NULL) - { - CCLog("OpenGL: glGenFramebuffers is NULL, try to detect an extension\n"); - if (strstr(gl_extensions, "ARB_framebuffer_object")) - { - CCLog("OpenGL: ARB_framebuffer_object is supported\n"); - - glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) wglGetProcAddress("glIsRenderbuffer"); - glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) wglGetProcAddress("glBindRenderbuffer"); - glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) wglGetProcAddress("glDeleteRenderbuffers"); - glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) wglGetProcAddress("glGenRenderbuffers"); - glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) wglGetProcAddress("glRenderbufferStorage"); - glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) wglGetProcAddress("glGetRenderbufferParameteriv"); - glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC) wglGetProcAddress("glIsFramebuffer"); - glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) wglGetProcAddress("glBindFramebuffer"); - glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) wglGetProcAddress("glDeleteFramebuffers"); - glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) wglGetProcAddress("glGenFramebuffers"); - glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) wglGetProcAddress("glCheckFramebufferStatus"); - glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC) wglGetProcAddress("glFramebufferTexture1D"); - glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) wglGetProcAddress("glFramebufferTexture2D"); - glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC) wglGetProcAddress("glFramebufferTexture3D"); - glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) wglGetProcAddress("glFramebufferRenderbuffer"); - glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) wglGetProcAddress("glGetFramebufferAttachmentParameteriv"); - glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) wglGetProcAddress("glGenerateMipmap"); - } - else - if (strstr(gl_extensions, "EXT_framebuffer_object")) - { - CCLog("GL: EXT_framebuffer_object is supported\n"); - glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) wglGetProcAddress("glIsRenderbufferEXT"); - glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) wglGetProcAddress("glBindRenderbufferEXT"); - glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) wglGetProcAddress("glDeleteRenderbuffersEXT"); - glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) wglGetProcAddress("glGenRenderbuffersEXT"); - glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) wglGetProcAddress("glRenderbufferStorageEXT"); - glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) wglGetProcAddress("glGetRenderbufferParameterivEXT"); - glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC) wglGetProcAddress("glIsFramebufferEXT"); - glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) wglGetProcAddress("glBindFramebufferEXT"); - glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) wglGetProcAddress("glDeleteFramebuffersEXT"); - glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) wglGetProcAddress("glGenFramebuffersEXT"); - glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) wglGetProcAddress("glCheckFramebufferStatusEXT"); - glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC) wglGetProcAddress("glFramebufferTexture1DEXT"); - glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) wglGetProcAddress("glFramebufferTexture2DEXT"); - glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC) wglGetProcAddress("glFramebufferTexture3DEXT"); - glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) wglGetProcAddress("glFramebufferRenderbufferEXT"); - glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) wglGetProcAddress("glGetFramebufferAttachmentParameterivEXT"); - glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) wglGetProcAddress("glGenerateMipmapEXT"); - } - else - { - CCLog("OpenGL: No framebuffers extension is supported\n"); - CCLog("OpenGL: Any call to Fbo will crash!\n"); - } - } -} - ////////////////////////////////////////////////////////////////////////// // impliment CCEGLView ////////////////////////////////////////////////////////////////////////// @@ -181,14 +119,14 @@ bool CCEGLView::initGL() if ( atof((const char*)glVersion) < 1.5 ) { char strComplain[256] = {0}; - sprintf(strComplain, - "Your OpenGL version is %s, but Cocos2d-x requires OpenGL 1.5 or higher on Windows. Please upgrade the driver of your video card", + sprintf(strComplain, + "Your OpenGL version is %s, but Cocos2d-x requires OpenGL 1.5 or higher on Windows. Please upgrade the driver of your video card", glVersion); CCMessageBox(strComplain, "OpenGL version tooooooooooold"); } GLenum GlewInitResult = glewInit(); - if (GLEW_OK != GlewInitResult) + if (GLEW_OK != GlewInitResult) { fprintf(stderr,"ERROR: %s\n",glewGetErrorString(GlewInitResult)); return false; @@ -198,7 +136,7 @@ bool CCEGLView::initGL() { CCLog("Ready for GLSL"); } - else + else { CCLog("Not totally ready :("); } @@ -211,9 +149,6 @@ bool CCEGLView::initGL() { CCLog("OpenGL 2.0 not supported"); } - - glew_dynamic_binding(); - return true; } @@ -230,7 +165,7 @@ void CCEGLView::destroyGL() bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) { bool bRet = false; - do + do { CC_BREAK_IF(m_hWnd); @@ -238,7 +173,7 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) WNDCLASS wc; // Windows Class Structure // Redraw On Size, And Own DC For Window. - wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; + wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = _WindowProc; // WndProc Handles Messages wc.cbClsExtra = 0; // No Extra Window Data wc.cbWndExtra = 0; // No Extra Window Data @@ -246,10 +181,10 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); // Load The Default Icon wc.hCursor = LoadCursor( NULL, IDC_ARROW ); // Load The Arrow Pointer wc.hbrBackground = NULL; // No Background Required For GL - wc.lpszMenuName = m_menu; // + wc.lpszMenuName = m_menu; // wc.lpszClassName = kWindowClassName; // Set The Class Name - CC_BREAK_IF(! RegisterClass(&wc) && 1410 != GetLastError()); + CC_BREAK_IF(! RegisterClass(&wc) && 1410 != GetLastError()); // center window position RECT rcDesktop; @@ -278,7 +213,7 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) bRet = initGL(); CC_BREAK_IF(!bRet); - + s_pMainWindow = this; bRet = true; } while (0); @@ -422,7 +357,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) default: if (m_wndproc) { - + m_wndproc(message, wParam, lParam, &bProcessed); if (bProcessed) break; } @@ -528,7 +463,7 @@ void CCEGLView::resize(int width, int height) kWindowClassName, frameSize.width, frameSize.height, 1.0f / m_windowTouchScaleX); SetWindowText(m_hWnd, buff); } - + AdjustWindowRectEx(&rcClient, GetWindowLong(m_hWnd, GWL_STYLE), false, GetWindowLong(m_hWnd, GWL_EXSTYLE)); // change width and height @@ -582,7 +517,7 @@ bool CCEGLView::setContentScaleFactor(float contentScaleFactor) CCEGLViewProtocol::setContentScaleFactor(contentScaleFactor); resize((int)(m_obScreenSize.width * contentScaleFactor), (int)(m_obScreenSize.height * contentScaleFactor)); centerWindow(); - + return true; } From a9f37d4e8bc624acffd4b1edec3684deb993b9d0 Mon Sep 17 00:00:00 2001 From: johnangel Date: Thu, 13 Sep 2012 19:22:03 +0200 Subject: [PATCH 03/64] OpenGL access violation fix --- cocos2dx/platform/win32/CCEGLView.cpp | 91 +++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 13 deletions(-) diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index aead83fd60..b21ae220d4 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -40,7 +40,7 @@ static void SetupPixelFormat(HDC hDC) int pixelFormat; PIXELFORMATDESCRIPTOR pfd = - { + { sizeof(PIXELFORMATDESCRIPTOR), // size 1, // version PFD_SUPPORT_OPENGL | // OpenGL window @@ -65,6 +65,68 @@ static void SetupPixelFormat(HDC hDC) SetPixelFormat(hDC, pixelFormat, &pfd); } +void glew_dynamic_binding() +{ + const char *gl_extensions = (const char*)glGetString(GL_EXTENSIONS); + + /* If the current opengl driver don't have framebuffers methods, + * Check if an extension exist + */ + if (glGenFramebuffers == NULL) + { + CCLog("OpenGL: glGenFramebuffers is NULL, try to detect an extension\n"); + if (strstr(gl_extensions, "ARB_framebuffer_object")) + { + CCLog("OpenGL: ARB_framebuffer_object is supported\n"); + + glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) wglGetProcAddress("glIsRenderbuffer"); + glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) wglGetProcAddress("glBindRenderbuffer"); + glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) wglGetProcAddress("glDeleteRenderbuffers"); + glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) wglGetProcAddress("glGenRenderbuffers"); + glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) wglGetProcAddress("glRenderbufferStorage"); + glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) wglGetProcAddress("glGetRenderbufferParameteriv"); + glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC) wglGetProcAddress("glIsFramebuffer"); + glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) wglGetProcAddress("glBindFramebuffer"); + glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) wglGetProcAddress("glDeleteFramebuffers"); + glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) wglGetProcAddress("glGenFramebuffers"); + glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) wglGetProcAddress("glCheckFramebufferStatus"); + glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC) wglGetProcAddress("glFramebufferTexture1D"); + glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) wglGetProcAddress("glFramebufferTexture2D"); + glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC) wglGetProcAddress("glFramebufferTexture3D"); + glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) wglGetProcAddress("glFramebufferRenderbuffer"); + glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) wglGetProcAddress("glGetFramebufferAttachmentParameteriv"); + glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) wglGetProcAddress("glGenerateMipmap"); + } + else + if (strstr(gl_extensions, "EXT_framebuffer_object")) + { + CCLog("GL: EXT_framebuffer_object is supported\n"); + glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) wglGetProcAddress("glIsRenderbufferEXT"); + glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) wglGetProcAddress("glBindRenderbufferEXT"); + glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) wglGetProcAddress("glDeleteRenderbuffersEXT"); + glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) wglGetProcAddress("glGenRenderbuffersEXT"); + glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) wglGetProcAddress("glRenderbufferStorageEXT"); + glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) wglGetProcAddress("glGetRenderbufferParameterivEXT"); + glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC) wglGetProcAddress("glIsFramebufferEXT"); + glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) wglGetProcAddress("glBindFramebufferEXT"); + glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) wglGetProcAddress("glDeleteFramebuffersEXT"); + glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) wglGetProcAddress("glGenFramebuffersEXT"); + glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) wglGetProcAddress("glCheckFramebufferStatusEXT"); + glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC) wglGetProcAddress("glFramebufferTexture1DEXT"); + glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) wglGetProcAddress("glFramebufferTexture2DEXT"); + glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC) wglGetProcAddress("glFramebufferTexture3DEXT"); + glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) wglGetProcAddress("glFramebufferRenderbufferEXT"); + glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) wglGetProcAddress("glGetFramebufferAttachmentParameterivEXT"); + glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) wglGetProcAddress("glGenerateMipmapEXT"); + } + else + { + CCLog("OpenGL: No framebuffers extension is supported\n"); + CCLog("OpenGL: Any call to Fbo will crash!\n"); + } + } +} + ////////////////////////////////////////////////////////////////////////// // impliment CCEGLView ////////////////////////////////////////////////////////////////////////// @@ -119,14 +181,14 @@ bool CCEGLView::initGL() if ( atof((const char*)glVersion) < 1.5 ) { char strComplain[256] = {0}; - sprintf(strComplain, - "Your OpenGL version is %s, but Cocos2d-x requires OpenGL 1.5 or higher on Windows. Please upgrade the driver of your video card", + sprintf(strComplain, + "Your OpenGL version is %s, but Cocos2d-x requires OpenGL 1.5 or higher on Windows. Please upgrade the driver of your video card", glVersion); CCMessageBox(strComplain, "OpenGL version tooooooooooold"); } GLenum GlewInitResult = glewInit(); - if (GLEW_OK != GlewInitResult) + if (GLEW_OK != GlewInitResult) { fprintf(stderr,"ERROR: %s\n",glewGetErrorString(GlewInitResult)); return false; @@ -136,7 +198,7 @@ bool CCEGLView::initGL() { CCLog("Ready for GLSL"); } - else + else { CCLog("Not totally ready :("); } @@ -149,6 +211,9 @@ bool CCEGLView::initGL() { CCLog("OpenGL 2.0 not supported"); } + + glew_dynamic_binding(); + return true; } @@ -165,7 +230,7 @@ void CCEGLView::destroyGL() bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) { bool bRet = false; - do + do { CC_BREAK_IF(m_hWnd); @@ -173,7 +238,7 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) WNDCLASS wc; // Windows Class Structure // Redraw On Size, And Own DC For Window. - wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; + wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = _WindowProc; // WndProc Handles Messages wc.cbClsExtra = 0; // No Extra Window Data wc.cbWndExtra = 0; // No Extra Window Data @@ -181,10 +246,10 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); // Load The Default Icon wc.hCursor = LoadCursor( NULL, IDC_ARROW ); // Load The Arrow Pointer wc.hbrBackground = NULL; // No Background Required For GL - wc.lpszMenuName = m_menu; // + wc.lpszMenuName = m_menu; // wc.lpszClassName = kWindowClassName; // Set The Class Name - CC_BREAK_IF(! RegisterClass(&wc) && 1410 != GetLastError()); + CC_BREAK_IF(! RegisterClass(&wc) && 1410 != GetLastError()); // center window position RECT rcDesktop; @@ -213,7 +278,7 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) bRet = initGL(); CC_BREAK_IF(!bRet); - + s_pMainWindow = this; bRet = true; } while (0); @@ -357,7 +422,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) default: if (m_wndproc) { - + m_wndproc(message, wParam, lParam, &bProcessed); if (bProcessed) break; } @@ -463,7 +528,7 @@ void CCEGLView::resize(int width, int height) kWindowClassName, frameSize.width, frameSize.height, 1.0f / m_windowTouchScaleX); SetWindowText(m_hWnd, buff); } - + AdjustWindowRectEx(&rcClient, GetWindowLong(m_hWnd, GWL_STYLE), false, GetWindowLong(m_hWnd, GWL_EXSTYLE)); // change width and height @@ -517,7 +582,7 @@ bool CCEGLView::setContentScaleFactor(float contentScaleFactor) CCEGLViewProtocol::setContentScaleFactor(contentScaleFactor); resize((int)(m_obScreenSize.width * contentScaleFactor), (int)(m_obScreenSize.height * contentScaleFactor)); centerWindow(); - + return true; } From fdec1ba4b9890495c18f14b2f7332ea98f0fdd35 Mon Sep 17 00:00:00 2001 From: johnangel Date: Sat, 15 Sep 2012 16:34:31 +0200 Subject: [PATCH 04/64] Fixing include paths to be able to compile cocos2d-x using external Visual Studio solution, without copying all files --- cocos2dx/proj.win32/cocos2d.vcxproj | 8 ++++---- extensions/proj.win32/libExtensions.vcxproj | 4 ++-- samples/HelloCpp/proj.win32/HelloCpp.vcxproj | 4 ++-- samples/HelloLua/proj.win32/HelloLua.vcxproj | 4 ++-- samples/TestCpp/proj.win32/TestCpp.vcxproj | 4 ++-- samples/TestJavascript/proj.win32/TestJavascript.vcxproj | 8 ++++---- samples/TestLua/proj.win32/TestLua.win32.vcxproj | 8 ++++---- scripting/lua/proj.win32/liblua.vcxproj | 4 ++-- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cocos2dx/proj.win32/cocos2d.vcxproj b/cocos2dx/proj.win32/cocos2d.vcxproj index 2b3e5d8ac5..2915b0809f 100644 --- a/cocos2dx/proj.win32/cocos2d.vcxproj +++ b/cocos2dx/proj.win32/cocos2d.vcxproj @@ -57,7 +57,7 @@ Disabled - ..;..\platform\win32;..\platform\third_party\win32\iconv;..\platform\third_party\win32\zlib;..\platform\third_party\win32\libpng;..\platform\third_party\win32\libjpeg;..\platform\third_party\win32\libtiff;..\platform\third_party\win32\libxml2;..\platform\third_party\win32\pthread;..\platform\third_party\win32\OGLES;..\include;..\kazmath\include;%(AdditionalIncludeDirectories) + $(ProjectDir)..;$(ProjectDir)..\platform\win32;$(ProjectDir)..\platform\third_party\win32\iconv;$(ProjectDir)..\platform\third_party\win32\zlib;$(ProjectDir)..\platform\third_party\win32\libpng;$(ProjectDir)..\platform\third_party\win32\libjpeg;$(ProjectDir)..\platform\third_party\win32\libtiff;$(ProjectDir)..\platform\third_party\win32\libxml2;$(ProjectDir)..\platform\third_party\win32\pthread;$(ProjectDir)..\platform\third_party\win32\OGLES;..\include;$(ProjectDir)..\kazmath\include;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true EnableFastChecks @@ -70,7 +70,7 @@ if not exist "$(OutDir)" mkdir "$(OutDir)" -xcopy /Y /Q "$(SolutionDir)cocos2dx\platform\third_party\win32\libraries\*.*" "$(OutDir)" +xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir)" @@ -95,7 +95,7 @@ xcopy /Y /Q "$(SolutionDir)cocos2dx\platform\third_party\win32\libraries\*.*" "$ - ..;..\platform\win32;..\platform\third_party\win32\iconv;..\platform\third_party\win32\zlib;..\platform\third_party\win32\libpng;..\platform\third_party\win32\libjpeg;..\platform\third_party\win32\libtiff;..\platform\third_party\win32\libxml2;..\platform\third_party\win32\pthread;..\platform\third_party\win32\OGLES;..\include;..\kazmath\include;%(AdditionalIncludeDirectories) + $(ProjectDir)..;$(ProjectDir)..\platform\win32;$(ProjectDir)..\platform\third_party\win32\iconv;$(ProjectDir)..\platform\third_party\win32\zlib;$(ProjectDir)..\platform\third_party\win32\libpng;$(ProjectDir)..\platform\third_party\win32\libjpeg;$(ProjectDir)..\platform\third_party\win32\libtiff;$(ProjectDir)..\platform\third_party\win32\libxml2;$(ProjectDir)..\platform\third_party\win32\pthread;$(ProjectDir)..\platform\third_party\win32\OGLES;..\include;$(ProjectDir)..\kazmath\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL @@ -106,7 +106,7 @@ xcopy /Y /Q "$(SolutionDir)cocos2dx\platform\third_party\win32\libraries\*.*" "$ if not exist "$(OutDir)" mkdir "$(OutDir)" -xcopy /Y /Q "$(SolutionDir)cocos2dx\platform\third_party\win32\libraries\*.*" "$(OutDir)" +xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir)" diff --git a/extensions/proj.win32/libExtensions.vcxproj b/extensions/proj.win32/libExtensions.vcxproj index dfa1658716..3d281b25d1 100644 --- a/extensions/proj.win32/libExtensions.vcxproj +++ b/extensions/proj.win32/libExtensions.vcxproj @@ -51,7 +51,7 @@ Disabled - $(SolutionDir)cocos2dx;$(SolutionDir)cocos2dx\include;$(SolutionDir)cocos2dx\kazmath\include;$(SolutionDir)cocos2dx\platform\win32;$(SolutionDir)cocos2dx\platform\third_party\win32;$(SolutionDir)cocos2dx\platform\third_party\win32\pthread;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES;..\;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\cocos2dx;$(ProjectDir)..\..\cocos2dx\include;$(ProjectDir)..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\pthread;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\OGLES;..\;%(AdditionalIncludeDirectories) WIN32;_WINDOWS;_DEBUG;_LIB;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true EnableFastChecks @@ -67,7 +67,7 @@ MaxSpeed true - $(SolutionDir)cocos2dx;$(SolutionDir)cocos2dx\include;$(SolutionDir)cocos2dx\kazmath\include;$(SolutionDir)cocos2dx\platform\win32;$(SolutionDir)cocos2dx\platform\third_party\win32;$(SolutionDir)cocos2dx\platform\third_party\win32\pthread;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES;..\;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\cocos2dx;$(ProjectDir)..\..\cocos2dx\include;$(ProjectDir)..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\pthread;$(ProjectDir)..\..\cocos2dx\platform\third_party\win32\OGLES;..\;%(AdditionalIncludeDirectories) WIN32;_WINDOWS;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL true diff --git a/samples/HelloCpp/proj.win32/HelloCpp.vcxproj b/samples/HelloCpp/proj.win32/HelloCpp.vcxproj index dd2fdeb548..840038a9e5 100644 --- a/samples/HelloCpp/proj.win32/HelloCpp.vcxproj +++ b/samples/HelloCpp/proj.win32/HelloCpp.vcxproj @@ -53,7 +53,7 @@ Disabled - $(SolutionDir)cocos2dx;$(SolutionDir)cocos2dx\include;$(SolutionDir)cocos2dx\kazmath\include;$(SolutionDir)cocos2dx\platform\win32;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES;..\Classes;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\..\cocos2dx;$(ProjectDir)..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\OGLES;..\Classes;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true EnableFastChecks @@ -81,7 +81,7 @@ MaxSpeed true - $(SolutionDir)cocos2dx;$(SolutionDir)cocos2dx\include;$(SolutionDir)cocos2dx\kazmath\include;$(SolutionDir)cocos2dx\platform\win32;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES;..\Classes;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\..\cocos2dx;$(ProjectDir)..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\OGLES;..\Classes;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL true diff --git a/samples/HelloLua/proj.win32/HelloLua.vcxproj b/samples/HelloLua/proj.win32/HelloLua.vcxproj index 86b1f3b804..1f668e0156 100644 --- a/samples/HelloLua/proj.win32/HelloLua.vcxproj +++ b/samples/HelloLua/proj.win32/HelloLua.vcxproj @@ -63,7 +63,7 @@ Disabled - .;..\Classes;$(SolutionDir)scripting\lua\cocos2dx_support;$(SolutionDir)scripting\lua\lua;$(SolutionDir)scripting\lua\tolua;$(SolutionDir)scripting\lua\src;$(SolutionDir)cocos2dx;$(SolutionDir)cocos2dx\include;$(SolutionDir)cocos2dx\kazmath\include;$(SolutionDir)cocos2dx\platform\win32;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES;$(SolutionDir)CocosDenshion\include;%(AdditionalIncludeDirectories) + $(ProjectDir)..\Classes;$(ProjectDir)..\..\..\scripting\lua\cocos2dx_support;$(ProjectDir)..\..\..\scripting\lua\lua;$(ProjectDir)..\..\..\scripting\lua\tolua;$(ProjectDir)..\..\..\scripting\lua\src;$(ProjectDir)..\..\..\cocos2dx;$(ProjectDir)..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\CocosDenshion\include;%(AdditionalIncludeDirectories) WIN32;_WINDOWS;STRICT;_DEBUG;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true EnableFastChecks @@ -101,7 +101,7 @@ HelloLua_p.c - .;..\Classes;$(SolutionDir)scripting\lua\cocos2dx_support;$(SolutionDir)scripting\lua\lua;$(SolutionDir)scripting\lua\tolua;$(SolutionDir)scripting\lua\src;$(SolutionDir)cocos2dx;$(SolutionDir)cocos2dx\include;$(SolutionDir)cocos2dx\kazmath\include;$(SolutionDir)cocos2dx\platform\win32;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES;$(SolutionDir)CocosDenshion\include;%(AdditionalIncludeDirectories) + $(ProjectDir)..\Classes;$(ProjectDir)..\..\..\scripting\lua\cocos2dx_support;$(ProjectDir)..\..\..\scripting\lua\lua;$(ProjectDir)..\..\..\scripting\lua\tolua;$(ProjectDir)..\..\..\scripting\lua\src;$(ProjectDir)..\..\..\cocos2dx;$(ProjectDir)..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\CocosDenshion\include;%(AdditionalIncludeDirectories) WIN32;_WINDOWS;STRICT;NDEBUG;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) diff --git a/samples/TestCpp/proj.win32/TestCpp.vcxproj b/samples/TestCpp/proj.win32/TestCpp.vcxproj index a2fc4033d9..6fcda8f57f 100644 --- a/samples/TestCpp/proj.win32/TestCpp.vcxproj +++ b/samples/TestCpp/proj.win32/TestCpp.vcxproj @@ -53,7 +53,7 @@ Disabled - $(SolutionDir)cocos2dx;$(SolutionDir)cocos2dx\include;$(SolutionDir)cocos2dx\kazmath\include;$(SolutionDir)cocos2dx\platform\win32;$(SolutionDir)cocos2dx\platform\third_party\win32;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES;$(SolutionDir)external;$(SolutionDir)external\chipmunk\include\chipmunk;$(SolutionDir)CocosDenshion\include;$(SolutionDir)extensions;..\Classes;..;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\..\cocos2dx;$(ProjectDir)..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\external;$(ProjectDir)..\..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\..\CocosDenshion\include;$(ProjectDir)..\..\..\extensions;..\Classes;..;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USE_MATH_DEFINES;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true EnableFastChecks @@ -81,7 +81,7 @@ MaxSpeed true - $(SolutionDir)cocos2dx;$(SolutionDir)cocos2dx\include;$(SolutionDir)cocos2dx\kazmath\include;$(SolutionDir)cocos2dx\platform\win32;$(SolutionDir)cocos2dx\platform\third_party\win32;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES;$(SolutionDir)external;$(SolutionDir)external\chipmunk\include\chipmunk;$(SolutionDir)CocosDenshion\include;$(SolutionDir)extensions;..\Classes;..;%(AdditionalIncludeDirectories) + $(ProjectDir)..\..\..\cocos2dx;$(ProjectDir)..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\external;$(ProjectDir)..\..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\..\CocosDenshion\include;$(ProjectDir)..\..\..\extensions;..\Classes;..;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USE_MATH_DEFINES;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL true diff --git a/samples/TestJavascript/proj.win32/TestJavascript.vcxproj b/samples/TestJavascript/proj.win32/TestJavascript.vcxproj index 15740b3ba1..12c8ee6196 100644 --- a/samples/TestJavascript/proj.win32/TestJavascript.vcxproj +++ b/samples/TestJavascript/proj.win32/TestJavascript.vcxproj @@ -63,7 +63,7 @@ Disabled - .;..\Classes;$(SolutionDir)scripting\javascript\spidermonkey-win32\include;$(SolutionDir)external\chipmunk\include\chipmunk;$(SolutionDir)scripting\javascript\bindings;$(SolutionDir)cocos2dx;$(SolutionDir)cocos2dx\include;$(SolutionDir)cocos2dx\kazmath\include;$(SolutionDir)cocos2dx\platform\win32;$(SolutionDir)cocos2dx\platform\third_party\win32;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES;$(SolutionDir)CocosDenshion\include;%(AdditionalIncludeDirectories) + $(ProjectDir)..\Classes;$(ProjectDir)..\..\..\scripting\javascript\spidermonkey-win32\include;$(ProjectDir)..\..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\..\scripting\javascript\bindings;$(ProjectDir)..\..\..\cocos2dx;$(ProjectDir)..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\CocosDenshion\include;%(AdditionalIncludeDirectories) WIN32;_WINDOWS;STRICT;_DEBUG;XP_WIN;JS_HAVE___INTN;JS_INTPTR_TYPE=int;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true EnableFastChecks @@ -81,7 +81,7 @@ if not exist "$(OutDir)" mkdir "$(OutDir)" -xcopy /Y /Q "$(SolutionDir)scripting\javascript\spidermonkey-win32\lib\*.*" "$(OutDir)" +xcopy /Y /Q "$(ProjectDir)..\..\..\scripting\javascript\spidermonkey-win32\lib\*.*" "$(OutDir)" @@ -106,7 +106,7 @@ xcopy /Y /Q "$(SolutionDir)scripting\javascript\spidermonkey-win32\lib\*.*" "$(O testjs_p.c - .;..\Classes;$(SolutionDir)scripting\javascript\spidermonkey-win32\include;$(SolutionDir)external\chipmunk\include\chipmunk;$(SolutionDir)scripting\javascript\bindings;$(SolutionDir)cocos2dx;$(SolutionDir)cocos2dx\include;$(SolutionDir)cocos2dx\kazmath\include;$(SolutionDir)cocos2dx\platform\win32;$(SolutionDir)cocos2dx\platform\third_party\win32;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES;$(SolutionDir)CocosDenshion\include;%(AdditionalIncludeDirectories) + $(ProjectDir)..\Classes;$(ProjectDir)..\..\..\scripting\javascript\spidermonkey-win32\include;$(ProjectDir)..\..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\..\scripting\javascript\bindings;$(ProjectDir)..\..\..\cocos2dx;$(ProjectDir)..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\CocosDenshion\include;%(AdditionalIncludeDirectories) WIN32;_WINDOWS;STRICT;NDEBUG;XP_WIN;JS_HAVE___INTN;JS_INTPTR_TYPE=int;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) @@ -125,7 +125,7 @@ xcopy /Y /Q "$(SolutionDir)scripting\javascript\spidermonkey-win32\lib\*.*" "$(O if not exist "$(OutDir)" mkdir "$(OutDir)" -xcopy /Y /Q "$(SolutionDir)scripting\javascript\spidermonkey-win32\lib\*.*" "$(OutDir)" +xcopy /Y /Q "$(ProjectDir)..\..\..\scripting\javascript\spidermonkey-win32\lib\*.*" "$(OutDir)" diff --git a/samples/TestLua/proj.win32/TestLua.win32.vcxproj b/samples/TestLua/proj.win32/TestLua.win32.vcxproj index 944cb48209..87e9eb2771 100644 --- a/samples/TestLua/proj.win32/TestLua.win32.vcxproj +++ b/samples/TestLua/proj.win32/TestLua.win32.vcxproj @@ -50,7 +50,7 @@ - .;..\Classes;$(SolutionDir)scripting\lua\cocos2dx_support;$(SolutionDir)scripting\lua\lua;$(SolutionDir)scripting\lua\tolua;$(SolutionDir)scripting\lua\src;$(SolutionDir)cocos2dx;$(SolutionDir)cocos2dx\include;$(SolutionDir)cocos2dx\kazmath\include;$(SolutionDir)cocos2dx\platform\win32;$(SolutionDir)cocos2dx\platform\third_party\win32;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES;$(SolutionDir)external;$(SolutionDir)external\chipmunk\include\chipmunk;$(SolutionDir)CocosDenshion\include;$(SolutionDir)scripting\lua\cocos2dx_support;$(SolutionDir)scripting\lua\tolua;$(SolutionDir)scripting\lua\lua;%(AdditionalIncludeDirectories) + $(ProjectDir)..\Classes;$(ProjectDir)..\..\..\scripting\lua\cocos2dx_support;$(ProjectDir)..\..\..\scripting\lua\lua;$(ProjectDir)..\..\..\scripting\lua\tolua;$(ProjectDir)..\..\..\scripting\lua\src;$(ProjectDir)..\..\..\cocos2dx;$(ProjectDir)..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\external;$(ProjectDir)..\..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\..\CocosDenshion\include;$(ProjectDir)..\..\..\scripting\lua\cocos2dx_support;$(ProjectDir)..\..\..\scripting\lua\tolua;$(ProjectDir)..\..\..\scripting\lua\lua;%(AdditionalIncludeDirectories) Level3 @@ -87,13 +87,13 @@ - xcopy $(SolutionDir)samples\TestCpp\Resources $(SolutionDir)samples\TestLua\Resources /e /Y + xcopy $(ProjectDir)..\..\TestCpp\Resources $(ProjectDir)..\..\TestLua\Resources /e /Y copy files from TestCpp to TestLua - .;..\Classes;$(SolutionDir)cocos2dx;$(SolutionDir)cocos2dx\include;$(SolutionDir)cocos2dx\kazmath\include;$(SolutionDir)cocos2dx\platform\win32;$(SolutionDir)cocos2dx\platform\third_party\win32;$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES;$(SolutionDir)external;$(SolutionDir)external\chipmunk\include\chipmunk;$(SolutionDir)CocosDenshion\include;$(SolutionDir)scripting\lua\cocos2dx_support;$(SolutionDir)scripting\lua\tolua;$(SolutionDir)scripting\lua\lua;%(AdditionalIncludeDirectories) + $(ProjectDir)..\Classes;$(ProjectDir)..\..\..\scripting\lua\cocos2dx_support;$(ProjectDir)..\..\..\scripting\lua\lua;$(ProjectDir)..\..\..\scripting\lua\tolua;$(ProjectDir)..\..\..\scripting\lua\src;$(ProjectDir)..\..\..\cocos2dx;$(ProjectDir)..\..\..\cocos2dx\include;$(ProjectDir)..\..\..\cocos2dx\kazmath\include;$(ProjectDir)..\..\..\cocos2dx\platform\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32;$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\OGLES;$(ProjectDir)..\..\..\external;$(ProjectDir)..\..\..\external\chipmunk\include\chipmunk;$(ProjectDir)..\..\..\CocosDenshion\include;$(ProjectDir)..\..\..\scripting\lua\cocos2dx_support;$(ProjectDir)..\..\..\scripting\lua\tolua;$(ProjectDir)..\..\..\scripting\lua\lua;%(AdditionalIncludeDirectories) Level3 @@ -129,7 +129,7 @@ - xcopy $(SolutionDir)samples\TestCpp\Resources $(SolutionDir)samples\TestLua\Resources /e /Y + xcopy $(ProjectDir)..\..\TestCpp\Resources $(ProjectDir)..\..\TestLua\Resources /e /Y copy files from TestCpp to TestLua diff --git a/scripting/lua/proj.win32/liblua.vcxproj b/scripting/lua/proj.win32/liblua.vcxproj index 924499b478..208819906e 100644 --- a/scripting/lua/proj.win32/liblua.vcxproj +++ b/scripting/lua/proj.win32/liblua.vcxproj @@ -51,7 +51,7 @@ Disabled - $(SolutionDir)scripting\lua\tolua;$(SolutionDir)scripting\lua\lua;%(AdditionalIncludeDirectories) + $(ProjectDir)..\tolua;$(ProjectDir)..\lua;%(AdditionalIncludeDirectories) WIN32;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true EnableFastChecks @@ -74,7 +74,7 @@ MaxSpeed true - $(SolutionDir)scripting\lua\tolua;$(SolutionDir)scripting\lua\lua;%(AdditionalIncludeDirectories) + $(ProjectDir)..\tolua;$(ProjectDir)..\lua;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBLUA_EXPORTS;%(PreprocessorDefinitions) MultiThreadedDLL true From acac470f7bba2608ac3a18fdb89abe53f47d9b94 Mon Sep 17 00:00:00 2001 From: johnangel Date: Wed, 19 Sep 2012 19:36:09 +0200 Subject: [PATCH 05/64] Fixing GPF when old OpenGL version is detected --- cocos2dx/platform/CCEGLViewProtocol.cpp | 4 +++- cocos2dx/platform/CCEGLViewProtocol.h | 2 +- cocos2dx/platform/win32/CCEGLView.cpp | 30 ++++++++++++++++++------- cocos2dx/platform/win32/CCEGLView.h | 2 +- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/cocos2dx/platform/CCEGLViewProtocol.cpp b/cocos2dx/platform/CCEGLViewProtocol.cpp index cd6ea0fbe7..1ee477f4c5 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.cpp +++ b/cocos2dx/platform/CCEGLViewProtocol.cpp @@ -112,9 +112,11 @@ const CCSize& CCEGLViewProtocol::getFrameSize() const return m_obScreenSize; } -void CCEGLViewProtocol::setFrameSize(float width, float height) +bool CCEGLViewProtocol::setFrameSize(float width, float height) { m_obDesignResolutionSize = m_obScreenSize = CCSizeMake(width, height); + + return true; } CCSize CCEGLViewProtocol::getVisibleSize() const diff --git a/cocos2dx/platform/CCEGLViewProtocol.h b/cocos2dx/platform/CCEGLViewProtocol.h index f0db5bf7f5..b2bf422326 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.h +++ b/cocos2dx/platform/CCEGLViewProtocol.h @@ -64,7 +64,7 @@ public: /** * Set the frame size of EGL view. */ - virtual void setFrameSize(float width, float height); + virtual bool setFrameSize(float width, float height); /** * Get the visible area size of opengl viewport. diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index b21ae220d4..f3060ff091 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -65,7 +65,7 @@ static void SetupPixelFormat(HDC hDC) SetPixelFormat(hDC, pixelFormat, &pfd); } -void glew_dynamic_binding() +bool glew_dynamic_binding() { const char *gl_extensions = (const char*)glGetString(GL_EXTENSIONS); @@ -100,7 +100,7 @@ void glew_dynamic_binding() else if (strstr(gl_extensions, "EXT_framebuffer_object")) { - CCLog("GL: EXT_framebuffer_object is supported\n"); + CCLog("OpenGL: EXT_framebuffer_object is supported\n"); glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) wglGetProcAddress("glIsRenderbufferEXT"); glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) wglGetProcAddress("glBindRenderbufferEXT"); glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) wglGetProcAddress("glDeleteRenderbuffersEXT"); @@ -123,8 +123,10 @@ void glew_dynamic_binding() { CCLog("OpenGL: No framebuffers extension is supported\n"); CCLog("OpenGL: Any call to Fbo will crash!\n"); + return false; } } + return true; } ////////////////////////////////////////////////////////////////////////// @@ -182,15 +184,16 @@ bool CCEGLView::initGL() { char strComplain[256] = {0}; sprintf(strComplain, - "Your OpenGL version is %s, but Cocos2d-x requires OpenGL 1.5 or higher on Windows. Please upgrade the driver of your video card", + "OpenGL 1.5 or higher is required (your version is %s). Please upgrade the driver of your video card.", glVersion); - CCMessageBox(strComplain, "OpenGL version tooooooooooold"); + CCMessageBox(strComplain, "OpenGL version too old"); + return false; } GLenum GlewInitResult = glewInit(); if (GLEW_OK != GlewInitResult) { - fprintf(stderr,"ERROR: %s\n",glewGetErrorString(GlewInitResult)); + CCMessageBox((char *)glewGetErrorString(GlewInitResult), "OpenGL error"); return false; } @@ -212,7 +215,11 @@ bool CCEGLView::initGL() CCLog("OpenGL 2.0 not supported"); } - glew_dynamic_binding(); + if(glew_dynamic_binding() == false) + { + CCMessageBox("No OpenGL framebuffer support. Please upgrade the driver of your video card.", "OpenGL error"); + return false; + } return true; } @@ -277,6 +284,7 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) resize(w, h); bRet = initGL(); + if(!bRet) destroyGL(); CC_BREAK_IF(!bRet); s_pMainWindow = this; @@ -536,13 +544,19 @@ void CCEGLView::resize(int width, int height) SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER); } -void CCEGLView::setFrameSize(float width, float height) +bool CCEGLView::setFrameSize(float width, float height) { - Create((LPCTSTR)m_szViewName, (int)width, (int)height); + if(!Create((LPCTSTR)m_szViewName, (int)width, (int)height)) + { + PostQuitMessage(-1); + return false; + } CCEGLViewProtocol::setFrameSize(width, height); resize(width, height); // adjust window size for menubar centerWindow(); + + return true; } void CCEGLView::centerWindow() diff --git a/cocos2dx/platform/win32/CCEGLView.h b/cocos2dx/platform/win32/CCEGLView.h index 2f8877772a..147cc16379 100644 --- a/cocos2dx/platform/win32/CCEGLView.h +++ b/cocos2dx/platform/win32/CCEGLView.h @@ -47,7 +47,7 @@ public: virtual void end(); virtual void swapBuffers(); virtual bool setContentScaleFactor(float contentScaleFactor); - virtual void setFrameSize(float width, float height); + virtual bool setFrameSize(float width, float height); virtual void setIMEKeyboardState(bool bOpen); virtual bool enableRetina(); From 778f663e76a9f1ce7b6c926b748822abaaa5e76f Mon Sep 17 00:00:00 2001 From: johnangel Date: Wed, 19 Sep 2012 19:56:58 +0200 Subject: [PATCH 06/64] Returning setViewName to be able to set game window title --- cocos2dx/platform/CCEGLViewProtocol.cpp | 13 +++++++++++++ cocos2dx/platform/CCEGLViewProtocol.h | 4 ++++ cocos2dx/platform/win32/CCEGLView.cpp | 2 ++ 3 files changed, 19 insertions(+) diff --git a/cocos2dx/platform/CCEGLViewProtocol.cpp b/cocos2dx/platform/CCEGLViewProtocol.cpp index 1ee477f4c5..5ce5f4dbe6 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.cpp +++ b/cocos2dx/platform/CCEGLViewProtocol.cpp @@ -171,6 +171,19 @@ void CCEGLViewProtocol::setScissorInPoints(float x , float y , float w , float h (GLsizei)(h * m_fScaleY)); } +void CCEGLViewProtocol::setViewName(const char* pszViewName) +{ + if (pszViewName != NULL && strlen(pszViewName) > 0) + { + strncpy(m_szViewName, pszViewName, sizeof(m_szViewName)); + } +} + +const char* CCEGLViewProtocol::getViewName() +{ + return m_szViewName; +} + void CCEGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float ys[]) { CCSet set; diff --git a/cocos2dx/platform/CCEGLViewProtocol.h b/cocos2dx/platform/CCEGLViewProtocol.h index b2bf422326..84b3d8dc4a 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.h +++ b/cocos2dx/platform/CCEGLViewProtocol.h @@ -106,6 +106,10 @@ public: * Set Scissor rectangle with points. */ virtual void setScissorInPoints(float x , float y , float w , float h); + + virtual void setViewName(const char* pszViewName); + + const char* getViewName(); /** * Enable retina mode. diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index f3060ff091..526437e4ef 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -530,11 +530,13 @@ void CCEGLView::resize(int width, int height) m_windowTouchScaleX = frameSize.width / width; m_windowTouchScaleY = frameSize.height / height; +/* TCHAR buff[MAX_PATH + 1]; memset(buff, 0, sizeof(buff)); swprintf_s(buff, MAX_PATH, L"%s - %0.0fx%0.0f - %0.2f", kWindowClassName, frameSize.width, frameSize.height, 1.0f / m_windowTouchScaleX); SetWindowText(m_hWnd, buff); +*/ } AdjustWindowRectEx(&rcClient, GetWindowLong(m_hWnd, GWL_STYLE), false, GetWindowLong(m_hWnd, GWL_EXSTYLE)); From 05eb4352e83e4061fe4f0d887f9e7dc8bfcb276a Mon Sep 17 00:00:00 2001 From: Sergey Vikhirev Date: Mon, 24 Sep 2012 14:22:02 +0400 Subject: [PATCH 07/64] Remove retina specific methods and logic --- cocos2dx/CCDirector.cpp | 37 ++------------ cocos2dx/CCDirector.h | 2 - cocos2dx/platform/CCEGLViewProtocol.cpp | 49 ++---------------- cocos2dx/platform/CCEGLViewProtocol.h | 12 ----- cocos2dx/platform/ios/CCEGLView.h | 1 - cocos2dx/platform/ios/CCEGLView.mm | 31 ++---------- cocos2dx/platform/ios/EAGLView.mm | 53 ++++++++++---------- samples/HelloCpp/Classes/AppDelegate.cpp | 44 ++++------------ samples/HelloCpp/Classes/HelloWorldScene.cpp | 15 ++---- 9 files changed, 55 insertions(+), 189 deletions(-) diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index 5b86564aad..d4a587e821 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -335,7 +335,7 @@ void CCDirector::setProjection(ccDirectorProjection kProjection) if (m_pobOpenGLView) { - m_pobOpenGLView->setViewPortInPoints(0, 0, sizePoint.width, sizePoint.height); + m_pobOpenGLView->setViewPortInPoints(0, 0, size.width, size.height); } switch (kProjection) @@ -345,7 +345,7 @@ void CCDirector::setProjection(ccDirectorProjection kProjection) kmGLMatrixMode(KM_GL_PROJECTION); kmGLLoadIdentity(); kmMat4 orthoMatrix; - kmMat4OrthographicProjection(&orthoMatrix, 0, size.width / CC_CONTENT_SCALE_FACTOR(), 0, size.height / CC_CONTENT_SCALE_FACTOR(), -1024, 1024 ); + kmMat4OrthographicProjection(&orthoMatrix, 0, size.width, 0, size.height, -1024, 1024 ); kmGLMultMatrix(&orthoMatrix); kmGLMatrixMode(KM_GL_MODELVIEW); kmGLLoadIdentity(); @@ -370,8 +370,8 @@ void CCDirector::setProjection(ccDirectorProjection kProjection) kmGLMatrixMode(KM_GL_MODELVIEW); kmGLLoadIdentity(); kmVec3 eye, center, up; - kmVec3Fill( &eye, sizePoint.width/2, sizePoint.height/2, zeye ); - kmVec3Fill( ¢er, sizePoint.width/2, sizePoint.height/2, 0.0f ); + kmVec3Fill( &eye, size.width/2, size.height/2, zeye ); + kmVec3Fill( ¢er, size.width/2, size.height/2, 0.0f ); kmVec3Fill( &up, 0.0f, 1.0f, 0.0f); kmMat4LookAt(&matrixLookup, &eye, ¢er, &up); kmGLMultMatrix(&matrixLookup); @@ -403,7 +403,7 @@ void CCDirector::purgeCachedData(void) float CCDirector::getZEye(void) { - return (m_obWinSizeInPixels.height / 1.1566f / CC_CONTENT_SCALE_FACTOR()); + return (m_obWinSizeInPixels.height / 1.1566f); } void CCDirector::setAlphaBlending(bool bOn) @@ -806,33 +806,6 @@ void CCDirector::updateContentScaleFactor() m_bIsContentScaleSupported = m_pobOpenGLView->setContentScaleFactor(m_fContentScaleFactor); } -bool CCDirector::enableRetinaDisplay(bool enabled) -{ - // Already enabled? - if (enabled && m_fContentScaleFactor == 2) - { - return true; - } - - // Already disabled? - if (!enabled && m_fContentScaleFactor == 1) - { - return false; - } - - if (! m_pobOpenGLView->enableRetina()) - { - return false; - } - - float newScale = (float)(enabled ? 2 : 1); - setContentScaleFactor(newScale); - - createStatsLabel(); - - return true; -} - float CCDirector::getContentScaleFactor(void) { return m_fContentScaleFactor; diff --git a/cocos2dx/CCDirector.h b/cocos2dx/CCDirector.h index 9cbc06d6b2..5293fab636 100644 --- a/cocos2dx/CCDirector.h +++ b/cocos2dx/CCDirector.h @@ -159,8 +159,6 @@ public: */ CCNode* getNotificationNode(); void setNotificationNode(CCNode *node); - - bool enableRetinaDisplay(bool bEnabelRetina); // window size diff --git a/cocos2dx/platform/CCEGLViewProtocol.cpp b/cocos2dx/platform/CCEGLViewProtocol.cpp index a4e6080377..63b2d3eb34 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.cpp +++ b/cocos2dx/platform/CCEGLViewProtocol.cpp @@ -46,7 +46,6 @@ CCEGLViewProtocol::CCEGLViewProtocol() : m_pDelegate(NULL) , m_fScaleY(1.0f) , m_fScaleX(1.0f) -, m_bIsRetinaEnabled(false) , m_eResolutionPolicy(kResolutionUnKnown) { } @@ -58,7 +57,6 @@ CCEGLViewProtocol::~CCEGLViewProtocol() void CCEGLViewProtocol::setDesignResolutionSize(float width, float height, ResolutionPolicy resolutionPolicy) { - CCAssert(m_bIsRetinaEnabled == false, "can not enable retina while set design resolution size!"); CCAssert(resolutionPolicy != kResolutionUnKnown, "should set resolutionPolicy"); if (width == 0.0f || height == 0.0f) @@ -97,11 +95,6 @@ void CCEGLViewProtocol::setDesignResolutionSize(float width, float height, Resol CCDirector::sharedDirector()->setGLDefaultValues(); } -bool CCEGLViewProtocol::enableRetina() -{ - return false; -} - const CCSize& CCEGLViewProtocol::getSize() const { return m_obDesignResolutionSize; @@ -193,18 +186,8 @@ void CCEGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float } CCTouch* pTouch = s_pTouches[nUnusedIndex] = new CCTouch(); - if (m_bIsRetinaEnabled) - { - // on iOS, though retina is enabled, the value got from os is also - // relative to its original size - pTouch->setTouchInfo(nUnusedIndex, (x - m_obViewPortRect.origin.x), - (y - m_obViewPortRect.origin.y)); - } - else - { - pTouch->setTouchInfo(nUnusedIndex, (x - m_obViewPortRect.origin.x) / m_fScaleX, + pTouch->setTouchInfo(nUnusedIndex, (x - m_obViewPortRect.origin.x) / m_fScaleX, (y - m_obViewPortRect.origin.y) / m_fScaleY); - } //CCLOG("x = %f y = %f", pTouch->getLocationInView().x, pTouch->getLocationInView().y); @@ -243,16 +226,8 @@ void CCEGLViewProtocol::handleTouchesMove(int num, int ids[], float xs[], float CCTouch* pTouch = s_pTouches[pIndex->getValue()]; if (pTouch) { - if (m_bIsRetinaEnabled) - { - pTouch->setTouchInfo(pIndex->getValue(), (x - m_obViewPortRect.origin.x), - (y - m_obViewPortRect.origin.y)); - } - else - { - pTouch->setTouchInfo(pIndex->getValue(), (x - m_obViewPortRect.origin.x) / m_fScaleX, - (y - m_obViewPortRect.origin.y) / m_fScaleY); - } + pTouch->setTouchInfo(pIndex->getValue(), (x - m_obViewPortRect.origin.x) / m_fScaleX, + (y - m_obViewPortRect.origin.y) / m_fScaleY); set.addObject(pTouch); } @@ -292,17 +267,8 @@ void CCEGLViewProtocol::getSetOfTouchesEndOrCancel(CCSet& set, int num, int ids[ if (pTouch) { CCLOGINFO("Ending touches with id: %d, x=%f, y=%f", id, x, y); - - if (m_bIsRetinaEnabled) - { - pTouch->setTouchInfo(pIndex->getValue(), (x - m_obViewPortRect.origin.x), - (y - m_obViewPortRect.origin.y)); - } - else - { - pTouch->setTouchInfo(pIndex->getValue(), (x - m_obViewPortRect.origin.x) / m_fScaleX, - (y - m_obViewPortRect.origin.y) / m_fScaleY); - } + pTouch->setTouchInfo(pIndex->getValue(), (x - m_obViewPortRect.origin.x) / m_fScaleX, + (y - m_obViewPortRect.origin.y) / m_fScaleY); set.addObject(pTouch); @@ -358,9 +324,4 @@ float CCEGLViewProtocol::getScaleY() const return m_fScaleY; } -bool CCEGLViewProtocol::isRetinaEnabled() const -{ - return m_bIsRetinaEnabled; -} - NS_CC_END diff --git a/cocos2dx/platform/CCEGLViewProtocol.h b/cocos2dx/platform/CCEGLViewProtocol.h index aa03d423a6..a9704bb946 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.h +++ b/cocos2dx/platform/CCEGLViewProtocol.h @@ -106,12 +106,6 @@ public: * Set Scissor rectangle with points. */ virtual void setScissorInPoints(float x , float y , float w , float h); - - /** - * Enable retina mode. - * You can't use it with setDesignResolutionSize - */ - virtual bool enableRetina(); /** Touch events are handled by default; if you want to customize your handlers, please override these functions: */ virtual void handleTouchesBegin(int num, int ids[], float xs[], float ys[]); @@ -133,11 +127,6 @@ public: * Get scale factor of the vertical direction. */ float getScaleY() const; - - /** - * Get retina mode status (on if true). - */ - bool isRetinaEnabled() const; private: void getSetOfTouchesEndOrCancel(CCSet& set, int num, int ids[], float xs[], float ys[]); @@ -156,7 +145,6 @@ protected: float m_fScaleX; float m_fScaleY; ResolutionPolicy m_eResolutionPolicy; - bool m_bIsRetinaEnabled; }; // end of platform group diff --git a/cocos2dx/platform/ios/CCEGLView.h b/cocos2dx/platform/ios/CCEGLView.h index de0251c3ac..cbba96ef1d 100644 --- a/cocos2dx/platform/ios/CCEGLView.h +++ b/cocos2dx/platform/ios/CCEGLView.h @@ -40,7 +40,6 @@ public: virtual bool isOpenGLReady(); virtual bool setContentScaleFactor(float contentScaleFactor); - virtual bool enableRetina(); // keep compatible virtual void end(); diff --git a/cocos2dx/platform/ios/CCEGLView.mm b/cocos2dx/platform/ios/CCEGLView.mm index 68fb7d15cc..7118c05872 100644 --- a/cocos2dx/platform/ios/CCEGLView.mm +++ b/cocos2dx/platform/ios/CCEGLView.mm @@ -49,34 +49,11 @@ bool CCEGLView::isOpenGLReady() bool CCEGLView::setContentScaleFactor(float contentScaleFactor) { assert(m_eResolutionPolicy == kResolutionUnKnown); // cannot enable retina mode - - if ([[EAGLView sharedEGLView] respondsToSelector:@selector(setContentScaleFactor:)]) - { - UIView * view = [EAGLView sharedEGLView]; - view.contentScaleFactor = contentScaleFactor; - [view setNeedsLayout]; + + m_fScaleX = m_fScaleY = contentScaleFactor; + [[EAGLView sharedEGLView] setNeedsLayout]; - m_fScaleX = m_fScaleY = contentScaleFactor; - m_bIsRetinaEnabled = true; - - return true; - } - else - { - return false; - } -} - -bool CCEGLView::enableRetina() -{ - bool ret = true; - - // can set content scale factor? - ret &= [[EAGLView sharedEGLView] respondsToSelector:@selector(setContentScaleFactor:)]; - // SD device? - ret &= ([[UIScreen mainScreen] scale] != 1.0f); - - return ret; + return true; } void CCEGLView::end() diff --git a/cocos2dx/platform/ios/EAGLView.mm b/cocos2dx/platform/ios/EAGLView.mm index 2f9ba0a360..811b475e1c 100755 --- a/cocos2dx/platform/ios/EAGLView.mm +++ b/cocos2dx/platform/ios/EAGLView.mm @@ -151,6 +151,11 @@ static EAGLView *view = 0; originalRect_ = self.frame; self.keyboardShowNotification = nil; + + if ([view respondsToSelector:@selector(setContentScaleFactor:)]) + { + view.contentScaleFactor = [[UIScreen mainScreen] scale]; + } } return self; @@ -200,13 +205,13 @@ static EAGLView *view = 0; -(int) getWidth { CGSize bound = [self bounds].size; - return bound.width; + return bound.width * self.contentScaleFactor; } -(int) getHeight { CGSize bound = [self bounds].size; - return bound.height; + return bound.height * self.contentScaleFactor; } @@ -401,8 +406,8 @@ static EAGLView *view = 0; int i = 0; for (UITouch *touch in touches) { ids[i] = (int)touch; - xs[i] = [touch locationInView: [touch view]].x; - ys[i] = [touch locationInView: [touch view]].y; + xs[i] = [touch locationInView: [touch view]].x * view.contentScaleFactor;; + ys[i] = [touch locationInView: [touch view]].y * view.contentScaleFactor;; ++i; } cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesBegin(i, ids, xs, ys); @@ -421,8 +426,8 @@ static EAGLView *view = 0; int i = 0; for (UITouch *touch in touches) { ids[i] = (int)touch; - xs[i] = [touch locationInView: [touch view]].x; - ys[i] = [touch locationInView: [touch view]].y; + xs[i] = [touch locationInView: [touch view]].x * view.contentScaleFactor;; + ys[i] = [touch locationInView: [touch view]].y * view.contentScaleFactor;; ++i; } cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesMove(i, ids, xs, ys); @@ -442,8 +447,8 @@ static EAGLView *view = 0; int i = 0; for (UITouch *touch in touches) { ids[i] = (int)touch; - xs[i] = [touch locationInView: [touch view]].x; - ys[i] = [touch locationInView: [touch view]].y; + xs[i] = [touch locationInView: [touch view]].x * view.contentScaleFactor;; + ys[i] = [touch locationInView: [touch view]].y * view.contentScaleFactor;; ++i; } cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesEnd(i, ids, xs, ys); @@ -463,8 +468,8 @@ static EAGLView *view = 0; int i = 0; for (UITouch *touch in touches) { ids[i] = (int)touch; - xs[i] = [touch locationInView: [touch view]].x; - ys[i] = [touch locationInView: [touch view]].y; + xs[i] = [touch locationInView: [touch view]].x * view.contentScaleFactor;; + ys[i] = [touch locationInView: [touch view]].y * view.contentScaleFactor;; ++i; } cocos2d::CCEGLView::sharedOpenGLView()->handleTouchesCancel(i, ids, xs, ys); @@ -806,21 +811,18 @@ static EAGLView *view = 0; notiInfo.end.size.height -= offestY; } - if (!cocos2d::CCEGLView::sharedOpenGLView()->isRetinaEnabled()) - { - float scaleX = cocos2d::CCEGLView::sharedOpenGLView()->getScaleX(); - float scaleY = cocos2d::CCEGLView::sharedOpenGLView()->getScaleY(); + float scaleX = cocos2d::CCEGLView::sharedOpenGLView()->getScaleX(); + float scaleY = cocos2d::CCEGLView::sharedOpenGLView()->getScaleY(); - notiInfo.begin.origin.x /= scaleX; - notiInfo.begin.origin.y /= scaleY; - notiInfo.begin.size.width /= scaleX; - notiInfo.begin.size.height /= scaleY; + notiInfo.begin.origin.x /= scaleX; + notiInfo.begin.origin.y /= scaleY; + notiInfo.begin.size.width /= scaleX; + notiInfo.begin.size.height /= scaleY; - notiInfo.end.origin.x /= scaleX; - notiInfo.end.origin.y /= scaleY; - notiInfo.end.size.width /= scaleX; - notiInfo.end.size.height /= scaleY; - } + notiInfo.end.origin.x /= scaleX; + notiInfo.end.origin.y /= scaleY; + notiInfo.end.size.width /= scaleX; + notiInfo.end.size.height /= scaleY; cocos2d::CCIMEDispatcher* dispatcher = cocos2d::CCIMEDispatcher::sharedDispatcher(); if (UIKeyboardWillShowNotification == type) @@ -860,10 +862,7 @@ static EAGLView *view = 0; if (dis < 0.0f) dis = 0.0f; - if (!cocos2d::CCEGLView::sharedOpenGLView()->isRetinaEnabled()) - { - dis *= cocos2d::CCEGLView::sharedOpenGLView()->getScaleY(); - } + dis *= cocos2d::CCEGLView::sharedOpenGLView()->getScaleY(); switch ([[UIApplication sharedApplication] statusBarOrientation]) { diff --git a/samples/HelloCpp/Classes/AppDelegate.cpp b/samples/HelloCpp/Classes/AppDelegate.cpp index b2c80149f5..f721e604f7 100644 --- a/samples/HelloCpp/Classes/AppDelegate.cpp +++ b/samples/HelloCpp/Classes/AppDelegate.cpp @@ -16,39 +16,17 @@ bool AppDelegate::applicationDidFinishLaunching() { CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); - - TargetPlatform target = getTargetPlatform(); - - if (target == kTargetIpad) - { - // ipad - - CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); - - // don't enable retina because we don't have ipad hd resource - CCEGLView::sharedOpenGLView()->setDesignResolutionSize(960, 640, kResolutionNoBorder); - } - else if (target == kTargetIphone) - { - // iphone - - if (pDirector->enableRetinaDisplay(true)) - { - // iphone hd - CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); - } - else - { - CCFileUtils::sharedFileUtils()->setResourceDirectory("iphone"); - } - } - else - { - // android, windows, blackberry, linux or mac - // use 960*640 resources as design resolution size - CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); - CCEGLView::sharedOpenGLView()->setDesignResolutionSize(960, 640, kResolutionNoBorder); - } + //pDirector->setProjection(kCCDirectorProjection2D); + + if (pDirector->getWinSize().height > 320) + { + CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); + pDirector->setContentScaleFactor(2.0f); + } + else + CCFileUtils::sharedFileUtils()->setResourceDirectory("iphone"); + + CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionShowAll); // turn on display FPS pDirector->setDisplayStats(true); diff --git a/samples/HelloCpp/Classes/HelloWorldScene.cpp b/samples/HelloCpp/Classes/HelloWorldScene.cpp index 43117c740f..28410ee365 100644 --- a/samples/HelloCpp/Classes/HelloWorldScene.cpp +++ b/samples/HelloCpp/Classes/HelloWorldScene.cpp @@ -27,7 +27,7 @@ bool HelloWorld::init() return false; } - CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); + CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); ///////////////////////////// @@ -41,14 +41,7 @@ bool HelloWorld::init() this, menu_selector(HelloWorld::menuCloseCallback)); - if (CCApplication::sharedApplication()->getTargetPlatform() == kTargetIphone) - { - pCloseItem->setPosition(ccp(visibleSize.width - 20 + origin.x, 20 + origin.y)); - } - else - { - pCloseItem->setPosition(ccp(visibleSize.width - 40 + origin.x, 40 + origin.y)); - } + pCloseItem->setPosition(ccp(winSize.width - 20 + origin.x, 20 + origin.y)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); @@ -63,7 +56,7 @@ bool HelloWorld::init() CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24); // position the label on the center of the screen - pLabel->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height - 50 + origin.y)); + pLabel->setPosition(ccp(winSize.width/2 + origin.x, winSize.height - 50 + origin.y)); // add the label as a child to this layer this->addChild(pLabel, 1); @@ -72,7 +65,7 @@ bool HelloWorld::init() CCSprite* pSprite = CCSprite::create("HelloWorld.png"); // position the sprite on the center of the screen - pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); + pSprite->setPosition(ccp(winSize.width/2 + origin.x, winSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(pSprite, 0); From 0f2dac9d8edf1cdfa0a295dd0788bebe88d9bcc5 Mon Sep 17 00:00:00 2001 From: johnangel Date: Mon, 1 Oct 2012 11:55:21 +0200 Subject: [PATCH 08/64] Saving data to C:\Documents and Settings\\Local Settings\Application Data as designed for Windows apps --- cocos2dx/platform/win32/CCFileUtils.cpp | 57 +++++++++++++++++++------ 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/cocos2dx/platform/win32/CCFileUtils.cpp b/cocos2dx/platform/win32/CCFileUtils.cpp index c7a25de12f..e8dd98ec0f 100644 --- a/cocos2dx/platform/win32/CCFileUtils.cpp +++ b/cocos2dx/platform/win32/CCFileUtils.cpp @@ -24,6 +24,7 @@ THE SOFTWARE. #define __CC_PLATFORM_FILEUTILS_CPP__ #include "platform/CCFileUtilsCommon_cpp.h" #include +#include #include "CCDirector.h" #include "CCApplication.h" @@ -39,10 +40,10 @@ static void _CheckPath() if (! s_pszResourcePath[0]) { WCHAR wszPath[MAX_PATH] = {0}; - int nNum = WideCharToMultiByte(CP_ACP, 0, wszPath, - GetCurrentDirectoryW(sizeof(wszPath), wszPath), + int nNum = WideCharToMultiByte(CP_ACP, 0, wszPath, + GetCurrentDirectoryW(sizeof(wszPath), wszPath), s_pszResourcePath, MAX_PATH, NULL, NULL); - s_pszResourcePath[nNum] = '\\'; + s_pszResourcePath[nNum] = '\\'; } } @@ -64,7 +65,7 @@ void CCFileUtils::purgeFileUtils() { s_pFileUtils->purgeCachedEntries(); } - + CC_SAFE_DELETE(s_pFileUtils); } @@ -85,7 +86,7 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) // path start with "x:", is absolute path pRet->m_sString = pszRelativePath; } - else if (strlen(pszRelativePath) > 0 + else if (strlen(pszRelativePath) > 0 && ('/' == pszRelativePath[0] || '\\' == pszRelativePath[0])) { // path start with '/' or '\', is absolute path without driver name @@ -122,7 +123,7 @@ const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) { // Can't find the file, return the relative path. pRet->m_sString = pszRelativePath; } - + return pRet->m_sString.c_str(); } @@ -141,7 +142,7 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz unsigned char* pBuffer = NULL; CCAssert(pszFileName != NULL && pSize != NULL && pszMode != NULL, "Invaild parameters."); *pSize = 0; - do + do { // read the file from hardware FILE *fp = fopen(pszFileName, pszMode); @@ -168,17 +169,45 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz string CCFileUtils::getWriteablePath() { - // return the path that the exe file saved in + // Get full path of executable, e.g. c:\Program Files (x86)\My Game Folder\MyGame.exe + char full_path[_MAX_PATH + 1]; + ::GetModuleFileNameA(NULL, full_path, _MAX_PATH + 1); - char full_path[_MAX_PATH + 1]; - ::GetModuleFileNameA(NULL, full_path, _MAX_PATH + 1); + // Get filename of executable only, e.g. MyGame.exe + char *base_name = strrchr(full_path, '\\'); - string ret((char*)full_path); + if(base_name) + { + char app_data_path[_MAX_PATH + 1]; - // remove xxx.exe - ret = ret.substr(0, ret.rfind("\\") + 1); + // Get local app data directory, e.g. C:\Documents and Settings\username\Local Settings\Application Data + if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, app_data_path))) + { + string ret((char*)app_data_path); - return ret; + // Adding executable filename, e.g. C:\Documents and Settings\username\Local Settings\Application Data\MyGame.exe + ret += base_name; + + // Remove ".exe" extension, e.g. C:\Documents and Settings\username\Local Settings\Application Data\MyGame + ret = ret.substr(0, ret.rfind(".")); + + ret += "\\"; + + // Create directory + if (SUCCEEDED(SHCreateDirectoryExA(NULL, ret.c_str(), NULL))) + { + return ret; + } + } + } + + // If fetching of local app data directory fails, use the executable one + string ret((char*)full_path); + + // remove xxx.exe + ret = ret.substr(0, ret.rfind("\\") + 1); + + return ret; } NS_CC_END From c6da27b793711dde6dc68bc9ee2e303352447f5c Mon Sep 17 00:00:00 2001 From: johnangel Date: Mon, 8 Oct 2012 17:22:27 +0200 Subject: [PATCH 09/64] Debug app uses executable directory; Non-debug app uses local app data directory --- cocos2dx/platform/win32/CCFileUtils.cpp | 45 +++++++++++++------------ 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/cocos2dx/platform/win32/CCFileUtils.cpp b/cocos2dx/platform/win32/CCFileUtils.cpp index e8dd98ec0f..77a67c95f7 100644 --- a/cocos2dx/platform/win32/CCFileUtils.cpp +++ b/cocos2dx/platform/win32/CCFileUtils.cpp @@ -173,33 +173,36 @@ string CCFileUtils::getWriteablePath() char full_path[_MAX_PATH + 1]; ::GetModuleFileNameA(NULL, full_path, _MAX_PATH + 1); - // Get filename of executable only, e.g. MyGame.exe - char *base_name = strrchr(full_path, '\\'); + // Debug app uses executable directory; Non-debug app uses local app data directory + #ifndef _DEBUG + // Get filename of executable only, e.g. MyGame.exe + char *base_name = strrchr(full_path, '\\'); - if(base_name) - { - char app_data_path[_MAX_PATH + 1]; - - // Get local app data directory, e.g. C:\Documents and Settings\username\Local Settings\Application Data - if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, app_data_path))) + if(base_name) { - string ret((char*)app_data_path); + char app_data_path[_MAX_PATH + 1]; - // Adding executable filename, e.g. C:\Documents and Settings\username\Local Settings\Application Data\MyGame.exe - ret += base_name; - - // Remove ".exe" extension, e.g. C:\Documents and Settings\username\Local Settings\Application Data\MyGame - ret = ret.substr(0, ret.rfind(".")); - - ret += "\\"; - - // Create directory - if (SUCCEEDED(SHCreateDirectoryExA(NULL, ret.c_str(), NULL))) + // Get local app data directory, e.g. C:\Documents and Settings\username\Local Settings\Application Data + if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, app_data_path))) { - return ret; + string ret((char*)app_data_path); + + // Adding executable filename, e.g. C:\Documents and Settings\username\Local Settings\Application Data\MyGame.exe + ret += base_name; + + // Remove ".exe" extension, e.g. C:\Documents and Settings\username\Local Settings\Application Data\MyGame + ret = ret.substr(0, ret.rfind(".")); + + ret += "\\"; + + // Create directory + if (SUCCEEDED(SHCreateDirectoryExA(NULL, ret.c_str(), NULL))) + { + return ret; + } } } - } + #endif // not defined _DEBUG // If fetching of local app data directory fails, use the executable one string ret((char*)full_path); From 72aa46afe53ba2d3c7bc59940c975fceb7203b42 Mon Sep 17 00:00:00 2001 From: johnangel Date: Mon, 8 Oct 2012 18:38:04 +0200 Subject: [PATCH 10/64] Refactoring code --- cocos2dx/platform/CCEGLViewProtocol.cpp | 4 +--- cocos2dx/platform/CCEGLViewProtocol.h | 2 +- cocos2dx/platform/win32/CCEGLView.cpp | 28 ++++++++++++------------- cocos2dx/platform/win32/CCEGLView.h | 6 +++--- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/cocos2dx/platform/CCEGLViewProtocol.cpp b/cocos2dx/platform/CCEGLViewProtocol.cpp index bc1751547d..da20ff8c35 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.cpp +++ b/cocos2dx/platform/CCEGLViewProtocol.cpp @@ -112,11 +112,9 @@ const CCSize& CCEGLViewProtocol::getFrameSize() const return m_obScreenSize; } -bool CCEGLViewProtocol::setFrameSize(float width, float height) +void CCEGLViewProtocol::setFrameSize(float width, float height) { m_obDesignResolutionSize = m_obScreenSize = CCSizeMake(width, height); - - return true; } CCSize CCEGLViewProtocol::getVisibleSize() const diff --git a/cocos2dx/platform/CCEGLViewProtocol.h b/cocos2dx/platform/CCEGLViewProtocol.h index 4644d5b97b..052b7e5414 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.h +++ b/cocos2dx/platform/CCEGLViewProtocol.h @@ -64,7 +64,7 @@ public: /** * Set the frame size of EGL view. */ - virtual bool setFrameSize(float width, float height); + virtual void setFrameSize(float width, float height); /** * Get the visible area size of opengl viewport. diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index 526437e4ef..043f68a968 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -69,9 +69,7 @@ bool glew_dynamic_binding() { const char *gl_extensions = (const char*)glGetString(GL_EXTENSIONS); - /* If the current opengl driver don't have framebuffers methods, - * Check if an extension exist - */ + // If the current opengl driver doesn't have framebuffers methods, check if an extension exists if (glGenFramebuffers == NULL) { CCLog("OpenGL: glGenFramebuffers is NULL, try to detect an extension\n"); @@ -234,7 +232,7 @@ void CCEGLView::destroyGL() } } -bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) +bool CCEGLView::Create() { bool bRet = false; do @@ -281,8 +279,6 @@ bool CCEGLView::Create(LPCTSTR pTitle, int w, int h) CC_BREAK_IF(! m_hWnd); - resize(w, h); - bRet = initGL(); if(!bRet) destroyGL(); CC_BREAK_IF(!bRet); @@ -546,19 +542,12 @@ void CCEGLView::resize(int width, int height) SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER); } -bool CCEGLView::setFrameSize(float width, float height) +void CCEGLView::setFrameSize(float width, float height) { - if(!Create((LPCTSTR)m_szViewName, (int)width, (int)height)) - { - PostQuitMessage(-1); - return false; - } CCEGLViewProtocol::setFrameSize(width, height); resize(width, height); // adjust window size for menubar centerWindow(); - - return true; } void CCEGLView::centerWindow() @@ -602,13 +591,22 @@ bool CCEGLView::setContentScaleFactor(float contentScaleFactor) return true; } -CCEGLView* CCEGLView::sharedOpenGLView() +CCEGLView* CCEGLView::sharedOpenGLView(const char* pTitle) { static CCEGLView* s_pEglView = NULL; if (s_pEglView == NULL) { s_pEglView = new CCEGLView(); + + s_pEglView->setViewName(pTitle); + + if(!s_pEglView->Create()) + { + delete s_pEglView; + s_pEglView = NULL; + } } + return s_pEglView; } diff --git a/cocos2dx/platform/win32/CCEGLView.h b/cocos2dx/platform/win32/CCEGLView.h index 147cc16379..dd6b2d486f 100644 --- a/cocos2dx/platform/win32/CCEGLView.h +++ b/cocos2dx/platform/win32/CCEGLView.h @@ -47,7 +47,7 @@ public: virtual void end(); virtual void swapBuffers(); virtual bool setContentScaleFactor(float contentScaleFactor); - virtual bool setFrameSize(float width, float height); + virtual void setFrameSize(float width, float height); virtual void setIMEKeyboardState(bool bOpen); virtual bool enableRetina(); @@ -55,7 +55,7 @@ public: void setWndProc(CUSTOM_WND_PROC proc); private: - virtual bool Create(LPCTSTR pTitle, int w, int h); + virtual bool Create(); bool initGL(); void destroyGL(); public: @@ -73,7 +73,7 @@ public: /** @brief get the shared main open gl window */ - static CCEGLView* sharedOpenGLView(); + static CCEGLView* sharedOpenGLView(const char* pTitle=NULL); protected: From e7340f6c1b154318f3327b793fd7833d347bb3de Mon Sep 17 00:00:00 2001 From: johnangel Date: Mon, 8 Oct 2012 18:46:19 +0200 Subject: [PATCH 11/64] ESC button on Windows will now behave like Back button on mobile phones --- cocos2dx/platform/win32/CCEGLView.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index 043f68a968..70ebf3e8be 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -358,6 +358,11 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) if (GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0) pDirector->getKeypadDispatcher()->dispatchKeypadMSG(wParam == VK_F1 ? kTypeBackClicked : kTypeMenuClicked); } + else if (wParam == VK_ESCAPE) + { + CCDirector::sharedDirector()->getKeypadDispatcher()->dispatchKeypadMSG(kTypeBackClicked); + } + if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); From e510bee238a171a76ad488ac9362c827be83b037 Mon Sep 17 00:00:00 2001 From: johnangel Date: Tue, 9 Oct 2012 10:58:56 +0200 Subject: [PATCH 12/64] Displaying window size in Debug mode --- cocos2dx/platform/win32/CCEGLView.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index 70ebf3e8be..a677391b83 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -531,13 +531,14 @@ void CCEGLView::resize(int width, int height) m_windowTouchScaleX = frameSize.width / width; m_windowTouchScaleY = frameSize.height / height; -/* + #ifdef _DEBUG TCHAR buff[MAX_PATH + 1]; memset(buff, 0, sizeof(buff)); - swprintf_s(buff, MAX_PATH, L"%s - %0.0fx%0.0f - %0.2f", - kWindowClassName, frameSize.width, frameSize.height, 1.0f / m_windowTouchScaleX); + swprintf_s(buff, MAX_PATH, L"%S - %0.0fx%0.0f - %0.2f", + m_szViewName, frameSize.width, frameSize.height, 1.0f / m_windowTouchScaleX); + SetWindowText(m_hWnd, buff); -*/ + #endif } AdjustWindowRectEx(&rcClient, GetWindowLong(m_hWnd, GWL_STYLE), false, GetWindowLong(m_hWnd, GWL_EXSTYLE)); From 77da7b58952d14f6d7e71540cd48fa9c556ee12c Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 11 Oct 2012 16:45:14 +0800 Subject: [PATCH 13/64] issue #1486: First commit based on BorMor's branch. --- samples/HelloCpp/Classes/HelloWorldScene.cpp | 10 ++++++---- samples/HelloCpp/Classes/HelloWorldScene.h | 3 --- .../Resources/iphonehd/HelloWorld.png.REMOVED.git-id | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/samples/HelloCpp/Classes/HelloWorldScene.cpp b/samples/HelloCpp/Classes/HelloWorldScene.cpp index 28410ee365..742fbbbfd7 100644 --- a/samples/HelloCpp/Classes/HelloWorldScene.cpp +++ b/samples/HelloCpp/Classes/HelloWorldScene.cpp @@ -27,7 +27,7 @@ bool HelloWorld::init() return false; } - CCSize winSize = CCDirector::sharedDirector()->getWinSize(); + CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); ///////////////////////////// @@ -41,7 +41,8 @@ bool HelloWorld::init() this, menu_selector(HelloWorld::menuCloseCallback)); - pCloseItem->setPosition(ccp(winSize.width - 20 + origin.x, 20 + origin.y)); + pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , + origin.y + pCloseItem->getContentSize().height/2)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); @@ -56,7 +57,8 @@ bool HelloWorld::init() CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24); // position the label on the center of the screen - pLabel->setPosition(ccp(winSize.width/2 + origin.x, winSize.height - 50 + origin.y)); + pLabel->setPosition(ccp(origin.x + visibleSize.width/2, + origin.y + visibleSize.height - pLabel->getContentSize().height)); // add the label as a child to this layer this->addChild(pLabel, 1); @@ -65,7 +67,7 @@ bool HelloWorld::init() CCSprite* pSprite = CCSprite::create("HelloWorld.png"); // position the sprite on the center of the screen - pSprite->setPosition(ccp(winSize.width/2 + origin.x, winSize.height/2 + origin.y)); + pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(pSprite, 0); diff --git a/samples/HelloCpp/Classes/HelloWorldScene.h b/samples/HelloCpp/Classes/HelloWorldScene.h index 4379df7ff0..cb4169f7cd 100644 --- a/samples/HelloCpp/Classes/HelloWorldScene.h +++ b/samples/HelloCpp/Classes/HelloWorldScene.h @@ -14,9 +14,6 @@ public: // a selector callback void menuCloseCallback(CCObject* pSender); - - // touch callback - void ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent); // implement the "static node()" method manually CREATE_FUNC(HelloWorld); diff --git a/samples/HelloCpp/Resources/iphonehd/HelloWorld.png.REMOVED.git-id b/samples/HelloCpp/Resources/iphonehd/HelloWorld.png.REMOVED.git-id index 9540c0bfb7..844d404ad6 100644 --- a/samples/HelloCpp/Resources/iphonehd/HelloWorld.png.REMOVED.git-id +++ b/samples/HelloCpp/Resources/iphonehd/HelloWorld.png.REMOVED.git-id @@ -1 +1 @@ -6b7a2544be32ce26e75737865743649598d83bdf \ No newline at end of file +7043498dfb68e43598d30ca3fa8059d460ee8672 \ No newline at end of file From cdf54a872f7fdb78c7a12c5dcf5d3b775561f71f Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 11 Oct 2012 17:02:27 +0800 Subject: [PATCH 14/64] issue #1486: A bug fix. --- cocos2dx/CCDirector.cpp | 5 ++--- cocos2dx/platform/CCEGLViewProtocol.cpp | 3 ++- samples/HelloCpp/Classes/AppDelegate.cpp | 11 ++++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index abd8804c06..1bcf44e723 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -331,8 +331,7 @@ void CCDirector::setNextDeltaTimeZero(bool bNextDeltaTimeZero) void CCDirector::setProjection(ccDirectorProjection kProjection) { - CCSize size = m_obWinSizeInPixels; - CCSize sizePoint = m_obWinSizeInPoints; + CCSize size = m_obWinSizeInPoints; if (m_pobOpenGLView) { @@ -404,7 +403,7 @@ void CCDirector::purgeCachedData(void) float CCDirector::getZEye(void) { - return (m_obWinSizeInPixels.height / 1.1566f); + return (m_obWinSizeInPoints.height / 1.1566f); } void CCDirector::setAlphaBlending(bool bOn) diff --git a/cocos2dx/platform/CCEGLViewProtocol.cpp b/cocos2dx/platform/CCEGLViewProtocol.cpp index 63b2d3eb34..2f2c37fbc6 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.cpp +++ b/cocos2dx/platform/CCEGLViewProtocol.cpp @@ -91,7 +91,8 @@ void CCEGLViewProtocol::setDesignResolutionSize(float width, float height, Resol // reset director's member variables to fit visible rect CCDirector::sharedDirector()->createStatsLabel(); - CCDirector::sharedDirector()->m_obWinSizeInPoints = CCDirector::sharedDirector()->m_obWinSizeInPixels = getSize(); + CCDirector::sharedDirector()->m_obWinSizeInPoints = getSize(); + CCDirector::sharedDirector()->m_obWinSizeInPixels = m_obScreenSize; CCDirector::sharedDirector()->setGLDefaultValues(); } diff --git a/samples/HelloCpp/Classes/AppDelegate.cpp b/samples/HelloCpp/Classes/AppDelegate.cpp index f721e604f7..969ff87183 100644 --- a/samples/HelloCpp/Classes/AppDelegate.cpp +++ b/samples/HelloCpp/Classes/AppDelegate.cpp @@ -21,13 +21,18 @@ bool AppDelegate::applicationDidFinishLaunching() { if (pDirector->getWinSize().height > 320) { CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); - pDirector->setContentScaleFactor(2.0f); + pDirector->setContentScaleFactor(2.0f); + } else + { CCFileUtils::sharedFileUtils()->setResourceDirectory("iphone"); + //pDirector->setContentScaleFactor(0.5f); + } - CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionShowAll); - + //CCEGLView::sharedOpenGLView()->setDesignResolutionSize(960, 640, kResolutionShowAll); + CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionShowAll); + // turn on display FPS pDirector->setDisplayStats(true); From b78e2c9130b4b5428afa42b49943c1772a53c04f Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 11 Oct 2012 18:33:43 +0800 Subject: [PATCH 15/64] issue #1486: Added iPad, ipadhd resources, and make some watermark for these pictures. --- samples/HelloCpp/Classes/AppDelegate.cpp | 21 ++++++++----- samples/HelloCpp/Classes/AppMacros.h | 30 +++++++++++++++++++ samples/HelloCpp/Classes/HelloWorldScene.cpp | 9 ++++-- .../ipad/HelloWorld.png.REMOVED.git-id | 1 + .../ipadhd/HelloWorld.png.REMOVED.git-id | 1 + .../iphone/HelloWorld.png.REMOVED.git-id | 2 +- .../iphonehd/HelloWorld.png.REMOVED.git-id | 1 - .../HelloCpp.xcodeproj/project.pbxproj | 14 ++++++--- 8 files changed, 62 insertions(+), 17 deletions(-) create mode 100644 samples/HelloCpp/Classes/AppMacros.h create mode 100644 samples/HelloCpp/Resources/ipad/HelloWorld.png.REMOVED.git-id create mode 100644 samples/HelloCpp/Resources/ipadhd/HelloWorld.png.REMOVED.git-id delete mode 100644 samples/HelloCpp/Resources/iphonehd/HelloWorld.png.REMOVED.git-id diff --git a/samples/HelloCpp/Classes/AppDelegate.cpp b/samples/HelloCpp/Classes/AppDelegate.cpp index 969ff87183..e9966ee571 100644 --- a/samples/HelloCpp/Classes/AppDelegate.cpp +++ b/samples/HelloCpp/Classes/AppDelegate.cpp @@ -1,5 +1,6 @@ #include "AppDelegate.h" #include "HelloWorldScene.h" +#include "AppMacros.h" USING_NS_CC; @@ -17,21 +18,25 @@ bool AppDelegate::applicationDidFinishLaunching() { pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); //pDirector->setProjection(kCCDirectorProjection2D); - - if (pDirector->getWinSize().height > 320) + CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize(); + + if (screenSize.height > 768) { - CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); - pDirector->setContentScaleFactor(2.0f); - + CCFileUtils::sharedFileUtils()->setResourceDirectory("ipadhd"); + pDirector->setContentScaleFactor(2048.0f/kDesignResolutionSize_width); } + else if (screenSize.height >= 640) + { + CCFileUtils::sharedFileUtils()->setResourceDirectory("ipad"); + pDirector->setContentScaleFactor(1024.0f/kDesignResolutionSize_width); + } else { CCFileUtils::sharedFileUtils()->setResourceDirectory("iphone"); - //pDirector->setContentScaleFactor(0.5f); + pDirector->setContentScaleFactor(480.0f/kDesignResolutionSize_width); } - //CCEGLView::sharedOpenGLView()->setDesignResolutionSize(960, 640, kResolutionShowAll); - CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionShowAll); + CCEGLView::sharedOpenGLView()->setDesignResolutionSize(kDesignResolutionSize_width, kDesignResolutionSize_height, kResolutionNoBorder); // turn on display FPS pDirector->setDisplayStats(true); diff --git a/samples/HelloCpp/Classes/AppMacros.h b/samples/HelloCpp/Classes/AppMacros.h new file mode 100644 index 0000000000..355f25a76f --- /dev/null +++ b/samples/HelloCpp/Classes/AppMacros.h @@ -0,0 +1,30 @@ +#ifndef __APPMACROS_H__ +#define __APPMACROS_H__ + + +#define kDesignResolution_480x320 0 +#define kDesignResolution_1024x768 1 +#define kDesignResolution_2048x1536 2 + +#define kTargetDesignResolutionSize kDesignResolution_2048x1536 + +#if (kTargetDesignResolutionSize == kDesignResolution_480x320) +#define kDesignResolutionSize_width 480.0f +#define kDesignResolutionSize_height 320.0f + + +#elif (kTargetDesignResolutionSize == kDesignResolution_1024x768) +#define kDesignResolutionSize_width 1024.0f +#define kDesignResolutionSize_height 768.0f + +#elif (kTargetDesignResolutionSize == kDesignResolution_2048x1536) +#define kDesignResolutionSize_width 2048.0f +#define kDesignResolutionSize_height 1536.0f + +#else +#error unknown target design resolution! +#endif + +#define kTitleFontSize (kDesignResolutionSize_width / 480.0f * 24) + +#endif /* __APPMACROS_H__ */ diff --git a/samples/HelloCpp/Classes/HelloWorldScene.cpp b/samples/HelloCpp/Classes/HelloWorldScene.cpp index 742fbbbfd7..20f7bc6767 100644 --- a/samples/HelloCpp/Classes/HelloWorldScene.cpp +++ b/samples/HelloCpp/Classes/HelloWorldScene.cpp @@ -1,7 +1,8 @@ #include "HelloWorldScene.h" - +#include "AppMacros.h" USING_NS_CC; + CCScene* HelloWorld::scene() { // 'scene' is an autorelease object @@ -54,8 +55,9 @@ bool HelloWorld::init() // add a label shows "Hello World" // create and initialize a label - CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24); - + + CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", kTitleFontSize); + // position the label on the center of the screen pLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height)); @@ -75,6 +77,7 @@ bool HelloWorld::init() return true; } + void HelloWorld::menuCloseCallback(CCObject* pSender) { CCDirector::sharedDirector()->end(); diff --git a/samples/HelloCpp/Resources/ipad/HelloWorld.png.REMOVED.git-id b/samples/HelloCpp/Resources/ipad/HelloWorld.png.REMOVED.git-id new file mode 100644 index 0000000000..fda9923fa3 --- /dev/null +++ b/samples/HelloCpp/Resources/ipad/HelloWorld.png.REMOVED.git-id @@ -0,0 +1 @@ +709d78b7f3eab27056a98d63e9153b35d57b84bc \ No newline at end of file diff --git a/samples/HelloCpp/Resources/ipadhd/HelloWorld.png.REMOVED.git-id b/samples/HelloCpp/Resources/ipadhd/HelloWorld.png.REMOVED.git-id new file mode 100644 index 0000000000..45e6087f95 --- /dev/null +++ b/samples/HelloCpp/Resources/ipadhd/HelloWorld.png.REMOVED.git-id @@ -0,0 +1 @@ +7aa1e9dc799acf384a1c4603054242cc09c1b63e \ No newline at end of file diff --git a/samples/HelloCpp/Resources/iphone/HelloWorld.png.REMOVED.git-id b/samples/HelloCpp/Resources/iphone/HelloWorld.png.REMOVED.git-id index f02d84fd8f..d391882e7d 100644 --- a/samples/HelloCpp/Resources/iphone/HelloWorld.png.REMOVED.git-id +++ b/samples/HelloCpp/Resources/iphone/HelloWorld.png.REMOVED.git-id @@ -1 +1 @@ -5fe89fb5bd58cedf13b0363f97b20e3ea7ff255d \ No newline at end of file +9d6facb31897d010352e7b57f4a82715c260408a \ No newline at end of file diff --git a/samples/HelloCpp/Resources/iphonehd/HelloWorld.png.REMOVED.git-id b/samples/HelloCpp/Resources/iphonehd/HelloWorld.png.REMOVED.git-id deleted file mode 100644 index 844d404ad6..0000000000 --- a/samples/HelloCpp/Resources/iphonehd/HelloWorld.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -7043498dfb68e43598d30ca3fa8059d460ee8672 \ No newline at end of file diff --git a/samples/HelloCpp/proj.ios/HelloCpp.xcodeproj/project.pbxproj b/samples/HelloCpp/proj.ios/HelloCpp.xcodeproj/project.pbxproj index c05d9414ce..15a357b86d 100644 --- a/samples/HelloCpp/proj.ios/HelloCpp.xcodeproj/project.pbxproj +++ b/samples/HelloCpp/proj.ios/HelloCpp.xcodeproj/project.pbxproj @@ -8,8 +8,9 @@ /* Begin PBXBuildFile section */ 15003FA315D2601D00B6775A /* iphone in Resources */ = {isa = PBXBuildFile; fileRef = 15003FA215D2601D00B6775A /* iphone */; }; - 15003FA515D2602400B6775A /* iphonehd in Resources */ = {isa = PBXBuildFile; fileRef = 15003FA415D2602400B6775A /* iphonehd */; }; 154269EB15B5669E00712A7F /* libcocos2dx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 154269D015B5644500712A7F /* libcocos2dx.a */; }; + 1A1CF3691626CEFF00AFC938 /* ipad in Resources */ = {isa = PBXBuildFile; fileRef = 1A1CF3671626CEFF00AFC938 /* ipad */; }; + 1A1CF36A1626CEFF00AFC938 /* ipadhd in Resources */ = {isa = PBXBuildFile; fileRef = 1A1CF3681626CEFF00AFC938 /* ipadhd */; }; 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; }; 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; }; 288765A50DF7441C002DB57D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765A40DF7441C002DB57D /* CoreGraphics.framework */; }; @@ -50,8 +51,10 @@ /* Begin PBXFileReference section */ 15003FA215D2601D00B6775A /* iphone */ = {isa = PBXFileReference; lastKnownFileType = folder; path = iphone; sourceTree = ""; }; - 15003FA415D2602400B6775A /* iphonehd */ = {isa = PBXFileReference; lastKnownFileType = folder; path = iphonehd; sourceTree = ""; }; 154269C815B5644500712A7F /* cocos2dx.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = cocos2dx.xcodeproj; path = ../../../cocos2dx/proj.ios/cocos2dx.xcodeproj; sourceTree = ""; }; + 1A1CF3661626CB6000AFC938 /* AppMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppMacros.h; sourceTree = ""; }; + 1A1CF3671626CEFF00AFC938 /* ipad */ = {isa = PBXFileReference; lastKnownFileType = folder; path = ipad; sourceTree = ""; }; + 1A1CF3681626CEFF00AFC938 /* ipadhd */ = {isa = PBXFileReference; lastKnownFileType = folder; path = ipadhd; sourceTree = ""; }; 1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 1D6058910D05DD3D006BFB54 /* HelloCpp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HelloCpp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; @@ -149,7 +152,8 @@ 784521C214EBA449009D533B /* Resources */ = { isa = PBXGroup; children = ( - 15003FA415D2602400B6775A /* iphonehd */, + 1A1CF3671626CEFF00AFC938 /* ipad */, + 1A1CF3681626CEFF00AFC938 /* ipadhd */, 15003FA215D2601D00B6775A /* iphone */, D4EF94ED15BD319D00D803EB /* Icon-144.png */, D4EF94EB15BD319B00D803EB /* Icon-72.png */, @@ -166,6 +170,7 @@ BF23D4E2143315EB00657E08 /* Classes */ = { isa = PBXGroup; children = ( + 1A1CF3661626CB6000AFC938 /* AppMacros.h */, BF23D4E3143315EB00657E08 /* AppDelegate.cpp */, BF23D4E4143315EB00657E08 /* AppDelegate.h */, BF23D4E5143315EB00657E08 /* HelloWorldScene.cpp */, @@ -261,10 +266,11 @@ D4EF94EC15BD319B00D803EB /* Icon-72.png in Resources */, D4EF94EE15BD319D00D803EB /* Icon-144.png in Resources */, 15003FA315D2601D00B6775A /* iphone in Resources */, - 15003FA515D2602400B6775A /* iphonehd in Resources */, D446FD79161028E9000ADA7B /* Default.png in Resources */, D446FD7B161028ED000ADA7B /* Default@2x.png in Resources */, D446FD7D161028F4000ADA7B /* Default-568h@2x.png in Resources */, + 1A1CF3691626CEFF00AFC938 /* ipad in Resources */, + 1A1CF36A1626CEFF00AFC938 /* ipadhd in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; From e1c0ea761b6b886b082f3414187e320f08a04d12 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 12 Oct 2012 09:58:42 +0800 Subject: [PATCH 16/64] issue #1486: Removed some unused codes, made it works on WINDOWS. --- cocos2dx/CCDirector.cpp | 22 +--------------------- cocos2dx/CCDirector.h | 5 ----- cocos2dx/platform/CCEGLViewProtocol.cpp | 6 ------ cocos2dx/platform/CCEGLViewProtocol.h | 6 ------ cocos2dx/platform/win32/CCEGLView.cpp | 21 +++------------------ cocos2dx/platform/win32/CCEGLView.h | 2 -- 6 files changed, 4 insertions(+), 58 deletions(-) diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index 1bcf44e723..c9d112cc71 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -136,7 +136,6 @@ bool CCDirector::init(void) m_pobOpenGLView = NULL; m_fContentScaleFactor = 1.0f; - m_bIsContentScaleSupported = false; // scheduler m_pScheduler = new CCScheduler(); @@ -314,12 +313,7 @@ void CCDirector::setOpenGLView(CCEGLView *pobOpenGLView) CHECK_GL_ERROR_DEBUG(); - if (m_fContentScaleFactor != 1) - { - updateContentScaleFactor(); - } - - m_pobOpenGLView->setTouchDelegate(m_pTouchDispatcher); + m_pobOpenGLView->setTouchDelegate(m_pTouchDispatcher); m_pTouchDispatcher->setDispatchEvents(true); } } @@ -804,11 +798,6 @@ void CCDirector::createStatsLabel() * mobile platforms specific functions **************************************************/ -void CCDirector::updateContentScaleFactor() -{ - m_bIsContentScaleSupported = m_pobOpenGLView->setContentScaleFactor(m_fContentScaleFactor); -} - float CCDirector::getContentScaleFactor(void) { return m_fContentScaleFactor; @@ -819,15 +808,6 @@ void CCDirector::setContentScaleFactor(float scaleFactor) if (scaleFactor != m_fContentScaleFactor) { m_fContentScaleFactor = scaleFactor; - m_obWinSizeInPixels = CCSizeMake(m_obWinSizeInPoints.width * scaleFactor, m_obWinSizeInPoints.height * scaleFactor); - - if (m_pobOpenGLView) - { - updateContentScaleFactor(); - } - - // update projection - setProjection(m_eProjection); } } diff --git a/cocos2dx/CCDirector.h b/cocos2dx/CCDirector.h index b1aef65d47..7b02fcb59b 100644 --- a/cocos2dx/CCDirector.h +++ b/cocos2dx/CCDirector.h @@ -328,8 +328,6 @@ protected: void purgeDirector(); bool m_bPurgeDirecotorInNextLoop; // this flag will be set to true in end() - void updateContentScaleFactor(void); - void setNextScene(void); void showStats(); @@ -406,9 +404,6 @@ protected: /* Projection protocol delegate */ CCDirectorDelegate *m_pProjectionDelegate; - - /* contentScaleFactor could be simulated */ - bool m_bIsContentScaleSupported; // CCEGLViewProtocol will recreate stats labels to fit visible rect friend class CCEGLViewProtocol; diff --git a/cocos2dx/platform/CCEGLViewProtocol.cpp b/cocos2dx/platform/CCEGLViewProtocol.cpp index 2f2c37fbc6..728a3aaedd 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.cpp +++ b/cocos2dx/platform/CCEGLViewProtocol.cpp @@ -141,12 +141,6 @@ void CCEGLViewProtocol::setTouchDelegate(EGLTouchDelegate * pDelegate) m_pDelegate = pDelegate; } -bool CCEGLViewProtocol::setContentScaleFactor(float contentScaleFactor) -{ - m_fScaleX = m_fScaleY = contentScaleFactor; - return false; -} - void CCEGLViewProtocol::setViewPortInPoints(float x , float y , float w , float h) { glViewport((GLint)(x * m_fScaleX + m_obViewPortRect.origin.x), diff --git a/cocos2dx/platform/CCEGLViewProtocol.h b/cocos2dx/platform/CCEGLViewProtocol.h index a9704bb946..879c70c229 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.h +++ b/cocos2dx/platform/CCEGLViewProtocol.h @@ -91,12 +91,6 @@ public: /** Set touch delegate */ virtual void setTouchDelegate(EGLTouchDelegate * pDelegate); - /** - * Set content scale factor. - * @return If the return value is true, the platform supports retina display mode. - */ - virtual bool setContentScaleFactor(float contentScaleFactor); - /** * Set opengl view port rectangle with points. */ diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index aead83fd60..71a0500ba1 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -231,7 +231,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) if (m_pDelegate && MK_LBUTTON == wParam) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; - CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR()); + CCPoint pt(point.x, point.y); CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp)) { @@ -249,7 +249,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) if (MK_LBUTTON == wParam && m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; - CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR()); + CCPoint pt(point.x, point.y); int id = 0; pt.x *= m_windowTouchScaleX; pt.y *= m_windowTouchScaleY; @@ -261,7 +261,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) if (m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; - CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR()); + CCPoint pt(point.x, point.y); int id = 0; pt.x *= m_windowTouchScaleX; pt.y *= m_windowTouchScaleY; @@ -408,12 +408,6 @@ void CCEGLView::setIMEKeyboardState(bool /*bOpen*/) } -bool CCEGLView::enableRetina() -{ - m_bIsRetinaEnabled = true; - return true; -} - void CCEGLView::setMenuResource(LPCWSTR menu) { m_menu = menu; @@ -512,15 +506,6 @@ void CCEGLView::centerWindow() SetWindowPos(m_hWnd, 0, offsetX, offsetY, 0, 0, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOZORDER); } -bool CCEGLView::setContentScaleFactor(float contentScaleFactor) -{ - CCEGLViewProtocol::setContentScaleFactor(contentScaleFactor); - resize((int)(m_obScreenSize.width * contentScaleFactor), (int)(m_obScreenSize.height * contentScaleFactor)); - centerWindow(); - - return true; -} - CCEGLView* CCEGLView::sharedOpenGLView() { static CCEGLView* s_pEglView = NULL; diff --git a/cocos2dx/platform/win32/CCEGLView.h b/cocos2dx/platform/win32/CCEGLView.h index 2f8877772a..8af8bf89e8 100644 --- a/cocos2dx/platform/win32/CCEGLView.h +++ b/cocos2dx/platform/win32/CCEGLView.h @@ -46,10 +46,8 @@ public: virtual bool isOpenGLReady(); virtual void end(); virtual void swapBuffers(); - virtual bool setContentScaleFactor(float contentScaleFactor); virtual void setFrameSize(float width, float height); virtual void setIMEKeyboardState(bool bOpen); - virtual bool enableRetina(); void setMenuResource(LPCWSTR menu); void setWndProc(CUSTOM_WND_PROC proc); From 98aa5dd4894f0f1a569bb71514ff6dd2d699f644 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 12 Oct 2012 10:02:49 +0800 Subject: [PATCH 17/64] issue #1486: Updated AppDelegate.cpp and proj.win32/main.cpp. --- samples/HelloCpp/Classes/AppDelegate.cpp | 2 +- samples/HelloCpp/proj.win32/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/HelloCpp/Classes/AppDelegate.cpp b/samples/HelloCpp/Classes/AppDelegate.cpp index e9966ee571..557e51d63a 100644 --- a/samples/HelloCpp/Classes/AppDelegate.cpp +++ b/samples/HelloCpp/Classes/AppDelegate.cpp @@ -25,7 +25,7 @@ bool AppDelegate::applicationDidFinishLaunching() { CCFileUtils::sharedFileUtils()->setResourceDirectory("ipadhd"); pDirector->setContentScaleFactor(2048.0f/kDesignResolutionSize_width); } - else if (screenSize.height >= 640) + else if (screenSize.height > 320) { CCFileUtils::sharedFileUtils()->setResourceDirectory("ipad"); pDirector->setContentScaleFactor(1024.0f/kDesignResolutionSize_width); diff --git a/samples/HelloCpp/proj.win32/main.cpp b/samples/HelloCpp/proj.win32/main.cpp index 2b81f7841a..f61bc4569e 100644 --- a/samples/HelloCpp/proj.win32/main.cpp +++ b/samples/HelloCpp/proj.win32/main.cpp @@ -15,6 +15,6 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, // create the application instance AppDelegate app; CCEGLView* eglView = CCEGLView::sharedOpenGLView(); - eglView->setFrameSize(960, 640 ); + eglView->setFrameSize(1136, 640 ); return CCApplication::sharedApplication()->run(); } From 965540ecec1918b5266d994ed4d3c64d3a88cdf9 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 12 Oct 2012 16:03:53 +0800 Subject: [PATCH 18/64] issue #1486: fix a warning in CCAutoreleasePool.cpp. --- cocos2dx/cocoa/CCAutoreleasePool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2dx/cocoa/CCAutoreleasePool.cpp b/cocos2dx/cocoa/CCAutoreleasePool.cpp index 791226942a..a825cab63e 100644 --- a/cocos2dx/cocoa/CCAutoreleasePool.cpp +++ b/cocos2dx/cocoa/CCAutoreleasePool.cpp @@ -50,7 +50,7 @@ void CCAutoreleasePool::addObject(CCObject* pObject) void CCAutoreleasePool::removeObject(CCObject* pObject) { - for (int i = 0; i < pObject->m_uAutoReleaseCount; ++i) + for (unsigned int i = 0; i < pObject->m_uAutoReleaseCount; ++i) { m_pManagedObjectArray->removeObject(pObject, false); } From 99a7dcefa4b765ce171c4490bca9e3dc95d51e00 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 12 Oct 2012 16:04:26 +0800 Subject: [PATCH 19/64] issue #1486: Updated lua bindings. --- .../cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id | 2 +- tools/tolua++/CCDirector.pkg | 1 - tools/tolua++/CCEGLViewProtocol.pkg | 11 ----------- 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id b/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id index 8079a39171..f4dc6b9364 100644 --- a/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id +++ b/scripting/lua/cocos2dx_support/LuaCocos2d.cpp.REMOVED.git-id @@ -1 +1 @@ -57601a5ee61c442f04b4d1bbfd2697330dfc63cb \ No newline at end of file +e4c5f54d0a54b4473017366d09c364ede1078c90 \ No newline at end of file diff --git a/tools/tolua++/CCDirector.pkg b/tools/tolua++/CCDirector.pkg index 4b17648a70..85a61cb6df 100644 --- a/tools/tolua++/CCDirector.pkg +++ b/tools/tolua++/CCDirector.pkg @@ -19,7 +19,6 @@ class CCDirector : public CCObject unsigned int getTotalFrames(void); CCEGLViewProtocol* getOpenGLView(void); - bool enableRetinaDisplay(bool bEnableRetina); CCSize getWinSize(void); CCSize getWinSizeInPixels(void); diff --git a/tools/tolua++/CCEGLViewProtocol.pkg b/tools/tolua++/CCEGLViewProtocol.pkg index f98ffaab73..3b5232a661 100644 --- a/tools/tolua++/CCEGLViewProtocol.pkg +++ b/tools/tolua++/CCEGLViewProtocol.pkg @@ -58,12 +58,6 @@ class CCEGLViewProtocol /** Set touch delegate */ void setTouchDelegate(EGLTouchDelegate * pDelegate); - /** - * Set content scale factor. - * @return If return true, it means the plaform supports retina display. - */ - bool setContentScaleFactor(float contentScaleFactor); - /** * Set opengl view port rectangle with points. */ @@ -89,9 +83,4 @@ class CCEGLViewProtocol * Get the scale factor of vertical direction. */ float getScaleY() const; - - /** - * Get whether the retina mode is enabled. - */ - bool isRetinaEnabled() const; }; From 04a4ebc571360ba86d8db89671a01e33b653c0cf Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 12 Oct 2012 16:18:28 +0800 Subject: [PATCH 20/64] issue #1486: Using relative coordinate for HelloLua. --- samples/HelloLua/Classes/AppDelegate.cpp | 2 +- samples/HelloLua/Resources/hello.lua | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/samples/HelloLua/Classes/AppDelegate.cpp b/samples/HelloLua/Classes/AppDelegate.cpp index 21ca3dcefc..c33c165795 100644 --- a/samples/HelloLua/Classes/AppDelegate.cpp +++ b/samples/HelloLua/Classes/AppDelegate.cpp @@ -26,7 +26,7 @@ bool AppDelegate::applicationDidFinishLaunching() CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); - CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionShowAll); + CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionNoBorder); // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices. // pDirector->enableRetinaDisplay(true); diff --git a/samples/HelloLua/Resources/hello.lua b/samples/HelloLua/Resources/hello.lua index 4bbd577856..7bd1f99e72 100644 --- a/samples/HelloLua/Resources/hello.lua +++ b/samples/HelloLua/Resources/hello.lua @@ -21,7 +21,8 @@ local function main() --------------- - local winSize = CCDirector:sharedDirector():getWinSize() + local visibleSize = CCDirector:sharedDirector():getVisibleSize() + local origin = CCDirector:sharedDirector():getVisibleOrigin() -- add the moving dog local function creatDog() @@ -37,7 +38,7 @@ local function main() local spriteDog = CCSprite:createWithSpriteFrame(frame0) spriteDog.isPaused = false - spriteDog:setPosition(0, winSize.height / 4 * 3) + spriteDog:setPosition(origin.x, origin.y + visibleSize.height / 4 * 3) local animFrames = CCArray:create() @@ -52,8 +53,8 @@ local function main() local function tick() if spriteDog.isPaused then return end local x, y = spriteDog:getPosition() - if x > winSize.width then - x = 0 + if x > origin.x + visibleSize.width then + x = origin.x else x = x + 1 end @@ -72,7 +73,7 @@ local function main() -- add in farm background local bg = CCSprite:create("farm.jpg") - bg:setPosition(winSize.width / 2 + 80, winSize.height / 2) + bg:setPosition(origin.x + visibleSize.width / 2 + 80, origin.y + visibleSize.height / 2) layerFarm:addChild(bg) -- add land sprite @@ -166,7 +167,7 @@ local function main() menuPopupItem:setPosition(0, 0) menuPopupItem:registerScriptTapHandler(menuCallbackClosePopup) menuPopup = CCMenu:createWithItem(menuPopupItem) - menuPopup:setPosition(winSize.width / 2, winSize.height / 2) + menuPopup:setPosition(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2) menuPopup:setVisible(false) layerMenu:addChild(menuPopup) @@ -175,7 +176,9 @@ local function main() menuToolsItem:setPosition(0, 0) menuToolsItem:registerScriptTapHandler(menuCallbackOpenPopup) menuTools = CCMenu:createWithItem(menuToolsItem) - menuTools:setPosition(30, 40) + local itemWidth = menuToolsItem:getContentSize().width + local itemHeight = menuToolsItem:getContentSize().height + menuTools:setPosition(origin.x + itemWidth/2, origin.y + itemHeight/2) layerMenu:addChild(menuTools) return layerMenu From 6178594068802625b562867b474bc257205f6a4f Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 12 Oct 2012 16:19:33 +0800 Subject: [PATCH 21/64] issue #1486: Updated lua templates. --- .../Templates/1033/Resources/hello.lua | 17 ++++++++++------- .../cocos2dx_lua.xctemplate/Resources/hello.lua | 17 ++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/template/msvc/CCAppWiz.win32/Templates/1033/Resources/hello.lua b/template/msvc/CCAppWiz.win32/Templates/1033/Resources/hello.lua index 4bbd577856..7bd1f99e72 100644 --- a/template/msvc/CCAppWiz.win32/Templates/1033/Resources/hello.lua +++ b/template/msvc/CCAppWiz.win32/Templates/1033/Resources/hello.lua @@ -21,7 +21,8 @@ local function main() --------------- - local winSize = CCDirector:sharedDirector():getWinSize() + local visibleSize = CCDirector:sharedDirector():getVisibleSize() + local origin = CCDirector:sharedDirector():getVisibleOrigin() -- add the moving dog local function creatDog() @@ -37,7 +38,7 @@ local function main() local spriteDog = CCSprite:createWithSpriteFrame(frame0) spriteDog.isPaused = false - spriteDog:setPosition(0, winSize.height / 4 * 3) + spriteDog:setPosition(origin.x, origin.y + visibleSize.height / 4 * 3) local animFrames = CCArray:create() @@ -52,8 +53,8 @@ local function main() local function tick() if spriteDog.isPaused then return end local x, y = spriteDog:getPosition() - if x > winSize.width then - x = 0 + if x > origin.x + visibleSize.width then + x = origin.x else x = x + 1 end @@ -72,7 +73,7 @@ local function main() -- add in farm background local bg = CCSprite:create("farm.jpg") - bg:setPosition(winSize.width / 2 + 80, winSize.height / 2) + bg:setPosition(origin.x + visibleSize.width / 2 + 80, origin.y + visibleSize.height / 2) layerFarm:addChild(bg) -- add land sprite @@ -166,7 +167,7 @@ local function main() menuPopupItem:setPosition(0, 0) menuPopupItem:registerScriptTapHandler(menuCallbackClosePopup) menuPopup = CCMenu:createWithItem(menuPopupItem) - menuPopup:setPosition(winSize.width / 2, winSize.height / 2) + menuPopup:setPosition(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2) menuPopup:setVisible(false) layerMenu:addChild(menuPopup) @@ -175,7 +176,9 @@ local function main() menuToolsItem:setPosition(0, 0) menuToolsItem:registerScriptTapHandler(menuCallbackOpenPopup) menuTools = CCMenu:createWithItem(menuToolsItem) - menuTools:setPosition(30, 40) + local itemWidth = menuToolsItem:getContentSize().width + local itemHeight = menuToolsItem:getContentSize().height + menuTools:setPosition(origin.x + itemWidth/2, origin.y + itemHeight/2) layerMenu:addChild(menuTools) return layerMenu diff --git a/template/xcode4/cocos2dx_lua.xctemplate/Resources/hello.lua b/template/xcode4/cocos2dx_lua.xctemplate/Resources/hello.lua index 4bbd577856..7bd1f99e72 100644 --- a/template/xcode4/cocos2dx_lua.xctemplate/Resources/hello.lua +++ b/template/xcode4/cocos2dx_lua.xctemplate/Resources/hello.lua @@ -21,7 +21,8 @@ local function main() --------------- - local winSize = CCDirector:sharedDirector():getWinSize() + local visibleSize = CCDirector:sharedDirector():getVisibleSize() + local origin = CCDirector:sharedDirector():getVisibleOrigin() -- add the moving dog local function creatDog() @@ -37,7 +38,7 @@ local function main() local spriteDog = CCSprite:createWithSpriteFrame(frame0) spriteDog.isPaused = false - spriteDog:setPosition(0, winSize.height / 4 * 3) + spriteDog:setPosition(origin.x, origin.y + visibleSize.height / 4 * 3) local animFrames = CCArray:create() @@ -52,8 +53,8 @@ local function main() local function tick() if spriteDog.isPaused then return end local x, y = spriteDog:getPosition() - if x > winSize.width then - x = 0 + if x > origin.x + visibleSize.width then + x = origin.x else x = x + 1 end @@ -72,7 +73,7 @@ local function main() -- add in farm background local bg = CCSprite:create("farm.jpg") - bg:setPosition(winSize.width / 2 + 80, winSize.height / 2) + bg:setPosition(origin.x + visibleSize.width / 2 + 80, origin.y + visibleSize.height / 2) layerFarm:addChild(bg) -- add land sprite @@ -166,7 +167,7 @@ local function main() menuPopupItem:setPosition(0, 0) menuPopupItem:registerScriptTapHandler(menuCallbackClosePopup) menuPopup = CCMenu:createWithItem(menuPopupItem) - menuPopup:setPosition(winSize.width / 2, winSize.height / 2) + menuPopup:setPosition(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2) menuPopup:setVisible(false) layerMenu:addChild(menuPopup) @@ -175,7 +176,9 @@ local function main() menuToolsItem:setPosition(0, 0) menuToolsItem:registerScriptTapHandler(menuCallbackOpenPopup) menuTools = CCMenu:createWithItem(menuToolsItem) - menuTools:setPosition(30, 40) + local itemWidth = menuToolsItem:getContentSize().width + local itemHeight = menuToolsItem:getContentSize().height + menuTools:setPosition(origin.x + itemWidth/2, origin.y + itemHeight/2) layerMenu:addChild(menuTools) return layerMenu From 36600d95b1cfacf561ac5cdede1d3e8a7f8b4380 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 12 Oct 2012 17:37:26 +0800 Subject: [PATCH 22/64] issue #1486: Calculate content scale factor by screen height. --- samples/HelloCpp/Classes/AppDelegate.cpp | 6 ++-- samples/TestCpp/Classes/AppDelegate.cpp | 40 ++++++++++-------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/samples/HelloCpp/Classes/AppDelegate.cpp b/samples/HelloCpp/Classes/AppDelegate.cpp index 557e51d63a..84e2527106 100644 --- a/samples/HelloCpp/Classes/AppDelegate.cpp +++ b/samples/HelloCpp/Classes/AppDelegate.cpp @@ -23,17 +23,17 @@ bool AppDelegate::applicationDidFinishLaunching() { if (screenSize.height > 768) { CCFileUtils::sharedFileUtils()->setResourceDirectory("ipadhd"); - pDirector->setContentScaleFactor(2048.0f/kDesignResolutionSize_width); + pDirector->setContentScaleFactor(1536.0f/kDesignResolutionSize_height); } else if (screenSize.height > 320) { CCFileUtils::sharedFileUtils()->setResourceDirectory("ipad"); - pDirector->setContentScaleFactor(1024.0f/kDesignResolutionSize_width); + pDirector->setContentScaleFactor(768.0f/kDesignResolutionSize_height); } else { CCFileUtils::sharedFileUtils()->setResourceDirectory("iphone"); - pDirector->setContentScaleFactor(480.0f/kDesignResolutionSize_width); + pDirector->setContentScaleFactor(320.0f/kDesignResolutionSize_height); } CCEGLView::sharedOpenGLView()->setDesignResolutionSize(kDesignResolutionSize_width, kDesignResolutionSize_height, kResolutionNoBorder); diff --git a/samples/TestCpp/Classes/AppDelegate.cpp b/samples/TestCpp/Classes/AppDelegate.cpp index 07f003403a..01f76e4ecf 100644 --- a/samples/TestCpp/Classes/AppDelegate.cpp +++ b/samples/TestCpp/Classes/AppDelegate.cpp @@ -22,32 +22,26 @@ bool AppDelegate::applicationDidFinishLaunching() CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); - TargetPlatform target = getTargetPlatform(); - - if (target == kTargetIpad) - { - // ipad + CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize(); + CCSize designSize = CCSizeMake(480, 320); - if (pDirector->enableRetinaDisplay(true)) - { - // ipad hd - CCFileUtils::sharedFileUtils()->setResourceDirectory("ipadhd"); - } - else - { - CCFileUtils::sharedFileUtils()->setResourceDirectory("ipad"); - } - } - else if (target == kTargetIphone) + if (screenSize.height > 768) { - // iphone - - if (pDirector->enableRetinaDisplay(true)) - { - // iphone hd - CCFileUtils::sharedFileUtils()->setResourceDirectory("hd"); - } + CCFileUtils::sharedFileUtils()->setResourceDirectory("ipadhd"); + pDirector->setContentScaleFactor(1536.0f/designSize.height); } + else if (screenSize.height > 640) + { + CCFileUtils::sharedFileUtils()->setResourceDirectory("ipad"); + pDirector->setContentScaleFactor(768.0f/designSize.height); + } + else if (screenSize.height > 320) + { + CCFileUtils::sharedFileUtils()->setResourceDirectory("hd"); + pDirector->setContentScaleFactor(640.0f/designSize.height); + } + + CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder); // turn on display FPS pDirector->setDisplayStats(true); From 32a9d51618887dfe30335cdb53b855e96daa331a Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 12 Oct 2012 17:37:49 +0800 Subject: [PATCH 23/64] issue #1486: Commented some unused codes. --- samples/TestCpp/Classes/BugsTest/Bug-899.cpp | 2 +- samples/TestCpp/Classes/BugsTest/BugsTest.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/TestCpp/Classes/BugsTest/Bug-899.cpp b/samples/TestCpp/Classes/BugsTest/Bug-899.cpp index 3d29611ad0..8c16059ba4 100644 --- a/samples/TestCpp/Classes/BugsTest/Bug-899.cpp +++ b/samples/TestCpp/Classes/BugsTest/Bug-899.cpp @@ -9,7 +9,7 @@ bool Bug899Layer::init() { - CCDirector::sharedDirector()->enableRetinaDisplay(true); +// CCDirector::sharedDirector()->enableRetinaDisplay(true); if (BugsTestBaseLayer::init()) { CCSprite *bg = CCSprite::create("Images/bugs/RetinaDisplay.jpg"); diff --git a/samples/TestCpp/Classes/BugsTest/BugsTest.cpp b/samples/TestCpp/Classes/BugsTest/BugsTest.cpp index 1100b881ae..020eafc061 100644 --- a/samples/TestCpp/Classes/BugsTest/BugsTest.cpp +++ b/samples/TestCpp/Classes/BugsTest/BugsTest.cpp @@ -165,7 +165,7 @@ void BugsTestBaseLayer::onEnter() void BugsTestBaseLayer::backCallback(CCObject* pSender) { - CCDirector::sharedDirector()->enableRetinaDisplay(false); +// CCDirector::sharedDirector()->enableRetinaDisplay(false); BugsTestScene* pScene = new BugsTestScene(); pScene->runThisTest(); pScene->autorelease(); From 0a39fa8bef5ffacb4821084491ba33086e96f859 Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 12 Oct 2012 17:43:43 +0800 Subject: [PATCH 24/64] fixed #1507: use SoundPool.OnLoadCompleteListener to play effect if it is not preloaded --- .../src/org/cocos2dx/lib/Cocos2dxSound.java | 116 ++++++++++++++---- 1 file changed, 94 insertions(+), 22 deletions(-) diff --git a/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxSound.java b/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxSound.java index 0b3c0bec14..b20b67b438 100644 --- a/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxSound.java +++ b/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxSound.java @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; +import java.util.concurrent.Semaphore; import android.content.Context; import android.media.AudioManager; @@ -56,6 +57,11 @@ public class Cocos2dxSound { private final HashMap> mPathStreamIDsMap = new HashMap>(); private final HashMap mPathSoundIDMap = new HashMap(); + + private final ArrayList mEffecToPlayWhenLoadedArray = new ArrayList(); + + private int mStreamIdSyn; + private Semaphore mSemaphore; private static final int MAX_SIMULTANEOUS_STREAMS_DEFAULT = 5; private static final float SOUND_RATE = 1.0f; @@ -77,9 +83,12 @@ public class Cocos2dxSound { private void initData() { this.mSoundPool = new SoundPool(Cocos2dxSound.MAX_SIMULTANEOUS_STREAMS_DEFAULT, AudioManager.STREAM_MUSIC, Cocos2dxSound.SOUND_QUALITY); - + this.mSoundPool.setOnLoadCompleteListener(new OnLoadCompletedListener()); + this.mLeftVolume = 0.5f; this.mRightVolume = 0.5f; + + this.mSemaphore = new Semaphore(0, true); } // =========================================================== @@ -127,15 +136,7 @@ public class Cocos2dxSound { if (soundID != null) { // play sound - streamID = this.mSoundPool.play(soundID.intValue(), this.mLeftVolume, this.mRightVolume, Cocos2dxSound.SOUND_PRIORITY, pLoop ? -1 : 0, Cocos2dxSound.SOUND_RATE); - - // record stream id - ArrayList streamIDs = this.mPathStreamIDsMap.get(pPath); - if (streamIDs == null) { - streamIDs = new ArrayList(); - this.mPathStreamIDsMap.put(pPath, streamIDs); - } - streamIDs.add(streamID); + streamID = this.doPlayEffect(pPath, soundID.intValue(), pLoop); } else { // the effect is not prepared soundID = this.preloadEffect(pPath); @@ -143,16 +144,21 @@ public class Cocos2dxSound { // can not preload effect return Cocos2dxSound.INVALID_SOUND_ID; } - - /* - * Someone reports that, it can not play effect for the first time. - * If you are lucky to meet it. There are two ways to resolve it. 1. - * Add some delay here. I don't know how long it is, so I don't add - * it here. 2. If you use 2.2(API level 8), you can call - * SoundPool.setOnLoadCompleteListener() to play the effect. Because - * the method is supported from 2.2, so I can't use it here. - */ - this.playEffect(pPath, pLoop); + + // only allow one playEffect at a time, or the semaphore will not work correctly + synchronized(this.mSoundPool) { + // add this effect into mEffecToPlayWhenLoadedArray, and it will be played when loaded completely + mEffecToPlayWhenLoadedArray.add(new SoundInfoForLoadedCompleted(pPath, soundID.intValue(), pLoop)); + + try { + // wait OnloadedCompleteListener to set streamID + this.mSemaphore.acquire(); + + streamID = this.mStreamIdSyn; + } catch(Exception e) { + return Cocos2dxSound.INVALID_SOUND_ID; + } + } } return streamID; @@ -183,8 +189,17 @@ public class Cocos2dxSound { } public void resumeAllEffects() { - // autoPause() is available since level 8 - this.mSoundPool.autoResume(); + // can not only invoke SoundPool.autoResume() here, because + // it only resumes all effects paused by pauseAllEffects() + if (!this.mPathStreamIDsMap.isEmpty()) { + final Iterator>> iter = this.mPathStreamIDsMap.entrySet().iterator(); + while (iter.hasNext()) { + final Entry> entry = iter.next(); + for (final int pStreamID : entry.getValue()) { + this.mSoundPool.resume(pStreamID); + } + } + } } @SuppressWarnings("unchecked") @@ -235,9 +250,12 @@ public class Cocos2dxSound { this.mSoundPool.release(); this.mPathStreamIDsMap.clear(); this.mPathSoundIDMap.clear(); + this.mEffecToPlayWhenLoadedArray.clear(); this.mLeftVolume = 0.5f; this.mRightVolume = 0.5f; + + this.initData(); } public int createSoundIDFromAsset(final String pPath) { @@ -256,8 +274,62 @@ public class Cocos2dxSound { return soundID; } + + private int doPlayEffect(final String pPath, final int soundId, final boolean pLoop) { + // play sound + int streamID = this.mSoundPool.play(soundId, this.mLeftVolume, this.mRightVolume, Cocos2dxSound.SOUND_PRIORITY, pLoop ? -1 : 0, Cocos2dxSound.SOUND_RATE); + + // record stream id + ArrayList streamIDs = this.mPathStreamIDsMap.get(pPath); + if (streamIDs == null) { + streamIDs = new ArrayList(); + this.mPathStreamIDsMap.put(pPath, streamIDs); + } + streamIDs.add(streamID); + + return streamID; + } // =========================================================== // Inner and Anonymous Classes // =========================================================== + + public class SoundInfoForLoadedCompleted { + public int soundID; + public boolean isLoop; + public String path; + + public SoundInfoForLoadedCompleted(String path, int soundId, boolean isLoop) { + this.path = path; + this.soundID = soundId; + this.isLoop = isLoop; + } + } + + public class OnLoadCompletedListener implements SoundPool.OnLoadCompleteListener { + + @Override + public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { + if (status == 0) + { + // only play effect that are in mEffecToPlayWhenLoadedArray + for ( SoundInfoForLoadedCompleted info : mEffecToPlayWhenLoadedArray) { + if (sampleId == info.soundID) { + // set the stream id which will be returned by playEffect() + mStreamIdSyn = doPlayEffect(info.path, info.soundID, info.isLoop); + + // remove it from array, because we will break here + // so it is safe to do + mEffecToPlayWhenLoadedArray.remove(info); + + break; + } + } + } else { + mStreamIdSyn = Cocos2dxSound.INVALID_SOUND_ID; + } + + mSemaphore.release(); + } + } } From 2ac7a5cbe486fa80c1bf0a5a84c0ebb4e7f57b0b Mon Sep 17 00:00:00 2001 From: folecr Date: Fri, 12 Oct 2012 09:48:37 -0700 Subject: [PATCH 25/64] microlattice : updating submodule reference to latest autogenerated bindings --- scripting/javascript/bindings/generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripting/javascript/bindings/generated b/scripting/javascript/bindings/generated index 7bee281e6c..24ab57efad 160000 --- a/scripting/javascript/bindings/generated +++ b/scripting/javascript/bindings/generated @@ -1 +1 @@ -Subproject commit 7bee281e6c33d25ed2874261da6658b66a43e073 +Subproject commit 24ab57efadfde067887981d11aef072f5f6cb624 From 6cf602ea3bbe8d1360a22be987e440f22ecf2486 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 13 Oct 2012 10:18:03 +0800 Subject: [PATCH 26/64] issue #1486: CCDirector::getWinSizeInPixel return 'winSize* CC_CONTENT_SCALE_FACTOR()'. This change fixes the wrong display bug in CCRenderTexture. --- cocos2dx/platform/CCEGLViewProtocol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2dx/platform/CCEGLViewProtocol.cpp b/cocos2dx/platform/CCEGLViewProtocol.cpp index 728a3aaedd..2b13b0fdbc 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.cpp +++ b/cocos2dx/platform/CCEGLViewProtocol.cpp @@ -92,7 +92,7 @@ void CCEGLViewProtocol::setDesignResolutionSize(float width, float height, Resol // reset director's member variables to fit visible rect CCDirector::sharedDirector()->createStatsLabel(); CCDirector::sharedDirector()->m_obWinSizeInPoints = getSize(); - CCDirector::sharedDirector()->m_obWinSizeInPixels = m_obScreenSize; + CCDirector::sharedDirector()->m_obWinSizeInPixels = CCSizeMake(m_obDesignResolutionSize.width*CC_CONTENT_SCALE_FACTOR(), m_obDesignResolutionSize.height*CC_CONTENT_SCALE_FACTOR()); CCDirector::sharedDirector()->setGLDefaultValues(); } From 7d1d46ee3f495edf88c751373b266ce84baa327c Mon Sep 17 00:00:00 2001 From: micahli Date: Sat, 13 Oct 2012 16:44:46 +0800 Subject: [PATCH 27/64] fix a bug with CCNotificationCenter that observer->performSelector(observer) may call CCNotificationCenter::removeObserver and cause CCARRAY_FOREACH(m_observers, obj) access invalid address --- cocos2dx/support/CCNotificationCenter.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cocos2dx/support/CCNotificationCenter.cpp b/cocos2dx/support/CCNotificationCenter.cpp index e852bac6ee..17041534ac 100644 --- a/cocos2dx/support/CCNotificationCenter.cpp +++ b/cocos2dx/support/CCNotificationCenter.cpp @@ -131,6 +131,7 @@ void CCNotificationCenter::unregisterScriptObserver(void) void CCNotificationCenter::postNotification(const char *name, CCObject *object) { + CCArray* intrestedObservers = CCArray::createWithCapacity(m_observers->count()); CCObject* obj = NULL; CCARRAY_FOREACH(m_observers, obj) { @@ -139,7 +140,13 @@ void CCNotificationCenter::postNotification(const char *name, CCObject *object) continue; if (!strcmp(name,observer->getName()) && (observer->getObject() == object || observer->getObject() == NULL || object == NULL)) - observer->performSelector(object); + intrestedObservers->addObject(observer); + } + + CCARRAY_FOREACH(intrestedObservers, obj) + { + CCNotificationObserver* observer = (CCNotificationObserver*) obj; + observer->performSelector(object); } if (m_scriptHandler) From 2c670a9efce6813c137445f4697252690c9f06dd Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 13 Oct 2012 18:19:37 +0800 Subject: [PATCH 28/64] issue #1486: Fix a bug in CCRenderTexture.cpp about calculate width and height by multiply CC_CONTENT_SCALE_FACTOR(). --- cocos2dx/misc_nodes/CCRenderTexture.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2dx/misc_nodes/CCRenderTexture.cpp b/cocos2dx/misc_nodes/CCRenderTexture.cpp index 68e63e45f9..8d30f9d902 100644 --- a/cocos2dx/misc_nodes/CCRenderTexture.cpp +++ b/cocos2dx/misc_nodes/CCRenderTexture.cpp @@ -174,8 +174,8 @@ bool CCRenderTexture::initWithWidthAndHeight(int w, int h, CCTexture2DPixelForma void *data = NULL; do { - w *= (int)CC_CONTENT_SCALE_FACTOR(); - h *= (int)CC_CONTENT_SCALE_FACTOR(); + w = (int)(w * CC_CONTENT_SCALE_FACTOR()); + h = (int)(h * CC_CONTENT_SCALE_FACTOR()); glGetIntegerv(GL_FRAMEBUFFER_BINDING, &m_nOldFBO); From 15695505282bdbf5003458d698705a04e7b3474d Mon Sep 17 00:00:00 2001 From: shinriyo Date: Sun, 14 Oct 2012 21:20:31 +0900 Subject: [PATCH 29/64] getDelta() is delta function I'm sorry, I mistook the pull request. --- cocos2dx/touch_dispatcher/CCTouch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2dx/touch_dispatcher/CCTouch.h b/cocos2dx/touch_dispatcher/CCTouch.h index 88c425a674..e1accc5564 100644 --- a/cocos2dx/touch_dispatcher/CCTouch.h +++ b/cocos2dx/touch_dispatcher/CCTouch.h @@ -46,7 +46,7 @@ public: CCPoint getLocation() const; /** returns the previous touch location in OpenGL coordinates */ CCPoint getPreviousLocation() const; - /** returns the current touch location in screen coordinates */ + /** returns the delta of 2 current touches locations in screen coordinates */ CCPoint getDelta() const; /** returns the current touch location in screen coordinates */ CCPoint getLocationInView() const; From 0e76827b7e07460460d9b1bea7f95808854d590f Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 14 Oct 2012 22:03:23 +0800 Subject: [PATCH 30/64] issue #1486: Commenting one line to avoid something like mosaic in 'CCControlExtensionTest', especially the display of 'huePickerBackground.png' when in 800*480 window size with 480*320 design resolution and hd(960*640) resources. --- extensions/GUI/CCControlExtension/CCControlColourPicker.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/extensions/GUI/CCControlExtension/CCControlColourPicker.cpp b/extensions/GUI/CCControlExtension/CCControlColourPicker.cpp index 2de4e1bc0d..0943a2f9ce 100644 --- a/extensions/GUI/CCControlExtension/CCControlColourPicker.cpp +++ b/extensions/GUI/CCControlExtension/CCControlColourPicker.cpp @@ -80,7 +80,10 @@ bool CCControlColourPicker::init() // MIPMAP // ccTexParams params = {GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT}; - spriteSheet->getTexture()->setAliasTexParameters(); + /* Comment next line to avoid something like mosaic in 'CCControlExtensionTest', + especially the display of 'huePickerBackground.png' when in 800*480 window size with 480*320 design resolution and hd(960*640) resources. + */ +// spriteSheet->getTexture()->setAliasTexParameters(); // spriteSheet->getTexture()->setTexParameters(¶ms); // spriteSheet->getTexture()->generateMipmap(); From 39a4af57cc7a3380285fbeb3c0f80ae726979c9a Mon Sep 17 00:00:00 2001 From: James Chen Date: Sun, 14 Oct 2012 22:21:57 +0800 Subject: [PATCH 31/64] issue #1486: Using relative position for ActionsTest and Box2dView. --- .../Classes/ActionsTest/ActionsTest.cpp | 20 ++++++++++--------- .../Classes/Box2DTestBed/Box2dView.cpp | 16 ++++++++------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/samples/TestCpp/Classes/ActionsTest/ActionsTest.cpp b/samples/TestCpp/Classes/ActionsTest/ActionsTest.cpp index 148b169ef7..3c3c8f17ba 100644 --- a/samples/TestCpp/Classes/ActionsTest/ActionsTest.cpp +++ b/samples/TestCpp/Classes/ActionsTest/ActionsTest.cpp @@ -164,25 +164,27 @@ void ActionsDemo::onEnter() addChild(m_tamara, 2); addChild(m_kathia, 3); - CCSize s = CCDirector::sharedDirector()->getWinSize(); + CCDirector* pDirector = CCDirector::sharedDirector(); + CCPoint visibleOrigin = pDirector->getVisibleOrigin(); + CCSize visibleSize = pDirector->getVisibleSize(); - m_grossini->setPosition(CCPointMake(s.width/2, s.height/3)); - m_tamara->setPosition(CCPointMake(s.width/2, 2*s.height/3)); - m_kathia->setPosition(CCPointMake(s.width/2, s.height/2)); + m_grossini->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/3)); + m_tamara->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+2*visibleSize.height/3)); + m_kathia->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/2)); // add title and subtitle std::string str = title(); const char * pTitle = str.c_str(); CCLabelTTF* label = CCLabelTTF::create(pTitle, "Arial", 18); addChild(label, 1); - label->setPosition( CCPointMake(s.width/2, s.height - 30) ); + label->setPosition( ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height - 30) ); std::string strSubtitle = subtitle(); if( ! strSubtitle.empty() ) { CCLabelTTF* l = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 22); addChild(l, 1); - l->setPosition( CCPointMake(s.width/2, s.height - 60) ); + l->setPosition( ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height - 60) ); } // add menu @@ -193,9 +195,9 @@ void ActionsDemo::onEnter() CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); menu->setPosition(CCPointZero); - item1->setPosition(CCPointMake(s.width/2 - item2->getContentSize().width*2, item2->getContentSize().height/2)); - item2->setPosition(CCPointMake(s.width/2, item2->getContentSize().height/2)); - item3->setPosition(CCPointMake(s.width/2 + item2->getContentSize().width*2, item2->getContentSize().height/2)); + item1->setPosition(ccp(visibleOrigin.x+visibleSize.width/2 - item2->getContentSize().width*2, visibleOrigin.y+item2->getContentSize().height/2)); + item2->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+item2->getContentSize().height/2)); + item3->setPosition(ccp(visibleOrigin.x+visibleSize.width/2 + item2->getContentSize().width*2, visibleOrigin.y+item2->getContentSize().height/2)); addChild(menu, 1); } diff --git a/samples/TestCpp/Classes/Box2DTestBed/Box2dView.cpp b/samples/TestCpp/Classes/Box2DTestBed/Box2dView.cpp index 7299626a0f..2d872f6b42 100644 --- a/samples/TestCpp/Classes/Box2DTestBed/Box2dView.cpp +++ b/samples/TestCpp/Classes/Box2DTestBed/Box2dView.cpp @@ -46,8 +46,10 @@ MenuLayer* MenuLayer::menuWithEntryID(int entryId) bool MenuLayer::initWithEntryID(int entryId) { - CCSize s = CCDirector::sharedDirector()->getWinSize(); - + CCDirector* pDirector = CCDirector::sharedDirector(); + CCPoint visibleOrigin = pDirector->getVisibleOrigin(); + CCSize visibleSize = pDirector->getVisibleSize(); + m_entryID = entryId; setTouchEnabled( true ); @@ -56,14 +58,14 @@ bool MenuLayer::initWithEntryID(int entryId) addChild(view, 0, kTagBox2DNode); view->setScale(15); view->setAnchorPoint( ccp(0,0) ); - view->setPosition( ccp(s.width/2, s.height/3) ); + view->setPosition( ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/3) ); //#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE) // CCLabelBMFont* label = CCLabelBMFont::create(view->title().c_str(), "fonts/arial16.fnt"); //#else CCLabelTTF* label = CCLabelTTF::create(view->title().c_str(), "Arial", 28); //#endif addChild(label, 1); - label->setPosition( ccp(s.width/2, s.height-50) ); + label->setPosition( ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height-50) ); CCMenuItemImage *item1 = CCMenuItemImage::create("Images/b1.png", "Images/b2.png", this, menu_selector(MenuLayer::backCallback) ); CCMenuItemImage *item2 = CCMenuItemImage::create("Images/r1.png","Images/r2.png", this, menu_selector(MenuLayer::restartCallback) ); @@ -72,9 +74,9 @@ bool MenuLayer::initWithEntryID(int entryId) CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); menu->setPosition( CCPointZero ); - item1->setPosition( ccp( s.width/2 - 100,30) ); - item2->setPosition( ccp( s.width/2, 30) ); - item3->setPosition( ccp( s.width/2 + 100,30) ); + item1->setPosition( ccp( visibleOrigin.x+visibleSize.width/2 - 100,visibleOrigin.y+30) ); + item2->setPosition( ccp( visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+30) ); + item3->setPosition( ccp( visibleOrigin.x+visibleSize.width/2 + 100,visibleOrigin.y+30) ); addChild(menu, 1); From c69a11296e97672ce87b0a67293fbae2a18b596b Mon Sep 17 00:00:00 2001 From: micahli Date: Mon, 15 Oct 2012 09:55:37 +0800 Subject: [PATCH 32/64] fix the potential Container iterator bug with CCNotification revert last fix which may contain other bugs --- cocos2dx/support/CCNotificationCenter.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/cocos2dx/support/CCNotificationCenter.cpp b/cocos2dx/support/CCNotificationCenter.cpp index 17041534ac..2fe860a129 100644 --- a/cocos2dx/support/CCNotificationCenter.cpp +++ b/cocos2dx/support/CCNotificationCenter.cpp @@ -131,22 +131,17 @@ void CCNotificationCenter::unregisterScriptObserver(void) void CCNotificationCenter::postNotification(const char *name, CCObject *object) { - CCArray* intrestedObservers = CCArray::createWithCapacity(m_observers->count()); + CCArray* ObserversCopy = CCArray::createWithCapacity(m_observers->count()); + ObserversCopy->addObjectsFromArray(m_observers); CCObject* obj = NULL; - CCARRAY_FOREACH(m_observers, obj) + CCARRAY_FOREACH(ObserversCopy, obj) { CCNotificationObserver* observer = (CCNotificationObserver*) obj; if (!observer) continue; if (!strcmp(name,observer->getName()) && (observer->getObject() == object || observer->getObject() == NULL || object == NULL)) - intrestedObservers->addObject(observer); - } - - CCARRAY_FOREACH(intrestedObservers, obj) - { - CCNotificationObserver* observer = (CCNotificationObserver*) obj; - observer->performSelector(object); + observer->performSelector(object); } if (m_scriptHandler) From 93d702e3ccb6d18ef49b8bc18cae64212c1bff7e Mon Sep 17 00:00:00 2001 From: minggo Date: Mon, 15 Oct 2012 12:03:15 +0800 Subject: [PATCH 33/64] fixed #1491:remove dependency of FontLabel lib --- cocos2dx/platform/ios/CCImage.mm | 35 +- cocos2dx/platform/ios/FontLabel/FontLabel.h | 44 - cocos2dx/platform/ios/FontLabel/FontLabel.m | 197 ---- .../ios/FontLabel/FontLabelStringDrawing.h | 82 -- .../ios/FontLabel/FontLabelStringDrawing.m | 916 ------------------ cocos2dx/platform/ios/FontLabel/FontManager.h | 85 -- cocos2dx/platform/ios/FontLabel/FontManager.m | 123 --- .../ios/FontLabel/ZAttributedString.h | 77 -- .../ios/FontLabel/ZAttributedString.m | 597 ------------ .../ios/FontLabel/ZAttributedStringPrivate.h | 24 - cocos2dx/platform/ios/FontLabel/ZFont.h | 47 - cocos2dx/platform/ios/FontLabel/ZFont.m | 170 ---- .../project.pbxproj.REMOVED.git-id | 2 +- samples/TestCpp/Classes/FontTest/FontTest.cpp | 10 +- 14 files changed, 18 insertions(+), 2391 deletions(-) delete mode 100644 cocos2dx/platform/ios/FontLabel/FontLabel.h delete mode 100644 cocos2dx/platform/ios/FontLabel/FontLabel.m delete mode 100644 cocos2dx/platform/ios/FontLabel/FontLabelStringDrawing.h delete mode 100644 cocos2dx/platform/ios/FontLabel/FontLabelStringDrawing.m delete mode 100644 cocos2dx/platform/ios/FontLabel/FontManager.h delete mode 100644 cocos2dx/platform/ios/FontLabel/FontManager.m delete mode 100644 cocos2dx/platform/ios/FontLabel/ZAttributedString.h delete mode 100644 cocos2dx/platform/ios/FontLabel/ZAttributedString.m delete mode 100644 cocos2dx/platform/ios/FontLabel/ZAttributedStringPrivate.h delete mode 100644 cocos2dx/platform/ios/FontLabel/ZFont.h delete mode 100644 cocos2dx/platform/ios/FontLabel/ZFont.m diff --git a/cocos2dx/platform/ios/CCImage.mm b/cocos2dx/platform/ios/CCImage.mm index fd80592627..d01967d48a 100644 --- a/cocos2dx/platform/ios/CCImage.mm +++ b/cocos2dx/platform/ios/CCImage.mm @@ -28,10 +28,6 @@ THE SOFTWARE. #import #import -// FontLabel support -#import "FontLabel/FontManager.h" -#import "FontLabel/FontLabelStringDrawing.h" - typedef struct { unsigned int height; @@ -171,7 +167,7 @@ static bool _isValidFontName(const char *fontName) return ret; } -static CGSize _calculateStringSizeWithFontOrZFont(NSString *str, id font, CGSize *constrainSize, bool isZfont) +static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize) { NSArray *listItems = [str componentsSeparatedByString: @"\n"]; CGSize dim = CGSizeZero; @@ -184,15 +180,7 @@ static CGSize _calculateStringSizeWithFontOrZFont(NSString *str, id font, CGSize for (NSString *s in listItems) { - CGSize tmp; - if (isZfont) - { - tmp = [FontLabelStringDrawingHelper sizeWithZFont:s zfont:font constrainedToSize:textRect]; - } - else - { - tmp = [s sizeWithFont:font constrainedToSize:textRect]; - } + CGSize tmp = [s sizeWithFont:font constrainedToSize:textRect]; if (tmp.width > dim.width) { @@ -228,19 +216,9 @@ static bool _initWithString(const char * pText, cocos2d::CCImage::ETextAlign eAl font = [UIFont fontWithName:fntName size:nSize]; if (font) { - dim = _calculateStringSizeWithFontOrZFont(str, font, &constrainSize, false); + dim = _calculateStringSize(str, font, &constrainSize); } - - if (! font) - { - font = [[FontManager sharedManager] zFontWithName:fntName pointSize:nSize]; - if (font) - { - dim =_calculateStringSizeWithFontOrZFont(str, font, &constrainSize, true); - } - } - - if (! font) + else { fntName = _isValidFontName(pFontName) ? fntName : @"MarkerFelt-Wide"; font = [UIFont fontWithName:fntName size:nSize]; @@ -252,7 +230,7 @@ static bool _initWithString(const char * pText, cocos2d::CCImage::ETextAlign eAl if (font) { - dim = _calculateStringSizeWithFontOrZFont(str, font, &constrainSize, false); + dim = _calculateStringSize(str, font, &constrainSize); } } @@ -314,6 +292,7 @@ static bool _initWithString(const char * pText, cocos2d::CCImage::ETextAlign eAl : UITextAlignmentLeft); // normal fonts + /* if( [font isKindOfClass:[UIFont class] ] ) { [str drawInRect:CGRectMake(0, startH, dim.width, dim.height) withFont:font lineBreakMode:(UILineBreakMode)UILineBreakModeWordWrap alignment:align]; @@ -322,6 +301,8 @@ static bool _initWithString(const char * pText, cocos2d::CCImage::ETextAlign eAl { [FontLabelStringDrawingHelper drawInRect:str rect:CGRectMake(0, startH, dim.width, dim.height) withZFont:font lineBreakMode:(UILineBreakMode)UILineBreakModeWordWrap alignment:align]; } + */ + [str drawInRect:CGRectMake(0, startH, dim.width, dim.height) withFont:font lineBreakMode:(UILineBreakMode)UILineBreakModeWordWrap alignment:align]; UIGraphicsPopContext(); diff --git a/cocos2dx/platform/ios/FontLabel/FontLabel.h b/cocos2dx/platform/ios/FontLabel/FontLabel.h deleted file mode 100644 index 6c1fa501be..0000000000 --- a/cocos2dx/platform/ios/FontLabel/FontLabel.h +++ /dev/null @@ -1,44 +0,0 @@ -// -// FontLabel.h -// FontLabel -// -// Created by Kevin Ballard on 5/8/09. -// Copyright © 2009 Zynga Game Networks -// -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import -#import - -@class ZFont; -@class ZAttributedString; - -@interface FontLabel : UILabel { - void *reserved; // works around a bug in UILabel - ZFont *zFont; - ZAttributedString *zAttributedText; -} -@property (nonatomic, setter=setCGFont:) CGFontRef cgFont __AVAILABILITY_INTERNAL_DEPRECATED; -@property (nonatomic, assign) CGFloat pointSize __AVAILABILITY_INTERNAL_DEPRECATED; -@property (nonatomic, retain, setter=setZFont:) ZFont *zFont; -// if attributedText is nil, fall back on using the inherited UILabel properties -// if attributedText is non-nil, the font/text/textColor -// in addition, adjustsFontSizeToFitWidth does not work with attributed text -@property (nonatomic, copy) ZAttributedString *zAttributedText; -// -initWithFrame:fontName:pointSize: uses FontManager to look up the font name -- (id)initWithFrame:(CGRect)frame fontName:(NSString *)fontName pointSize:(CGFloat)pointSize; -- (id)initWithFrame:(CGRect)frame zFont:(ZFont *)font; -- (id)initWithFrame:(CGRect)frame font:(CGFontRef)font pointSize:(CGFloat)pointSize __AVAILABILITY_INTERNAL_DEPRECATED; -@end diff --git a/cocos2dx/platform/ios/FontLabel/FontLabel.m b/cocos2dx/platform/ios/FontLabel/FontLabel.m deleted file mode 100644 index 3e60ad6b78..0000000000 --- a/cocos2dx/platform/ios/FontLabel/FontLabel.m +++ /dev/null @@ -1,197 +0,0 @@ -// -// FontLabel.m -// FontLabel -// -// Created by Kevin Ballard on 5/8/09. -// Copyright © 2009 Zynga Game Networks -// -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import "FontLabel.h" -#import "FontManager.h" -#import "FontLabelStringDrawing.h" -#import "ZFont.h" - -@interface ZFont (ZFontPrivate) -@property (nonatomic, readonly) CGFloat ratio; -@end - -@implementation FontLabel -@synthesize zFont; -@synthesize zAttributedText; - -- (id)initWithFrame:(CGRect)frame fontName:(NSString *)fontName pointSize:(CGFloat)pointSize { - return [self initWithFrame:frame zFont:[[FontManager sharedManager] zFontWithName:fontName pointSize:pointSize]]; -} - -- (id)initWithFrame:(CGRect)frame zFont:(ZFont *)font { - if ((self = [super initWithFrame:frame])) { - zFont = [font retain]; - } - return self; -} - -- (id)initWithFrame:(CGRect)frame font:(CGFontRef)font pointSize:(CGFloat)pointSize { - return [self initWithFrame:frame zFont:[ZFont fontWithCGFont:font size:pointSize]]; -} - -- (CGFontRef)cgFont { - return self.zFont.cgFont; -} - -- (void)setCGFont:(CGFontRef)font { - if (self.zFont.cgFont != font) { - self.zFont = [ZFont fontWithCGFont:font size:self.zFont.pointSize]; - } -} - -- (CGFloat)pointSize { - return self.zFont.pointSize; -} - -- (void)setPointSize:(CGFloat)pointSize { - if (self.zFont.pointSize != pointSize) { - self.zFont = [ZFont fontWithCGFont:self.zFont.cgFont size:pointSize]; - } -} - -- (void)setZAttributedText:(ZAttributedString *)attStr { - if (zAttributedText != attStr) { - [zAttributedText release]; - zAttributedText = [attStr copy]; - [self setNeedsDisplay]; - } -} - -- (void)drawTextInRect:(CGRect)rect { - if (self.zFont == NULL && self.zAttributedText == nil) { - [super drawTextInRect:rect]; - return; - } - - if (self.zAttributedText == nil) { - // this method is documented as setting the text color for us, but that doesn't appear to be the case - if (self.highlighted) { - [(self.highlightedTextColor ?: [UIColor whiteColor]) setFill]; - } else { - [(self.textColor ?: [UIColor blackColor]) setFill]; - } - - ZFont *actualFont = self.zFont; - CGSize origSize = rect.size; - if (self.numberOfLines == 1) { - origSize.height = actualFont.leading; - CGPoint point = CGPointMake(rect.origin.x, - rect.origin.y + roundf(((rect.size.height - actualFont.leading) / 2.0f))); - CGSize size = [self.text sizeWithZFont:actualFont]; - if (self.adjustsFontSizeToFitWidth && self.minimumFontSize < actualFont.pointSize) { - if (size.width > origSize.width) { - CGFloat desiredRatio = (origSize.width * actualFont.ratio) / size.width; - CGFloat desiredPointSize = desiredRatio * actualFont.pointSize / actualFont.ratio; - actualFont = [actualFont fontWithSize:MAX(MAX(desiredPointSize, self.minimumFontSize), 1.0f)]; - size = [self.text sizeWithZFont:actualFont]; - } - if (!CGSizeEqualToSize(origSize, size)) { - switch (self.baselineAdjustment) { - case UIBaselineAdjustmentAlignCenters: - point.y += roundf((origSize.height - size.height) / 2.0f); - break; - case UIBaselineAdjustmentAlignBaselines: - point.y += (self.zFont.ascender - actualFont.ascender); - break; - case UIBaselineAdjustmentNone: - break; - } - } - } - size.width = MIN(size.width, origSize.width); - // adjust the point for alignment - switch (self.textAlignment) { - case UITextAlignmentLeft: - break; - case UITextAlignmentCenter: - point.x += (origSize.width - size.width) / 2.0f; - break; - case UITextAlignmentRight: - point.x += origSize.width - size.width; - break; - default: - break; - } - [self.text drawAtPoint:point forWidth:size.width withZFont:actualFont lineBreakMode:self.lineBreakMode]; - } else { - CGSize size = [self.text sizeWithZFont:actualFont constrainedToSize:origSize lineBreakMode:self.lineBreakMode numberOfLines:self.numberOfLines]; - CGPoint point = rect.origin; - point.y += roundf((rect.size.height - size.height) / 2.0f); - rect = (CGRect){point, CGSizeMake(rect.size.width, size.height)}; - [self.text drawInRect:rect withZFont:actualFont lineBreakMode:self.lineBreakMode alignment:self.textAlignment numberOfLines:self.numberOfLines]; - } - } else { - ZAttributedString *attStr = self.zAttributedText; - if (self.highlighted) { - // modify the string to change the base color - ZMutableAttributedString *mutStr = [[attStr mutableCopy] autorelease]; - NSRange activeRange = NSMakeRange(0, attStr.length); - while (activeRange.length > 0) { - NSRange effective; - UIColor *color = [attStr attribute:ZForegroundColorAttributeName atIndex:activeRange.location - longestEffectiveRange:&effective inRange:activeRange]; - if (color == nil) { - [mutStr addAttribute:ZForegroundColorAttributeName value:[UIColor whiteColor] range:effective]; - } - activeRange.location += effective.length, activeRange.length -= effective.length; - } - attStr = mutStr; - } - CGSize size = [attStr sizeConstrainedToSize:rect.size lineBreakMode:self.lineBreakMode numberOfLines:self.numberOfLines]; - CGPoint point = rect.origin; - point.y += roundf((rect.size.height - size.height) / 2.0f); - rect = (CGRect){point, CGSizeMake(rect.size.width, size.height)}; - [attStr drawInRect:rect withLineBreakMode:self.lineBreakMode alignment:self.textAlignment numberOfLines:self.numberOfLines]; - } -} - -- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines { - if (self.zFont == NULL && self.zAttributedText == nil) { - return [super textRectForBounds:bounds limitedToNumberOfLines:numberOfLines]; - } - - if (numberOfLines == 1) { - // if numberOfLines == 1 we need to use the version that converts spaces - CGSize size; - if (self.zAttributedText == nil) { - size = [self.text sizeWithZFont:self.zFont]; - } else { - size = [self.zAttributedText size]; - } - bounds.size.width = MIN(bounds.size.width, size.width); - bounds.size.height = MIN(bounds.size.height, size.height); - } else { - if (numberOfLines > 0) bounds.size.height = MIN(bounds.size.height, self.zFont.leading * numberOfLines); - if (self.zAttributedText == nil) { - bounds.size = [self.text sizeWithZFont:self.zFont constrainedToSize:bounds.size lineBreakMode:self.lineBreakMode]; - } else { - bounds.size = [self.zAttributedText sizeConstrainedToSize:bounds.size lineBreakMode:self.lineBreakMode]; - } - } - return bounds; -} - -- (void)dealloc { - [zFont release]; - [zAttributedText release]; - [super dealloc]; -} -@end diff --git a/cocos2dx/platform/ios/FontLabel/FontLabelStringDrawing.h b/cocos2dx/platform/ios/FontLabel/FontLabelStringDrawing.h deleted file mode 100644 index 68661e0c9a..0000000000 --- a/cocos2dx/platform/ios/FontLabel/FontLabelStringDrawing.h +++ /dev/null @@ -1,82 +0,0 @@ -// -// FontLabelStringDrawing.h -// FontLabel -// -// Created by Kevin Ballard on 5/5/09. -// Copyright © 2009 Zynga Game Networks -// Copyright (c) 2011 cocos2d-x.org -// -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import -#import "ZAttributedString.h" - -@class ZFont; - -@interface NSString (FontLabelStringDrawing) -// CGFontRef-based methods -- (CGSize)sizeWithCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize __AVAILABILITY_INTERNAL_DEPRECATED; -- (CGSize)sizeWithCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize constrainedToSize:(CGSize)size __AVAILABILITY_INTERNAL_DEPRECATED; -- (CGSize)sizeWithCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize constrainedToSize:(CGSize)size - lineBreakMode:(UILineBreakMode)lineBreakMode __AVAILABILITY_INTERNAL_DEPRECATED; -- (CGSize)drawAtPoint:(CGPoint)point withCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize __AVAILABILITY_INTERNAL_DEPRECATED; -- (CGSize)drawInRect:(CGRect)rect withCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize __AVAILABILITY_INTERNAL_DEPRECATED; -- (CGSize)drawInRect:(CGRect)rect withCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize - lineBreakMode:(UILineBreakMode)lineBreakMode __AVAILABILITY_INTERNAL_DEPRECATED; -- (CGSize)drawInRect:(CGRect)rect withCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize - lineBreakMode:(UILineBreakMode)lineBreakMode alignment:(UITextAlignment)alignment __AVAILABILITY_INTERNAL_DEPRECATED; - -// ZFont-based methods -- (CGSize)sizeWithZFont:(ZFont *)font; -- (CGSize)sizeWithZFont:(ZFont *)font constrainedToSize:(CGSize)size; -- (CGSize)sizeWithZFont:(ZFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode; -- (CGSize)sizeWithZFont:(ZFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode - numberOfLines:(NSUInteger)numberOfLines; -- (CGSize)drawAtPoint:(CGPoint)point withZFont:(ZFont *)font; -- (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width withZFont:(ZFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode; -- (CGSize)drawInRect:(CGRect)rect withZFont:(ZFont *)font; -- (CGSize)drawInRect:(CGRect)rect withZFont:(ZFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode; -- (CGSize)drawInRect:(CGRect)rect withZFont:(ZFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode - alignment:(UITextAlignment)alignment; -- (CGSize)drawInRect:(CGRect)rect withZFont:(ZFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode - alignment:(UITextAlignment)alignment numberOfLines:(NSUInteger)numberOfLines; -@end - -@interface ZAttributedString (ZAttributedStringDrawing) -- (CGSize)size; -- (CGSize)sizeConstrainedToSize:(CGSize)size; -- (CGSize)sizeConstrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode; -- (CGSize)sizeConstrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode - numberOfLines:(NSUInteger)numberOfLines; -- (CGSize)drawAtPoint:(CGPoint)point; -- (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode; -- (CGSize)drawInRect:(CGRect)rect; -- (CGSize)drawInRect:(CGRect)rect withLineBreakMode:(UILineBreakMode)lineBreakMode; -- (CGSize)drawInRect:(CGRect)rect withLineBreakMode:(UILineBreakMode)lineBreakMode alignment:(UITextAlignment)alignment; -- (CGSize)drawInRect:(CGRect)rect withLineBreakMode:(UILineBreakMode)lineBreakMode alignment:(UITextAlignment)alignment - numberOfLines:(NSUInteger)numberOfLines; -@end - -// This class is used to invoke in .mm file. -// Can not invoke FontLabelStringDrawing directly in .mm. -// It seems that, in .mm it can not support category. -@interface FontLabelStringDrawingHelper : NSObject { -} -+ (CGSize)sizeWithZFont:(NSString*)string zfont:(ZFont *)font; -+ (CGSize)sizeWithZFont:(NSString *)string zfont:(ZFont *)font constrainedToSize:(CGSize)size; -+ (CGSize)drawInRect:(NSString*)string rect:(CGRect)rect withZFont:(ZFont *)font - lineBreakMode:(UILineBreakMode)lineBreakMode - alignment:(UITextAlignment)alignment; -@end diff --git a/cocos2dx/platform/ios/FontLabel/FontLabelStringDrawing.m b/cocos2dx/platform/ios/FontLabel/FontLabelStringDrawing.m deleted file mode 100644 index f7fcbf1a72..0000000000 --- a/cocos2dx/platform/ios/FontLabel/FontLabelStringDrawing.m +++ /dev/null @@ -1,916 +0,0 @@ -// -// FontLabelStringDrawing.m -// FontLabel -// -// Created by Kevin Ballard on 5/5/09. -// Copyright © 2009 Zynga Game Networks -// Copyright (c) 2011 cocos2d-x.org -// -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import "FontLabelStringDrawing.h" -#import "ZFont.h" -#import "ZAttributedStringPrivate.h" - -@interface ZFont (ZFontPrivate) -@property (nonatomic, readonly) CGFloat ratio; -@end - -#define kUnicodeHighSurrogateStart 0xD800 -#define kUnicodeHighSurrogateEnd 0xDBFF -#define kUnicodeHighSurrogateMask kUnicodeHighSurrogateStart -#define kUnicodeLowSurrogateStart 0xDC00 -#define kUnicodeLowSurrogateEnd 0xDFFF -#define kUnicodeLowSurrogateMask kUnicodeLowSurrogateStart -#define kUnicodeSurrogateTypeMask 0xFC00 -#define UnicharIsHighSurrogate(c) ((c & kUnicodeSurrogateTypeMask) == kUnicodeHighSurrogateMask) -#define UnicharIsLowSurrogate(c) ((c & kUnicodeSurrogateTypeMask) == kUnicodeLowSurrogateMask) -#define ConvertSurrogatePairToUTF32(high, low) ((UInt32)((high - 0xD800) * 0x400 + (low - 0xDC00) + 0x10000)) - -typedef enum { - kFontTableFormat4 = 4, - kFontTableFormat12 = 12, -} FontTableFormat; - -typedef struct fontTable { - NSUInteger retainCount; - CFDataRef cmapTable; - FontTableFormat format; - union { - struct { - UInt16 segCountX2; - UInt16 *endCodes; - UInt16 *startCodes; - UInt16 *idDeltas; - UInt16 *idRangeOffsets; - } format4; - struct { - UInt32 nGroups; - struct { - UInt32 startCharCode; - UInt32 endCharCode; - UInt32 startGlyphCode; - } *groups; - } format12; - } cmap; -} fontTable; - -static FontTableFormat supportedFormats[] = { kFontTableFormat4, kFontTableFormat12 }; -static size_t supportedFormatsCount = sizeof(supportedFormats) / sizeof(FontTableFormat); - -static fontTable *newFontTable(CFDataRef cmapTable, FontTableFormat format) { - fontTable *table = (struct fontTable *)malloc(sizeof(struct fontTable)); - table->retainCount = 1; - table->cmapTable = CFRetain(cmapTable); - table->format = format; - return table; -} - -static fontTable *retainFontTable(fontTable *table) { - if (table != NULL) { - table->retainCount++; - } - return table; -} - -static void releaseFontTable(fontTable *table) { - if (table != NULL) { - if (table->retainCount <= 1) { - CFRelease(table->cmapTable); - free(table); - } else { - table->retainCount--; - } - } -} - -static const void *fontTableRetainCallback(CFAllocatorRef allocator, const void *value) { - return retainFontTable((fontTable *)value); -} - -static void fontTableReleaseCallback(CFAllocatorRef allocator, const void *value) { - releaseFontTable((fontTable *)value); -} - -static const CFDictionaryValueCallBacks kFontTableDictionaryValueCallBacks = { - .version = 0, - .retain = &fontTableRetainCallback, - .release = &fontTableReleaseCallback, - .copyDescription = NULL, - .equal = NULL -}; - -// read the cmap table from the font -// we only know how to understand some of the table formats at the moment -static fontTable *readFontTableFromCGFont(CGFontRef font) { - CFDataRef cmapTable = CGFontCopyTableForTag(font, 'cmap'); - NSCAssert1(cmapTable != NULL, @"CGFontCopyTableForTag returned NULL for 'cmap' tag in font %@", - (font ? [(id)CFCopyDescription(font) autorelease] : @"(null)")); - const UInt8 * const bytes = CFDataGetBytePtr(cmapTable); - NSCAssert1(OSReadBigInt16(bytes, 0) == 0, @"cmap table for font %@ has bad version number", - (font ? [(id)CFCopyDescription(font) autorelease] : @"(null)")); - UInt16 numberOfSubtables = OSReadBigInt16(bytes, 2); - const UInt8 *unicodeSubtable = NULL; - //UInt16 unicodeSubtablePlatformID; - UInt16 unicodeSubtablePlatformSpecificID; - FontTableFormat unicodeSubtableFormat; - const UInt8 * const encodingSubtables = &bytes[4]; - for (UInt16 i = 0; i < numberOfSubtables; i++) { - const UInt8 * const encodingSubtable = &encodingSubtables[8 * i]; - UInt16 platformID = OSReadBigInt16(encodingSubtable, 0); - UInt16 platformSpecificID = OSReadBigInt16(encodingSubtable, 2); - // find the best subtable - // best is defined by a combination of encoding and format - // At the moment we only support format 4, so ignore all other format tables - // We prefer platformID == 0, but we will also accept Microsoft's unicode format - if (platformID == 0 || (platformID == 3 && platformSpecificID == 1)) { - BOOL preferred = NO; - if (unicodeSubtable == NULL) { - preferred = YES; - } else if (platformID == 0 && platformSpecificID > unicodeSubtablePlatformSpecificID) { - preferred = YES; - } - if (preferred) { - UInt32 offset = OSReadBigInt32(encodingSubtable, 4); - const UInt8 *subtable = &bytes[offset]; - UInt16 format = OSReadBigInt16(subtable, 0); - for (size_t i = 0; i < supportedFormatsCount; i++) { - if (format == supportedFormats[i]) { - if (format >= 8) { - // the version is a fixed-point - UInt16 formatFrac = OSReadBigInt16(subtable, 2); - if (formatFrac != 0) { - // all the current formats with a Fixed version are always *.0 - continue; - } - } - unicodeSubtable = subtable; - //unicodeSubtablePlatformID = platformID; - unicodeSubtablePlatformSpecificID = platformSpecificID; - unicodeSubtableFormat = format; - break; - } - } - } - } - } - fontTable *table = NULL; - if (unicodeSubtable != NULL) { - table = newFontTable(cmapTable, unicodeSubtableFormat); - switch (unicodeSubtableFormat) { - case kFontTableFormat4: - // subtable format 4 - //UInt16 length = OSReadBigInt16(unicodeSubtable, 2); - //UInt16 language = OSReadBigInt16(unicodeSubtable, 4); - table->cmap.format4.segCountX2 = OSReadBigInt16(unicodeSubtable, 6); - //UInt16 searchRange = OSReadBigInt16(unicodeSubtable, 8); - //UInt16 entrySelector = OSReadBigInt16(unicodeSubtable, 10); - //UInt16 rangeShift = OSReadBigInt16(unicodeSubtable, 12); - table->cmap.format4.endCodes = (UInt16*)&unicodeSubtable[14]; - table->cmap.format4.startCodes = (UInt16*)&((UInt8*)table->cmap.format4.endCodes)[table->cmap.format4.segCountX2+2]; - table->cmap.format4.idDeltas = (UInt16*)&((UInt8*)table->cmap.format4.startCodes)[table->cmap.format4.segCountX2]; - table->cmap.format4.idRangeOffsets = (UInt16*)&((UInt8*)table->cmap.format4.idDeltas)[table->cmap.format4.segCountX2]; - //UInt16 *glyphIndexArray = &idRangeOffsets[segCountX2]; - break; - case kFontTableFormat12: - table->cmap.format12.nGroups = OSReadBigInt32(unicodeSubtable, 12); - table->cmap.format12.groups = (void *)&unicodeSubtable[16]; - break; - default: - releaseFontTable(table); - table = NULL; - } - } - CFRelease(cmapTable); - return table; -} - -// outGlyphs must be at least size n -static void mapCharactersToGlyphsInFont(const fontTable *table, unichar characters[], size_t charLen, CGGlyph outGlyphs[], size_t *outGlyphLen) { - if (table != NULL) { - NSUInteger j = 0; - switch (table->format) { - case kFontTableFormat4: { - for (NSUInteger i = 0; i < charLen; i++, j++) { - unichar c = characters[i]; - UInt16 segOffset; - BOOL foundSegment = NO; - for (segOffset = 0; segOffset < table->cmap.format4.segCountX2; segOffset += 2) { - UInt16 endCode = OSReadBigInt16(table->cmap.format4.endCodes, segOffset); - if (endCode >= c) { - foundSegment = YES; - break; - } - } - if (!foundSegment) { - // no segment - // this is an invalid font - outGlyphs[j] = 0; - } else { - UInt16 startCode = OSReadBigInt16(table->cmap.format4.startCodes, segOffset); - if (!(startCode <= c)) { - // the code falls in a hole between segments - outGlyphs[j] = 0; - } else { - UInt16 idRangeOffset = OSReadBigInt16(table->cmap.format4.idRangeOffsets, segOffset); - if (idRangeOffset == 0) { - UInt16 idDelta = OSReadBigInt16(table->cmap.format4.idDeltas, segOffset); - outGlyphs[j] = (c + idDelta) % 65536; - } else { - // use the glyphIndexArray - UInt16 glyphOffset = idRangeOffset + 2 * (c - startCode); - outGlyphs[j] = OSReadBigInt16(&((UInt8*)table->cmap.format4.idRangeOffsets)[segOffset], glyphOffset); - } - } - } - } - break; - } - case kFontTableFormat12: { - UInt32 lastSegment = UINT32_MAX; - for (NSUInteger i = 0; i < charLen; i++, j++) { - unichar c = characters[i]; - UInt32 c32 = c; - if (UnicharIsHighSurrogate(c)) { - if (i+1 < charLen) { // do we have another character after this one? - unichar cc = characters[i+1]; - if (UnicharIsLowSurrogate(cc)) { - c32 = ConvertSurrogatePairToUTF32(c, cc); - i++; - } - } - } - // Start the heuristic search - // If this is an ASCII char, just do a linear search - // Otherwise do a hinted, modified binary search - // Start the first pivot at the last range found - // And when moving the pivot, limit the movement by increasing - // powers of two. This should help with locality - __typeof__(table->cmap.format12.groups[0]) *foundGroup = NULL; - if (c32 <= 0x7F) { - // ASCII - for (UInt32 idx = 0; idx < table->cmap.format12.nGroups; idx++) { - __typeof__(table->cmap.format12.groups[idx]) *group = &table->cmap.format12.groups[idx]; - if (c32 < OSSwapBigToHostInt32(group->startCharCode)) { - // we've fallen into a hole - break; - } else if (c32 <= OSSwapBigToHostInt32(group->endCharCode)) { - // this is the range - foundGroup = group; - break; - } - } - } else { - // heuristic search - UInt32 maxJump = (lastSegment == UINT32_MAX ? UINT32_MAX / 2 : 8); - UInt32 lowIdx = 0, highIdx = table->cmap.format12.nGroups; // highIdx is the first invalid idx - UInt32 pivot = (lastSegment == UINT32_MAX ? lowIdx + (highIdx - lowIdx) / 2 : lastSegment); - while (highIdx > lowIdx) { - __typeof__(table->cmap.format12.groups[pivot]) *group = &table->cmap.format12.groups[pivot]; - if (c32 < OSSwapBigToHostInt32(group->startCharCode)) { - highIdx = pivot; - } else if (c32 > OSSwapBigToHostInt32(group->endCharCode)) { - lowIdx = pivot + 1; - } else { - // we've hit the range - foundGroup = group; - break; - } - if (highIdx - lowIdx > maxJump * 2) { - if (highIdx == pivot) { - pivot -= maxJump; - } else { - pivot += maxJump; - } - maxJump *= 2; - } else { - pivot = lowIdx + (highIdx - lowIdx) / 2; - } - } - if (foundGroup != NULL) lastSegment = pivot; - } - if (foundGroup == NULL) { - outGlyphs[j] = 0; - } else { - outGlyphs[j] = (CGGlyph)(OSSwapBigToHostInt32(foundGroup->startGlyphCode) + - (c32 - OSSwapBigToHostInt32(foundGroup->startCharCode))); - } - } - break; - } - } - if (outGlyphLen != NULL) *outGlyphLen = j; - } else { - // we have no table, so just null out the glyphs - bzero(outGlyphs, charLen*sizeof(CGGlyph)); - if (outGlyphLen != NULL) *outGlyphLen = 0; - } -} - -static BOOL mapGlyphsToAdvancesInFont(ZFont *font, size_t n, CGGlyph glyphs[], CGFloat outAdvances[]) { - int advances[n]; - if (CGFontGetGlyphAdvances(font.cgFont, glyphs, n, advances)) { - CGFloat ratio = font.ratio; - - for (size_t i = 0; i < n; i++) { - outAdvances[i] = advances[i]*ratio; - } - return YES; - } else { - bzero(outAdvances, n*sizeof(CGFloat)); - } - return NO; -} - -static id getValueOrDefaultForRun(ZAttributeRun *run, NSString *key) { - id value = [run.attributes objectForKey:key]; - if (value == nil) { - static NSDictionary *defaultValues = nil; - if (defaultValues == nil) { - defaultValues = [[NSDictionary alloc] initWithObjectsAndKeys: - [ZFont fontWithUIFont:[UIFont systemFontOfSize:12]], ZFontAttributeName, - [UIColor blackColor], ZForegroundColorAttributeName, - [UIColor clearColor], ZBackgroundColorAttributeName, - [NSNumber numberWithInt:ZUnderlineStyleNone], ZUnderlineStyleAttributeName, - nil]; - } - value = [defaultValues objectForKey:key]; - } - return value; -} - -static void readRunInformation(NSArray *attributes, NSUInteger len, CFMutableDictionaryRef fontTableMap, - NSUInteger index, ZAttributeRun **currentRun, NSUInteger *nextRunStart, - ZFont **currentFont, fontTable **currentTable) { - *currentRun = [attributes objectAtIndex:index]; - *nextRunStart = ([attributes count] > index+1 ? [[attributes objectAtIndex:index+1] index] : len); - *currentFont = getValueOrDefaultForRun(*currentRun, ZFontAttributeName); - if (!CFDictionaryGetValueIfPresent(fontTableMap, (*currentFont).cgFont, (const void **)currentTable)) { - *currentTable = readFontTableFromCGFont((*currentFont).cgFont); - CFDictionarySetValue(fontTableMap, (*currentFont).cgFont, *currentTable); - releaseFontTable(*currentTable); - } -} - -static CGSize drawOrSizeTextConstrainedToSize(BOOL performDraw, NSString *string, NSArray *attributes, CGSize constrainedSize, NSUInteger maxLines, - UILineBreakMode lineBreakMode, UITextAlignment alignment, BOOL ignoreColor) { - NSUInteger len = [string length]; - NSUInteger idx = 0; - CGPoint drawPoint = CGPointZero; - CGSize retValue = CGSizeZero; - CGContextRef ctx = (performDraw ? UIGraphicsGetCurrentContext() : NULL); - - BOOL convertNewlines = (maxLines == 1); - - // Extract the characters from the string - // Convert newlines to spaces if necessary - unichar *characters = (unichar *)malloc(sizeof(unichar) * len); - if (convertNewlines) { - NSCharacterSet *charset = [NSCharacterSet newlineCharacterSet]; - NSRange range = NSMakeRange(0, len); - size_t cIdx = 0; - while (range.length > 0) { - NSRange newlineRange = [string rangeOfCharacterFromSet:charset options:0 range:range]; - if (newlineRange.location == NSNotFound) { - [string getCharacters:&characters[cIdx] range:range]; - cIdx += range.length; - break; - } else { - NSUInteger delta = newlineRange.location - range.location; - if (newlineRange.location > range.location) { - [string getCharacters:&characters[cIdx] range:NSMakeRange(range.location, delta)]; - } - cIdx += delta; - characters[cIdx] = (unichar)' '; - cIdx++; - delta += newlineRange.length; - range.location += delta, range.length -= delta; - if (newlineRange.length == 1 && range.length >= 1 && - [string characterAtIndex:newlineRange.location] == (unichar)'\r' && - [string characterAtIndex:range.location] == (unichar)'\n') { - // CRLF sequence, skip the LF - range.location += 1, range.length -= 1; - } - } - } - len = cIdx; - } else { - [string getCharacters:characters range:NSMakeRange(0, len)]; - } - - // Create storage for glyphs and advances - CGGlyph *glyphs; - CGFloat *advances; - { - NSUInteger maxRunLength = 0; - ZAttributeRun *a = [attributes objectAtIndex:0]; - for (NSUInteger i = 1; i < [attributes count]; i++) { - ZAttributeRun *b = [attributes objectAtIndex:i]; - maxRunLength = MAX(maxRunLength, b.index - a.index); - a = b; - } - maxRunLength = MAX(maxRunLength, len - a.index); - maxRunLength++; // for a potential ellipsis - glyphs = (CGGlyph *)malloc(sizeof(CGGlyph) * maxRunLength); - advances = (CGFloat *)malloc(sizeof(CGFloat) * maxRunLength); - } - - // Use this table to cache all fontTable objects - CFMutableDictionaryRef fontTableMap = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, - &kFontTableDictionaryValueCallBacks); - - // Fetch initial style values - NSUInteger currentRunIdx = 0; - ZAttributeRun *currentRun; - NSUInteger nextRunStart; - ZFont *currentFont; - fontTable *currentTable; - -#define READ_RUN() readRunInformation(attributes, len, fontTableMap, \ - currentRunIdx, ¤tRun, &nextRunStart, \ - ¤tFont, ¤tTable) - - READ_RUN(); - - // fetch the glyphs for the first run - size_t glyphCount; - NSUInteger glyphIdx; - -#define READ_GLYPHS() do { \ - mapCharactersToGlyphsInFont(currentTable, &characters[currentRun.index], (nextRunStart - currentRun.index), glyphs, &glyphCount); \ - mapGlyphsToAdvancesInFont(currentFont, (nextRunStart - currentRun.index), glyphs, advances); \ - glyphIdx = 0; \ - } while (0) - - READ_GLYPHS(); - - NSMutableCharacterSet *alphaCharset = [NSMutableCharacterSet alphanumericCharacterSet]; - [alphaCharset addCharactersInString:@"([{'\"\u2019\u02BC"]; - - // scan left-to-right looking for newlines or until we hit the width constraint - // When we hit a wrapping point, calculate truncation as follows: - // If we have room to draw at least one more character on the next line, no truncation - // Otherwise apply the truncation algorithm to the current line. - // After calculating any truncation, draw. - // Each time we hit the end of an attribute run, calculate the new font and make sure - // it fits (vertically) within the size constraint. If not, truncate this line. - // When we draw, iterate over the attribute runs for this line and draw each run separately - BOOL lastLine = NO; // used to indicate truncation and to stop the iterating - NSUInteger lineCount = 1; - while (idx < len && !lastLine) { - if (maxLines > 0 && lineCount == maxLines) { - lastLine = YES; - } - // scan left-to-right - struct { - NSUInteger index; - NSUInteger glyphIndex; - NSUInteger currentRunIdx; - } indexCache = { idx, glyphIdx, currentRunIdx }; - CGSize lineSize = CGSizeMake(0, currentFont.leading); - CGFloat lineAscender = currentFont.ascender; - struct { - NSUInteger index; - NSUInteger glyphIndex; - NSUInteger currentRunIdx; - CGSize lineSize; - } lastWrapCache = {0, 0, 0, CGSizeZero}; - BOOL inAlpha = NO; // used for calculating wrap points - - BOOL finishLine = NO; - for (;idx <= len && !finishLine;) { - NSUInteger skipCount = 0; - if (idx == len) { - finishLine = YES; - lastLine = YES; - } else { - if (idx >= nextRunStart) { - // cycle the font and table and grab the next set of glyphs - do { - currentRunIdx++; - READ_RUN(); - } while (idx >= nextRunStart); - READ_GLYPHS(); - // re-scan the characters to synchronize the glyph index - for (NSUInteger j = currentRun.index; j < idx; j++) { - if (UnicharIsHighSurrogate(characters[j]) && j+1 lineSize.height) { - lineSize.height = currentFont.leading; - if (retValue.height + currentFont.ascender > constrainedSize.height) { - lastLine = YES; - finishLine = YES; - } - } - lineAscender = MAX(lineAscender, currentFont.ascender); - } - unichar c = characters[idx]; - // Mark a wrap point before spaces and after any stretch of non-alpha characters - BOOL markWrap = NO; - if (c == (unichar)' ') { - markWrap = YES; - } else if ([alphaCharset characterIsMember:c]) { - if (!inAlpha) { - markWrap = YES; - inAlpha = YES; - } - } else { - inAlpha = NO; - } - if (markWrap) { - lastWrapCache = (__typeof__(lastWrapCache)){ - .index = idx, - .glyphIndex = glyphIdx, - .currentRunIdx = currentRunIdx, - .lineSize = lineSize - }; - } - // process the line - if (c == (unichar)'\n' || c == 0x0085) { // U+0085 is the NEXT_LINE unicode character - finishLine = YES; - skipCount = 1; - } else if (c == (unichar)'\r') { - finishLine = YES; - // check for CRLF - if (idx+1 < len && characters[idx+1] == (unichar)'\n') { - skipCount = 2; - } else { - skipCount = 1; - } - } else if (lineSize.width + advances[glyphIdx] > constrainedSize.width) { - finishLine = YES; - if (retValue.height + lineSize.height + currentFont.ascender > constrainedSize.height) { - lastLine = YES; - } - // walk backwards if wrapping is necessary - if (lastWrapCache.index > indexCache.index && lineBreakMode != UILineBreakModeCharacterWrap && - (!lastLine || lineBreakMode != UILineBreakModeClip)) { - // we're doing some sort of word wrapping - idx = lastWrapCache.index; - lineSize = lastWrapCache.lineSize; - if (!lastLine) { - // re-check if this is the last line - if (lastWrapCache.currentRunIdx != currentRunIdx) { - currentRunIdx = lastWrapCache.currentRunIdx; - READ_RUN(); - READ_GLYPHS(); - } - if (retValue.height + lineSize.height + currentFont.ascender > constrainedSize.height) { - lastLine = YES; - } - } - glyphIdx = lastWrapCache.glyphIndex; - // skip any spaces - for (NSUInteger j = idx; j < len && characters[j] == (unichar)' '; j++) { - skipCount++; - } - } - } - } - if (finishLine) { - // TODO: support head/middle truncation - if (lastLine && idx < len && lineBreakMode == UILineBreakModeTailTruncation) { - // truncate - unichar ellipsis = 0x2026; // ellipsis (…) - CGGlyph ellipsisGlyph; - mapCharactersToGlyphsInFont(currentTable, &ellipsis, 1, &ellipsisGlyph, NULL); - CGFloat ellipsisWidth; - mapGlyphsToAdvancesInFont(currentFont, 1, &ellipsisGlyph, &ellipsisWidth); - while ((idx - indexCache.index) > 1 && lineSize.width + ellipsisWidth > constrainedSize.width) { - // we have more than 1 character and we're too wide, so back up - idx--; - if (UnicharIsHighSurrogate(characters[idx]) && UnicharIsLowSurrogate(characters[idx+1])) { - idx--; - } - if (idx < currentRun.index) { - ZFont *oldFont = currentFont; - do { - currentRunIdx--; - READ_RUN(); - } while (idx < currentRun.index); - READ_GLYPHS(); - glyphIdx = glyphCount-1; - if (oldFont != currentFont) { - mapCharactersToGlyphsInFont(currentTable, &ellipsis, 1, &ellipsisGlyph, NULL); - mapGlyphsToAdvancesInFont(currentFont, 1, &ellipsisGlyph, &ellipsisWidth); - } - } else { - glyphIdx--; - } - lineSize.width -= advances[glyphIdx]; - } - // skip any spaces before truncating - while ((idx - indexCache.index) > 1 && characters[idx-1] == (unichar)' ') { - idx--; - if (idx < currentRun.index) { - currentRunIdx--; - READ_RUN(); - READ_GLYPHS(); - glyphIdx = glyphCount-1; - } else { - glyphIdx--; - } - lineSize.width -= advances[glyphIdx]; - } - lineSize.width += ellipsisWidth; - glyphs[glyphIdx] = ellipsisGlyph; - idx++; - glyphIdx++; - } - retValue.width = MAX(retValue.width, lineSize.width); - retValue.height += lineSize.height; - - // draw - if (performDraw) { - switch (alignment) { - case UITextAlignmentLeft: - drawPoint.x = 0; - break; - case UITextAlignmentCenter: - drawPoint.x = (constrainedSize.width - lineSize.width) / 2.0f; - break; - case UITextAlignmentRight: - drawPoint.x = constrainedSize.width - lineSize.width; - break; - default: - break; - } - NSUInteger stopGlyphIdx = glyphIdx; - NSUInteger lastRunIdx = currentRunIdx; - NSUInteger stopCharIdx = idx; - idx = indexCache.index; - if (currentRunIdx != indexCache.currentRunIdx) { - currentRunIdx = indexCache.currentRunIdx; - READ_RUN(); - READ_GLYPHS(); - } - glyphIdx = indexCache.glyphIndex; - for (NSUInteger drawIdx = currentRunIdx; drawIdx <= lastRunIdx; drawIdx++) { - if (drawIdx != currentRunIdx) { - currentRunIdx = drawIdx; - READ_RUN(); - READ_GLYPHS(); - } - NSUInteger numGlyphs; - if (drawIdx == lastRunIdx) { - numGlyphs = stopGlyphIdx - glyphIdx; - idx = stopCharIdx; - } else { - numGlyphs = glyphCount - glyphIdx; - idx = nextRunStart; - } - CGContextSetFont(ctx, currentFont.cgFont); - CGContextSetFontSize(ctx, currentFont.pointSize); - // calculate the fragment size - CGFloat fragmentWidth = 0; - for (NSUInteger g = 0; g < numGlyphs; g++) { - fragmentWidth += advances[glyphIdx + g]; - } - - if (!ignoreColor) { - UIColor *foregroundColor = getValueOrDefaultForRun(currentRun, ZForegroundColorAttributeName); - UIColor *backgroundColor = getValueOrDefaultForRun(currentRun, ZBackgroundColorAttributeName); - if (backgroundColor != nil && ![backgroundColor isEqual:[UIColor clearColor]]) { - [backgroundColor setFill]; - UIRectFillUsingBlendMode((CGRect){ drawPoint, { fragmentWidth, lineSize.height } }, kCGBlendModeNormal); - } - [foregroundColor setFill]; - } - - CGContextShowGlyphsAtPoint(ctx, drawPoint.x, drawPoint.y + lineAscender, &glyphs[glyphIdx], numGlyphs); - NSNumber *underlineStyle = getValueOrDefaultForRun(currentRun, ZUnderlineStyleAttributeName); - if ([underlineStyle integerValue] & ZUnderlineStyleMask) { - // we only support single for the time being - UIRectFill(CGRectMake(drawPoint.x, drawPoint.y + lineAscender, fragmentWidth, 1)); - } - drawPoint.x += fragmentWidth; - glyphIdx += numGlyphs; - } - drawPoint.y += lineSize.height; - } - idx += skipCount; - glyphIdx += skipCount; - lineCount++; - } else { - lineSize.width += advances[glyphIdx]; - glyphIdx++; - idx++; - if (idx < len && UnicharIsHighSurrogate(characters[idx-1]) && UnicharIsLowSurrogate(characters[idx])) { - // skip the second half of the surrogate pair - idx++; - } - } - } - } - CFRelease(fontTableMap); - free(glyphs); - free(advances); - free(characters); - -#undef READ_GLYPHS -#undef READ_RUN - - return retValue; -} - -static NSArray *attributeRunForFont(ZFont *font) { - return [NSArray arrayWithObject:[ZAttributeRun attributeRunWithIndex:0 - attributes:[NSDictionary dictionaryWithObject:font - forKey:ZFontAttributeName]]]; -} - -static CGSize drawTextInRect(CGRect rect, NSString *text, NSArray *attributes, UILineBreakMode lineBreakMode, - UITextAlignment alignment, NSUInteger numberOfLines, BOOL ignoreColor) { - CGContextRef ctx = UIGraphicsGetCurrentContext(); - - CGContextSaveGState(ctx); - - // flip it upside-down because our 0,0 is upper-left, whereas ttfs are for screens where 0,0 is lower-left - CGAffineTransform textTransform = CGAffineTransformMake(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f); - CGContextSetTextMatrix(ctx, textTransform); - - CGContextTranslateCTM(ctx, rect.origin.x, rect.origin.y); - - CGContextSetTextDrawingMode(ctx, kCGTextFill); - CGSize size = drawOrSizeTextConstrainedToSize(YES, text, attributes, rect.size, numberOfLines, lineBreakMode, alignment, ignoreColor); - - CGContextRestoreGState(ctx); - - return size; -} - -@implementation NSString (FontLabelStringDrawing) -// CGFontRef-based methods -- (CGSize)sizeWithCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize { - return [self sizeWithZFont:[ZFont fontWithCGFont:font size:pointSize]]; -} - -- (CGSize)sizeWithCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize constrainedToSize:(CGSize)size { - return [self sizeWithZFont:[ZFont fontWithCGFont:font size:pointSize] constrainedToSize:size]; -} - -- (CGSize)sizeWithCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize constrainedToSize:(CGSize)size - lineBreakMode:(UILineBreakMode)lineBreakMode { - return [self sizeWithZFont:[ZFont fontWithCGFont:font size:pointSize] constrainedToSize:size lineBreakMode:lineBreakMode]; -} - -- (CGSize)drawAtPoint:(CGPoint)point withCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize { - return [self drawAtPoint:point withZFont:[ZFont fontWithCGFont:font size:pointSize]]; -} - -- (CGSize)drawInRect:(CGRect)rect withCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize { - return [self drawInRect:rect withZFont:[ZFont fontWithCGFont:font size:pointSize]]; -} - -- (CGSize)drawInRect:(CGRect)rect withCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize lineBreakMode:(UILineBreakMode)lineBreakMode { - return [self drawInRect:rect withZFont:[ZFont fontWithCGFont:font size:pointSize] lineBreakMode:lineBreakMode]; -} - -- (CGSize)drawInRect:(CGRect)rect withCGFont:(CGFontRef)font pointSize:(CGFloat)pointSize - lineBreakMode:(UILineBreakMode)lineBreakMode alignment:(UITextAlignment)alignment { - return [self drawInRect:rect withZFont:[ZFont fontWithCGFont:font size:pointSize] lineBreakMode:lineBreakMode alignment:alignment]; -} - -// ZFont-based methods -- (CGSize)sizeWithZFont:(ZFont *)font { - CGSize size = drawOrSizeTextConstrainedToSize(NO, self, attributeRunForFont(font), CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX), 1, - UILineBreakModeClip, UITextAlignmentLeft, YES); - return CGSizeMake(ceilf(size.width), ceilf(size.height)); -} - -- (CGSize)sizeWithZFont:(ZFont *)font constrainedToSize:(CGSize)size { - return [self sizeWithZFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap]; -} - -/* - According to experimentation with UIStringDrawing, this can actually return a CGSize whose height is greater - than the one passed in. The two cases are as follows: - 1. If the given size parameter's height is smaller than a single line, the returned value will - be the height of one line. - 2. If the given size parameter's height falls between multiples of a line height, and the wrapped string - actually extends past the size.height, and the difference between size.height and the previous multiple - of a line height is >= the font's ascender, then the returned size's height is extended to the next line. - To put it simply, if the baseline point of a given line falls in the given size, the entire line will - be present in the output size. - */ -- (CGSize)sizeWithZFont:(ZFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode { - size = drawOrSizeTextConstrainedToSize(NO, self, attributeRunForFont(font), size, 0, lineBreakMode, UITextAlignmentLeft, YES); - return CGSizeMake(ceilf(size.width), ceilf(size.height)); -} - -- (CGSize)sizeWithZFont:(ZFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode - numberOfLines:(NSUInteger)numberOfLines { - size = drawOrSizeTextConstrainedToSize(NO, self, attributeRunForFont(font), size, numberOfLines, lineBreakMode, UITextAlignmentLeft, YES); - return CGSizeMake(ceilf(size.width), ceilf(size.height)); -} - -- (CGSize)drawAtPoint:(CGPoint)point withZFont:(ZFont *)font { - return [self drawAtPoint:point forWidth:CGFLOAT_MAX withZFont:font lineBreakMode:UILineBreakModeClip]; -} - -- (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width withZFont:(ZFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode { - return drawTextInRect((CGRect){ point, { width, CGFLOAT_MAX } }, self, attributeRunForFont(font), lineBreakMode, UITextAlignmentLeft, 1, YES); -} - -- (CGSize)drawInRect:(CGRect)rect withZFont:(ZFont *)font { - return [self drawInRect:rect withZFont:font lineBreakMode:UILineBreakModeWordWrap]; -} - -- (CGSize)drawInRect:(CGRect)rect withZFont:(ZFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode { - return [self drawInRect:rect withZFont:font lineBreakMode:lineBreakMode alignment:UITextAlignmentLeft]; -} - -- (CGSize)drawInRect:(CGRect)rect withZFont:(ZFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode - alignment:(UITextAlignment)alignment { - return drawTextInRect(rect, self, attributeRunForFont(font), lineBreakMode, alignment, 0, YES); -} - -- (CGSize)drawInRect:(CGRect)rect withZFont:(ZFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode - alignment:(UITextAlignment)alignment numberOfLines:(NSUInteger)numberOfLines { - return drawTextInRect(rect, self, attributeRunForFont(font), lineBreakMode, alignment, numberOfLines, YES); -} -@end - -@implementation ZAttributedString (ZAttributedStringDrawing) -- (CGSize)size { - CGSize size = drawOrSizeTextConstrainedToSize(NO, self.string, self.attributes, CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX), 1, - UILineBreakModeClip, UITextAlignmentLeft, NO); - return CGSizeMake(ceilf(size.width), ceilf(size.height)); -} - -- (CGSize)sizeConstrainedToSize:(CGSize)size { - return [self sizeConstrainedToSize:size lineBreakMode:UILineBreakModeWordWrap]; -} - -- (CGSize)sizeConstrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode { - size = drawOrSizeTextConstrainedToSize(NO, self.string, self.attributes, size, 0, lineBreakMode, UITextAlignmentLeft, NO); - return CGSizeMake(ceilf(size.width), ceilf(size.height)); -} - -- (CGSize)sizeConstrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode - numberOfLines:(NSUInteger)numberOfLines { - size = drawOrSizeTextConstrainedToSize(NO, self.string, self.attributes, size, numberOfLines, lineBreakMode, UITextAlignmentLeft, NO); - return CGSizeMake(ceilf(size.width), ceilf(size.height)); -} - -- (CGSize)drawAtPoint:(CGPoint)point { - return [self drawAtPoint:point forWidth:CGFLOAT_MAX lineBreakMode:UILineBreakModeClip]; -} - -- (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode { - return drawTextInRect((CGRect){ point, { width, CGFLOAT_MAX } }, self.string, self.attributes, lineBreakMode, UITextAlignmentLeft, 1, NO); -} - -- (CGSize)drawInRect:(CGRect)rect { - return [self drawInRect:rect withLineBreakMode:UILineBreakModeWordWrap]; -} - -- (CGSize)drawInRect:(CGRect)rect withLineBreakMode:(UILineBreakMode)lineBreakMode { - return [self drawInRect:rect withLineBreakMode:lineBreakMode alignment:UITextAlignmentLeft]; -} - -- (CGSize)drawInRect:(CGRect)rect withLineBreakMode:(UILineBreakMode)lineBreakMode alignment:(UITextAlignment)alignment { - return drawTextInRect(rect, self.string, self.attributes, lineBreakMode, alignment, 0, NO); -} - -- (CGSize)drawInRect:(CGRect)rect withLineBreakMode:(UILineBreakMode)lineBreakMode alignment:(UITextAlignment)alignment - numberOfLines:(NSUInteger)numberOfLines { - return drawTextInRect(rect, self.string, self.attributes, lineBreakMode, alignment, numberOfLines, NO); -} -@end - -@implementation FontLabelStringDrawingHelper -+ (CGSize)sizeWithZFont:(NSString*)string zfont:(ZFont *)font { - CGSize size = drawOrSizeTextConstrainedToSize(NO, string, attributeRunForFont(font), CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX), 1, - UILineBreakModeClip, UITextAlignmentLeft, YES); - return CGSizeMake(ceilf(size.width), ceilf(size.height)); -} - -+ (CGSize)sizeWithZFont:(NSString *)string zfont:(ZFont *)font constrainedToSize:(CGSize)size { - CGSize s = drawOrSizeTextConstrainedToSize(NO, string, attributeRunForFont(font), size, 0, UILineBreakModeWordWrap, UITextAlignmentLeft, YES); - return CGSizeMake(ceilf(s.width), ceilf(s.height)); -} - - - -+ (CGSize)drawInRect:(NSString*)string rect:(CGRect)rect withZFont:(ZFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode - alignment:(UITextAlignment)alignment { - return [string drawInRect:rect withZFont:font lineBreakMode:lineBreakMode alignment:alignment]; -} -@end - diff --git a/cocos2dx/platform/ios/FontLabel/FontManager.h b/cocos2dx/platform/ios/FontLabel/FontManager.h deleted file mode 100644 index 4d3a52bf4c..0000000000 --- a/cocos2dx/platform/ios/FontLabel/FontManager.h +++ /dev/null @@ -1,85 +0,0 @@ -// -// FontManager.h -// FontLabel -// -// Created by Kevin Ballard on 5/5/09. -// Copyright © 2009 Zynga Game Networks -// -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import -#import - -@class ZFont; - -@interface FontManager : NSObject { - CFMutableDictionaryRef fonts; - NSMutableDictionary *urls; -} -+ (FontManager *)sharedManager; -/*! - @method - @abstract Loads a TTF font from the main bundle - @param filename The name of the font file to load (with or without extension). - @return YES if the font was loaded, NO if an error occurred - @discussion If the font has already been loaded, this method does nothing and returns YES. - This method first attempts to load the font by appending .ttf to the filename. - If that file does not exist, it tries the filename exactly as given. -*/ -- (BOOL)loadFont:(NSString *)filename; -/*! - @method - @abstract Loads a font from the given file URL - @param url A file URL that points to a font file - @return YES if the font was loaded, NO if an error occurred - @discussion If the font has already been loaded, this method does nothing and returns YES. -*/ -- (BOOL)loadFontURL:(NSURL *)url; -/*! - @method - @abstract Returns the loaded font with the given filename - @param filename The name of the font file that was given to -loadFont: - @return A CGFontRef, or NULL if the specified font cannot be found - @discussion If the font has not been loaded yet, -loadFont: will be - called with the given name first. -*/ -- (CGFontRef)fontWithName:(NSString *)filename __AVAILABILITY_INTERNAL_DEPRECATED; -/*! - @method - @abstract Returns a ZFont object corresponding to the loaded font with the given filename and point size - @param filename The name of the font file that was given to -loadFont: - @param pointSize The point size of the font - @return A ZFont, or NULL if the specified font cannot be found - @discussion If the font has not been loaded yet, -loadFont: will be - called with the given name first. -*/ -- (ZFont *)zFontWithName:(NSString *)filename pointSize:(CGFloat)pointSize; -/*! - @method - @abstract Returns a ZFont object corresponding to the loaded font with the given file URL and point size - @param url A file URL that points to a font file - @param pointSize The point size of the font - @return A ZFont, or NULL if the specified font cannot be loaded - @discussion If the font has not been loaded yet, -loadFontURL: will be called with the given URL first. -*/ -- (ZFont *)zFontWithURL:(NSURL *)url pointSize:(CGFloat)pointSize; -/*! - @method - @abstract Returns a CFArrayRef of all loaded CGFont objects - @return A CFArrayRef of all loaded CGFont objects - @description You are responsible for releasing the CFArrayRef -*/ -- (CFArrayRef)copyAllFonts; -@end diff --git a/cocos2dx/platform/ios/FontLabel/FontManager.m b/cocos2dx/platform/ios/FontLabel/FontManager.m deleted file mode 100644 index 76ceeac7c2..0000000000 --- a/cocos2dx/platform/ios/FontLabel/FontManager.m +++ /dev/null @@ -1,123 +0,0 @@ -// -// FontManager.m -// FontLabel -// -// Created by Kevin Ballard on 5/5/09. -// Copyright © 2009 Zynga Game Networks -// -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import "FontManager.h" -#import "ZFont.h" - -static FontManager *sharedFontManager = nil; - -@implementation FontManager -+ (FontManager *)sharedManager { - @synchronized(self) { - if (sharedFontManager == nil) { - sharedFontManager = [[self alloc] init]; - } - } - return sharedFontManager; -} - -- (id)init { - if ((self = [super init])) { - fonts = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - urls = [[NSMutableDictionary alloc] init]; - } - return self; -} - -- (BOOL)loadFont:(NSString *)filename { - NSString *fontPath = [[NSBundle mainBundle] pathForResource:filename ofType:@"ttf"]; - if (fontPath == nil) { - fontPath = [[NSBundle mainBundle] pathForResource:filename ofType:nil]; - } - if (fontPath == nil) return NO; - - NSURL *url = [NSURL fileURLWithPath:fontPath]; - if ([self loadFontURL:url]) { - [urls setObject:url forKey:filename]; - return YES; - } - return NO; -} - -- (BOOL)loadFontURL:(NSURL *)url { - CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL((CFURLRef)url); - if (fontDataProvider == NULL) return NO; - CGFontRef newFont = CGFontCreateWithDataProvider(fontDataProvider); - CGDataProviderRelease(fontDataProvider); - if (newFont == NULL) return NO; - - CFDictionarySetValue(fonts, url, newFont); - CGFontRelease(newFont); - return YES; -} - -- (CGFontRef)fontWithName:(NSString *)filename { - CGFontRef font = NULL; - NSURL *url = [urls objectForKey:filename]; - if (url == nil && [self loadFont:filename]) { - url = [urls objectForKey:filename]; - } - if (url != nil) { - font = (CGFontRef)CFDictionaryGetValue(fonts, url); - } - return font; -} - -- (ZFont *)zFontWithName:(NSString *)filename pointSize:(CGFloat)pointSize { - NSURL *url = [urls objectForKey:filename]; - if (url == nil && [self loadFont:filename]) { - url = [urls objectForKey:filename]; - } - if (url != nil) { - CGFontRef cgFont = (CGFontRef)CFDictionaryGetValue(fonts, url); - if (cgFont != NULL) { - return [ZFont fontWithCGFont:cgFont size:pointSize]; - } - } - return nil; -} - -- (ZFont *)zFontWithURL:(NSURL *)url pointSize:(CGFloat)pointSize { - CGFontRef cgFont = (CGFontRef)CFDictionaryGetValue(fonts, url); - if (cgFont == NULL && [self loadFontURL:url]) { - cgFont = (CGFontRef)CFDictionaryGetValue(fonts, url); - } - if (cgFont != NULL) { - return [ZFont fontWithCGFont:cgFont size:pointSize]; - } - return nil; -} - -- (CFArrayRef)copyAllFonts { - CFIndex count = CFDictionaryGetCount(fonts); - CGFontRef *values = (CGFontRef *)malloc(sizeof(CGFontRef) * count); - CFDictionaryGetKeysAndValues(fonts, NULL, (const void **)values); - CFArrayRef array = CFArrayCreate(NULL, (const void **)values, count, &kCFTypeArrayCallBacks); - free(values); - return array; -} - -- (void)dealloc { - CFRelease(fonts); - [urls release]; - [super dealloc]; -} -@end diff --git a/cocos2dx/platform/ios/FontLabel/ZAttributedString.h b/cocos2dx/platform/ios/FontLabel/ZAttributedString.h deleted file mode 100644 index 2ddd5cafd1..0000000000 --- a/cocos2dx/platform/ios/FontLabel/ZAttributedString.h +++ /dev/null @@ -1,77 +0,0 @@ -// -// ZAttributedString.h -// FontLabel -// -// Created by Kevin Ballard on 9/22/09. -// Copyright 2009 Zynga Game Networks. All rights reserved. -// - -#import - -#if NS_BLOCKS_AVAILABLE -#define Z_BLOCKS 1 -#else -// set this to 1 if you are using PLBlocks -#define Z_BLOCKS 0 -#endif - -#if Z_BLOCKS -enum { - ZAttributedStringEnumerationReverse = (1UL << 1), - ZAttributedStringEnumerationLongestEffectiveRangeNotRequired = (1UL << 20) -}; -typedef NSUInteger ZAttributedStringEnumerationOptions; -#endif - -@interface ZAttributedString : NSObject { - NSMutableString *_buffer; - NSMutableArray *_attributes; -} -@property (nonatomic, readonly) NSUInteger length; -@property (nonatomic, readonly) NSString *string; -- (id)initWithAttributedString:(ZAttributedString *)attr; -- (id)initWithString:(NSString *)str; -- (id)initWithString:(NSString *)str attributes:(NSDictionary *)attributes; -- (id)attribute:(NSString *)attributeName atIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange; -- (id)attribute:(NSString *)attributeName atIndex:(NSUInteger)index longestEffectiveRange:(NSRangePointer)aRange inRange:(NSRange)rangeLimit; -- (ZAttributedString *)attributedSubstringFromRange:(NSRange)aRange; -- (NSDictionary *)attributesAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange; -- (NSDictionary *)attributesAtIndex:(NSUInteger)index longestEffectiveRange:(NSRangePointer)aRange inRange:(NSRange)rangeLimit; -#if Z_BLOCKS -- (void)enumerateAttribute:(NSString *)attrName inRange:(NSRange)enumerationRange options:(ZAttributedStringEnumerationOptions)opts - usingBlock:(void (^)(id value, NSRange range, BOOL *stop))block; -- (void)enumerateAttributesInRange:(NSRange)enumerationRange options:(ZAttributedStringEnumerationOptions)opts - usingBlock:(void (^)(NSDictionary *attrs, NSRange range, BOOL *stop))block; -#endif -- (BOOL)isEqualToAttributedString:(ZAttributedString *)otherString; -@end - -@interface ZMutableAttributedString : ZAttributedString { -} -- (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)range; -- (void)addAttributes:(NSDictionary *)attributes range:(NSRange)range; -- (void)appendAttributedString:(ZAttributedString *)str; -- (void)deleteCharactersInRange:(NSRange)range; -- (void)insertAttributedString:(ZAttributedString *)str atIndex:(NSUInteger)idx; -- (void)removeAttribute:(NSString *)name range:(NSRange)range; -- (void)replaceCharactersInRange:(NSRange)range withAttributedString:(ZAttributedString *)str; -- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)str; -- (void)setAttributedString:(ZAttributedString *)str; -- (void)setAttributes:(NSDictionary *)attributes range:(NSRange)range; -@end - -extern NSString * const ZFontAttributeName; -extern NSString * const ZForegroundColorAttributeName; -extern NSString * const ZBackgroundColorAttributeName; -extern NSString * const ZUnderlineStyleAttributeName; - -enum { - ZUnderlineStyleNone = 0x00, - ZUnderlineStyleSingle = 0x01 -}; -#define ZUnderlineStyleMask 0x00FF - -enum { - ZUnderlinePatternSolid = 0x0000 -}; -#define ZUnderlinePatternMask 0xFF00 diff --git a/cocos2dx/platform/ios/FontLabel/ZAttributedString.m b/cocos2dx/platform/ios/FontLabel/ZAttributedString.m deleted file mode 100644 index 485695f078..0000000000 --- a/cocos2dx/platform/ios/FontLabel/ZAttributedString.m +++ /dev/null @@ -1,597 +0,0 @@ -// -// ZAttributedString.m -// FontLabel -// -// Created by Kevin Ballard on 9/22/09. -// Copyright 2009 Zynga Game Networks. All rights reserved. -// - -#import "ZAttributedString.h" -#import "ZAttributedStringPrivate.h" - -@interface ZAttributedString () -- (NSUInteger)indexOfEffectiveAttributeRunForIndex:(NSUInteger)index; -- (NSDictionary *)attributesAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange uniquingOnName:(NSString *)attributeName; -- (NSDictionary *)attributesAtIndex:(NSUInteger)index longestEffectiveRange:(NSRangePointer)aRange - inRange:(NSRange)rangeLimit uniquingOnName:(NSString *)attributeName; -@end - -@interface ZAttributedString () -@property (nonatomic, readonly) NSArray *attributes; -@end - -@implementation ZAttributedString -@synthesize string = _buffer; -@synthesize attributes = _attributes; - -- (id)initWithAttributedString:(ZAttributedString *)attr { - NSParameterAssert(attr != nil); - if ((self = [super init])) { - _buffer = [attr->_buffer mutableCopy]; - _attributes = [[NSMutableArray alloc] initWithArray:attr->_attributes copyItems:YES]; - } - return self; -} - -- (id)initWithString:(NSString *)str { - return [self initWithString:str attributes:nil]; -} - -- (id)initWithString:(NSString *)str attributes:(NSDictionary *)attributes { - if ((self = [super init])) { - _buffer = [str mutableCopy]; - _attributes = [[NSMutableArray alloc] initWithObjects:[ZAttributeRun attributeRunWithIndex:0 attributes:attributes], nil]; - } - return self; -} - -- (id)init { - return [self initWithString:@"" attributes:nil]; -} - -- (id)initWithCoder:(NSCoder *)decoder { - if ((self = [super init])) { - _buffer = [[decoder decodeObjectForKey:@"buffer"] mutableCopy]; - _attributes = [[decoder decodeObjectForKey:@"attributes"] mutableCopy]; - } - return self; -} - -- (void)encodeWithCoder:(NSCoder *)aCoder { - [aCoder encodeObject:_buffer forKey:@"buffer"]; - [aCoder encodeObject:_attributes forKey:@"attributes"]; -} - -- (id)copyWithZone:(NSZone *)zone { - return [self retain]; -} - -- (id)mutableCopyWithZone:(NSZone *)zone { - return [(ZMutableAttributedString *)[ZMutableAttributedString allocWithZone:zone] initWithAttributedString:self]; -} - -- (NSUInteger)length { - return [_buffer length]; -} - -- (NSString *)description { - NSMutableArray *components = [NSMutableArray arrayWithCapacity:[_attributes count]*2]; - NSRange range = NSMakeRange(0, 0); - for (NSUInteger i = 0; i <= [_attributes count]; i++) { - range.location = NSMaxRange(range); - ZAttributeRun *run; - if (i < [_attributes count]) { - run = [_attributes objectAtIndex:i]; - range.length = run.index - range.location; - } else { - run = nil; - range.length = [_buffer length] - range.location; - } - if (range.length > 0) { - [components addObject:[NSString stringWithFormat:@"\"%@\"", [_buffer substringWithRange:range]]]; - } - if (run != nil) { - NSMutableArray *attrDesc = [NSMutableArray arrayWithCapacity:[run.attributes count]]; - for (id key in run.attributes) { - [attrDesc addObject:[NSString stringWithFormat:@"%@: %@", key, [run.attributes objectForKey:key]]]; - } - [components addObject:[NSString stringWithFormat:@"{%@}", [attrDesc componentsJoinedByString:@", "]]]; - } - } - return [NSString stringWithFormat:@"%@", [components componentsJoinedByString:@" "]]; -} - -- (id)attribute:(NSString *)attributeName atIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange { - NSParameterAssert(attributeName != nil); - return [[self attributesAtIndex:index effectiveRange:aRange uniquingOnName:attributeName] objectForKey:attributeName]; -} - -- (id)attribute:(NSString *)attributeName atIndex:(NSUInteger)index longestEffectiveRange:(NSRangePointer)aRange inRange:(NSRange)rangeLimit { - NSParameterAssert(attributeName != nil); - return [[self attributesAtIndex:index longestEffectiveRange:aRange inRange:rangeLimit uniquingOnName:attributeName] objectForKey:attributeName]; -} - -- (ZAttributedString *)attributedSubstringFromRange:(NSRange)aRange { - if (NSMaxRange(aRange) > [_buffer length]) { - @throw [NSException exceptionWithName:NSRangeException reason:@"range was outside of the attributed string" userInfo:nil]; - } - ZMutableAttributedString *newStr = [self mutableCopy]; - if (aRange.location > 0) { - [newStr deleteCharactersInRange:NSMakeRange(0, aRange.location)]; - } - if (NSMaxRange(aRange) < [_buffer length]) { - [newStr deleteCharactersInRange:NSMakeRange(aRange.length, [_buffer length] - NSMaxRange(aRange))]; - } - return [newStr autorelease]; -} - -- (NSDictionary *)attributesAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange { - return [NSDictionary dictionaryWithDictionary:[self attributesAtIndex:index effectiveRange:aRange uniquingOnName:nil]]; -} - -- (NSDictionary *)attributesAtIndex:(NSUInteger)index longestEffectiveRange:(NSRangePointer)aRange inRange:(NSRange)rangeLimit { - return [NSDictionary dictionaryWithDictionary:[self attributesAtIndex:index longestEffectiveRange:aRange inRange:rangeLimit uniquingOnName:nil]]; -} - -#if Z_BLOCKS -// Warning: this code has not been tested. The only guarantee is that it compiles. -- (void)enumerateAttribute:(NSString *)attrName inRange:(NSRange)enumerationRange options:(ZAttributedStringEnumerationOptions)opts - usingBlock:(void (^)(id, NSRange, BOOL*))block { - if (opts & ZAttributedStringEnumerationLongestEffectiveRangeNotRequired) { - [self enumerateAttributesInRange:enumerationRange options:opts usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop) { - id value = [attrs objectForKey:attrName]; - if (value != nil) { - block(value, range, stop); - } - }]; - } else { - __block id oldValue = nil; - __block NSRange effectiveRange = NSMakeRange(0, 0); - [self enumerateAttributesInRange:enumerationRange options:opts usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop) { - id value = [attrs objectForKey:attrName]; - if (oldValue == nil) { - oldValue = value; - effectiveRange = range; - } else if (value != nil && [oldValue isEqual:value]) { - // combine the attributes - effectiveRange = NSUnionRange(effectiveRange, range); - } else { - BOOL innerStop = NO; - block(oldValue, effectiveRange, &innerStop); - if (innerStop) { - *stop = YES; - oldValue = nil; - } else { - oldValue = value; - } - } - }]; - if (oldValue != nil) { - BOOL innerStop = NO; // necessary for the block, but unused - block(oldValue, effectiveRange, &innerStop); - } - } -} - -- (void)enumerateAttributesInRange:(NSRange)enumerationRange options:(ZAttributedStringEnumerationOptions)opts - usingBlock:(void (^)(NSDictionary*, NSRange, BOOL*))block { - // copy the attributes so we can mutate the string if necessary during enumeration - // also clip the array during copy to only the subarray of attributes that cover the requested range - NSArray *attrs; - if (NSEqualRanges(enumerationRange, NSMakeRange(0, 0))) { - attrs = [NSArray arrayWithArray:_attributes]; - } else { - // in this binary search, last is the first run after the range - NSUInteger first = 0, last = [_attributes count]; - while (last > first+1) { - NSUInteger pivot = (last + first) / 2; - ZAttributeRun *run = [_attributes objectAtIndex:pivot]; - if (run.index < enumerationRange.location) { - first = pivot; - } else if (run.index >= NSMaxRange(enumerationRange)) { - last = pivot; - } - } - attrs = [_attributes subarrayWithRange:NSMakeRange(first, last-first)]; - } - if (opts & ZAttributedStringEnumerationReverse) { - NSUInteger end = [_buffer length]; - for (ZAttributeRun *run in [attrs reverseObjectEnumerator]) { - BOOL stop = NO; - NSUInteger start = run.index; - // clip to enumerationRange - start = MAX(start, enumerationRange.location); - end = MIN(end, NSMaxRange(enumerationRange)); - block(run.attributes, NSMakeRange(start, end - start), &stop); - if (stop) break; - end = run.index; - } - } else { - NSUInteger start = 0; - ZAttributeRun *run = [attrs objectAtIndex:0]; - NSInteger offset = 0; - NSInteger oldLength = [_buffer length]; - for (NSUInteger i = 1;;i++) { - NSUInteger end; - if (i >= [attrs count]) { - end = oldLength; - } else { - end = [[attrs objectAtIndex:i] index]; - } - BOOL stop = NO; - NSUInteger clippedStart = MAX(start, enumerationRange.location); - NSUInteger clippedEnd = MIN(end, NSMaxRange(enumerationRange)); - block(run.attributes, NSMakeRange(clippedStart + offset, clippedEnd - start), &stop); - if (stop || i >= [attrs count]) break; - start = end; - NSUInteger newLength = [_buffer length]; - offset += (newLength - oldLength); - oldLength = newLength; - } - } -} -#endif - -- (BOOL)isEqualToAttributedString:(ZAttributedString *)otherString { - return ([_buffer isEqualToString:otherString->_buffer] && [_attributes isEqualToArray:otherString->_attributes]); -} - -- (BOOL)isEqual:(id)object { - return [object isKindOfClass:[ZAttributedString class]] && [self isEqualToAttributedString:(ZAttributedString *)object]; -} - -#pragma mark - - -- (NSUInteger)indexOfEffectiveAttributeRunForIndex:(NSUInteger)index { - NSUInteger first = 0, last = [_attributes count]; - while (last > first + 1) { - NSUInteger pivot = (last + first) / 2; - ZAttributeRun *run = [_attributes objectAtIndex:pivot]; - if (run.index > index) { - last = pivot; - } else if (run.index < index) { - first = pivot; - } else { - first = pivot; - break; - } - } - return first; -} - -- (NSDictionary *)attributesAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange uniquingOnName:(NSString *)attributeName { - if (index >= [_buffer length]) { - @throw [NSException exceptionWithName:NSRangeException reason:@"index beyond range of attributed string" userInfo:nil]; - } - NSUInteger runIndex = [self indexOfEffectiveAttributeRunForIndex:index]; - ZAttributeRun *run = [_attributes objectAtIndex:runIndex]; - if (aRange != NULL) { - aRange->location = run.index; - runIndex++; - if (runIndex < [_attributes count]) { - aRange->length = [[_attributes objectAtIndex:runIndex] index] - aRange->location; - } else { - aRange->length = [_buffer length] - aRange->location; - } - } - return run.attributes; -} -- (NSDictionary *)attributesAtIndex:(NSUInteger)index longestEffectiveRange:(NSRangePointer)aRange - inRange:(NSRange)rangeLimit uniquingOnName:(NSString *)attributeName { - if (index >= [_buffer length]) { - @throw [NSException exceptionWithName:NSRangeException reason:@"index beyond range of attributed string" userInfo:nil]; - } else if (NSMaxRange(rangeLimit) > [_buffer length]) { - @throw [NSException exceptionWithName:NSRangeException reason:@"rangeLimit beyond range of attributed string" userInfo:nil]; - } - NSUInteger runIndex = [self indexOfEffectiveAttributeRunForIndex:index]; - ZAttributeRun *run = [_attributes objectAtIndex:runIndex]; - if (aRange != NULL) { - if (attributeName != nil) { - id value = [run.attributes objectForKey:attributeName]; - NSUInteger endRunIndex = runIndex+1; - runIndex--; - // search backwards - while (1) { - if (run.index <= rangeLimit.location) { - break; - } - ZAttributeRun *prevRun = [_attributes objectAtIndex:runIndex]; - id prevValue = [prevRun.attributes objectForKey:attributeName]; - if (prevValue == value || (value != nil && [prevValue isEqual:value])) { - runIndex--; - run = prevRun; - } else { - break; - } - } - // search forwards - ZAttributeRun *endRun = nil; - while (endRunIndex < [_attributes count]) { - ZAttributeRun *nextRun = [_attributes objectAtIndex:endRunIndex]; - if (nextRun.index >= NSMaxRange(rangeLimit)) { - endRun = nextRun; - break; - } - id nextValue = [nextRun.attributes objectForKey:attributeName]; - if (nextValue == value || (value != nil && [nextValue isEqual:value])) { - endRunIndex++; - } else { - endRun = nextRun; - break; - } - } - aRange->location = MAX(run.index, rangeLimit.location); - aRange->length = MIN((endRun ? endRun.index : [_buffer length]), NSMaxRange(rangeLimit)) - aRange->location; - } else { - // with no attribute name, we don't need to do any real searching, - // as we already guarantee each run has unique attributes. - // just make sure to clip the range to the rangeLimit - aRange->location = MAX(run.index, rangeLimit.location); - ZAttributeRun *endRun = (runIndex+1 < [_attributes count] ? [_attributes objectAtIndex:runIndex+1] : nil); - aRange->length = MIN((endRun ? endRun.index : [_buffer length]), NSMaxRange(rangeLimit)) - aRange->location; - } - } - return run.attributes; -} - -- (void)dealloc { - [_buffer release]; - [_attributes release]; - [super dealloc]; -} -@end - -@interface ZMutableAttributedString () -- (void)cleanupAttributesInRange:(NSRange)range; -- (NSRange)rangeOfAttributeRunsForRange:(NSRange)range; -- (void)offsetRunsInRange:(NSRange )range byOffset:(NSInteger)offset; -@end - -@implementation ZMutableAttributedString -- (id)copyWithZone:(NSZone *)zone { - return [(ZAttributedString *)[ZAttributedString allocWithZone:zone] initWithAttributedString:self]; -} - -- (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)range { - range = [self rangeOfAttributeRunsForRange:range]; - for (ZAttributeRun *run in [_attributes subarrayWithRange:range]) { - [run.attributes setObject:value forKey:name]; - } - [self cleanupAttributesInRange:range]; -} - -- (void)addAttributes:(NSDictionary *)attributes range:(NSRange)range { - range = [self rangeOfAttributeRunsForRange:range]; - for (ZAttributeRun *run in [_attributes subarrayWithRange:range]) { - [run.attributes addEntriesFromDictionary:attributes]; - } - [self cleanupAttributesInRange:range]; -} - -- (void)appendAttributedString:(ZAttributedString *)str { - [self insertAttributedString:str atIndex:[_buffer length]]; -} - -- (void)deleteCharactersInRange:(NSRange)range { - NSRange runRange = [self rangeOfAttributeRunsForRange:range]; - [_buffer replaceCharactersInRange:range withString:@""]; - [_attributes removeObjectsInRange:runRange]; - for (NSUInteger i = runRange.location; i < [_attributes count]; i++) { - ZAttributeRun *run = [_attributes objectAtIndex:i]; - ZAttributeRun *newRun = [[ZAttributeRun alloc] initWithIndex:(run.index - range.length) attributes:run.attributes]; - [_attributes replaceObjectAtIndex:i withObject:newRun]; - [newRun release]; - } - [self cleanupAttributesInRange:NSMakeRange(runRange.location, 0)]; -} - -- (void)insertAttributedString:(ZAttributedString *)str atIndex:(NSUInteger)idx { - [self replaceCharactersInRange:NSMakeRange(idx, 0) withAttributedString:str]; -} - -- (void)removeAttribute:(NSString *)name range:(NSRange)range { - range = [self rangeOfAttributeRunsForRange:range]; - for (ZAttributeRun *run in [_attributes subarrayWithRange:range]) { - [run.attributes removeObjectForKey:name]; - } - [self cleanupAttributesInRange:range]; -} - -- (void)replaceCharactersInRange:(NSRange)range withAttributedString:(ZAttributedString *)str { - NSRange replaceRange = [self rangeOfAttributeRunsForRange:range]; - NSInteger offset = [str->_buffer length] - range.length; - [_buffer replaceCharactersInRange:range withString:str->_buffer]; - [_attributes replaceObjectsInRange:replaceRange withObjectsFromArray:str->_attributes]; - NSRange newRange = NSMakeRange(replaceRange.location, [str->_attributes count]); - [self offsetRunsInRange:newRange byOffset:range.location]; - [self offsetRunsInRange:NSMakeRange(NSMaxRange(newRange), [_attributes count] - NSMaxRange(newRange)) byOffset:offset]; - [self cleanupAttributesInRange:NSMakeRange(newRange.location, 0)]; - [self cleanupAttributesInRange:NSMakeRange(NSMaxRange(newRange), 0)]; -} - -- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)str { - [self replaceCharactersInRange:range withAttributedString:[[[ZAttributedString alloc] initWithString:str] autorelease]]; -} - -- (void)setAttributedString:(ZAttributedString *)str { - [_buffer release], _buffer = [str->_buffer mutableCopy]; - [_attributes release], _attributes = [str->_attributes mutableCopy]; -} - -- (void)setAttributes:(NSDictionary *)attributes range:(NSRange)range { - range = [self rangeOfAttributeRunsForRange:range]; - for (ZAttributeRun *run in [_attributes subarrayWithRange:range]) { - [run.attributes setDictionary:attributes]; - } - [self cleanupAttributesInRange:range]; -} - -#pragma mark - - -// splits the existing runs to provide one or more new runs for the given range -- (NSRange)rangeOfAttributeRunsForRange:(NSRange)range { - NSParameterAssert(NSMaxRange(range) <= [_buffer length]); - - // find (or create) the first run - NSUInteger first = 0; - ZAttributeRun *lastRun = nil; - for (;;first++) { - if (first >= [_attributes count]) { - // we didn't find a run - first = [_attributes count]; - ZAttributeRun *newRun = [[ZAttributeRun alloc] initWithIndex:range.location attributes:lastRun.attributes]; - [_attributes addObject:newRun]; - [newRun release]; - break; - } - ZAttributeRun *run = [_attributes objectAtIndex:first]; - if (run.index == range.location) { - break; - } else if (run.index > range.location) { - ZAttributeRun *newRun = [[ZAttributeRun alloc] initWithIndex:range.location attributes:lastRun.attributes]; - [_attributes insertObject:newRun atIndex:first]; - [newRun release]; - break; - } - lastRun = run; - } - - if (((ZAttributeRun *)[_attributes lastObject]).index < NSMaxRange(range)) { - NSRange subrange = NSMakeRange(first, [_attributes count] - first); - if (NSMaxRange(range) < [_buffer length]) { - ZAttributeRun *newRun = [[ZAttributeRun alloc] initWithIndex:NSMaxRange(range) - attributes:(NSDictionary*)[(ZAttributeRun *)[_attributes lastObject] attributes]]; - [_attributes addObject:newRun]; - [newRun release]; - } - return subrange; - } else { - // find the last run within and the first run after the range - NSUInteger lastIn = first, firstAfter = [_attributes count]-1; - while (firstAfter > lastIn + 1) { - NSUInteger idx = (firstAfter + lastIn) / 2; - ZAttributeRun *run = [_attributes objectAtIndex:idx]; - if (run.index < range.location) { - lastIn = idx; - } else if (run.index > range.location) { - firstAfter = idx; - } else { - // this is definitively the first run after the range - firstAfter = idx; - break; - } - } - if ([[_attributes objectAtIndex:firstAfter] index] > NSMaxRange(range)) { - // the first after is too far after, insert another run! - ZAttributeRun *newRun = [[ZAttributeRun alloc] initWithIndex:NSMaxRange(range) - attributes:[(ZAttributeRun *)[_attributes objectAtIndex:firstAfter-1] attributes]]; - [_attributes insertObject:newRun atIndex:firstAfter]; - [newRun release]; - } - return NSMakeRange(lastIn, firstAfter - lastIn); - } -} - -- (void)cleanupAttributesInRange:(NSRange)range { - // expand the range to include one surrounding attribute on each side - if (range.location > 0) { - range.location -= 1; - range.length += 1; - } - if (NSMaxRange(range) < [_attributes count]) { - range.length += 1; - } else { - // make sure the range is capped to the attributes count - range.length = [_attributes count] - range.location; - } - if (range.length == 0) return; - ZAttributeRun *lastRun = [_attributes objectAtIndex:range.location]; - for (NSUInteger i = range.location+1; i < NSMaxRange(range);) { - ZAttributeRun *run = [_attributes objectAtIndex:i]; - if ([lastRun.attributes isEqualToDictionary:run.attributes]) { - [_attributes removeObjectAtIndex:i]; - range.length -= 1; - } else { - lastRun = run; - i++; - } - } -} - -- (void)offsetRunsInRange:(NSRange)range byOffset:(NSInteger)offset { - for (NSUInteger i = range.location; i < NSMaxRange(range); i++) { - ZAttributeRun *run = [_attributes objectAtIndex:i]; - ZAttributeRun *newRun = [[ZAttributeRun alloc] initWithIndex:run.index + offset attributes:run.attributes]; - [_attributes replaceObjectAtIndex:i withObject:newRun]; - [newRun release]; - } -} -@end - -@implementation ZAttributeRun -@synthesize index = _index; -@synthesize attributes = _attributes; - -+ (id)attributeRunWithIndex:(NSUInteger)idx attributes:(NSDictionary *)attrs { - return [[[self alloc] initWithIndex:idx attributes:attrs] autorelease]; -} - -- (id)initWithIndex:(NSUInteger)idx attributes:(NSDictionary *)attrs { - NSParameterAssert(idx >= 0); - if ((self = [super init])) { - _index = idx; - if (attrs == nil) { - _attributes = [[NSMutableDictionary alloc] init]; - } else { - _attributes = [attrs mutableCopy]; - } - } - return self; -} - -- (id)initWithCoder:(NSCoder *)decoder { - if ((self = [super init])) { - _index = [[decoder decodeObjectForKey:@"index"] unsignedIntegerValue]; - _attributes = [[decoder decodeObjectForKey:@"attributes"] mutableCopy]; - } - return self; -} - -- (id)init { - return [self initWithIndex:0 attributes:[NSDictionary dictionary]]; -} - -- (id)copyWithZone:(NSZone *)zone { - return [[ZAttributeRun allocWithZone:zone] initWithIndex:_index attributes:_attributes]; -} - -- (void)encodeWithCoder:(NSCoder *)aCoder { - [aCoder encodeObject:[NSNumber numberWithUnsignedInteger:_index] forKey:@"index"]; - [aCoder encodeObject:_attributes forKey:@"attributes"]; -} - -- (NSString *)description { - NSMutableArray *components = [NSMutableArray arrayWithCapacity:[_attributes count]]; - for (id key in _attributes) { - [components addObject:[NSString stringWithFormat:@"%@=%@", key, [_attributes objectForKey:key]]]; - } - return [NSString stringWithFormat:@"<%@: %p index=%lu attributes={%@}>", - NSStringFromClass([self class]), self, (unsigned long)_index, [components componentsJoinedByString:@" "]]; -} - -- (BOOL)isEqual:(id)object { - if (![object isKindOfClass:[ZAttributeRun class]]) return NO; - ZAttributeRun *other = (ZAttributeRun *)object; - return _index == other->_index && [_attributes isEqualToDictionary:other->_attributes]; -} - -- (void)dealloc { - [_attributes release]; - [super dealloc]; -} -@end - -NSString * const ZFontAttributeName = @"ZFontAttributeName"; -NSString * const ZForegroundColorAttributeName = @"ZForegroundColorAttributeName"; -NSString * const ZBackgroundColorAttributeName = @"ZBackgroundColorAttributeName"; -NSString * const ZUnderlineStyleAttributeName = @"ZUnderlineStyleAttributeName"; diff --git a/cocos2dx/platform/ios/FontLabel/ZAttributedStringPrivate.h b/cocos2dx/platform/ios/FontLabel/ZAttributedStringPrivate.h deleted file mode 100644 index f13a4e0caf..0000000000 --- a/cocos2dx/platform/ios/FontLabel/ZAttributedStringPrivate.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// ZAttributedStringPrivate.h -// FontLabel -// -// Created by Kevin Ballard on 9/23/09. -// Copyright 2009 Zynga Game Networks. All rights reserved. -// - -#import -#import "ZAttributedString.h" - -@interface ZAttributeRun : NSObject { - NSUInteger _index; - NSMutableDictionary *_attributes; -} -@property (nonatomic, readonly) NSUInteger index; -@property (nonatomic, readonly) NSMutableDictionary *attributes; -+ (id)attributeRunWithIndex:(NSUInteger)idx attributes:(NSDictionary *)attrs; -- (id)initWithIndex:(NSUInteger)idx attributes:(NSDictionary *)attrs; -@end - -@interface ZAttributedString (ZAttributedStringPrivate) -@property (nonatomic, readonly) NSArray *attributes; -@end diff --git a/cocos2dx/platform/ios/FontLabel/ZFont.h b/cocos2dx/platform/ios/FontLabel/ZFont.h deleted file mode 100644 index 43de175f03..0000000000 --- a/cocos2dx/platform/ios/FontLabel/ZFont.h +++ /dev/null @@ -1,47 +0,0 @@ -// -// ZFont.h -// FontLabel -// -// Created by Kevin Ballard on 7/2/09. -// Copyright © 2009 Zynga Game Networks -// -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import -#import - -@interface ZFont : NSObject { - CGFontRef _cgFont; - CGFloat _pointSize; - CGFloat _ratio; - NSString *_familyName; - NSString *_fontName; - NSString *_postScriptName; -} -@property (nonatomic, readonly) CGFontRef cgFont; -@property (nonatomic, readonly) CGFloat pointSize; -@property (nonatomic, readonly) CGFloat ascender; -@property (nonatomic, readonly) CGFloat descender; -@property (nonatomic, readonly) CGFloat leading; -@property (nonatomic, readonly) CGFloat xHeight; -@property (nonatomic, readonly) CGFloat capHeight; -@property (nonatomic, readonly) NSString *familyName; -@property (nonatomic, readonly) NSString *fontName; -@property (nonatomic, readonly) NSString *postScriptName; -+ (ZFont *)fontWithCGFont:(CGFontRef)cgFont size:(CGFloat)fontSize; -+ (ZFont *)fontWithUIFont:(UIFont *)uiFont; -- (id)initWithCGFont:(CGFontRef)cgFont size:(CGFloat)fontSize; -- (ZFont *)fontWithSize:(CGFloat)fontSize; -@end diff --git a/cocos2dx/platform/ios/FontLabel/ZFont.m b/cocos2dx/platform/ios/FontLabel/ZFont.m deleted file mode 100644 index a20d96913a..0000000000 --- a/cocos2dx/platform/ios/FontLabel/ZFont.m +++ /dev/null @@ -1,170 +0,0 @@ -// -// ZFont.m -// FontLabel -// -// Created by Kevin Ballard on 7/2/09. -// Copyright © 2009 Zynga Game Networks -// -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import "ZFont.h" - -@interface ZFont () -@property (nonatomic, readonly) CGFloat ratio; -- (NSString *)copyNameTableEntryForID:(UInt16)nameID; -@end - -@implementation ZFont -@synthesize cgFont=_cgFont, pointSize=_pointSize, ratio=_ratio; - -+ (ZFont *)fontWithCGFont:(CGFontRef)cgFont size:(CGFloat)fontSize { - return [[[self alloc] initWithCGFont:cgFont size:fontSize] autorelease]; -} - -+ (ZFont *)fontWithUIFont:(UIFont *)uiFont { - NSParameterAssert(uiFont != nil); - CGFontRef cgFont = CGFontCreateWithFontName((CFStringRef)uiFont.fontName); - ZFont *zFont = [[self alloc] initWithCGFont:cgFont size:uiFont.pointSize]; - CGFontRelease(cgFont); - return [zFont autorelease]; -} - -- (id)initWithCGFont:(CGFontRef)cgFont size:(CGFloat)fontSize { - if ((self = [super init])) { - _cgFont = CGFontRetain(cgFont); - _pointSize = fontSize; - _ratio = fontSize/CGFontGetUnitsPerEm(cgFont); - } - return self; -} - -- (id)init { - NSAssert(NO, @"-init is not valid for ZFont"); - return nil; -} - -- (CGFloat)ascender { - return ceilf(self.ratio * CGFontGetAscent(self.cgFont)); -} - -- (CGFloat)descender { - return floorf(self.ratio * CGFontGetDescent(self.cgFont)); -} - -- (CGFloat)leading { - return (self.ascender - self.descender); -} - -- (CGFloat)capHeight { - return ceilf(self.ratio * CGFontGetCapHeight(self.cgFont)); -} - -- (CGFloat)xHeight { - return ceilf(self.ratio * CGFontGetXHeight(self.cgFont)); -} - -- (NSString *)familyName { - if (_familyName == nil) { - _familyName = [self copyNameTableEntryForID:1]; - } - return _familyName; -} - -- (NSString *)fontName { - if (_fontName == nil) { - _fontName = [self copyNameTableEntryForID:4]; - } - return _fontName; -} - -- (NSString *)postScriptName { - if (_postScriptName == nil) { - _postScriptName = [self copyNameTableEntryForID:6]; - } - return _postScriptName; -} - -- (ZFont *)fontWithSize:(CGFloat)fontSize { - if (fontSize == self.pointSize) return self; - NSParameterAssert(fontSize > 0.0); - return [[[ZFont alloc] initWithCGFont:self.cgFont size:fontSize] autorelease]; -} - -- (BOOL)isEqual:(id)object { - if (![object isKindOfClass:[ZFont class]]) return NO; - ZFont *font = (ZFont *)object; - return (font.cgFont == self.cgFont && font.pointSize == self.pointSize); -} - -- (NSString *)copyNameTableEntryForID:(UInt16)aNameID { - CFDataRef nameTable = CGFontCopyTableForTag(self.cgFont, 'name'); - NSAssert1(nameTable != NULL, @"CGFontCopyTableForTag returned NULL for 'name' tag in font %@", - [(id)CFCopyDescription(self.cgFont) autorelease]); - const UInt8 * const bytes = CFDataGetBytePtr(nameTable); - NSAssert1(OSReadBigInt16(bytes, 0) == 0, @"name table for font %@ has bad version number", - [(id)CFCopyDescription(self.cgFont) autorelease]); - const UInt16 count = OSReadBigInt16(bytes, 2); - const UInt16 stringOffset = OSReadBigInt16(bytes, 4); - const UInt8 * const nameRecords = &bytes[6]; - UInt16 nameLength = 0; - UInt16 nameOffset = 0; - NSStringEncoding encoding = 0; - for (UInt16 idx = 0; idx < count; idx++) { - const uintptr_t recordOffset = 12 * idx; - const UInt16 nameID = OSReadBigInt16(nameRecords, recordOffset + 6); - if (nameID != aNameID) continue; - const UInt16 platformID = OSReadBigInt16(nameRecords, recordOffset + 0); - const UInt16 platformSpecificID = OSReadBigInt16(nameRecords, recordOffset + 2); - encoding = 0; - // for now, we only support a subset of encodings - switch (platformID) { - case 0: // Unicode - encoding = NSUTF16StringEncoding; - break; - case 1: // Macintosh - switch (platformSpecificID) { - case 0: - encoding = NSMacOSRomanStringEncoding; - break; - } - case 3: // Microsoft - switch (platformSpecificID) { - case 1: - encoding = NSUTF16StringEncoding; - break; - } - } - if (encoding == 0) continue; - nameLength = OSReadBigInt16(nameRecords, recordOffset + 8); - nameOffset = OSReadBigInt16(nameRecords, recordOffset + 10); - break; - } - NSString *result = nil; - if (nameOffset > 0) { - const UInt8 *nameBytes = &bytes[stringOffset + nameOffset]; - result = [[NSString alloc] initWithBytes:nameBytes length:nameLength encoding:encoding]; - } - CFRelease(nameTable); - return result; -} - -- (void)dealloc { - CGFontRelease(_cgFont); - [_familyName release]; - [_fontName release]; - [_postScriptName release]; - [super dealloc]; -} -@end diff --git a/cocos2dx/proj.ios/cocos2dx.xcodeproj/project.pbxproj.REMOVED.git-id b/cocos2dx/proj.ios/cocos2dx.xcodeproj/project.pbxproj.REMOVED.git-id index 8bbb77b590..c15f5bb754 100644 --- a/cocos2dx/proj.ios/cocos2dx.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/cocos2dx/proj.ios/cocos2dx.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -c6b576d638eb4ac03aebd8111bba28397aa96625 \ No newline at end of file +d9f2b205ba4de8125ca7740a1740767028020681 \ No newline at end of file diff --git a/samples/TestCpp/Classes/FontTest/FontTest.cpp b/samples/TestCpp/Classes/FontTest/FontTest.cpp index 8d401de22c..75a7be595c 100644 --- a/samples/TestCpp/Classes/FontTest/FontTest.cpp +++ b/samples/TestCpp/Classes/FontTest/FontTest.cpp @@ -13,15 +13,23 @@ static int fontIdx = 0; static std::string fontList[] = { #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + // custom ttf files are defined in Test-info.plist "American Typewriter", "Marker Felt", -#endif + "A Damn Mess", + "Abberancy", + "Abduction", + "Paint Boy", + "Schwarzwald Regular", + "Scissor Cuts", +#else "fonts/A Damn Mess.ttf", "fonts/Abberancy.ttf", "fonts/Abduction.ttf", "fonts/Paint Boy.ttf", "fonts/Schwarzwald Regular.ttf", "fonts/Scissor Cuts.ttf", +#endif }; static int fontCount = sizeof(fontList) / sizeof(*fontList); From a65f13defe6cc9d9a206da8674b35730d00048e2 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 15 Oct 2012 13:01:36 +0800 Subject: [PATCH 34/64] issue #1486: Fix bugs for CCEditBox iOS port. --- cocos2dx/platform/ios/EAGLView.mm | 55 ++++++++++++-------- extensions/GUI/CCEditBox/CCEditBoxImplIOS.h | 1 + extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm | 41 +++++++-------- 3 files changed, 53 insertions(+), 44 deletions(-) diff --git a/cocos2dx/platform/ios/EAGLView.mm b/cocos2dx/platform/ios/EAGLView.mm index 811b475e1c..46588c2a17 100755 --- a/cocos2dx/platform/ios/EAGLView.mm +++ b/cocos2dx/platform/ios/EAGLView.mm @@ -791,6 +791,32 @@ static EAGLView *view = 0; break; } + float scaleX = cocos2d::CCEGLView::sharedOpenGLView()->getScaleX(); + float scaleY = cocos2d::CCEGLView::sharedOpenGLView()->getScaleY(); + + + if (self.contentScaleFactor == 2.0f) + { + // Convert to pixel coordinate + + begin = CGRectApplyAffineTransform(begin, CGAffineTransformScale(CGAffineTransformIdentity, 2.0f, 2.0f)); + end = CGRectApplyAffineTransform(end, CGAffineTransformScale(CGAffineTransformIdentity, 2.0f, 2.0f)); + } + + float offestY = cocos2d::CCEGLView::sharedOpenGLView()->getViewPortRect().origin.y; + CCLOG("offestY = %f", offestY); + if (offestY < 0.0f) + { + begin.origin.y += offestY; + begin.size.height -= offestY; + end.size.height -= offestY; + } + + // Convert to desigin coordinate + begin = CGRectApplyAffineTransform(begin, CGAffineTransformScale(CGAffineTransformIdentity, 1.0f/scaleX, 1.0f/scaleY)); + end = CGRectApplyAffineTransform(end, CGAffineTransformScale(CGAffineTransformIdentity, 1.0f/scaleX, 1.0f/scaleY)); + + cocos2d::CCIMEKeyboardNotificationInfo notiInfo; notiInfo.begin = cocos2d::CCRect(begin.origin.x, begin.origin.y, @@ -802,28 +828,6 @@ static EAGLView *view = 0; end.size.height); notiInfo.duration = (float)aniDuration; - float offestY = cocos2d::CCEGLView::sharedOpenGLView()->getViewPortRect().origin.y; - - if (offestY > 0.0f) - { - notiInfo.begin.origin.y += offestY; - notiInfo.begin.size.height -= offestY; - notiInfo.end.size.height -= offestY; - } - - float scaleX = cocos2d::CCEGLView::sharedOpenGLView()->getScaleX(); - float scaleY = cocos2d::CCEGLView::sharedOpenGLView()->getScaleY(); - - notiInfo.begin.origin.x /= scaleX; - notiInfo.begin.origin.y /= scaleY; - notiInfo.begin.size.width /= scaleX; - notiInfo.begin.size.height /= scaleY; - - notiInfo.end.origin.x /= scaleX; - notiInfo.end.origin.y /= scaleY; - notiInfo.end.size.width /= scaleX; - notiInfo.end.size.height /= scaleY; - cocos2d::CCIMEDispatcher* dispatcher = cocos2d::CCIMEDispatcher::sharedDispatcher(); if (UIKeyboardWillShowNotification == type) { @@ -858,12 +862,17 @@ static EAGLView *view = 0; [UIView setAnimationDuration:duration]; [UIView setAnimationBeginsFromCurrentState:YES]; - // NSLog(@"[animation] dis = %f\n", dis); + //NSLog(@"[animation] dis = %f, scale = %f \n", dis, cocos2d::CCEGLView::sharedOpenGLView()->getScaleY()); if (dis < 0.0f) dis = 0.0f; dis *= cocos2d::CCEGLView::sharedOpenGLView()->getScaleY(); + if (self.contentScaleFactor == 2.0f) + { + dis /= 2.0f; + } + switch ([[UIApplication sharedApplication] statusBarOrientation]) { case UIInterfaceOrientationPortrait: diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplIOS.h b/extensions/GUI/CCEditBox/CCEditBoxImplIOS.h index 8d5d9a340b..78c6b928f9 100644 --- a/extensions/GUI/CCEditBox/CCEditBoxImplIOS.h +++ b/extensions/GUI/CCEditBox/CCEditBoxImplIOS.h @@ -64,6 +64,7 @@ private: CCSize m_tContentSize; void* m_pSysEdit; int m_nMaxTextLength; + bool m_bInRetinaMode; }; diff --git a/extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm b/extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm index 576fda9233..30307c68dc 100644 --- a/extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm +++ b/extensions/GUI/CCEditBox/CCEditBoxImplIOS.mm @@ -42,7 +42,7 @@ CCEditBoxImplIOS::CCEditBoxImplIOS(CCEditBox* pEditText) , m_pSysEdit(NULL) , m_nMaxTextLength(-1) { - + m_bInRetinaMode = [[EAGLView sharedEGLView] contentScaleFactor] == 2.0f ? true : false; } CCEditBoxImplIOS::~CCEditBoxImplIOS() @@ -64,15 +64,14 @@ bool CCEditBoxImplIOS::initWithSize(const CCSize& size) { CCEGLViewProtocol* eglView = CCEGLView::sharedOpenGLView(); - CGRect rect; - if (eglView->isRetinaEnabled()) + CGRect rect = CGRectMake(0, 0, size.width * eglView->getScaleX(),size.height * eglView->getScaleY()); + + if (m_bInRetinaMode) { - rect = CGRectMake(0, 0, size.width,size.height); - } - else - { - rect = CGRectMake(0, 0, size.width * eglView->getScaleX(),size.height * eglView->getScaleY()); + rect.size.width /= 2.0f; + rect.size.height /= 2.0f; } + m_pSysEdit = [[EditBoxImplIOS alloc] initWithFrame:rect editBox:this]; if (!m_pSysEdit) break; @@ -195,29 +194,29 @@ void CCEditBoxImplIOS::setPlaceHolder(const char* pText) GET_IMPL.textField.placeholder = [NSString stringWithUTF8String:pText]; } -static CGPoint convertDesignCoordToScreenCoord(const CCPoint& designCoord) +static CGPoint convertDesignCoordToScreenCoord(const CCPoint& designCoord, bool bInRetinaMode) { - float viewH = (float)[[EAGLView sharedEGLView] getHeight]; CCEGLViewProtocol* eglView = CCEGLView::sharedOpenGLView(); - CCPoint visiblePos; - if (eglView->isRetinaEnabled()) - { - visiblePos = ccp(designCoord.x, designCoord.y); - } - else - { - visiblePos = ccp(designCoord.x * eglView->getScaleX(), designCoord.y * eglView->getScaleY()); - } - + float viewH = (float)[[EAGLView sharedEGLView] getHeight]; + + CCPoint visiblePos = ccp(designCoord.x * eglView->getScaleX(), designCoord.y * eglView->getScaleY()); CCPoint screenGLPos = ccpAdd(visiblePos, eglView->getViewPortRect().origin); + CGPoint screenPos = CGPointMake(screenGLPos.x, viewH - screenGLPos.y); + + if (bInRetinaMode) + { + screenPos.x = screenPos.x / 2.0f; + screenPos.y = screenPos.y / 2.0f; + } + CCLOG("[EditBox] pos x = %f, y = %f", screenGLPos.x, screenGLPos.y); return screenPos; } void CCEditBoxImplIOS::setPosition(const CCPoint& pos) { //TODO should consider anchor point, the default value is (0.5, 0,5) - [GET_IMPL setPosition:convertDesignCoordToScreenCoord(ccp(pos.x-m_tContentSize.width/2, pos.y+m_tContentSize.height/2))]; + [GET_IMPL setPosition:convertDesignCoordToScreenCoord(ccp(pos.x-m_tContentSize.width/2, pos.y+m_tContentSize.height/2), m_bInRetinaMode)]; } void CCEditBoxImplIOS::setContentSize(const CCSize& size) From 4955c14928e02519791c0a1747eb33bbf6761772 Mon Sep 17 00:00:00 2001 From: folecr Date: Sun, 14 Oct 2012 22:12:24 -0700 Subject: [PATCH 35/64] Fix --git-dir parameter for git submodule operations --- tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh index 9023c335e7..d3cd98d98d 100755 --- a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh +++ b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh @@ -58,7 +58,7 @@ ELAPSEDSECS=`date +%s` echo Using "$ELAPSEDSECS" in the branch names for pseudo-uniqueness GENERATED_BRANCH=autogeneratedbindings_"$ELAPSEDSECS" -GENERATED_GITDIR="$COCOS2DX_ROOT"/scripting/javascript/bindings/generated/.git +GENERATED_GITDIR="$COCOS2DX_ROOT"/.git/modules/scripting/javascript/bindings/generated GENERATED_WORKTREE="$COCOS2DX_ROOT"/scripting/javascript/bindings/generated # git command shortcut From d2ed5567b7f25132813e38b4b92782ef4e8d8569 Mon Sep 17 00:00:00 2001 From: folecr Date: Sun, 14 Oct 2012 22:13:21 -0700 Subject: [PATCH 36/64] Test for diffs in existing files * before proceeding with committing and pushing changes * remove "set -e" so that above test makes sense * verbose git operations where possible --- .../mac/android/generate-js-cxx-bindings.sh | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh index d3cd98d98d..fa0948963d 100755 --- a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh +++ b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh @@ -21,9 +21,6 @@ # * REMOTE_AUTOGEN_BINDINGS_REPOSITORY # * Ensure you have ssh access to above repositories -# Exit on error -set -e - DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" COCOS2DX_ROOT="$DIR"/../../../.. @@ -52,7 +49,10 @@ if [ -z "${COMMITTAG+aaa}" ]; then # ... if COMMITTAG is not set, use this machine's hostname COMMITTAG=`hostname -s` fi + +echo echo Using "'$COMMITTAG'" in the commit messages +echo ELAPSEDSECS=`date +%s` echo Using "$ELAPSEDSECS" in the branch names for pseudo-uniqueness @@ -64,16 +64,37 @@ GENERATED_WORKTREE="$COCOS2DX_ROOT"/scripting/javascript/bindings/generated # git command shortcut gitcmd_GEN="git --git-dir=$GENERATED_GITDIR --work-tree=$GENERATED_WORKTREE" -# testing... +# 2. In JSBindings repo, Check if there are any files that are different from the index +# Run status to record the output in the log ${gitcmd_GEN} status -# 2. In JSBindings repo, Check out a branch named "autogeneratedbindings" and commit the auto generated bindings to it -${gitcmd_GEN} add README cocos2dx.cpp cocos2dx.hpp cocos2dxapi.js -${gitcmd_GEN} checkout origin/master -b "$GENERATED_BRANCH" -${gitcmd_GEN} commit -m "$COMMITTAG : autogenerated bindings" +echo +echo Diffing... +echo -# 3. In JSBindings repo, Push the commit with generated bindings to "master" of the auto generated bindings repository -${gitcmd_GEN} push "$REMOTE_AUTOGEN_BINDINGS_REPOSITORY" "$GENERATED_BRANCH":master +${gitcmd_GEN} diff --stat --exit-code + +DIFF_RETVAL=$? +if [ $DIFF_RETVAL -eq 0 ] +then + echo + echo "No differences in generated files" + echo "Exiting with success." + echo + exit 0 +else + echo + echo "Generated files differ from the version checked in to the index. Continuing." + echo +fi + +# 3. In JSBindings repo, Check out a branch named "autogeneratedbindings" and commit the auto generated bindings to it +${gitcmd_GEN} add --verbose README cocos2dx.cpp cocos2dx.hpp cocos2dxapi.js +${gitcmd_GEN} checkout origin/master -b "$GENERATED_BRANCH" +${gitcmd_GEN} commit --verbose -m "$COMMITTAG : autogenerated bindings" + +# 4. In JSBindings repo, Push the commit with generated bindings to "master" of the auto generated bindings repository +${gitcmd_GEN} push --verbose "$REMOTE_AUTOGEN_BINDINGS_REPOSITORY" "$GENERATED_BRANCH":master if [ -z "${REMOTE_COCOS2DX_REPOSITORY+aaa}" ]; then echo @@ -93,13 +114,13 @@ COCOS_BRANCH=updategeneratedsubmodule_"$ELAPSEDSECS" pushd "${DIR}" -# 4. In Cocos2D-X repo, Checkout a branch named "updategeneratedsubmodule" Update the submodule reference to point to the commit with generated bindings +# 5. In Cocos2D-X repo, Checkout a branch named "updategeneratedsubmodule" Update the submodule reference to point to the commit with generated bindings cd "${COCOS2DX_ROOT}" git add scripting/javascript/bindings/generated git checkout origin/gles20 -b "$COCOS_BRANCH" git commit -m "$COMMITTAG : updating submodule reference to latest autogenerated bindings" -# 5. In Cocos2D-X repo, Push the commit with updated submodule to "gles20" of the cocos2d-x repository +# 6. In Cocos2D-X repo, Push the commit with updated submodule to "gles20" of the cocos2d-x repository git push "$REMOTE_COCOS2DX_REPOSITORY" "$COCOS_BRANCH":gles20 popd From 8d0dc8d2a7bcee9c011d768ef12c977f900cf333 Mon Sep 17 00:00:00 2001 From: johnangel Date: Mon, 15 Oct 2012 10:39:42 +0200 Subject: [PATCH 37/64] Windows Touch support for desktop --- cocos2dx/platform/win32/CCEGLView.cpp | 78 +++++++++++++++++++++++++++ cocos2dx/platform/win32/CCEGLView.h | 1 + 2 files changed, 79 insertions(+) diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index a677391b83..986720b254 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -35,6 +35,34 @@ THE SOFTWARE. NS_CC_BEGIN +// Windows Touch define +#define MOUSEEVENTF_FROMTOUCH 0xFF515700 + +// Windows Touch functions +// Workaround to be able tu run app on Windows XP +typedef WINUSERAPI BOOL (WINAPI *RegisterTouchWindowFn)(_In_ HWND hwnd, _In_ ULONG ulFlags); +typedef WINUSERAPI BOOL (WINAPI *UnregisterTouchWindowFn)(_In_ HWND hwnd); +typedef WINUSERAPI LPARAM (WINAPI *GetMessageExtraInfoFn)(VOID); +typedef WINUSERAPI BOOL (WINAPI *GetTouchInputInfoFn)(_In_ HTOUCHINPUT hTouchInput, _In_ UINT cInputs, __out_ecount(cInputs) PTOUCHINPUT pInputs, _In_ int cbSize); +typedef WINUSERAPI BOOL (WINAPI *CloseTouchInputHandleFn)(_In_ HTOUCHINPUT hTouchInput); + +RegisterTouchWindowFn RegisterTouchWindowFunction = NULL; +UnregisterTouchWindowFn UnregisterTouchWindowFunction = NULL; +GetMessageExtraInfoFn GetMessageExtraInfoFunction = NULL; +GetTouchInputInfoFn GetTouchInputInfoFunction = NULL; +CloseTouchInputHandleFn CloseTouchInputHandleFunction = NULL; + +bool CheckTouchSupport() +{ + RegisterTouchWindowFunction = (RegisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "RegisterTouchWindow"); + UnregisterTouchWindowFunction = (UnregisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "UnregisterTouchWindow"); + GetMessageExtraInfoFunction = (GetMessageExtraInfoFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "GetMessageExtraInfo"); + GetTouchInputInfoFunction = (GetTouchInputInfoFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "GetTouchInputInfo"); + CloseTouchInputHandleFunction = (CloseTouchInputHandleFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "CloseTouchInputHandle"); + + return (RegisterTouchWindowFunction && UnregisterTouchWindowFunction && GetMessageExtraInfoFunction && GetTouchInputInfoFunction && CloseTouchInputHandleFunction); +} + static void SetupPixelFormat(HDC hDC) { int pixelFormat; @@ -159,6 +187,7 @@ CCEGLView::CCEGLView() , m_windowTouchScaleY(1.0f) { strcpy(m_szViewName, "Cocos2dxWin32"); + m_Touch = false; } CCEGLView::~CCEGLView() @@ -287,6 +316,9 @@ bool CCEGLView::Create() bRet = true; } while (0); + m_Touch = CheckTouchSupport(); + if(m_Touch) m_Touch = (RegisterTouchWindowFunction(m_hWnd, 0) != 0); + return bRet; } @@ -297,6 +329,9 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) switch (message) { case WM_LBUTTONDOWN: + // Don't process message generated by Windows Touch + if (m_Touch && (GetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; + if (m_pDelegate && MK_LBUTTON == wParam) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; @@ -315,6 +350,9 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) break; case WM_MOUSEMOVE: + // Don't process message generated by Windows Touch + if (m_Touch && (GetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; + if (MK_LBUTTON == wParam && m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; @@ -327,6 +365,9 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) break; case WM_LBUTTONUP: + // Don't process message generated by Windows Touch + if (m_Touch && (GetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; + if (m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; @@ -340,6 +381,42 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) m_bCaptured = false; } break; + + case WM_TOUCH: + { + BOOL bHandled = FALSE; + UINT cInputs = LOWORD(wParam); + PTOUCHINPUT pInputs = new TOUCHINPUT[cInputs]; + if (pInputs) + { + if (GetTouchInputInfoFunction((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT))) + { + for (UINT i=0; i < cInputs; i++) + { + TOUCHINPUT ti = pInputs[i]; + CCPoint pt(TOUCH_COORD_TO_PIXEL(ti.x)/CC_CONTENT_SCALE_FACTOR(), TOUCH_COORD_TO_PIXEL(ti.y)/CC_CONTENT_SCALE_FACTOR()); + CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); + if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp)) + { + pt.x *= m_windowTouchScaleX; + pt.y *= m_windowTouchScaleY; + + if((ti.dwFlags & TOUCHEVENTF_DOWN)!=0) + handleTouchesBegin(1, reinterpret_cast(&ti.dwID), &pt.x, &pt.y); + else if((ti.dwFlags & TOUCHEVENTF_MOVE)!=0) + handleTouchesMove(1, reinterpret_cast(&ti.dwID), &pt.x, &pt.y); + else if((ti.dwFlags & TOUCHEVENTF_UP)!=0) + handleTouchesEnd(1, reinterpret_cast(&ti.dwID), &pt.x, &pt.y); + } + } + bHandled = TRUE; + } + delete [] pInputs; + } + if (bHandled) CloseTouchInputHandleFunction((HTOUCHINPUT)lParam); + } + break; + case WM_SIZE: switch (wParam) { @@ -460,6 +537,7 @@ void CCEGLView::end() { if (m_hWnd) { + if(m_Touch) UnregisterTouchWindowFunction(m_hWnd); DestroyWindow(m_hWnd); m_hWnd = NULL; } diff --git a/cocos2dx/platform/win32/CCEGLView.h b/cocos2dx/platform/win32/CCEGLView.h index dd6b2d486f..7c611d5b26 100644 --- a/cocos2dx/platform/win32/CCEGLView.h +++ b/cocos2dx/platform/win32/CCEGLView.h @@ -83,6 +83,7 @@ private: HDC m_hDC; HGLRC m_hRC; LPFN_ACCELEROMETER_KEYHOOK m_lpfnAccelerometerKeyHook; + bool m_Touch; LPCWSTR m_menu; CUSTOM_WND_PROC m_wndproc; From c202671636aecdb7c13c3360a817d16ff0644d08 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 15 Oct 2012 17:31:25 +0800 Subject: [PATCH 38/64] Update to latest generated bindings. --- scripting/javascript/bindings/generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripting/javascript/bindings/generated b/scripting/javascript/bindings/generated index 24ab57efad..79337ba58c 160000 --- a/scripting/javascript/bindings/generated +++ b/scripting/javascript/bindings/generated @@ -1 +1 @@ -Subproject commit 24ab57efadfde067887981d11aef072f5f6cb624 +Subproject commit 79337ba58c9b43e603a0ec41db6cdb968d7284f2 From deed3ddc3377c80d5a22525ee428cfdcb7c02c4a Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 15 Oct 2012 18:50:46 +0800 Subject: [PATCH 40/64] Updated AppDelegate of SampleGame for iOS port. --- samples/SimpleGame/Classes/AppDelegate.cpp | 31 +++++-------------- .../SimpleGame/Classes/HelloWorldScene.cpp | 5 +-- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/samples/SimpleGame/Classes/AppDelegate.cpp b/samples/SimpleGame/Classes/AppDelegate.cpp index e810c9fa23..664d791f25 100644 --- a/samples/SimpleGame/Classes/AppDelegate.cpp +++ b/samples/SimpleGame/Classes/AppDelegate.cpp @@ -18,37 +18,20 @@ bool AppDelegate::applicationDidFinishLaunching() { pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); - TargetPlatform target = getTargetPlatform(); + CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize(); + CCSize designSize = CCSizeMake(480, 320); - if (target == kTargetIpad) + if (screenSize.height > 320) { - // ipad - CCFileUtils::sharedFileUtils()->setResourceDirectory("hd"); - - // don't enable retina because we don't have ipad hd resource - CCEGLView::sharedOpenGLView()->setDesignResolutionSize(960, 640, kResolutionNoBorder); + pDirector->setContentScaleFactor(640.0f/designSize.height); } - else if (target == kTargetIphone) - { - if (CCDirector::sharedDirector()->enableRetinaDisplay(true)) - { - // well, it's a iPhone 4, iPhone 4S or iPhone 5 - CCFileUtils::sharedFileUtils()->setResourceDirectory("hd"); - } - else - { - // iPhone 3GS and before, with 480x320 resolution - CCFileUtils::sharedFileUtils()->setResourceDirectory("sd"); - } - } - else + else { - // android, windows, blackberry, linux or mac - // use 960*640 resources as design resolution size CCFileUtils::sharedFileUtils()->setResourceDirectory("sd"); - CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionNoBorder); + pDirector->setContentScaleFactor(320.0f/designSize.height); } + CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder); // turn on display FPS pDirector->setDisplayStats(true); diff --git a/samples/SimpleGame/Classes/HelloWorldScene.cpp b/samples/SimpleGame/Classes/HelloWorldScene.cpp index 50708b2e56..cafabb69d1 100755 --- a/samples/SimpleGame/Classes/HelloWorldScene.cpp +++ b/samples/SimpleGame/Classes/HelloWorldScene.cpp @@ -199,8 +199,9 @@ void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event) // Set up initial location of projectile CCSize winSize = CCDirector::sharedDirector()->getVisibleSize(); + CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CCSprite *projectile = CCSprite::create("Projectile.png", CCRectMake(0, 0, 20, 20)); - projectile->setPosition( ccp(20, winSize.height/2) ); + projectile->setPosition( ccp(origin.x+20, origin.y+winSize.height/2) ); // Determinie offset of location to projectile float offX = location.x - projectile->getPosition().x; @@ -213,7 +214,7 @@ void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event) this->addChild(projectile); // Determine where we wish to shoot the projectile to - float realX = winSize.width + (projectile->getContentSize().width/2); + float realX = origin.x+winSize.width + (projectile->getContentSize().width/2); float ratio = offY / offX; float realY = (realX * ratio) + projectile->getPosition().y; CCPoint realDest = ccp(realX, realY); From 5780f0aabddaa4916fc3432efe41b40341c47c74 Mon Sep 17 00:00:00 2001 From: folecr Date: Mon, 15 Oct 2012 13:23:44 -0700 Subject: [PATCH 41/64] Diff with origin/master * rather than the default - HEAD --- .../jenkins_scripts/mac/android/generate-js-cxx-bindings.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh index fa0948963d..ed93280326 100755 --- a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh +++ b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh @@ -69,10 +69,10 @@ gitcmd_GEN="git --git-dir=$GENERATED_GITDIR --work-tree=$GENERATED_WORKTREE" ${gitcmd_GEN} status echo -echo Diffing... +echo Comparing with origin/master ... echo -${gitcmd_GEN} diff --stat --exit-code +${gitcmd_GEN} diff --stat --exit-code origin/master DIFF_RETVAL=$? if [ $DIFF_RETVAL -eq 0 ] @@ -84,7 +84,7 @@ then exit 0 else echo - echo "Generated files differ from the version checked in to the index. Continuing." + echo "Generated files differ from origin/master. Continuing." echo fi From 93b5667ffea6cb7e6bf79744b342c238d28bc8ca Mon Sep 17 00:00:00 2001 From: folecr Date: Mon, 15 Oct 2012 14:27:54 -0700 Subject: [PATCH 42/64] Exit on error except in the one case where a non-zero return value is expected --- .../mac/android/generate-js-cxx-bindings.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh index ed93280326..8979fd2561 100755 --- a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh +++ b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh @@ -24,6 +24,9 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" COCOS2DX_ROOT="$DIR"/../../../.. +# Exit on error +set -e + # 1. Generate JS bindings COCOS2DX_ROOT="$COCOS2DX_ROOT" /bin/bash ../../../tojs/genbindings.sh @@ -72,6 +75,9 @@ echo echo Comparing with origin/master ... echo +# Don't exit on non-zero return value +set +e + ${gitcmd_GEN} diff --stat --exit-code origin/master DIFF_RETVAL=$? @@ -88,6 +94,9 @@ else echo fi +# Exit on error +set -e + # 3. In JSBindings repo, Check out a branch named "autogeneratedbindings" and commit the auto generated bindings to it ${gitcmd_GEN} add --verbose README cocos2dx.cpp cocos2dx.hpp cocos2dxapi.js ${gitcmd_GEN} checkout origin/master -b "$GENERATED_BRANCH" From 689ceec7801fb81a49088c9f9184319d984090b6 Mon Sep 17 00:00:00 2001 From: folecr Date: Mon, 15 Oct 2012 15:12:17 -0700 Subject: [PATCH 43/64] Generate pull requests * Commit changes to generated branch of cocos2d-x repo instead of gles20 * Generate pull request from the generated branch to the specified base --- .../mac/android/generate-js-cxx-bindings.sh | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh index 8979fd2561..74f3dd7c7d 100755 --- a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh +++ b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh @@ -17,13 +17,23 @@ # # For automatically pushing changes: # -# * REMOTE_COCOS2DX_REPOSITORY # * REMOTE_AUTOGEN_BINDINGS_REPOSITORY -# * Ensure you have ssh access to above repositories +# * REMOTE_COCOS2DX_REPOSITORY +# * Note : Ensure you have commit access to above repositories +# * COCOS2DX_PULL_BASE +# * hub +# * see http://defunkt.io/hub/ +# * Ensure that hub has an OAuth token to REMOTE_COCOS2DX_REPOSITORY +# * see http://defunkt.io/hub/hub.1.html#CONFIGURATION DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" COCOS2DX_ROOT="$DIR"/../../../.. +if [ -z "${HUB+aaa}" ]; then +# ... if HUB is not set, use "$HOME/bin/hub" + HUB="$HOME/bin/hub" +fi + # Exit on error set -e @@ -130,6 +140,22 @@ git checkout origin/gles20 -b "$COCOS_BRANCH" git commit -m "$COMMITTAG : updating submodule reference to latest autogenerated bindings" # 6. In Cocos2D-X repo, Push the commit with updated submodule to "gles20" of the cocos2d-x repository -git push "$REMOTE_COCOS2DX_REPOSITORY" "$COCOS_BRANCH":gles20 +git push "$REMOTE_COCOS2DX_REPOSITORY" "$COCOS_BRANCH" + +if [ -z "${COCOS2DX_PULL_BASE+aaa}" ]; then + echo + echo Environment variable is not set COCOS2DX_PULL_BASE + echo This script will NOT automatically generate pull requests + echo unless this variable is set. + echo + echo Exiting with success. + echo +# example +# COCOS2DX_PULL_BASE="cocos2d/cocos2d-x:gles20" + exit 0 +fi + +# 7. +${HUB} pull-request "$COMMITTAG : updating submodule reference to latest autogenerated bindings" -b "$COCOS2DX_PULL_BASE" -h "$COCOS_BRANCH" popd From ae90c096669e35b08cf8abcf96cd11612748fe1c Mon Sep 17 00:00:00 2001 From: folecr Date: Mon, 15 Oct 2012 15:36:56 -0700 Subject: [PATCH 44/64] Fix order of git operations --- tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh index 74f3dd7c7d..372a2c1548 100755 --- a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh +++ b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh @@ -108,8 +108,8 @@ fi set -e # 3. In JSBindings repo, Check out a branch named "autogeneratedbindings" and commit the auto generated bindings to it -${gitcmd_GEN} add --verbose README cocos2dx.cpp cocos2dx.hpp cocos2dxapi.js ${gitcmd_GEN} checkout origin/master -b "$GENERATED_BRANCH" +${gitcmd_GEN} add --verbose README cocos2dx.cpp cocos2dx.hpp cocos2dxapi.js ${gitcmd_GEN} commit --verbose -m "$COMMITTAG : autogenerated bindings" # 4. In JSBindings repo, Push the commit with generated bindings to "master" of the auto generated bindings repository From b109c75ceffb4fbcf11481f7bb795cdb9660518f Mon Sep 17 00:00:00 2001 From: folecr Date: Mon, 15 Oct 2012 16:26:01 -0700 Subject: [PATCH 45/64] cd to submodule directory for git operations on submodule * instead of using the --git-dir and --git-worktree options * cd-ing to the submodule directory seems to behave differently * ... and more reliably --- .../mac/android/generate-js-cxx-bindings.sh | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh index 372a2c1548..c4587bd103 100755 --- a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh +++ b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh @@ -71,15 +71,14 @@ ELAPSEDSECS=`date +%s` echo Using "$ELAPSEDSECS" in the branch names for pseudo-uniqueness GENERATED_BRANCH=autogeneratedbindings_"$ELAPSEDSECS" -GENERATED_GITDIR="$COCOS2DX_ROOT"/.git/modules/scripting/javascript/bindings/generated GENERATED_WORKTREE="$COCOS2DX_ROOT"/scripting/javascript/bindings/generated -# git command shortcut -gitcmd_GEN="git --git-dir=$GENERATED_GITDIR --work-tree=$GENERATED_WORKTREE" - # 2. In JSBindings repo, Check if there are any files that are different from the index + +pushd "$GENERATED_WORKTREE" + # Run status to record the output in the log -${gitcmd_GEN} status +git status echo echo Comparing with origin/master ... @@ -88,7 +87,7 @@ echo # Don't exit on non-zero return value set +e -${gitcmd_GEN} diff --stat --exit-code origin/master +git diff --stat --exit-code origin/master DIFF_RETVAL=$? if [ $DIFF_RETVAL -eq 0 ] @@ -108,12 +107,14 @@ fi set -e # 3. In JSBindings repo, Check out a branch named "autogeneratedbindings" and commit the auto generated bindings to it -${gitcmd_GEN} checkout origin/master -b "$GENERATED_BRANCH" -${gitcmd_GEN} add --verbose README cocos2dx.cpp cocos2dx.hpp cocos2dxapi.js -${gitcmd_GEN} commit --verbose -m "$COMMITTAG : autogenerated bindings" +git checkout origin/master -b "$GENERATED_BRANCH" +git add --verbose README cocos2dx.cpp cocos2dx.hpp cocos2dxapi.js +git commit --verbose -m "$COMMITTAG : autogenerated bindings" # 4. In JSBindings repo, Push the commit with generated bindings to "master" of the auto generated bindings repository -${gitcmd_GEN} push --verbose "$REMOTE_AUTOGEN_BINDINGS_REPOSITORY" "$GENERATED_BRANCH":master +git push --verbose "$REMOTE_AUTOGEN_BINDINGS_REPOSITORY" "$GENERATED_BRANCH":master + +popd if [ -z "${REMOTE_COCOS2DX_REPOSITORY+aaa}" ]; then echo From a22c84d3d131f29c3c698240148f5b395aa1c898 Mon Sep 17 00:00:00 2001 From: folecr Date: Mon, 15 Oct 2012 16:30:03 -0700 Subject: [PATCH 46/64] Update examples and documentation --- .../mac/android/generate-js-cxx-bindings.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh index c4587bd103..80d97dc601 100755 --- a/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh +++ b/tools/jenkins_scripts/mac/android/generate-js-cxx-bindings.sh @@ -49,12 +49,12 @@ if [ -z "${REMOTE_AUTOGEN_BINDINGS_REPOSITORY+aaa}" ]; then echo Environment variable must be set REMOTE_AUTOGEN_BINDINGS_REPOSITORY echo This script expects to automatically push changes echo to this repo + echo example + echo REMOTE_AUTOGEN_BINDINGS_REPOSITORY=\"git@github.com:folecr/cocos2dx-autogen-bindings.git\" + echo REMOTE_AUTOGEN_BINDINGS_REPOSITORY=\"\$HOME/test/cocos2dx-autogen-bindings\" echo echo Exiting with failure. echo -# example -# REMOTE_AUTOGEN_BINDINGS_REPOSITORY="git@github.com:folecr/cocos2dx-autogen-bindings.git" -# REMOTE_AUTOGEN_BINDINGS_REPOSITORY="$HOME/test/cocos2dx-autogen-bindings" exit 1 fi @@ -121,12 +121,12 @@ if [ -z "${REMOTE_COCOS2DX_REPOSITORY+aaa}" ]; then echo Environment variable is not set REMOTE_COCOS2DX_REPOSITORY echo This script will NOT automatically push changes echo unless this variable is set. + echo example + echo REMOTE_COCOS2DX_REPOSITORY=\"git@github.com:cocos2d/cocos2d-x.git\" + echo REMOTE_COCOS2DX_REPOSITORY=\"\$HOME/test/cocos2d-x\" echo echo Exiting with success. echo -# example -# REMOTE_COCOS2DX_REPOSITORY="git@github.com:cocos2d/cocos2d-x.git" -# REMOTE_COCOS2DX_REPOSITORY="$HOME/test/cocos2d-x" exit 0 fi @@ -148,11 +148,12 @@ if [ -z "${COCOS2DX_PULL_BASE+aaa}" ]; then echo Environment variable is not set COCOS2DX_PULL_BASE echo This script will NOT automatically generate pull requests echo unless this variable is set. + echo example + echo COCOS2DX_PULL_BASE=\"cocos2d/cocos2d-x:gles20\" + echo COCOS2DX_PULL_BASE=\"username/repository:branch\" echo echo Exiting with success. echo -# example -# COCOS2DX_PULL_BASE="cocos2d/cocos2d-x:gles20" exit 0 fi From fb657f674de9918558dcdef7a52dcb38b6ab1d1f Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 16 Oct 2012 11:31:04 +0800 Subject: [PATCH 47/64] fixed #1510: Application will freeze when 'numberOfCellsInTableView' returns zero. --- extensions/GUI/CCScrollView/CCTableView.cpp | 59 ++++++++++++++------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/extensions/GUI/CCScrollView/CCTableView.cpp b/extensions/GUI/CCScrollView/CCTableView.cpp index 35a4cb5310..0e970d1577 100644 --- a/extensions/GUI/CCScrollView/CCTableView.cpp +++ b/extensions/GUI/CCScrollView/CCTableView.cpp @@ -131,15 +131,19 @@ CCTableViewCell *CCTableView::cellAtIndex(unsigned int idx) void CCTableView::updateCellAtIndex(unsigned int idx) { - if (idx == CC_INVALID_INDEX || idx > m_pDataSource->numberOfCellsInTableView(this)-1) + if (idx == CC_INVALID_INDEX) { return; } - - CCTableViewCell *cell; - - cell = this->_cellWithIndex(idx); - if (cell) { + unsigned int uCountOfItems = m_pDataSource->numberOfCellsInTableView(this); + if (0 == uCountOfItems || idx > uCountOfItems-1) + { + return; + } + + CCTableViewCell* cell = this->_cellWithIndex(idx); + if (cell) + { this->_moveCellOutOfSight(cell); } cell = m_pDataSource->tableCellAtIndex(this, idx); @@ -149,11 +153,19 @@ void CCTableView::updateCellAtIndex(unsigned int idx) void CCTableView::insertCellAtIndex(unsigned int idx) { - if (idx == CC_INVALID_INDEX || idx > m_pDataSource->numberOfCellsInTableView(this)-1) { + if (idx == CC_INVALID_INDEX) + { return; } - CCTableViewCell *cell; - int newIdx; + + unsigned int uCountOfItems = m_pDataSource->numberOfCellsInTableView(this); + if (0 == uCountOfItems || idx > uCountOfItems-1) + { + return; + } + + CCTableViewCell* cell = NULL; + int newIdx = 0; cell = (CCTableViewCell*)m_pCellsUsed->objectWithObjectID(idx); if (cell) @@ -178,12 +190,19 @@ void CCTableView::insertCellAtIndex(unsigned int idx) void CCTableView::removeCellAtIndex(unsigned int idx) { - if (idx == CC_INVALID_INDEX || idx > m_pDataSource->numberOfCellsInTableView(this)-1) { + if (idx == CC_INVALID_INDEX) + { return; } - CCTableViewCell *cell; - unsigned int newIdx; + unsigned int uCountOfItems = m_pDataSource->numberOfCellsInTableView(this); + if (0 == uCountOfItems || idx > uCountOfItems-1) + { + return; + } + + CCTableViewCell* cell = NULL; + unsigned int newIdx = 0; cell = this->_cellWithIndex(idx); if (!cell) { @@ -362,15 +381,19 @@ void CCTableView::_setIndexForCell(unsigned int index, CCTableViewCell *cell) void CCTableView::scrollViewDidScroll(CCScrollView* view) { - unsigned int startIdx = 0, endIdx = 0, idx = 0, maxIdx = 0; - CCPoint offset; + unsigned int uCountOfItems = m_pDataSource->numberOfCellsInTableView(this); + if (0 == uCountOfItems) + { + return; + } - offset = ccpMult(this->getContentOffset(), -1); - maxIdx = MAX(m_pDataSource->numberOfCellsInTableView(this)-1, 0); - + unsigned int startIdx = 0, endIdx = 0, idx = 0, maxIdx = 0; + CCPoint offset = ccpMult(this->getContentOffset(), -1); + maxIdx = MAX(uCountOfItems-1, 0); const CCSize cellSize = m_pDataSource->cellSizeForTable(this); - if (m_eVordering == kCCTableViewFillTopDown) { + if (m_eVordering == kCCTableViewFillTopDown) + { offset.y = offset.y + m_tViewSize.height/this->getContainer()->getScaleY() - cellSize.height; } startIdx = this->_indexFromOffset(offset); From cc8b2556a9f7719156aa5419fa04e9687f3acdb5 Mon Sep 17 00:00:00 2001 From: johnangel Date: Tue, 16 Oct 2012 08:33:25 +0200 Subject: [PATCH 48/64] Revert accidentally deleted submodule --- scripting/javascript/bindings/generated | 1 + 1 file changed, 1 insertion(+) create mode 160000 scripting/javascript/bindings/generated diff --git a/scripting/javascript/bindings/generated b/scripting/javascript/bindings/generated new file mode 160000 index 0000000000..bb14056784 --- /dev/null +++ b/scripting/javascript/bindings/generated @@ -0,0 +1 @@ +Subproject commit bb14056784ea0d3ab3f30ae5a86c1bd3ad483703 From bb6a2c58de62dbb2a5744a042d90f78f2ebb0765 Mon Sep 17 00:00:00 2001 From: wenbin1989 Date: Tue, 16 Oct 2012 16:10:14 +0800 Subject: [PATCH 49/64] fix getDeviceModel bug in android CocosDenshion deviceModel must be used before release, otherwise it will cause garbled character when getDeviceModel sometimes. --- CocosDenshion/android/SimpleAudioEngine.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CocosDenshion/android/SimpleAudioEngine.cpp b/CocosDenshion/android/SimpleAudioEngine.cpp index 91d6bbfa5d..0949f997ed 100644 --- a/CocosDenshion/android/SimpleAudioEngine.cpp +++ b/CocosDenshion/android/SimpleAudioEngine.cpp @@ -155,16 +155,17 @@ SimpleAudioEngine::SimpleAudioEngine() methodInfo.env->DeleteLocalRef(methodInfo.classID); const char* deviceModel = methodInfo.env->GetStringUTFChars(jstr, NULL); - methodInfo.env->ReleaseStringUTFChars(jstr, deviceModel); - methodInfo.env->DeleteLocalRef(jstr); - + LOGD(deviceModel); - + if (strcmp(I9100_MODEL, deviceModel) == 0) { LOGD("i9100 model\nSwitch to OpenSLES"); s_bI9100 = true; } + + methodInfo.env->ReleaseStringUTFChars(jstr, deviceModel); + methodInfo.env->DeleteLocalRef(jstr); } SimpleAudioEngine::~SimpleAudioEngine() From 5cfff102addac0856d3df6839c166b448147e55f Mon Sep 17 00:00:00 2001 From: wenbin1989 Date: Tue, 16 Oct 2012 16:20:41 +0800 Subject: [PATCH 50/64] fix bug in android CocosDenshion the method called by JNI is moved from Cocos2dxActivity.java to Cocos2dxHelper.java. --- CocosDenshion/android/opensl/OpenSLEngine.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CocosDenshion/android/opensl/OpenSLEngine.cpp b/CocosDenshion/android/opensl/OpenSLEngine.cpp index cf5ce66160..8495395de2 100644 --- a/CocosDenshion/android/opensl/OpenSLEngine.cpp +++ b/CocosDenshion/android/opensl/OpenSLEngine.cpp @@ -18,7 +18,7 @@ OpenSLEngine::~OpenSLEngine() /********************************************************************************** * jni **********************************************************************************/ -#define CLASS_NAME "org/cocos2dx/lib/Cocos2dxActivity" +#define CLASS_NAME "org/cocos2dx/lib/Cocos2dxHelper" typedef struct JniMethodInfo_ { @@ -672,4 +672,4 @@ float OpenSLEngine::getEffectsVolume() { float volume = (m_effectVolume - MIN_VOLUME_MILLIBEL) / (1.0f * RANGE_VOLUME_MILLIBEL); return volume; -} \ No newline at end of file +} From b51ff47ed7b7b8ca66ae4f2786c911648824b724 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 16 Oct 2012 18:24:00 +0800 Subject: [PATCH 51/64] Updated mozjs.lib and mozjs.dll for win32 port. Built with Release mode. --- .../javascript/spidermonkey-win32/lib/mozjs.dll.REMOVED.git-id | 2 +- .../javascript/spidermonkey-win32/lib/mozjs.lib.REMOVED.git-id | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripting/javascript/spidermonkey-win32/lib/mozjs.dll.REMOVED.git-id b/scripting/javascript/spidermonkey-win32/lib/mozjs.dll.REMOVED.git-id index ce19573d07..bd2eb378be 100644 --- a/scripting/javascript/spidermonkey-win32/lib/mozjs.dll.REMOVED.git-id +++ b/scripting/javascript/spidermonkey-win32/lib/mozjs.dll.REMOVED.git-id @@ -1 +1 @@ -a63c014d165a6c8390f07040db1cb55d588edd53 \ No newline at end of file +29c015353614a093d22d1bee3429e9188d368789 \ No newline at end of file diff --git a/scripting/javascript/spidermonkey-win32/lib/mozjs.lib.REMOVED.git-id b/scripting/javascript/spidermonkey-win32/lib/mozjs.lib.REMOVED.git-id index 34063b98d0..4975ee6cb8 100644 --- a/scripting/javascript/spidermonkey-win32/lib/mozjs.lib.REMOVED.git-id +++ b/scripting/javascript/spidermonkey-win32/lib/mozjs.lib.REMOVED.git-id @@ -1 +1 @@ -7fd7d46ae368602d9da448188c2ccdde3d43b984 \ No newline at end of file +8754a55b4cfc1c5e9d997ae3ed037cdfd5943c6c \ No newline at end of file From 054128c5ee0d49d26af66e3cb7e92aeae03afa3d Mon Sep 17 00:00:00 2001 From: johnangel Date: Tue, 16 Oct 2012 18:53:31 +0200 Subject: [PATCH 52/64] Correction for touch and display area --- cocos2dx/platform/win32/CCEGLView.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index 5830b4163b..1b101243d2 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -299,8 +299,8 @@ bool CCEGLView::Create() wszBuf, // Window Title WS_CAPTION | WS_POPUPWINDOW | WS_MINIMIZEBOX, // Defined Window Style 0, 0, // Window Position - 0, // Window Width - 0, // Window Height + 480, // Window Width + 320, // Window Height NULL, // No Parent Window NULL, // No Menu hInstance, // Instance From cd82403638e92e09e93b8a06bbc882d9cd309d07 Mon Sep 17 00:00:00 2001 From: johnangel Date: Tue, 16 Oct 2012 19:02:24 +0200 Subject: [PATCH 53/64] Fix to make MultiTouchTest work properly --- cocos2dx/platform/win32/CCEGLView.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index 1b101243d2..f56797c0af 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -335,7 +335,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) if (m_pDelegate && MK_LBUTTON == wParam) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; - CCPoint pt(point.x, point.y); + CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR()); CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp)) { @@ -356,7 +356,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) if (MK_LBUTTON == wParam && m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; - CCPoint pt(point.x, point.y); + CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR()); int id = 0; pt.x *= m_windowTouchScaleX; pt.y *= m_windowTouchScaleY; @@ -371,7 +371,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) if (m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; - CCPoint pt(point.x, point.y); + CCPoint pt(point.x/CC_CONTENT_SCALE_FACTOR(), point.y/CC_CONTENT_SCALE_FACTOR()); int id = 0; pt.x *= m_windowTouchScaleX; pt.y *= m_windowTouchScaleY; @@ -394,18 +394,22 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) for (UINT i=0; i < cInputs; i++) { TOUCHINPUT ti = pInputs[i]; - CCPoint pt(TOUCH_COORD_TO_PIXEL(ti.x)/CC_CONTENT_SCALE_FACTOR(), TOUCH_COORD_TO_PIXEL(ti.y)/CC_CONTENT_SCALE_FACTOR()); + POINT input; + input.x = TOUCH_COORD_TO_PIXEL(ti.x); + input.y = TOUCH_COORD_TO_PIXEL(ti.y); + ScreenToClient(m_hWnd, &input); + CCPoint pt(input.x/CC_CONTENT_SCALE_FACTOR(), input.y/CC_CONTENT_SCALE_FACTOR()); CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp)) { pt.x *= m_windowTouchScaleX; pt.y *= m_windowTouchScaleY; - if((ti.dwFlags & TOUCHEVENTF_DOWN)!=0) + if (ti.dwFlags & TOUCHEVENTF_DOWN) handleTouchesBegin(1, reinterpret_cast(&ti.dwID), &pt.x, &pt.y); - else if((ti.dwFlags & TOUCHEVENTF_MOVE)!=0) + else if (ti.dwFlags & TOUCHEVENTF_MOVE) handleTouchesMove(1, reinterpret_cast(&ti.dwID), &pt.x, &pt.y); - else if((ti.dwFlags & TOUCHEVENTF_UP)!=0) + else if (ti.dwFlags & TOUCHEVENTF_UP) handleTouchesEnd(1, reinterpret_cast(&ti.dwID), &pt.x, &pt.y); } } From f0e7d5a87b20915e4af14df1d2280c1f82b62e24 Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 17 Oct 2012 09:33:56 +0800 Subject: [PATCH 54/64] Update AUTHORS --- AUTHORS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS b/AUTHORS index e0af625e66..0a0722ea95 100644 --- a/AUTHORS +++ b/AUTHORS @@ -12,6 +12,9 @@ Developers: Rolando Abarca Javascript Binding and testjs + wenbin wang + fix getDeviceModel bug in android CocosDenshion + Horcruxes fix the bug that CCArray::createWithContentsOfFile() may not read file data on iOS From 3f7b79fb080981077f413e0f4d42907665fd2457 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 17 Oct 2012 15:14:34 +0800 Subject: [PATCH 55/64] issue #1511: Rename some static variables. --- cocos2dx/platform/win32/CCEGLView.cpp | 39 ++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index a69a99b4f5..db91542e47 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -47,21 +47,21 @@ typedef WINUSERAPI LPARAM (WINAPI *GetMessageExtraInfoFn)(VOID); typedef WINUSERAPI BOOL (WINAPI *GetTouchInputInfoFn)(_In_ HTOUCHINPUT hTouchInput, _In_ UINT cInputs, __out_ecount(cInputs) PTOUCHINPUT pInputs, _In_ int cbSize); typedef WINUSERAPI BOOL (WINAPI *CloseTouchInputHandleFn)(_In_ HTOUCHINPUT hTouchInput); -RegisterTouchWindowFn RegisterTouchWindowFunction = NULL; -UnregisterTouchWindowFn UnregisterTouchWindowFunction = NULL; -GetMessageExtraInfoFn GetMessageExtraInfoFunction = NULL; -GetTouchInputInfoFn GetTouchInputInfoFunction = NULL; -CloseTouchInputHandleFn CloseTouchInputHandleFunction = NULL; +static RegisterTouchWindowFn s_pfRegisterTouchWindowFunction = NULL; +static UnregisterTouchWindowFn s_pfUnregisterTouchWindowFunction = NULL; +static GetMessageExtraInfoFn s_pfGetMessageExtraInfoFunction = NULL; +static GetTouchInputInfoFn s_pfGetTouchInputInfoFunction = NULL; +static CloseTouchInputHandleFn s_pfCloseTouchInputHandleFunction = NULL; bool CheckTouchSupport() { - RegisterTouchWindowFunction = (RegisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "RegisterTouchWindow"); - UnregisterTouchWindowFunction = (UnregisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "UnregisterTouchWindow"); - GetMessageExtraInfoFunction = (GetMessageExtraInfoFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "GetMessageExtraInfo"); - GetTouchInputInfoFunction = (GetTouchInputInfoFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "GetTouchInputInfo"); - CloseTouchInputHandleFunction = (CloseTouchInputHandleFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "CloseTouchInputHandle"); + s_pfRegisterTouchWindowFunction = (RegisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "RegisterTouchWindow"); + s_pfUnregisterTouchWindowFunction = (UnregisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "UnregisterTouchWindow"); + s_pfGetMessageExtraInfoFunction = (GetMessageExtraInfoFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "GetMessageExtraInfo"); + s_pfGetTouchInputInfoFunction = (GetTouchInputInfoFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "GetTouchInputInfo"); + s_pfCloseTouchInputHandleFunction = (CloseTouchInputHandleFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "CloseTouchInputHandle"); - return (RegisterTouchWindowFunction && UnregisterTouchWindowFunction && GetMessageExtraInfoFunction && GetTouchInputInfoFunction && CloseTouchInputHandleFunction); + return (s_pfRegisterTouchWindowFunction && s_pfUnregisterTouchWindowFunction && s_pfGetMessageExtraInfoFunction && s_pfGetTouchInputInfoFunction && s_pfCloseTouchInputHandleFunction); } #endif /* #if(WINVER >= 0x0601) */ @@ -323,7 +323,7 @@ bool CCEGLView::Create() m_bSupportTouch = CheckTouchSupport(); if(m_bSupportTouch) { - m_bSupportTouch = (RegisterTouchWindowFunction(m_hWnd, 0) != 0); + m_bSupportTouch = (s_pfRegisterTouchWindowFunction(m_hWnd, 0) != 0); } #endif /* #if(WINVER >= 0x0601) */ @@ -339,7 +339,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) case WM_LBUTTONDOWN: #if(WINVER >= 0x0601) // Don't process message generated by Windows Touch - if (m_bSupportTouch && (GetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; + if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(WINVER >= 0x0601) */ if (m_pDelegate && MK_LBUTTON == wParam) @@ -362,7 +362,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) case WM_MOUSEMOVE: #if(WINVER >= 0x0601) // Don't process message generated by Windows Touch - if (m_bSupportTouch && (GetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; + if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(WINVER >= 0x0601) */ if (MK_LBUTTON == wParam && m_bCaptured) { @@ -378,7 +378,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) case WM_LBUTTONUP: #if(WINVER >= 0x0601) // Don't process message generated by Windows Touch - if (m_bSupportTouch && (GetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; + if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(WINVER >= 0x0601) */ if (m_bCaptured) { @@ -401,7 +401,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) PTOUCHINPUT pInputs = new TOUCHINPUT[cInputs]; if (pInputs) { - if (GetTouchInputInfoFunction((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT))) + if (s_pfGetTouchInputInfoFunction((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT))) { for (UINT i=0; i < cInputs; i++) { @@ -429,7 +429,10 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) } delete [] pInputs; } - if (bHandled) CloseTouchInputHandleFunction((HTOUCHINPUT)lParam); + if (bHandled) + { + s_pfCloseTouchInputHandleFunction((HTOUCHINPUT)lParam); + } } break; #endif /* #if(WINVER >= 0x0601) */ @@ -551,7 +554,7 @@ void CCEGLView::end() #if(WINVER >= 0x0601) if(m_bSupportTouch) { - UnregisterTouchWindowFunction(m_hWnd); + s_pfUnregisterTouchWindowFunction(m_hWnd); } #endif /* #if(WINVER >= 0x0601) */ DestroyWindow(m_hWnd); From 249ef92697e3ff67bb20411d1b3d14954f0f8e38 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 17 Oct 2012 15:38:03 +0800 Subject: [PATCH 56/64] fix a bug about wrong touch area for windows. --- cocos2dx/platform/win32/CCEGLView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index db91542e47..ec3442fd6f 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -410,7 +410,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) input.x = TOUCH_COORD_TO_PIXEL(ti.x); input.y = TOUCH_COORD_TO_PIXEL(ti.y); ScreenToClient(m_hWnd, &input); - CCPoint pt(input.x/CC_CONTENT_SCALE_FACTOR(), input.y/CC_CONTENT_SCALE_FACTOR()); + CCPoint pt(input.x, input.y); CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp)) { From 5ab37c86b22fd6c26fb19f5379b8c14653e27688 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 17 Oct 2012 16:50:07 +0800 Subject: [PATCH 57/64] Fix a bug about calculating client area on win32. --- cocos2dx/platform/win32/CCEGLView.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index ec3442fd6f..dcd1fb679a 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -302,8 +302,9 @@ bool CCEGLView::Create() wszBuf, // Window Title WS_CAPTION | WS_POPUPWINDOW | WS_MINIMIZEBOX, // Defined Window Style 0, 0, // Window Position - 100, // Window Width - 100, // Window Height + //TODO: Initializing width with a large value to avoid get a wrong client area by 'GetClientRect'. + 1000, // Window Width + 1000, // Window Height NULL, // No Parent Window NULL, // No Menu hInstance, // Instance @@ -582,6 +583,11 @@ void CCEGLView::setIMEKeyboardState(bool /*bOpen*/) void CCEGLView::setMenuResource(LPCWSTR menu) { m_menu = menu; + if (m_hWnd != NULL) + { + HMENU hMenu = LoadMenu(GetModuleHandle(NULL), menu); + SetMenu(m_hWnd, hMenu); + } } void CCEGLView::setWndProc(CUSTOM_WND_PROC proc) @@ -631,7 +637,7 @@ void CCEGLView::resize(int width, int height) #endif } - AdjustWindowRectEx(&rcClient, GetWindowLong(m_hWnd, GWL_STYLE), false, GetWindowLong(m_hWnd, GWL_EXSTYLE)); + AdjustWindowRectEx(&rcClient, GetWindowLong(m_hWnd, GWL_STYLE), FALSE, GetWindowLong(m_hWnd, GWL_EXSTYLE)); // change width and height SetWindowPos(m_hWnd, 0, 0, 0, width + ptDiff.x, height + ptDiff.y, From 9f7019e48c12b4ce619d4494b3c90491da5fe58f Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 17 Oct 2012 16:52:09 +0800 Subject: [PATCH 58/64] Updated a comment. --- cocos2dx/platform/win32/CCEGLView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index dcd1fb679a..8b5ea9f0b6 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -302,7 +302,7 @@ bool CCEGLView::Create() wszBuf, // Window Title WS_CAPTION | WS_POPUPWINDOW | WS_MINIMIZEBOX, // Defined Window Style 0, 0, // Window Position - //TODO: Initializing width with a large value to avoid get a wrong client area by 'GetClientRect'. + //TODO: Initializing width with a large value to avoid getting a wrong client area by 'GetClientRect' function. 1000, // Window Width 1000, // Window Height NULL, // No Parent Window From c1ab8a6ead29f20226e08f0548b78d93f6788834 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 18 Oct 2012 09:54:24 +0800 Subject: [PATCH 59/64] fixed #1511: Changed '#if(WINVER >= 0x0601)' to '#if(_MSC_VER >= 1600)'. --- cocos2dx/platform/win32/CCEGLView.cpp | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index 8b5ea9f0b6..c28dbbc576 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -35,7 +35,7 @@ THE SOFTWARE. NS_CC_BEGIN -#if(WINVER >= 0x0601) +#if(_MSC_VER >= 1600) // Visual Studio 2010 or higher version. // Windows Touch define #define MOUSEEVENTF_FROMTOUCH 0xFF515700 @@ -64,7 +64,7 @@ bool CheckTouchSupport() return (s_pfRegisterTouchWindowFunction && s_pfUnregisterTouchWindowFunction && s_pfGetMessageExtraInfoFunction && s_pfGetTouchInputInfoFunction && s_pfCloseTouchInputHandleFunction); } -#endif /* #if(WINVER >= 0x0601) */ +#endif /* #if(_MSC_VER >= 1600) */ static void SetupPixelFormat(HDC hDC) { @@ -320,13 +320,13 @@ bool CCEGLView::Create() bRet = true; } while (0); -#if(WINVER >= 0x0601) +#if(_MSC_VER >= 1600) m_bSupportTouch = CheckTouchSupport(); if(m_bSupportTouch) { m_bSupportTouch = (s_pfRegisterTouchWindowFunction(m_hWnd, 0) != 0); } -#endif /* #if(WINVER >= 0x0601) */ +#endif /* #if(_MSC_VER >= 1600) */ return bRet; } @@ -338,10 +338,10 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) switch (message) { case WM_LBUTTONDOWN: -#if(WINVER >= 0x0601) +#if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; -#endif /* #if(WINVER >= 0x0601) */ +#endif /* #if(_MSC_VER >= 1600) */ if (m_pDelegate && MK_LBUTTON == wParam) { @@ -361,10 +361,10 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) break; case WM_MOUSEMOVE: -#if(WINVER >= 0x0601) +#if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; -#endif /* #if(WINVER >= 0x0601) */ +#endif /* #if(_MSC_VER >= 1600) */ if (MK_LBUTTON == wParam && m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; @@ -377,10 +377,10 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) break; case WM_LBUTTONUP: -#if(WINVER >= 0x0601) +#if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; -#endif /* #if(WINVER >= 0x0601) */ +#endif /* #if(_MSC_VER >= 1600) */ if (m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; @@ -394,7 +394,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) m_bCaptured = false; } break; -#if(WINVER >= 0x0601) +#if(_MSC_VER >= 1600) case WM_TOUCH: { BOOL bHandled = FALSE; @@ -436,7 +436,7 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) } } break; -#endif /* #if(WINVER >= 0x0601) */ +#endif /* #if(_MSC_VER >= 1600) */ case WM_SIZE: switch (wParam) { @@ -552,12 +552,12 @@ void CCEGLView::end() { if (m_hWnd) { -#if(WINVER >= 0x0601) +#if(_MSC_VER >= 1600) if(m_bSupportTouch) { s_pfUnregisterTouchWindowFunction(m_hWnd); } -#endif /* #if(WINVER >= 0x0601) */ +#endif /* #if(_MSC_VER >= 1600) */ DestroyWindow(m_hWnd); m_hWnd = NULL; } From bfa7991a9449bc7cf7c19a35f8ab55e07a2a47f0 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 18 Oct 2012 10:15:46 +0800 Subject: [PATCH 60/64] fixed #1466:restore shader when comming to background --- .../TestCpp/Classes/ShaderTest/ShaderTest.cpp | 18 ++++++++++++++++++ .../TestCpp/Classes/ShaderTest/ShaderTest.h | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/samples/TestCpp/Classes/ShaderTest/ShaderTest.cpp b/samples/TestCpp/Classes/ShaderTest/ShaderTest.cpp index ef476077fa..0e8e42e723 100644 --- a/samples/TestCpp/Classes/ShaderTest/ShaderTest.cpp +++ b/samples/TestCpp/Classes/ShaderTest/ShaderTest.cpp @@ -150,6 +150,11 @@ ShaderNode::ShaderNode() { } +ShaderNode::~ShaderNode() +{ + CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, EVNET_COME_TO_FOREGROUND); +} + ShaderNode* ShaderNode::shaderNodeWithVertex(const char *vert, const char *frag) { ShaderNode *node = new ShaderNode(); @@ -161,6 +166,10 @@ ShaderNode* ShaderNode::shaderNodeWithVertex(const char *vert, const char *frag) bool ShaderNode::initWithVertex(const char *vert, const char *frag) { + CCNotificationCenter::sharedNotificationCenter()->addObserver(this, + callfuncO_selector(ShaderNode::listenBackToForeground), + EVNET_COME_TO_FOREGROUND, + NULL); loadShaderVertex(vert, frag); @@ -171,10 +180,19 @@ bool ShaderNode::initWithVertex(const char *vert, const char *frag) setContentSize(CCSizeMake(SIZE_X, SIZE_Y)); setAnchorPoint(ccp(0.5f, 0.5f)); + + m_vertFileName = vert; + m_fragFileName = frag; return true; } +void ShaderNode::listenBackToForeground(CCObject *obj) +{ + this->setShaderProgram(NULL); + loadShaderVertex(m_vertFileName.c_str(), m_fragFileName.c_str()); +} + void ShaderNode::loadShaderVertex(const char *vert, const char *frag) { CCGLProgram *shader = new CCGLProgram(); diff --git a/samples/TestCpp/Classes/ShaderTest/ShaderTest.h b/samples/TestCpp/Classes/ShaderTest/ShaderTest.h index 22bfdea063..d6cdb0eab0 100644 --- a/samples/TestCpp/Classes/ShaderTest/ShaderTest.h +++ b/samples/TestCpp/Classes/ShaderTest/ShaderTest.h @@ -114,9 +114,11 @@ class ShaderNode : public CCNode { public: ShaderNode(); + ~ShaderNode(); bool initWithVertex(const char *vert, const char *frag); void loadShaderVertex(const char *vert, const char *frag); + void listenBackToForeground(CCObject *obj); virtual void update(float dt); virtual void setPosition(const CCPoint &newPosition); @@ -130,6 +132,8 @@ private: ccVertex2F m_resolution; float m_time; GLuint m_uniformCenter, m_uniformResolution, m_uniformTime; + std::string m_vertFileName; + std::string m_fragFileName; }; class ShaderTestScene : public TestScene From b6426f01ff6eeff6e8bea5090b43ee82594d7b5c Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 18 Oct 2012 10:39:56 +0800 Subject: [PATCH 61/64] fixed #1466:restore shader when comming to background --- .../TestCpp/Classes/ShaderTest/ShaderTest.cpp | 79 ++++++++++++------- 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/samples/TestCpp/Classes/ShaderTest/ShaderTest.cpp b/samples/TestCpp/Classes/ShaderTest/ShaderTest.cpp index 0e8e42e723..0b7350f0fd 100644 --- a/samples/TestCpp/Classes/ShaderTest/ShaderTest.cpp +++ b/samples/TestCpp/Classes/ShaderTest/ShaderTest.cpp @@ -456,9 +456,12 @@ std::string ShaderPlasma::subtitle() class SpriteBlur : public CCSprite { public: + ~SpriteBlur(); void setBlurSize(float f); bool initWithTexture(CCTexture2D* texture, const CCRect& rect); void draw(); + void initProgram(); + void listenBackToForeground(CCObject *obj); static SpriteBlur* create(const char *pszFileName); @@ -469,6 +472,11 @@ public: GLuint subLocation; }; +SpriteBlur::~SpriteBlur() +{ + CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, EVNET_COME_TO_FOREGROUND); +} + SpriteBlur* SpriteBlur::create(const char *pszFileName) { SpriteBlur* pRet = new SpriteBlur(); @@ -484,48 +492,65 @@ SpriteBlur* SpriteBlur::create(const char *pszFileName) return pRet; } +void SpriteBlur::listenBackToForeground(CCObject *obj) +{ + setShaderProgram(NULL); + initProgram(); +} + bool SpriteBlur::initWithTexture(CCTexture2D* texture, const CCRect& rect) { if( CCSprite::initWithTexture(texture, rect) ) { + CCNotificationCenter::sharedNotificationCenter()->addObserver(this, + callfuncO_selector(ShaderNode::listenBackToForeground), + EVNET_COME_TO_FOREGROUND, + NULL); + CCSize s = getTexture()->getContentSizeInPixels(); blur_ = ccp(1/s.width, 1/s.height); sub_[0] = sub_[1] = sub_[2] = sub_[3] = 0; - GLchar * fragSource = (GLchar*) CCString::createWithContentsOfFile( - CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("Shaders/example_Blur.fsh"))->getCString(); - CCGLProgram* pProgram = new CCGLProgram(); - pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_vert, fragSource); - setShaderProgram(pProgram); - pProgram->release(); - - CHECK_GL_ERROR_DEBUG(); - - getShaderProgram()->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position); - getShaderProgram()->addAttribute(kCCAttributeNameColor, kCCVertexAttrib_Color); - getShaderProgram()->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords); - - CHECK_GL_ERROR_DEBUG(); - - getShaderProgram()->link(); - - CHECK_GL_ERROR_DEBUG(); - - getShaderProgram()->updateUniforms(); - - CHECK_GL_ERROR_DEBUG(); - - subLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "substract"); - blurLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "blurSize"); - - CHECK_GL_ERROR_DEBUG(); + this->initProgram(); + return true; } return false; } +void SpriteBlur::initProgram() +{ + GLchar * fragSource = (GLchar*) CCString::createWithContentsOfFile( + CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("Shaders/example_Blur.fsh"))->getCString(); + CCGLProgram* pProgram = new CCGLProgram(); + pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_vert, fragSource); + setShaderProgram(pProgram); + pProgram->release(); + + CHECK_GL_ERROR_DEBUG(); + + getShaderProgram()->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position); + getShaderProgram()->addAttribute(kCCAttributeNameColor, kCCVertexAttrib_Color); + getShaderProgram()->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords); + + CHECK_GL_ERROR_DEBUG(); + + getShaderProgram()->link(); + + CHECK_GL_ERROR_DEBUG(); + + getShaderProgram()->updateUniforms(); + + CHECK_GL_ERROR_DEBUG(); + + subLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "substract"); + blurLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "blurSize"); + + CHECK_GL_ERROR_DEBUG(); +} + void SpriteBlur::draw() { ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex ); From 501ceb21ebe2fe3f792ddb3f4b01157a9969984c Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 18 Oct 2012 11:00:44 +0800 Subject: [PATCH 62/64] fixed #1466:restore shader when comming to background --- samples/TestCpp/Classes/ShaderTest/ShaderTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/TestCpp/Classes/ShaderTest/ShaderTest.cpp b/samples/TestCpp/Classes/ShaderTest/ShaderTest.cpp index 0b7350f0fd..565fecf34f 100644 --- a/samples/TestCpp/Classes/ShaderTest/ShaderTest.cpp +++ b/samples/TestCpp/Classes/ShaderTest/ShaderTest.cpp @@ -503,7 +503,7 @@ bool SpriteBlur::initWithTexture(CCTexture2D* texture, const CCRect& rect) if( CCSprite::initWithTexture(texture, rect) ) { CCNotificationCenter::sharedNotificationCenter()->addObserver(this, - callfuncO_selector(ShaderNode::listenBackToForeground), + callfuncO_selector(SpriteBlur::listenBackToForeground), EVNET_COME_TO_FOREGROUND, NULL); @@ -523,7 +523,7 @@ bool SpriteBlur::initWithTexture(CCTexture2D* texture, const CCRect& rect) void SpriteBlur::initProgram() { GLchar * fragSource = (GLchar*) CCString::createWithContentsOfFile( - CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("Shaders/example_Blur.fsh"))->getCString(); + CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("Shaders/example_Blur.fsh"))->getCString(); CCGLProgram* pProgram = new CCGLProgram(); pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_vert, fragSource); setShaderProgram(pProgram); From 29a63a3b0fd73b1d86368637960516e249dc0b93 Mon Sep 17 00:00:00 2001 From: wenbin1989 Date: Thu, 18 Oct 2012 14:36:49 +0800 Subject: [PATCH 63/64] Fix stack overflow in CCLog --- cocos2dx/platform/android/CCCommon.cpp | 2 +- cocos2dx/platform/blackberry/CCCommon.cpp | 2 +- cocos2dx/platform/ios/CCCommon.mm | 2 +- cocos2dx/platform/mac/CCCommon.mm | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos2dx/platform/android/CCCommon.cpp b/cocos2dx/platform/android/CCCommon.cpp index 594a138e08..4daeff5041 100644 --- a/cocos2dx/platform/android/CCCommon.cpp +++ b/cocos2dx/platform/android/CCCommon.cpp @@ -38,7 +38,7 @@ void CCLog(const char * pszFormat, ...) va_list args; va_start(args, pszFormat); - vsprintf(buf, pszFormat, args); + vsnprintf(buf, MAX_LEN, pszFormat, args); va_end(args); __android_log_print(ANDROID_LOG_DEBUG, "cocos2d-x debug info", buf); diff --git a/cocos2dx/platform/blackberry/CCCommon.cpp b/cocos2dx/platform/blackberry/CCCommon.cpp index e79cf6816c..efa0a7469b 100644 --- a/cocos2dx/platform/blackberry/CCCommon.cpp +++ b/cocos2dx/platform/blackberry/CCCommon.cpp @@ -34,7 +34,7 @@ void CCLog(const char * pszFormat, ...) va_list args; va_start(args, pszFormat); - vsprintf(buf, pszFormat, args); + vsnprintf(buf, MAX_LEN, pszFormat, args); va_end(args); fprintf(stderr, "cocos2d-x debug info %s\n", buf); diff --git a/cocos2dx/platform/ios/CCCommon.mm b/cocos2dx/platform/ios/CCCommon.mm index a2c2a7d17f..a8f5cfd1d1 100644 --- a/cocos2dx/platform/ios/CCCommon.mm +++ b/cocos2dx/platform/ios/CCCommon.mm @@ -38,7 +38,7 @@ void CCLog(const char * pszFormat, ...) va_list ap; va_start(ap, pszFormat); - vsprintf(szBuf, pszFormat, ap); + vsnprintf(szBuf, kMaxLogLen, pszFormat, ap); va_end(ap); printf("%s", szBuf); printf("\n"); diff --git a/cocos2dx/platform/mac/CCCommon.mm b/cocos2dx/platform/mac/CCCommon.mm index 088907e03c..1f431a5f24 100755 --- a/cocos2dx/platform/mac/CCCommon.mm +++ b/cocos2dx/platform/mac/CCCommon.mm @@ -39,7 +39,7 @@ void CCLog(const char * pszFormat, ...) va_list ap; va_start(ap, pszFormat); - vsprintf(szBuf, pszFormat, ap); + vsnprintf(szBuf, kMaxLogLen, pszFormat, ap); va_end(ap); printf("%s", szBuf); printf("\n"); From 549dd92d8e0d970cb6371223914b83a51dff74b5 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 18 Oct 2012 15:53:08 +0800 Subject: [PATCH 64/64] fixed #1516: The font size of labels for displaying FPS,SPF,DrawCount is incorrect in different design resolutions. --- cocos2dx/CCDirector.cpp | 11 ++++++----- cocos2dx/platform/CCEGLViewProtocol.cpp | 6 ++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index c9d112cc71..80c9a6f60b 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -775,20 +775,21 @@ void CCDirector::createStatsLabel() m_pDrawsLabel = new CCLabelAtlas(); m_pDrawsLabel->initWithString("000", "fps_images.png", 12, 32, '.'); */ - m_pFPSLabel = CCLabelTTF::create("00.0", "Arial", 24); + int fontSize = (int)(m_obWinSizeInPoints.height / 320.0f * 24); + m_pFPSLabel = CCLabelTTF::create("00.0", "Arial", fontSize); m_pFPSLabel->retain(); - m_pSPFLabel = CCLabelTTF::create("0.000", "Arial", 24); + m_pSPFLabel = CCLabelTTF::create("0.000", "Arial", fontSize); m_pSPFLabel->retain(); - m_pDrawsLabel = CCLabelTTF::create("000", "Arial", 24); + m_pDrawsLabel = CCLabelTTF::create("000", "Arial", fontSize); m_pDrawsLabel->retain(); //CCTexture2D::setDefaultAlphaPixelFormat(currentFormat); CCSize contentSize = m_pDrawsLabel->getContentSize(); - m_pDrawsLabel->setPosition(ccpAdd(ccp(contentSize.width/2, contentSize.height/2 + 40), CC_DIRECTOR_STATS_POSITION)); + m_pDrawsLabel->setPosition(ccpAdd(ccp(contentSize.width/2, contentSize.height*5/2), CC_DIRECTOR_STATS_POSITION)); contentSize = m_pSPFLabel->getContentSize(); - m_pSPFLabel->setPosition(ccpAdd(ccp(contentSize.width/2, contentSize.height/2 + 20), CC_DIRECTOR_STATS_POSITION)); + m_pSPFLabel->setPosition(ccpAdd(ccp(contentSize.width/2, contentSize.height*3/2), CC_DIRECTOR_STATS_POSITION)); contentSize = m_pFPSLabel->getContentSize(); m_pFPSLabel->setPosition(ccpAdd(ccp(contentSize.width/2, contentSize.height/2), CC_DIRECTOR_STATS_POSITION)); } diff --git a/cocos2dx/platform/CCEGLViewProtocol.cpp b/cocos2dx/platform/CCEGLViewProtocol.cpp index 741c5be938..d1e8d90772 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.cpp +++ b/cocos2dx/platform/CCEGLViewProtocol.cpp @@ -87,12 +87,10 @@ void CCEGLViewProtocol::setDesignResolutionSize(float width, float height, Resol m_eResolutionPolicy = resolutionPolicy; - //setViewPortInPoints(0, 0,m_obScreenSize.width, m_obScreenSize.height); - - // reset director's member variables to fit visible rect - CCDirector::sharedDirector()->createStatsLabel(); + // reset director's member variables to fit visible rect CCDirector::sharedDirector()->m_obWinSizeInPoints = getSize(); CCDirector::sharedDirector()->m_obWinSizeInPixels = CCSizeMake(m_obDesignResolutionSize.width*CC_CONTENT_SCALE_FACTOR(), m_obDesignResolutionSize.height*CC_CONTENT_SCALE_FACTOR()); + CCDirector::sharedDirector()->createStatsLabel(); CCDirector::sharedDirector()->setGLDefaultValues(); }