mirror of https://github.com/axmolengine/axmol.git
issue #1515: Refactored some codes for win32 port.
This commit is contained in:
parent
0b101bedd0
commit
a5e260dbdb
|
@ -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,8 +184,7 @@ CCEGLView::CCEGLView()
|
||||||
, m_lpfnAccelerometerKeyHook(NULL)
|
, m_lpfnAccelerometerKeyHook(NULL)
|
||||||
, m_menu(NULL)
|
, m_menu(NULL)
|
||||||
, m_wndproc(NULL)
|
, m_wndproc(NULL)
|
||||||
, m_windowTouchScaleX(1.0f)
|
, m_fFrameZoomFactor(1.0f)
|
||||||
, m_windowTouchScaleY(1.0f)
|
|
||||||
, m_bSupportTouch(false)
|
, m_bSupportTouch(false)
|
||||||
{
|
{
|
||||||
strcpy(m_szViewName, "Cocos2dxWin32");
|
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)};
|
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
|
||||||
CCPoint pt(point.x, point.y);
|
CCPoint pt(point.x, point.y);
|
||||||
pt.x *= m_windowTouchScaleX;
|
pt.x /= m_fFrameZoomFactor;
|
||||||
pt.y *= m_windowTouchScaleY;
|
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))
|
||||||
{
|
{
|
||||||
|
@ -368,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;
|
||||||
|
@ -384,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();
|
||||||
|
@ -413,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);
|
||||||
|
@ -621,14 +620,11 @@ void CCEGLView::resize(int width, int 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
|
||||||
}
|
}
|
||||||
|
@ -642,6 +638,7 @@ void CCEGLView::resize(int width, int height)
|
||||||
|
|
||||||
void CCEGLView::setFrameZoom(float fZoomFactor)
|
void CCEGLView::setFrameZoom(float fZoomFactor)
|
||||||
{
|
{
|
||||||
|
m_fFrameZoomFactor = fZoomFactor;
|
||||||
resize(m_obScreenSize.width * fZoomFactor, m_obScreenSize.height * fZoomFactor);
|
resize(m_obScreenSize.width * fZoomFactor, m_obScreenSize.height * fZoomFactor);
|
||||||
centerWindow();
|
centerWindow();
|
||||||
CCDirector::sharedDirector()->setProjection(CCDirector::sharedDirector()->getProjection());
|
CCDirector::sharedDirector()->setProjection(CCDirector::sharedDirector()->getProjection());
|
||||||
|
@ -689,10 +686,10 @@ void CCEGLView::centerWindow()
|
||||||
|
|
||||||
void CCEGLView::setViewPortInPoints(float x , float y , float w , float h)
|
void CCEGLView::setViewPortInPoints(float x , float y , float w , float h)
|
||||||
{
|
{
|
||||||
glViewport((GLint)(x * m_fScaleX / m_windowTouchScaleX + m_obViewPortRect.origin.x / m_windowTouchScaleX),
|
glViewport((GLint)(x * m_fScaleX * m_fFrameZoomFactor + m_obViewPortRect.origin.x * m_fFrameZoomFactor),
|
||||||
(GLint)(y * m_fScaleY / m_windowTouchScaleY + m_obViewPortRect.origin.y / m_windowTouchScaleY),
|
(GLint)(y * m_fScaleY * m_fFrameZoomFactor + m_obViewPortRect.origin.y * m_fFrameZoomFactor),
|
||||||
(GLsizei)(w * m_fScaleX / m_windowTouchScaleX),
|
(GLsizei)(w * m_fScaleX * m_fFrameZoomFactor),
|
||||||
(GLsizei)(h * m_fScaleY / m_windowTouchScaleY));
|
(GLsizei)(h * m_fScaleY * m_fFrameZoomFactor));
|
||||||
}
|
}
|
||||||
|
|
||||||
CCEGLView* CCEGLView::sharedOpenGLView()
|
CCEGLView* CCEGLView::sharedOpenGLView()
|
||||||
|
|
|
@ -91,8 +91,7 @@ private:
|
||||||
LPCWSTR m_menu;
|
LPCWSTR m_menu;
|
||||||
CUSTOM_WND_PROC m_wndproc;
|
CUSTOM_WND_PROC m_wndproc;
|
||||||
|
|
||||||
float m_windowTouchScaleX;
|
float m_fFrameZoomFactor;
|
||||||
float m_windowTouchScaleY;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
Loading…
Reference in New Issue