From 0b101bedd02abe13b9928e07f5c5db7d93bf78b3 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 18 Oct 2012 10:54:19 +0800 Subject: [PATCH] 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(); }