issue #1515: Adding a zoom function for debugging large resolution (e.g.new ipad) app on desktop.

This commit is contained in:
James Chen 2012-10-18 10:54:19 +08:00
parent c1ab8a6ead
commit 0b101bedd0
3 changed files with 26 additions and 9 deletions

View File

@ -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;

View File

@ -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;
};

View File

@ -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();
}