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()
|
CCEGLView::CCEGLView()
|
||||||
: bIsInit(false)
|
: bIsInit(false)
|
||||||
|
, m_fFrameZoomFactor(1.0f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +110,7 @@ void charEventHandle(int iCharID,int iCharState) {
|
||||||
|
|
||||||
void mouseButtonEventHandle(int iMouseID,int iMouseState) {
|
void mouseButtonEventHandle(int iMouseID,int iMouseState) {
|
||||||
if (iMouseID == GLFW_MOUSE_BUTTON_LEFT) {
|
if (iMouseID == GLFW_MOUSE_BUTTON_LEFT) {
|
||||||
|
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
|
||||||
//get current mouse pos
|
//get current mouse pos
|
||||||
int x,y;
|
int x,y;
|
||||||
glfwGetMousePos(&x, &y);
|
glfwGetMousePos(&x, &y);
|
||||||
|
@ -120,12 +122,14 @@ void mouseButtonEventHandle(int iMouseID,int iMouseState) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
oPoint.x /= pEGLView->m_fFrameZoomFactor;
|
||||||
|
oPoint.y /= pEGLView->m_fFrameZoomFactor;
|
||||||
int id = 0;
|
int id = 0;
|
||||||
if (iMouseState == GLFW_PRESS) {
|
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) {
|
} 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
|
//to test move
|
||||||
if (iButtonState == GLFW_PRESS) {
|
if (iButtonState == GLFW_PRESS) {
|
||||||
int id = 0;
|
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
|
||||||
float x = (float)iPosX;
|
int id = 0;
|
||||||
float y = (float)iPosY;
|
float x = (float)iPosX;
|
||||||
CCEGLView::sharedOpenGLView()->handleTouchesMove(1, &id, &x, &y);
|
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()
|
bool CCEGLView::isOpenGLReady()
|
||||||
{
|
{
|
||||||
return bIsInit;
|
return bIsInit;
|
||||||
|
|
|
@ -32,6 +32,11 @@ public:
|
||||||
* iDepth is not the buffer depth of opengl, it indicate how may bits for a pixel
|
* 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 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 bool isOpenGLReady();
|
||||||
virtual void end();
|
virtual void end();
|
||||||
virtual void swapBuffers();
|
virtual void swapBuffers();
|
||||||
|
@ -42,13 +47,13 @@ public:
|
||||||
*/
|
*/
|
||||||
static CCEGLView* sharedOpenGLView();
|
static CCEGLView* sharedOpenGLView();
|
||||||
private:
|
private:
|
||||||
bool initGL();
|
bool initGL();
|
||||||
void destroyGL();
|
void destroyGL();
|
||||||
private:
|
private:
|
||||||
bool m_bCaptured;
|
|
||||||
//store current mouse point for moving, valid if and only if the mouse pressed
|
//store current mouse point for moving, valid if and only if the mouse pressed
|
||||||
CCPoint m_mousePoint;
|
CCPoint m_mousePoint;
|
||||||
bool bIsInit;
|
bool bIsInit;
|
||||||
|
float m_fFrameZoomFactor;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -53,7 +53,7 @@ static GetMessageExtraInfoFn s_pfGetMessageExtraInfoFunction = NULL;
|
||||||
static GetTouchInputInfoFn s_pfGetTouchInputInfoFunction = NULL;
|
static GetTouchInputInfoFn s_pfGetTouchInputInfoFunction = NULL;
|
||||||
static CloseTouchInputHandleFn s_pfCloseTouchInputHandleFunction = NULL;
|
static CloseTouchInputHandleFn s_pfCloseTouchInputHandleFunction = NULL;
|
||||||
|
|
||||||
bool CheckTouchSupport()
|
static bool CheckTouchSupport()
|
||||||
{
|
{
|
||||||
s_pfRegisterTouchWindowFunction = (RegisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "RegisterTouchWindow");
|
s_pfRegisterTouchWindowFunction = (RegisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "RegisterTouchWindow");
|
||||||
s_pfUnregisterTouchWindowFunction = (UnregisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "UnregisterTouchWindow");
|
s_pfUnregisterTouchWindowFunction = (UnregisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "UnregisterTouchWindow");
|
||||||
|
@ -96,7 +96,7 @@ static void SetupPixelFormat(HDC hDC)
|
||||||
SetPixelFormat(hDC, pixelFormat, &pfd);
|
SetPixelFormat(hDC, pixelFormat, &pfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool glew_dynamic_binding()
|
static bool glew_dynamic_binding()
|
||||||
{
|
{
|
||||||
const char *gl_extensions = (const char*)glGetString(GL_EXTENSIONS);
|
const char *gl_extensions = (const char*)glGetString(GL_EXTENSIONS);
|
||||||
|
|
||||||
|
@ -184,10 +184,7 @@ CCEGLView::CCEGLView()
|
||||||
, m_lpfnAccelerometerKeyHook(NULL)
|
, m_lpfnAccelerometerKeyHook(NULL)
|
||||||
, m_menu(NULL)
|
, m_menu(NULL)
|
||||||
, m_wndproc(NULL)
|
, m_wndproc(NULL)
|
||||||
, m_windowWidth(0)
|
, m_fFrameZoomFactor(1.0f)
|
||||||
, m_windowHeight(0)
|
|
||||||
, m_windowTouchScaleX(1.0f)
|
|
||||||
, m_windowTouchScaleY(1.0f)
|
|
||||||
, m_bSupportTouch(false)
|
, m_bSupportTouch(false)
|
||||||
{
|
{
|
||||||
strcpy(m_szViewName, "Cocos2dxWin32");
|
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)};
|
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
|
||||||
CCPoint pt(point.x, point.y);
|
CCPoint pt(point.x, point.y);
|
||||||
|
pt.x /= m_fFrameZoomFactor;
|
||||||
|
pt.y /= m_fFrameZoomFactor;
|
||||||
CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
|
CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
|
||||||
if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp))
|
if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp))
|
||||||
{
|
{
|
||||||
m_bCaptured = true;
|
m_bCaptured = true;
|
||||||
SetCapture(m_hWnd);
|
SetCapture(m_hWnd);
|
||||||
int id = 0;
|
int id = 0;
|
||||||
pt.x *= m_windowTouchScaleX;
|
|
||||||
pt.y *= m_windowTouchScaleY;
|
|
||||||
handleTouchesBegin(1, &id, &pt.x, &pt.y);
|
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)};
|
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
|
||||||
CCPoint pt(point.x, point.y);
|
CCPoint pt(point.x, point.y);
|
||||||
int id = 0;
|
int id = 0;
|
||||||
pt.x *= m_windowTouchScaleX;
|
pt.x /= m_fFrameZoomFactor;
|
||||||
pt.y *= m_windowTouchScaleY;
|
pt.y /= m_fFrameZoomFactor;
|
||||||
handleTouchesMove(1, &id, &pt.x, &pt.y);
|
handleTouchesMove(1, &id, &pt.x, &pt.y);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -386,8 +383,8 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
|
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
|
||||||
CCPoint pt(point.x, point.y);
|
CCPoint pt(point.x, point.y);
|
||||||
int id = 0;
|
int id = 0;
|
||||||
pt.x *= m_windowTouchScaleX;
|
pt.x /= m_fFrameZoomFactor;
|
||||||
pt.y *= m_windowTouchScaleY;
|
pt.y /= m_fFrameZoomFactor;
|
||||||
handleTouchesEnd(1, &id, &pt.x, &pt.y);
|
handleTouchesEnd(1, &id, &pt.x, &pt.y);
|
||||||
|
|
||||||
ReleaseCapture();
|
ReleaseCapture();
|
||||||
|
@ -415,8 +412,8 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
|
CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
|
||||||
if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp))
|
if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp))
|
||||||
{
|
{
|
||||||
pt.x *= m_windowTouchScaleX;
|
pt.x /= m_fFrameZoomFactor;
|
||||||
pt.y *= m_windowTouchScaleY;
|
pt.y /= m_fFrameZoomFactor;
|
||||||
|
|
||||||
if (ti.dwFlags & TOUCHEVENTF_DOWN)
|
if (ti.dwFlags & TOUCHEVENTF_DOWN)
|
||||||
handleTouchesBegin(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y);
|
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.right = rcClient.left + width;
|
||||||
rcClient.bottom = rcClient.top + height;
|
rcClient.bottom = rcClient.top + height;
|
||||||
|
|
||||||
m_windowWidth = width;
|
|
||||||
m_windowHeight = height;
|
|
||||||
const CCSize& frameSize = getFrameSize();
|
const CCSize& frameSize = getFrameSize();
|
||||||
if (frameSize.width > 0)
|
if (frameSize.width > 0)
|
||||||
{
|
{
|
||||||
m_windowTouchScaleX = frameSize.width / width;
|
|
||||||
m_windowTouchScaleY = frameSize.height / height;
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
TCHAR buff[MAX_PATH + 1];
|
TCHAR buff[MAX_PATH + 1];
|
||||||
memset(buff, 0, sizeof(buff));
|
memset(buff, 0, sizeof(buff));
|
||||||
swprintf_s(buff, MAX_PATH, L"%s - %0.0fx%0.0f - %0.2f",
|
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);
|
SetWindowText(m_hWnd, buff);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -644,6 +636,14 @@ void CCEGLView::resize(int width, int height)
|
||||||
SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER);
|
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)
|
void CCEGLView::setFrameSize(float width, float height)
|
||||||
{
|
{
|
||||||
CCEGLViewProtocol::setFrameSize(width, 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);
|
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()
|
CCEGLView* CCEGLView::sharedOpenGLView()
|
||||||
{
|
{
|
||||||
static CCEGLView* s_pEglView = NULL;
|
static CCEGLView* s_pEglView = NULL;
|
||||||
|
|
|
@ -62,11 +62,16 @@ public:
|
||||||
// win32 platform function
|
// win32 platform function
|
||||||
HWND getHWnd();
|
HWND getHWnd();
|
||||||
void resize(int width, int height);
|
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();
|
void centerWindow();
|
||||||
|
|
||||||
typedef void (*LPFN_ACCELEROMETER_KEYHOOK)( UINT message,WPARAM wParam, LPARAM lParam );
|
typedef void (*LPFN_ACCELEROMETER_KEYHOOK)( UINT message,WPARAM wParam, LPARAM lParam );
|
||||||
void setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook );
|
void setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook );
|
||||||
|
|
||||||
|
virtual void setViewPortInPoints(float x , float y , float w , float h);
|
||||||
// static function
|
// static function
|
||||||
/**
|
/**
|
||||||
@brief get the shared main open gl window
|
@brief get the shared main open gl window
|
||||||
|
@ -86,10 +91,7 @@ private:
|
||||||
LPCWSTR m_menu;
|
LPCWSTR m_menu;
|
||||||
CUSTOM_WND_PROC m_wndproc;
|
CUSTOM_WND_PROC m_wndproc;
|
||||||
|
|
||||||
int m_windowWidth;
|
float m_fFrameZoomFactor;
|
||||||
int m_windowHeight;
|
|
||||||
float m_windowTouchScaleX;
|
|
||||||
float m_windowTouchScaleY;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -29,6 +29,9 @@ int main(int argc, char **argv)
|
||||||
AppDelegate app;
|
AppDelegate app;
|
||||||
CCApplication::sharedApplication()->setResourceRootPath(resourcePath.c_str());
|
CCApplication::sharedApplication()->setResourceRootPath(resourcePath.c_str());
|
||||||
CCEGLView* eglView = CCEGLView::sharedOpenGLView();
|
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();
|
return CCApplication::sharedApplication()->run();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,9 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
|
||||||
// create the application instance
|
// create the application instance
|
||||||
AppDelegate app;
|
AppDelegate app;
|
||||||
CCEGLView* eglView = CCEGLView::sharedOpenGLView();
|
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();
|
return CCApplication::sharedApplication()->run();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue