From 0b101bedd02abe13b9928e07f5c5db7d93bf78b3 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 18 Oct 2012 10:54:19 +0800 Subject: [PATCH 1/4] issue #1515: Adding a zoom function for debugging large resolution (e.g.new ipad) app on desktop. --- cocos2dx/platform/win32/CCEGLView.cpp | 23 +++++++++++++++++------ cocos2dx/platform/win32/CCEGLView.h | 7 +++++-- samples/HelloCpp/proj.win32/main.cpp | 5 ++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index c28dbbc576..115da6b749 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -184,8 +184,6 @@ CCEGLView::CCEGLView() , m_lpfnAccelerometerKeyHook(NULL) , m_menu(NULL) , m_wndproc(NULL) -, m_windowWidth(0) -, m_windowHeight(0) , m_windowTouchScaleX(1.0f) , m_windowTouchScaleY(1.0f) , m_bSupportTouch(false) @@ -347,14 +345,14 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; CCPoint pt(point.x, point.y); + pt.x *= m_windowTouchScaleX; + pt.y *= m_windowTouchScaleY; CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp)) { m_bCaptured = true; SetCapture(m_hWnd); int id = 0; - pt.x *= m_windowTouchScaleX; - pt.y *= m_windowTouchScaleY; handleTouchesBegin(1, &id, &pt.x, &pt.y); } } @@ -620,8 +618,6 @@ void CCEGLView::resize(int width, int height) rcClient.right = rcClient.left + width; rcClient.bottom = rcClient.top + height; - m_windowWidth = width; - m_windowHeight = height; const CCSize& frameSize = getFrameSize(); if (frameSize.width > 0) { @@ -644,6 +640,13 @@ void CCEGLView::resize(int width, int height) SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER); } +void CCEGLView::setFrameZoom(float fZoomFactor) +{ + resize(m_obScreenSize.width * fZoomFactor, m_obScreenSize.height * fZoomFactor); + centerWindow(); + CCDirector::sharedDirector()->setProjection(CCDirector::sharedDirector()->getProjection()); +} + void CCEGLView::setFrameSize(float width, float height) { CCEGLViewProtocol::setFrameSize(width, height); @@ -684,6 +687,14 @@ void CCEGLView::centerWindow() SetWindowPos(m_hWnd, 0, offsetX, offsetY, 0, 0, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOZORDER); } +void CCEGLView::setViewPortInPoints(float x , float y , float w , float h) +{ + glViewport((GLint)(x * m_fScaleX / m_windowTouchScaleX + m_obViewPortRect.origin.x / m_windowTouchScaleX), + (GLint)(y * m_fScaleY / m_windowTouchScaleY + m_obViewPortRect.origin.y / m_windowTouchScaleY), + (GLsizei)(w * m_fScaleX / m_windowTouchScaleX), + (GLsizei)(h * m_fScaleY / m_windowTouchScaleY)); +} + CCEGLView* CCEGLView::sharedOpenGLView() { static CCEGLView* s_pEglView = NULL; diff --git a/cocos2dx/platform/win32/CCEGLView.h b/cocos2dx/platform/win32/CCEGLView.h index a33be9e244..53394b5e90 100644 --- a/cocos2dx/platform/win32/CCEGLView.h +++ b/cocos2dx/platform/win32/CCEGLView.h @@ -62,11 +62,16 @@ public: // win32 platform function HWND getHWnd(); void resize(int width, int height); + /* + * Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop. + */ + void setFrameZoom(float fZoomFactor); void centerWindow(); typedef void (*LPFN_ACCELEROMETER_KEYHOOK)( UINT message,WPARAM wParam, LPARAM lParam ); void setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook ); + virtual void setViewPortInPoints(float x , float y , float w , float h); // static function /** @brief get the shared main open gl window @@ -86,8 +91,6 @@ private: LPCWSTR m_menu; CUSTOM_WND_PROC m_wndproc; - int m_windowWidth; - int m_windowHeight; float m_windowTouchScaleX; float m_windowTouchScaleY; }; diff --git a/samples/HelloCpp/proj.win32/main.cpp b/samples/HelloCpp/proj.win32/main.cpp index f61bc4569e..560a587bda 100644 --- a/samples/HelloCpp/proj.win32/main.cpp +++ b/samples/HelloCpp/proj.win32/main.cpp @@ -15,6 +15,9 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, // create the application instance AppDelegate app; CCEGLView* eglView = CCEGLView::sharedOpenGLView(); - eglView->setFrameSize(1136, 640 ); + eglView->setFrameSize(2048, 1536); + // The resolution of ipad3 is very large. In general, PC's resolution is smaller than it. + // So we need to invoke 'setFrameZoom'(only valid on desktop(win32, mac, linux)) to make the window smaller. + eglView->setFrameZoom(0.4f); return CCApplication::sharedApplication()->run(); } From 41c784ec61a60140dcb0513e1679d04ddac254bc Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 18 Oct 2012 11:51:02 +0800 Subject: [PATCH 2/4] issue #1515: [LINUX support] Adding a zoom function for debugging large resolution (e.g.new ipad) app on desktop. --- cocos2dx/platform/linux/CCEGLView.cpp | 34 ++++++++++++++++++++++----- cocos2dx/platform/linux/CCEGLView.h | 11 ++++++--- samples/HelloCpp/proj.linux/main.cpp | 5 +++- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/cocos2dx/platform/linux/CCEGLView.cpp b/cocos2dx/platform/linux/CCEGLView.cpp index c0ba1181bc..961c6de158 100644 --- a/cocos2dx/platform/linux/CCEGLView.cpp +++ b/cocos2dx/platform/linux/CCEGLView.cpp @@ -77,6 +77,7 @@ NS_CC_BEGIN CCEGLView::CCEGLView() : bIsInit(false) +, m_fFrameZoomFactor(1.0f) { } @@ -109,6 +110,7 @@ void charEventHandle(int iCharID,int iCharState) { void mouseButtonEventHandle(int iMouseID,int iMouseState) { if (iMouseID == GLFW_MOUSE_BUTTON_LEFT) { + CCEGLView* pEGLView = CCEGLView::sharedOpenGLView(); //get current mouse pos int x,y; glfwGetMousePos(&x, &y); @@ -120,12 +122,14 @@ void mouseButtonEventHandle(int iMouseID,int iMouseState) { return; } */ + oPoint.x /= pEGLView->m_fFrameZoomFactor; + oPoint.y /= pEGLView->m_fFrameZoomFactor; int id = 0; if (iMouseState == GLFW_PRESS) { - CCEGLView::sharedOpenGLView()->handleTouchesBegin(1, &id, &oPoint.x, &oPoint.y); + pEGLView->handleTouchesBegin(1, &id, &oPoint.x, &oPoint.y); } else if (iMouseState == GLFW_RELEASE) { - CCEGLView::sharedOpenGLView()->handleTouchesEnd(1, &id, &oPoint.x, &oPoint.y); + pEGLView->handleTouchesEnd(1, &id, &oPoint.x, &oPoint.y); } } } @@ -135,10 +139,13 @@ void mousePosEventHandle(int iPosX,int iPosY) { //to test move if (iButtonState == GLFW_PRESS) { - int id = 0; - float x = (float)iPosX; - float y = (float)iPosY; - CCEGLView::sharedOpenGLView()->handleTouchesMove(1, &id, &x, &y); + CCEGLView* pEGLView = CCEGLView::sharedOpenGLView(); + int id = 0; + float x = (float)iPosX; + float y = (float)iPosY; + x /= pEGLView->m_fFrameZoomFactor; + y /= pEGLView->m_fFrameZoomFactor; + pEGLView->handleTouchesMove(1, &id, &x, &y); } } @@ -234,6 +241,21 @@ void CCEGLView::setFrameSize(float width, float height) } } +void CCEGLView::setFrameZoom(float fZoomFactor) +{ + m_fFrameZoomFactor = fZoomFactor; + glfwSetWindowSize(m_obScreenSize.width * fZoomFactor, m_obScreenSize.height * fZoomFactor); + CCDirector::sharedDirector()->setProjection(CCDirector::sharedDirector()->getProjection()); +} + +void CCEGLView::setViewPortInPoints(float x , float y , float w , float h) +{ + glViewport((GLint)(x * m_fScaleX * m_fFrameZoomFactor+ m_obViewPortRect.origin.x * m_fFrameZoomFactor), + (GLint)(y * m_fScaleY * m_fFrameZoomFactor + m_obViewPortRect.origin.y * m_fFrameZoomFactor), + (GLsizei)(w * m_fScaleX * m_fFrameZoomFactor), + (GLsizei)(h * m_fScaleY * m_fFrameZoomFactor)); +} + bool CCEGLView::isOpenGLReady() { return bIsInit; diff --git a/cocos2dx/platform/linux/CCEGLView.h b/cocos2dx/platform/linux/CCEGLView.h index 19a4b4f1dc..18d9e6e26c 100644 --- a/cocos2dx/platform/linux/CCEGLView.h +++ b/cocos2dx/platform/linux/CCEGLView.h @@ -32,6 +32,11 @@ public: * iDepth is not the buffer depth of opengl, it indicate how may bits for a pixel */ virtual void setFrameSize(float width, float height); + virtual void setViewPortInPoints(float x , float y , float w , float h); + /* + * Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop. + */ + void setFrameZoom(float fZoomFactor); virtual bool isOpenGLReady(); virtual void end(); virtual void swapBuffers(); @@ -42,13 +47,13 @@ public: */ static CCEGLView* sharedOpenGLView(); private: - bool initGL(); - void destroyGL(); + bool initGL(); + void destroyGL(); private: - bool m_bCaptured; //store current mouse point for moving, valid if and only if the mouse pressed CCPoint m_mousePoint; bool bIsInit; + float m_fFrameZoomFactor; }; NS_CC_END diff --git a/samples/HelloCpp/proj.linux/main.cpp b/samples/HelloCpp/proj.linux/main.cpp index bb6061e8fe..e85ef17632 100644 --- a/samples/HelloCpp/proj.linux/main.cpp +++ b/samples/HelloCpp/proj.linux/main.cpp @@ -29,6 +29,9 @@ int main(int argc, char **argv) AppDelegate app; CCApplication::sharedApplication()->setResourceRootPath(resourcePath.c_str()); CCEGLView* eglView = CCEGLView::sharedOpenGLView(); - eglView->setFrameSize(960, 640); + eglView->setFrameSize(2048, 1536); + // The resolution of ipad3 is very large. In general, PC's resolution is smaller than it. + // So we need to invoke 'setFrameZoom'(only valid on desktop(win32, mac, linux)) to make the window smaller. + eglView->setFrameZoom(0.4f); return CCApplication::sharedApplication()->run(); } From a5e260dbdbbf69b7baefda4bc971bc519bc5d7ec Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 18 Oct 2012 12:01:30 +0800 Subject: [PATCH 3/4] issue #1515: Refactored some codes for win32 port. --- cocos2dx/platform/win32/CCEGLView.cpp | 37 ++++++++++++--------------- cocos2dx/platform/win32/CCEGLView.h | 3 +-- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/cocos2dx/platform/win32/CCEGLView.cpp b/cocos2dx/platform/win32/CCEGLView.cpp index 115da6b749..cef474d1fe 100644 --- a/cocos2dx/platform/win32/CCEGLView.cpp +++ b/cocos2dx/platform/win32/CCEGLView.cpp @@ -53,7 +53,7 @@ static GetMessageExtraInfoFn s_pfGetMessageExtraInfoFunction = NULL; static GetTouchInputInfoFn s_pfGetTouchInputInfoFunction = NULL; static CloseTouchInputHandleFn s_pfCloseTouchInputHandleFunction = NULL; -bool CheckTouchSupport() +static bool CheckTouchSupport() { s_pfRegisterTouchWindowFunction = (RegisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "RegisterTouchWindow"); s_pfUnregisterTouchWindowFunction = (UnregisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "UnregisterTouchWindow"); @@ -96,7 +96,7 @@ static void SetupPixelFormat(HDC hDC) SetPixelFormat(hDC, pixelFormat, &pfd); } -bool glew_dynamic_binding() +static bool glew_dynamic_binding() { const char *gl_extensions = (const char*)glGetString(GL_EXTENSIONS); @@ -184,8 +184,7 @@ CCEGLView::CCEGLView() , m_lpfnAccelerometerKeyHook(NULL) , m_menu(NULL) , m_wndproc(NULL) -, m_windowTouchScaleX(1.0f) -, m_windowTouchScaleY(1.0f) +, m_fFrameZoomFactor(1.0f) , m_bSupportTouch(false) { strcpy(m_szViewName, "Cocos2dxWin32"); @@ -345,8 +344,8 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; CCPoint pt(point.x, point.y); - pt.x *= m_windowTouchScaleX; - pt.y *= m_windowTouchScaleY; + pt.x /= m_fFrameZoomFactor; + pt.y /= m_fFrameZoomFactor; CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp)) { @@ -368,8 +367,8 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; CCPoint pt(point.x, point.y); int id = 0; - pt.x *= m_windowTouchScaleX; - pt.y *= m_windowTouchScaleY; + pt.x /= m_fFrameZoomFactor; + pt.y /= m_fFrameZoomFactor; handleTouchesMove(1, &id, &pt.x, &pt.y); } break; @@ -384,8 +383,8 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; CCPoint pt(point.x, point.y); int id = 0; - pt.x *= m_windowTouchScaleX; - pt.y *= m_windowTouchScaleY; + pt.x /= m_fFrameZoomFactor; + pt.y /= m_fFrameZoomFactor; handleTouchesEnd(1, &id, &pt.x, &pt.y); ReleaseCapture(); @@ -413,8 +412,8 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 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; + pt.x /= m_fFrameZoomFactor; + pt.y /= m_fFrameZoomFactor; if (ti.dwFlags & TOUCHEVENTF_DOWN) handleTouchesBegin(1, reinterpret_cast(&ti.dwID), &pt.x, &pt.y); @@ -621,14 +620,11 @@ void CCEGLView::resize(int width, int height) const CCSize& frameSize = getFrameSize(); if (frameSize.width > 0) { - 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); + kWindowClassName, frameSize.width, frameSize.height, m_fFrameZoomFactor); SetWindowText(m_hWnd, buff); #endif } @@ -642,6 +638,7 @@ void CCEGLView::resize(int width, int height) void CCEGLView::setFrameZoom(float fZoomFactor) { + m_fFrameZoomFactor = fZoomFactor; resize(m_obScreenSize.width * fZoomFactor, m_obScreenSize.height * fZoomFactor); centerWindow(); CCDirector::sharedDirector()->setProjection(CCDirector::sharedDirector()->getProjection()); @@ -689,10 +686,10 @@ void CCEGLView::centerWindow() void CCEGLView::setViewPortInPoints(float x , float y , float w , float h) { - glViewport((GLint)(x * m_fScaleX / m_windowTouchScaleX + m_obViewPortRect.origin.x / m_windowTouchScaleX), - (GLint)(y * m_fScaleY / m_windowTouchScaleY + m_obViewPortRect.origin.y / m_windowTouchScaleY), - (GLsizei)(w * m_fScaleX / m_windowTouchScaleX), - (GLsizei)(h * m_fScaleY / m_windowTouchScaleY)); + glViewport((GLint)(x * m_fScaleX * m_fFrameZoomFactor + m_obViewPortRect.origin.x * m_fFrameZoomFactor), + (GLint)(y * m_fScaleY * m_fFrameZoomFactor + m_obViewPortRect.origin.y * m_fFrameZoomFactor), + (GLsizei)(w * m_fScaleX * m_fFrameZoomFactor), + (GLsizei)(h * m_fScaleY * m_fFrameZoomFactor)); } CCEGLView* CCEGLView::sharedOpenGLView() diff --git a/cocos2dx/platform/win32/CCEGLView.h b/cocos2dx/platform/win32/CCEGLView.h index 53394b5e90..a7ba9710f2 100644 --- a/cocos2dx/platform/win32/CCEGLView.h +++ b/cocos2dx/platform/win32/CCEGLView.h @@ -91,8 +91,7 @@ private: LPCWSTR m_menu; CUSTOM_WND_PROC m_wndproc; - float m_windowTouchScaleX; - float m_windowTouchScaleY; + float m_fFrameZoomFactor; }; NS_CC_END From f40b6ac4eb244de43a7ae7f85751f2d54320d861 Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 19 Oct 2012 11:33:06 +0800 Subject: [PATCH 4/4] fixed #1515: implement zoom function on mac os --- cocos2dx/platform/mac/CCEGLView.h | 4 ++ cocos2dx/platform/mac/CCEGLView.mm | 12 +++++- cocos2dx/platform/mac/EAGLView.h | 6 +++ cocos2dx/platform/mac/EAGLView.mm | 42 +++++++++++++++---- samples/HelloCpp/proj.mac/AppController.mm | 5 ++- .../HelloCpp.xcodeproj/project.pbxproj | 22 ++++++---- 6 files changed, 72 insertions(+), 19 deletions(-) diff --git a/cocos2dx/platform/mac/CCEGLView.h b/cocos2dx/platform/mac/CCEGLView.h index 10ef42f59d..c0182b8bbd 100755 --- a/cocos2dx/platform/mac/CCEGLView.h +++ b/cocos2dx/platform/mac/CCEGLView.h @@ -45,6 +45,10 @@ public: virtual bool setContentScaleFactor(float contentScaleFactor); virtual void end(); virtual void swapBuffers(void); + /** + * Set opengl view port rectangle with points. + */ + virtual void setViewPortInPoints(float x , float y , float w , float h); virtual void setIMEKeyboardState(bool bOpen); virtual void setMultiTouchMask(bool mask); diff --git a/cocos2dx/platform/mac/CCEGLView.mm b/cocos2dx/platform/mac/CCEGLView.mm index b641fbcd1a..92d22ab021 100755 --- a/cocos2dx/platform/mac/CCEGLView.mm +++ b/cocos2dx/platform/mac/CCEGLView.mm @@ -43,8 +43,6 @@ CCEGLView* CCEGLView::sharedOpenGLView(void) CCEGLView::CCEGLView(void) { - m_obScreenSize.width = m_obDesignResolutionSize.width = [[EAGLView sharedEGLView] getWidth]; - m_obScreenSize.height = m_obDesignResolutionSize.height = [[EAGLView sharedEGLView] getHeight]; } CCEGLView::~CCEGLView(void) @@ -90,6 +88,16 @@ void CCEGLView::setIMEKeyboardState(bool bOpen) } } +void CCEGLView::setViewPortInPoints(float x , float y , float w , float h) +{ + float frameZoomFactor = [[EAGLView sharedEGLView] frameZoomFactor]; + + glViewport((GLint)(x * m_fScaleX * frameZoomFactor + m_obViewPortRect.origin.x * frameZoomFactor), + (GLint)(y * m_fScaleY * frameZoomFactor + m_obViewPortRect.origin.y * frameZoomFactor), + (GLsizei)(w * m_fScaleX * frameZoomFactor), + (GLsizei)(h * m_fScaleY * frameZoomFactor)); +} + void CCEGLView::setMultiTouchMask(bool mask) { //EAGLView *glView = [EAGLView sharedEGLView]; diff --git a/cocos2dx/platform/mac/EAGLView.h b/cocos2dx/platform/mac/EAGLView.h index 1dad10f082..80412ffc31 100755 --- a/cocos2dx/platform/mac/EAGLView.h +++ b/cocos2dx/platform/mac/EAGLView.h @@ -78,6 +78,8 @@ THE SOFTWARE. NSWindow *windowGLView_; NSView *superViewGLView_; NSRect originalWinRect_; // Original size and position + + float frameZoomFactor_; } @property (nonatomic, readwrite, assign) id eventDelegate; @@ -85,6 +87,8 @@ THE SOFTWARE. // whether or not the view is in fullscreen mode @property (nonatomic, readonly) BOOL isFullScreen; +@property (nonatomic, readwrite) float frameZoomFactor; + // initializes the MacGLView with a frame rect and an OpenGL context - (id) initWithFrame:(NSRect)frameRect shareContext:(NSOpenGLContext*)context; @@ -97,6 +101,8 @@ THE SOFTWARE. /** returns the depth format of the view in BPP */ - (NSUInteger) depthFormat; +- (void) setFrameZoomFactor:(float)frameZoomFactor; + // get the view object +(id) sharedEGLView; diff --git a/cocos2dx/platform/mac/EAGLView.mm b/cocos2dx/platform/mac/EAGLView.mm index 98bb6367e1..b10ff34cf6 100755 --- a/cocos2dx/platform/mac/EAGLView.mm +++ b/cocos2dx/platform/mac/EAGLView.mm @@ -38,6 +38,7 @@ THE SOFTWARE. #import "CCIMEDispatcher.h" #import "CCWindow.h" #import "CCEventDispatcher.h" +#import "CCEGLView.h" //USING_NS_CC; @@ -45,7 +46,7 @@ static EAGLView *view; @implementation EAGLView -@synthesize eventDelegate = eventDelegate_, isFullScreen = isFullScreen_; +@synthesize eventDelegate = eventDelegate_, isFullScreen = isFullScreen_, frameZoomFactor=frameZoomFactor_; +(id) sharedEGLView { @@ -83,6 +84,10 @@ static EAGLView *view; // event delegate eventDelegate_ = [CCEventDispatcher sharedDispatcher]; } + + cocos2d::CCEGLView::sharedOpenGLView()->setFrameSize(frameRect.size.width, frameRect.size.height); + + frameZoomFactor_ = 1.0f; view = self; return self; @@ -117,6 +122,29 @@ static EAGLView *view; return 24; } +- (void) setFrameZoomFactor:(float)frameZoomFactor +{ + frameZoomFactor_ = frameZoomFactor; + + NSRect winRect = [[self window] frame]; + NSRect viewRect = [self frame]; + + // compute the margin width and margin height + float diffX = winRect.size.width - viewRect.size.width; + float diffY = winRect.size.height - viewRect.size.height; + + // new window width and height + float newWindowWidth = (int)(viewRect.size.width * frameZoomFactor + diffX); + float newWindowHeight = (int)(viewRect.size.height * frameZoomFactor + diffY); + + // display window in the center of the screen + NSRect screenRect = [[NSScreen mainScreen] frame]; + float originX = (screenRect.size.width - newWindowWidth) / 2; + float originY = (screenRect.size.height - newWindowHeight) / 2; + + [[self window] setFrame:NSMakeRect(originX, originY, newWindowWidth, newWindowHeight) display:true]; +} + - (void) reshape { // We draw on a secondary thread through the display link @@ -289,8 +317,8 @@ static EAGLView *view; float ys[1] = {0.0f}; ids[0] = [theEvent eventNumber]; - xs[0] = x; - ys[0] = y; + xs[0] = x / frameZoomFactor_; + ys[0] = y / frameZoomFactor_; cocos2d::CCDirector::sharedDirector()->getOpenGLView()->handleTouchesBegin(1, ids, xs, ys); } @@ -313,8 +341,8 @@ static EAGLView *view; float ys[1] = {0.0f}; ids[0] = [theEvent eventNumber]; - xs[0] = x; - ys[0] = y; + xs[0] = x / frameZoomFactor_; + ys[0] = y / frameZoomFactor_; cocos2d::CCDirector::sharedDirector()->getOpenGLView()->handleTouchesMove(1, ids, xs, ys); } @@ -332,8 +360,8 @@ static EAGLView *view; float ys[1] = {0.0f}; ids[0] = [theEvent eventNumber]; - xs[0] = x; - ys[0] = y; + xs[0] = x / frameZoomFactor_; + ys[0] = y / frameZoomFactor_; cocos2d::CCDirector::sharedDirector()->getOpenGLView()->handleTouchesEnd(1, ids, xs, ys); } diff --git a/samples/HelloCpp/proj.mac/AppController.mm b/samples/HelloCpp/proj.mac/AppController.mm index 687b81c60b..2f659d780b 100644 --- a/samples/HelloCpp/proj.mac/AppController.mm +++ b/samples/HelloCpp/proj.mac/AppController.mm @@ -36,7 +36,7 @@ static AppDelegate s_sharedApplication; // create the window // note that using NSResizableWindowMask causes the window to be a little // smaller and therefore ipad graphics are not loaded - NSRect rect = NSMakeRect(200, 200, 480, 320); + NSRect rect = NSMakeRect(0, 0, 2048, 1536); window = [[NSWindow alloc] initWithContentRect:rect styleMask:( NSClosableWindowMask | NSTitledWindowMask ) backing:NSBackingStoreBuffered @@ -45,7 +45,6 @@ static AppDelegate s_sharedApplication; // allocate our GL view // (isn't there already a shared EAGLView?) glView = [[EAGLView alloc] initWithFrame:rect]; - [glView initWithFrame:rect]; // set window parameters [window becomeFirstResponder]; @@ -53,6 +52,8 @@ static AppDelegate s_sharedApplication; [window setTitle:@"HelloCpp"]; [window makeKeyAndOrderFront:self]; [window setAcceptsMouseMovedEvents:NO]; + + [glView setFrameZoomFactor:0.4]; cocos2d::CCApplication::sharedApplication()->run(); } diff --git a/samples/HelloCpp/proj.mac/HelloCpp.xcodeproj/project.pbxproj b/samples/HelloCpp/proj.mac/HelloCpp.xcodeproj/project.pbxproj index 85868ca9c1..1a2a8dfcea 100644 --- a/samples/HelloCpp/proj.mac/HelloCpp.xcodeproj/project.pbxproj +++ b/samples/HelloCpp/proj.mac/HelloCpp.xcodeproj/project.pbxproj @@ -7,8 +7,9 @@ objects = { /* Begin PBXBuildFile section */ - 15E102C815D389F1001D70A3 /* iphonehd in Resources */ = {isa = PBXBuildFile; fileRef = 15E102C715D389F1001D70A3 /* iphonehd */; }; - 15E102CA15D389F7001D70A3 /* iphone in Resources */ = {isa = PBXBuildFile; fileRef = 15E102C915D389F7001D70A3 /* iphone */; }; + 1514DA3F163004980095A81C /* ipad in Resources */ = {isa = PBXBuildFile; fileRef = 1514DA3C163004980095A81C /* ipad */; }; + 1514DA40163004980095A81C /* ipadhd in Resources */ = {isa = PBXBuildFile; fileRef = 1514DA3D163004980095A81C /* ipadhd */; }; + 1514DA41163004980095A81C /* iphone in Resources */ = {isa = PBXBuildFile; fileRef = 1514DA3E163004980095A81C /* iphone */; }; 41BC70AD15BF7CCE006A0A6C /* Icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 41BC70AC15BF7CCE006A0A6C /* Icon.icns */; }; 41BC70B715BF7E14006A0A6C /* libcocos2dx.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 41CD6C5C15BF74E5005E6F29 /* libcocos2dx.a */; }; 41CD6C6515BF7574005E6F29 /* AppController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 41CD6C6315BF7574005E6F29 /* AppController.mm */; }; @@ -47,8 +48,10 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 15E102C715D389F1001D70A3 /* iphonehd */ = {isa = PBXFileReference; lastKnownFileType = folder; name = iphonehd; path = ../Resources/iphonehd; sourceTree = ""; }; - 15E102C915D389F7001D70A3 /* iphone */ = {isa = PBXFileReference; lastKnownFileType = folder; name = iphone; path = ../Resources/iphone; sourceTree = ""; }; + 1514DA3C163004980095A81C /* ipad */ = {isa = PBXFileReference; lastKnownFileType = folder; name = ipad; path = ../Resources/ipad; sourceTree = ""; }; + 1514DA3D163004980095A81C /* ipadhd */ = {isa = PBXFileReference; lastKnownFileType = folder; name = ipadhd; path = ../Resources/ipadhd; sourceTree = ""; }; + 1514DA3E163004980095A81C /* iphone */ = {isa = PBXFileReference; lastKnownFileType = folder; name = iphone; path = ../Resources/iphone; sourceTree = ""; }; + 15A6969B1630E63B00D7A229 /* AppMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppMacros.h; path = ../Classes/AppMacros.h; sourceTree = ""; }; 41BC70AC15BF7CCE006A0A6C /* Icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = Icon.icns; sourceTree = ""; }; 41CD6C5115BF748C005E6F29 /* HelloCpp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HelloCpp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 41CD6C5415BF74E5005E6F29 /* cocos2dx.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = cocos2dx.xcodeproj; path = ../../../cocos2dx/proj.mac/cocos2dx.xcodeproj; sourceTree = ""; }; @@ -120,6 +123,7 @@ 41CD6C5D15BF750B005E6F29 /* Classes */ = { isa = PBXGroup; children = ( + 15A6969B1630E63B00D7A229 /* AppMacros.h */, 41CD6C7115BF76FB005E6F29 /* AppDelegate.cpp */, 41CD6C7215BF76FB005E6F29 /* AppDelegate.h */, 41CD6C7315BF76FB005E6F29 /* HelloWorldScene.cpp */, @@ -162,8 +166,9 @@ 41CD6C6115BF7556005E6F29 /* Resources */ = { isa = PBXGroup; children = ( - 15E102C915D389F7001D70A3 /* iphone */, - 15E102C715D389F1001D70A3 /* iphonehd */, + 1514DA3C163004980095A81C /* ipad */, + 1514DA3D163004980095A81C /* ipadhd */, + 1514DA3E163004980095A81C /* iphone */, ); name = Resources; sourceTree = ""; @@ -256,8 +261,9 @@ 41CD6C6E15BF7673005E6F29 /* InfoPlist.strings in Resources */, 41CD6C6F15BF7673005E6F29 /* MainMenu.xib in Resources */, 41BC70AD15BF7CCE006A0A6C /* Icon.icns in Resources */, - 15E102C815D389F1001D70A3 /* iphonehd in Resources */, - 15E102CA15D389F7001D70A3 /* iphone in Resources */, + 1514DA3F163004980095A81C /* ipad in Resources */, + 1514DA40163004980095A81C /* ipadhd in Resources */, + 1514DA41163004980095A81C /* iphone in Resources */, ); runOnlyForDeploymentPostprocessing = 0; };