mirror of https://github.com/axmolengine/axmol.git
Merge branch 'gles20' of https://github.com/dumganhar/cocos2d-x into zoom-scale
This commit is contained in:
commit
986a0a34c0
|
@ -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) {
|
||||
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
|
||||
int id = 0;
|
||||
float x = (float)iPosX;
|
||||
float y = (float)iPosY;
|
||||
CCEGLView::sharedOpenGLView()->handleTouchesMove(1, &id, &x, &y);
|
||||
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;
|
||||
|
|
|
@ -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();
|
||||
|
@ -45,10 +50,10 @@ private:
|
|||
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
|
||||
|
|
|
@ -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,10 +184,7 @@ 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_fFrameZoomFactor(1.0f)
|
||||
, m_bSupportTouch(false)
|
||||
{
|
||||
strcpy(m_szViewName, "Cocos2dxWin32");
|
||||
|
@ -347,14 +344,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_fFrameZoomFactor;
|
||||
pt.y /= m_fFrameZoomFactor;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -370,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;
|
||||
|
@ -386,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();
|
||||
|
@ -415,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<int*>(&ti.dwID), &pt.x, &pt.y);
|
||||
|
@ -620,19 +617,14 @@ 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)
|
||||
{
|
||||
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
|
||||
}
|
||||
|
@ -644,6 +636,14 @@ void CCEGLView::resize(int width, int height)
|
|||
SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER);
|
||||
}
|
||||
|
||||
void CCEGLView::setFrameZoom(float fZoomFactor)
|
||||
{
|
||||
m_fFrameZoomFactor = 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 +684,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_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()
|
||||
{
|
||||
static CCEGLView* s_pEglView = NULL;
|
||||
|
|
|
@ -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,10 +91,7 @@ private:
|
|||
LPCWSTR m_menu;
|
||||
CUSTOM_WND_PROC m_wndproc;
|
||||
|
||||
int m_windowWidth;
|
||||
int m_windowHeight;
|
||||
float m_windowTouchScaleX;
|
||||
float m_windowTouchScaleY;
|
||||
float m_fFrameZoomFactor;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue