2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "CCEGLView.h"
|
2012-06-19 17:22:55 +08:00
|
|
|
#include "cocoa/CCSet.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "ccMacros.h"
|
|
|
|
#include "CCDirector.h"
|
2012-06-19 17:22:55 +08:00
|
|
|
#include "touch_dispatcher/CCTouch.h"
|
|
|
|
#include "touch_dispatcher/CCTouchDispatcher.h"
|
|
|
|
#include "text_input_node/CCIMEDispatcher.h"
|
|
|
|
#include "keypad_dispatcher/CCKeypadDispatcher.h"
|
2012-08-20 16:32:22 +08:00
|
|
|
#include "support/CCPointExtension.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "CCApplication.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2012-10-18 09:54:24 +08:00
|
|
|
#if(_MSC_VER >= 1600) // Visual Studio 2010 or higher version.
|
2012-10-16 14:42:30 +08:00
|
|
|
// Windows Touch define
|
|
|
|
#define MOUSEEVENTF_FROMTOUCH 0xFF515700
|
2012-10-15 16:39:42 +08:00
|
|
|
|
2012-10-16 14:42:30 +08:00
|
|
|
// Windows Touch functions
|
|
|
|
// Workaround to be able tu run app on Windows XP
|
|
|
|
typedef WINUSERAPI BOOL (WINAPI *RegisterTouchWindowFn)(_In_ HWND hwnd, _In_ ULONG ulFlags);
|
|
|
|
typedef WINUSERAPI BOOL (WINAPI *UnregisterTouchWindowFn)(_In_ HWND hwnd);
|
|
|
|
typedef WINUSERAPI LPARAM (WINAPI *GetMessageExtraInfoFn)(VOID);
|
|
|
|
typedef WINUSERAPI BOOL (WINAPI *GetTouchInputInfoFn)(_In_ HTOUCHINPUT hTouchInput, _In_ UINT cInputs, __out_ecount(cInputs) PTOUCHINPUT pInputs, _In_ int cbSize);
|
|
|
|
typedef WINUSERAPI BOOL (WINAPI *CloseTouchInputHandleFn)(_In_ HTOUCHINPUT hTouchInput);
|
2012-10-15 16:39:42 +08:00
|
|
|
|
2012-10-17 15:14:34 +08:00
|
|
|
static RegisterTouchWindowFn s_pfRegisterTouchWindowFunction = NULL;
|
|
|
|
static UnregisterTouchWindowFn s_pfUnregisterTouchWindowFunction = NULL;
|
|
|
|
static GetMessageExtraInfoFn s_pfGetMessageExtraInfoFunction = NULL;
|
|
|
|
static GetTouchInputInfoFn s_pfGetTouchInputInfoFunction = NULL;
|
|
|
|
static CloseTouchInputHandleFn s_pfCloseTouchInputHandleFunction = NULL;
|
2012-10-15 16:39:42 +08:00
|
|
|
|
2012-10-18 12:01:30 +08:00
|
|
|
static bool CheckTouchSupport()
|
2012-10-16 14:42:30 +08:00
|
|
|
{
|
2012-10-17 15:14:34 +08:00
|
|
|
s_pfRegisterTouchWindowFunction = (RegisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "RegisterTouchWindow");
|
|
|
|
s_pfUnregisterTouchWindowFunction = (UnregisterTouchWindowFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "UnregisterTouchWindow");
|
|
|
|
s_pfGetMessageExtraInfoFunction = (GetMessageExtraInfoFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "GetMessageExtraInfo");
|
|
|
|
s_pfGetTouchInputInfoFunction = (GetTouchInputInfoFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "GetTouchInputInfo");
|
|
|
|
s_pfCloseTouchInputHandleFunction = (CloseTouchInputHandleFn)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "CloseTouchInputHandle");
|
2012-10-16 14:42:30 +08:00
|
|
|
|
2012-10-17 15:14:34 +08:00
|
|
|
return (s_pfRegisterTouchWindowFunction && s_pfUnregisterTouchWindowFunction && s_pfGetMessageExtraInfoFunction && s_pfGetTouchInputInfoFunction && s_pfCloseTouchInputHandleFunction);
|
2012-10-16 14:42:30 +08:00
|
|
|
}
|
2012-10-15 16:39:42 +08:00
|
|
|
|
2012-10-18 09:54:24 +08:00
|
|
|
#endif /* #if(_MSC_VER >= 1600) */
|
2012-10-17 15:08:25 +08:00
|
|
|
|
2012-06-01 13:44:28 +08:00
|
|
|
static void SetupPixelFormat(HDC hDC)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-06-01 13:44:28 +08:00
|
|
|
int pixelFormat;
|
|
|
|
|
|
|
|
PIXELFORMATDESCRIPTOR pfd =
|
2012-09-14 01:22:03 +08:00
|
|
|
{
|
2012-06-01 13:44:28 +08:00
|
|
|
sizeof(PIXELFORMATDESCRIPTOR), // size
|
|
|
|
1, // version
|
|
|
|
PFD_SUPPORT_OPENGL | // OpenGL window
|
|
|
|
PFD_DRAW_TO_WINDOW | // render to window
|
|
|
|
PFD_DOUBLEBUFFER, // support double-buffering
|
|
|
|
PFD_TYPE_RGBA, // color type
|
2012-11-22 09:54:11 +08:00
|
|
|
32, // preferred color depth
|
2012-06-01 13:44:28 +08:00
|
|
|
0, 0, 0, 0, 0, 0, // color bits (ignored)
|
|
|
|
0, // no alpha buffer
|
|
|
|
0, // alpha bits (ignored)
|
|
|
|
0, // no accumulation buffer
|
|
|
|
0, 0, 0, 0, // accum bits (ignored)
|
2012-11-22 09:54:11 +08:00
|
|
|
24, // depth buffer
|
|
|
|
8, // no stencil buffer
|
2012-06-01 13:44:28 +08:00
|
|
|
0, // no auxiliary buffers
|
|
|
|
PFD_MAIN_PLANE, // main layer
|
|
|
|
0, // reserved
|
|
|
|
0, 0, 0, // no layer, visible, damage masks
|
|
|
|
};
|
|
|
|
|
|
|
|
pixelFormat = ChoosePixelFormat(hDC, &pfd);
|
|
|
|
SetPixelFormat(hDC, pixelFormat, &pfd);
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-10-18 12:01:30 +08:00
|
|
|
static bool glew_dynamic_binding()
|
2012-09-14 01:22:03 +08:00
|
|
|
{
|
|
|
|
const char *gl_extensions = (const char*)glGetString(GL_EXTENSIONS);
|
|
|
|
|
2012-10-09 00:38:04 +08:00
|
|
|
// If the current opengl driver doesn't have framebuffers methods, check if an extension exists
|
2012-09-14 01:22:03 +08:00
|
|
|
if (glGenFramebuffers == NULL)
|
|
|
|
{
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog("OpenGL: glGenFramebuffers is NULL, try to detect an extension");
|
2012-09-14 01:22:03 +08:00
|
|
|
if (strstr(gl_extensions, "ARB_framebuffer_object"))
|
|
|
|
{
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog("OpenGL: ARB_framebuffer_object is supported");
|
2012-09-14 01:22:03 +08:00
|
|
|
|
|
|
|
glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) wglGetProcAddress("glIsRenderbuffer");
|
|
|
|
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) wglGetProcAddress("glBindRenderbuffer");
|
|
|
|
glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) wglGetProcAddress("glDeleteRenderbuffers");
|
|
|
|
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) wglGetProcAddress("glGenRenderbuffers");
|
|
|
|
glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) wglGetProcAddress("glRenderbufferStorage");
|
|
|
|
glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) wglGetProcAddress("glGetRenderbufferParameteriv");
|
|
|
|
glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC) wglGetProcAddress("glIsFramebuffer");
|
|
|
|
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) wglGetProcAddress("glBindFramebuffer");
|
|
|
|
glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) wglGetProcAddress("glDeleteFramebuffers");
|
|
|
|
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) wglGetProcAddress("glGenFramebuffers");
|
|
|
|
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) wglGetProcAddress("glCheckFramebufferStatus");
|
|
|
|
glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC) wglGetProcAddress("glFramebufferTexture1D");
|
|
|
|
glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) wglGetProcAddress("glFramebufferTexture2D");
|
|
|
|
glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC) wglGetProcAddress("glFramebufferTexture3D");
|
|
|
|
glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) wglGetProcAddress("glFramebufferRenderbuffer");
|
|
|
|
glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) wglGetProcAddress("glGetFramebufferAttachmentParameteriv");
|
|
|
|
glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) wglGetProcAddress("glGenerateMipmap");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (strstr(gl_extensions, "EXT_framebuffer_object"))
|
|
|
|
{
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog("OpenGL: EXT_framebuffer_object is supported");
|
2012-09-14 01:22:03 +08:00
|
|
|
glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) wglGetProcAddress("glIsRenderbufferEXT");
|
|
|
|
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) wglGetProcAddress("glBindRenderbufferEXT");
|
|
|
|
glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) wglGetProcAddress("glDeleteRenderbuffersEXT");
|
|
|
|
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) wglGetProcAddress("glGenRenderbuffersEXT");
|
|
|
|
glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) wglGetProcAddress("glRenderbufferStorageEXT");
|
|
|
|
glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) wglGetProcAddress("glGetRenderbufferParameterivEXT");
|
|
|
|
glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC) wglGetProcAddress("glIsFramebufferEXT");
|
|
|
|
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) wglGetProcAddress("glBindFramebufferEXT");
|
|
|
|
glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) wglGetProcAddress("glDeleteFramebuffersEXT");
|
|
|
|
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) wglGetProcAddress("glGenFramebuffersEXT");
|
|
|
|
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) wglGetProcAddress("glCheckFramebufferStatusEXT");
|
|
|
|
glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC) wglGetProcAddress("glFramebufferTexture1DEXT");
|
|
|
|
glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) wglGetProcAddress("glFramebufferTexture2DEXT");
|
|
|
|
glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC) wglGetProcAddress("glFramebufferTexture3DEXT");
|
|
|
|
glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) wglGetProcAddress("glFramebufferRenderbufferEXT");
|
|
|
|
glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) wglGetProcAddress("glGetFramebufferAttachmentParameterivEXT");
|
|
|
|
glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) wglGetProcAddress("glGenerateMipmapEXT");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog("OpenGL: No framebuffers extension is supported");
|
|
|
|
CCLog("OpenGL: Any call to Fbo will crash!");
|
2012-09-20 01:36:09 +08:00
|
|
|
return false;
|
2012-09-14 01:22:03 +08:00
|
|
|
}
|
|
|
|
}
|
2012-09-20 01:36:09 +08:00
|
|
|
return true;
|
2012-09-14 01:22:03 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2013-06-20 14:13:12 +08:00
|
|
|
// impliment EGLView
|
2012-04-19 14:35:52 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2013-06-20 14:13:12 +08:00
|
|
|
static EGLView* s_pMainWindow = NULL;
|
2012-06-01 13:44:28 +08:00
|
|
|
static const WCHAR* kWindowClassName = L"Cocos2dxWin32";
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
static LRESULT CALLBACK _WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
if (s_pMainWindow && s_pMainWindow->getHWnd() == hWnd)
|
|
|
|
{
|
|
|
|
return s_pMainWindow->WindowProc(uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
EGLView::EGLView()
|
2013-06-15 14:03:30 +08:00
|
|
|
: _captured(false)
|
|
|
|
, _wnd(NULL)
|
|
|
|
, _DC(NULL)
|
|
|
|
, _RC(NULL)
|
|
|
|
, _lpfnAccelerometerKeyHook(NULL)
|
|
|
|
, _menu(NULL)
|
|
|
|
, _wndproc(NULL)
|
|
|
|
, _frameZoomFactor(1.0f)
|
|
|
|
, _supportTouch(false)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
strcpy(_viewName, "Cocos2dxWin32");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
EGLView::~EGLView()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-06-01 13:44:28 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool EGLView::initGL()
|
2012-06-01 13:44:28 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_DC = GetDC(_wnd);
|
|
|
|
SetupPixelFormat(_DC);
|
2012-06-01 13:44:28 +08:00
|
|
|
//SetupPalette();
|
2013-06-15 14:03:30 +08:00
|
|
|
_RC = wglCreateContext(_DC);
|
|
|
|
wglMakeCurrent(_DC, _RC);
|
2012-06-01 13:44:28 +08:00
|
|
|
|
2012-09-13 15:52:46 +08:00
|
|
|
// check OpenGL version at first
|
2012-09-13 15:53:57 +08:00
|
|
|
const GLubyte* glVersion = glGetString(GL_VERSION);
|
|
|
|
CCLOG("OpenGL version = %s", glVersion);
|
|
|
|
|
|
|
|
if ( atof((const char*)glVersion) < 1.5 )
|
|
|
|
{
|
|
|
|
char strComplain[256] = {0};
|
2012-09-14 01:22:03 +08:00
|
|
|
sprintf(strComplain,
|
2012-09-20 01:36:09 +08:00
|
|
|
"OpenGL 1.5 or higher is required (your version is %s). Please upgrade the driver of your video card.",
|
2012-09-13 15:53:57 +08:00
|
|
|
glVersion);
|
2013-06-20 14:13:12 +08:00
|
|
|
MessageBox(strComplain, "OpenGL version too old");
|
2012-09-20 01:36:09 +08:00
|
|
|
return false;
|
2012-09-13 15:53:57 +08:00
|
|
|
}
|
2012-09-13 15:52:46 +08:00
|
|
|
|
2012-06-01 13:44:28 +08:00
|
|
|
GLenum GlewInitResult = glewInit();
|
2012-09-14 01:22:03 +08:00
|
|
|
if (GLEW_OK != GlewInitResult)
|
2012-06-01 13:44:28 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
MessageBox((char *)glewGetErrorString(GlewInitResult), "OpenGL error");
|
2012-06-01 13:44:28 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)
|
|
|
|
{
|
2012-09-13 02:17:56 +08:00
|
|
|
CCLog("Ready for GLSL");
|
2012-06-01 13:44:28 +08:00
|
|
|
}
|
2012-09-14 01:22:03 +08:00
|
|
|
else
|
2012-06-01 13:44:28 +08:00
|
|
|
{
|
2012-09-13 02:17:56 +08:00
|
|
|
CCLog("Not totally ready :(");
|
2012-06-01 13:44:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (glewIsSupported("GL_VERSION_2_0"))
|
|
|
|
{
|
2012-09-13 02:17:56 +08:00
|
|
|
CCLog("Ready for OpenGL 2.0");
|
2012-06-01 13:44:28 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-13 02:17:56 +08:00
|
|
|
CCLog("OpenGL 2.0 not supported");
|
2012-06-01 13:44:28 +08:00
|
|
|
}
|
2012-09-14 01:22:03 +08:00
|
|
|
|
2012-09-20 01:36:09 +08:00
|
|
|
if(glew_dynamic_binding() == false)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
MessageBox("No OpenGL framebuffer support. Please upgrade the driver of your video card.", "OpenGL error");
|
2012-09-20 01:36:09 +08:00
|
|
|
return false;
|
|
|
|
}
|
2012-09-14 01:22:03 +08:00
|
|
|
|
2013-01-07 19:17:50 +08:00
|
|
|
// Enable point size by default on windows.
|
2012-11-22 10:04:35 +08:00
|
|
|
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
|
|
|
|
|
2012-06-01 13:44:28 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void EGLView::destroyGL()
|
2012-06-01 13:44:28 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_DC != NULL && _RC != NULL)
|
2012-06-01 13:44:28 +08:00
|
|
|
{
|
|
|
|
// deselect rendering context and delete it
|
2013-06-15 14:03:30 +08:00
|
|
|
wglMakeCurrent(_DC, NULL);
|
|
|
|
wglDeleteContext(_RC);
|
2012-06-01 13:44:28 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool EGLView::Create()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
bool bRet = false;
|
2012-09-14 01:22:03 +08:00
|
|
|
do
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_BREAK_IF(_wnd);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
HINSTANCE hInstance = GetModuleHandle( NULL );
|
|
|
|
WNDCLASS wc; // Windows Class Structure
|
|
|
|
|
|
|
|
// Redraw On Size, And Own DC For Window.
|
2012-09-14 01:22:03 +08:00
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
|
2012-04-19 14:35:52 +08:00
|
|
|
wc.lpfnWndProc = _WindowProc; // WndProc Handles Messages
|
|
|
|
wc.cbClsExtra = 0; // No Extra Window Data
|
|
|
|
wc.cbWndExtra = 0; // No Extra Window Data
|
|
|
|
wc.hInstance = hInstance; // Set The Instance
|
|
|
|
wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); // Load The Default Icon
|
|
|
|
wc.hCursor = LoadCursor( NULL, IDC_ARROW ); // Load The Arrow Pointer
|
|
|
|
wc.hbrBackground = NULL; // No Background Required For GL
|
2013-06-15 14:03:30 +08:00
|
|
|
wc.lpszMenuName = _menu; //
|
2012-04-19 14:35:52 +08:00
|
|
|
wc.lpszClassName = kWindowClassName; // Set The Class Name
|
|
|
|
|
2012-09-14 01:22:03 +08:00
|
|
|
CC_BREAK_IF(! RegisterClass(&wc) && 1410 != GetLastError());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// center window position
|
|
|
|
RECT rcDesktop;
|
|
|
|
GetWindowRect(GetDesktopWindow(), &rcDesktop);
|
|
|
|
|
2012-06-01 13:44:28 +08:00
|
|
|
WCHAR wszBuf[50] = {0};
|
2013-06-15 14:03:30 +08:00
|
|
|
MultiByteToWideChar(CP_UTF8, 0, _viewName, -1, wszBuf, sizeof(wszBuf));
|
2012-06-01 13:44:28 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// create window
|
2013-06-15 14:03:30 +08:00
|
|
|
_wnd = CreateWindowEx(
|
2012-04-19 14:35:52 +08:00
|
|
|
WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, // Extended Style For The Window
|
|
|
|
kWindowClassName, // Class Name
|
2012-06-01 13:44:28 +08:00
|
|
|
wszBuf, // Window Title
|
2012-04-19 14:35:52 +08:00
|
|
|
WS_CAPTION | WS_POPUPWINDOW | WS_MINIMIZEBOX, // Defined Window Style
|
|
|
|
0, 0, // Window Position
|
2012-10-17 16:52:09 +08:00
|
|
|
//TODO: Initializing width with a large value to avoid getting a wrong client area by 'GetClientRect' function.
|
2012-10-17 16:50:07 +08:00
|
|
|
1000, // Window Width
|
|
|
|
1000, // Window Height
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL, // No Parent Window
|
|
|
|
NULL, // No Menu
|
|
|
|
hInstance, // Instance
|
|
|
|
NULL );
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_BREAK_IF(! _wnd);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-01 13:44:28 +08:00
|
|
|
bRet = initGL();
|
2012-09-20 01:36:09 +08:00
|
|
|
if(!bRet) destroyGL();
|
2012-06-01 13:44:28 +08:00
|
|
|
CC_BREAK_IF(!bRet);
|
2012-09-14 01:22:03 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
s_pMainWindow = this;
|
|
|
|
bRet = true;
|
|
|
|
} while (0);
|
|
|
|
|
2012-10-18 09:54:24 +08:00
|
|
|
#if(_MSC_VER >= 1600)
|
2013-06-15 14:03:30 +08:00
|
|
|
_supportTouch = CheckTouchSupport();
|
|
|
|
if(_supportTouch)
|
2012-10-17 15:08:25 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_supportTouch = (s_pfRegisterTouchWindowFunction(_wnd, 0) != 0);
|
2012-10-17 15:08:25 +08:00
|
|
|
}
|
2012-10-18 09:54:24 +08:00
|
|
|
#endif /* #if(_MSC_VER >= 1600) */
|
2012-10-15 16:39:42 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
LRESULT EGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-09-02 04:38:52 +08:00
|
|
|
BOOL bProcessed = FALSE;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
case WM_LBUTTONDOWN:
|
2012-10-18 09:54:24 +08:00
|
|
|
#if(_MSC_VER >= 1600)
|
2012-10-15 16:39:42 +08:00
|
|
|
// Don't process message generated by Windows Touch
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_supportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break;
|
2012-10-18 09:54:24 +08:00
|
|
|
#endif /* #if(_MSC_VER >= 1600) */
|
2012-10-15 16:39:42 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_delegate && MK_LBUTTON == wParam)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-04-23 14:30:38 +08:00
|
|
|
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
|
2013-06-20 14:13:12 +08:00
|
|
|
Point pt(point.x, point.y);
|
2013-06-15 14:03:30 +08:00
|
|
|
pt.x /= _frameZoomFactor;
|
|
|
|
pt.y /= _frameZoomFactor;
|
2013-06-20 14:13:12 +08:00
|
|
|
Point tmp = ccp(pt.x, _screenSize.height - pt.y);
|
|
|
|
if (_viewPortRect.equals(RectZero) || _viewPortRect.containsPoint(tmp))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_captured = true;
|
|
|
|
SetCapture(_wnd);
|
2012-04-20 15:23:00 +08:00
|
|
|
int id = 0;
|
|
|
|
handleTouchesBegin(1, &id, &pt.x, &pt.y);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_MOUSEMOVE:
|
2012-10-18 09:54:24 +08:00
|
|
|
#if(_MSC_VER >= 1600)
|
2012-10-15 16:39:42 +08:00
|
|
|
// Don't process message generated by Windows Touch
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_supportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break;
|
2012-10-18 09:54:24 +08:00
|
|
|
#endif /* #if(_MSC_VER >= 1600) */
|
2013-06-15 14:03:30 +08:00
|
|
|
if (MK_LBUTTON == wParam && _captured)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-04-23 14:30:38 +08:00
|
|
|
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
|
2013-06-20 14:13:12 +08:00
|
|
|
Point pt(point.x, point.y);
|
2012-04-20 15:23:00 +08:00
|
|
|
int id = 0;
|
2013-06-15 14:03:30 +08:00
|
|
|
pt.x /= _frameZoomFactor;
|
|
|
|
pt.y /= _frameZoomFactor;
|
2012-04-20 15:23:00 +08:00
|
|
|
handleTouchesMove(1, &id, &pt.x, &pt.y);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_LBUTTONUP:
|
2012-10-18 09:54:24 +08:00
|
|
|
#if(_MSC_VER >= 1600)
|
2012-10-15 16:39:42 +08:00
|
|
|
// Don't process message generated by Windows Touch
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_supportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break;
|
2012-10-18 09:54:24 +08:00
|
|
|
#endif /* #if(_MSC_VER >= 1600) */
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_captured)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-04-23 14:30:38 +08:00
|
|
|
POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
|
2013-06-20 14:13:12 +08:00
|
|
|
Point pt(point.x, point.y);
|
2012-04-20 15:23:00 +08:00
|
|
|
int id = 0;
|
2013-06-15 14:03:30 +08:00
|
|
|
pt.x /= _frameZoomFactor;
|
|
|
|
pt.y /= _frameZoomFactor;
|
2012-04-20 15:23:00 +08:00
|
|
|
handleTouchesEnd(1, &id, &pt.x, &pt.y);
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
ReleaseCapture();
|
2013-06-15 14:03:30 +08:00
|
|
|
_captured = false;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
break;
|
2012-10-18 09:54:24 +08:00
|
|
|
#if(_MSC_VER >= 1600)
|
2012-10-15 16:39:42 +08:00
|
|
|
case WM_TOUCH:
|
|
|
|
{
|
2012-10-17 15:08:25 +08:00
|
|
|
BOOL bHandled = FALSE;
|
|
|
|
UINT cInputs = LOWORD(wParam);
|
|
|
|
PTOUCHINPUT pInputs = new TOUCHINPUT[cInputs];
|
|
|
|
if (pInputs)
|
2012-10-15 16:39:42 +08:00
|
|
|
{
|
2012-10-17 15:14:34 +08:00
|
|
|
if (s_pfGetTouchInputInfoFunction((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT)))
|
2012-10-15 16:39:42 +08:00
|
|
|
{
|
2012-10-17 15:08:25 +08:00
|
|
|
for (UINT i=0; i < cInputs; i++)
|
|
|
|
{
|
|
|
|
TOUCHINPUT ti = pInputs[i];
|
|
|
|
POINT input;
|
|
|
|
input.x = TOUCH_COORD_TO_PIXEL(ti.x);
|
|
|
|
input.y = TOUCH_COORD_TO_PIXEL(ti.y);
|
2013-06-15 14:03:30 +08:00
|
|
|
ScreenToClient(_wnd, &input);
|
2013-06-20 14:13:12 +08:00
|
|
|
Point pt(input.x, input.y);
|
|
|
|
Point tmp = ccp(pt.x, _screenSize.height - pt.y);
|
|
|
|
if (_viewPortRect.equals(RectZero) || _viewPortRect.containsPoint(tmp))
|
2012-10-17 15:08:25 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
pt.x /= _frameZoomFactor;
|
|
|
|
pt.y /= _frameZoomFactor;
|
2012-10-17 15:08:25 +08:00
|
|
|
|
|
|
|
if (ti.dwFlags & TOUCHEVENTF_DOWN)
|
|
|
|
handleTouchesBegin(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y);
|
|
|
|
else if (ti.dwFlags & TOUCHEVENTF_MOVE)
|
|
|
|
handleTouchesMove(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y);
|
|
|
|
else if (ti.dwFlags & TOUCHEVENTF_UP)
|
|
|
|
handleTouchesEnd(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bHandled = TRUE;
|
|
|
|
}
|
|
|
|
delete [] pInputs;
|
|
|
|
}
|
2012-10-17 15:14:34 +08:00
|
|
|
if (bHandled)
|
|
|
|
{
|
|
|
|
s_pfCloseTouchInputHandleFunction((HTOUCHINPUT)lParam);
|
|
|
|
}
|
2012-10-15 16:39:42 +08:00
|
|
|
}
|
|
|
|
break;
|
2012-10-18 09:54:24 +08:00
|
|
|
#endif /* #if(_MSC_VER >= 1600) */
|
2012-04-19 14:35:52 +08:00
|
|
|
case WM_SIZE:
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case SIZE_RESTORED:
|
2013-06-20 14:13:12 +08:00
|
|
|
Application::sharedApplication()->applicationWillEnterForeground();
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
case SIZE_MINIMIZED:
|
2013-06-20 14:13:12 +08:00
|
|
|
Application::sharedApplication()->applicationDidEnterBackground();
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
if (wParam == VK_F1 || wParam == VK_F2)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Director* pDirector = Director::sharedDirector();
|
2012-04-19 14:35:52 +08:00
|
|
|
if (GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0)
|
|
|
|
pDirector->getKeypadDispatcher()->dispatchKeypadMSG(wParam == VK_F1 ? kTypeBackClicked : kTypeMenuClicked);
|
|
|
|
}
|
2012-12-20 04:11:26 +08:00
|
|
|
else if (wParam == VK_ESCAPE)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Director::sharedDirector()->getKeypadDispatcher()->dispatchKeypadMSG(kTypeBackClicked);
|
2012-12-20 04:11:26 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if ( _lpfnAccelerometerKeyHook!=NULL )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
(*_lpfnAccelerometerKeyHook)( message,wParam,lParam );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_KEYUP:
|
2013-06-15 14:03:30 +08:00
|
|
|
if ( _lpfnAccelerometerKeyHook!=NULL )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
(*_lpfnAccelerometerKeyHook)( message,wParam,lParam );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_CHAR:
|
|
|
|
{
|
|
|
|
if (wParam < 0x20)
|
|
|
|
{
|
|
|
|
if (VK_BACK == wParam)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else if (VK_RETURN == wParam)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
IMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else if (VK_TAB == wParam)
|
|
|
|
{
|
|
|
|
// tab input
|
|
|
|
}
|
|
|
|
else if (VK_ESCAPE == wParam)
|
|
|
|
{
|
|
|
|
// ESC input
|
2012-09-02 04:38:52 +08:00
|
|
|
//CCDirector::sharedDirector()->end();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (wParam < 128)
|
|
|
|
{
|
|
|
|
// ascii char
|
2013-06-20 14:13:12 +08:00
|
|
|
IMEDispatcher::sharedDispatcher()->dispatchInsertText((const char *)&wParam, 1);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char szUtf8[8] = {0};
|
|
|
|
int nLen = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)&wParam, 1, szUtf8, sizeof(szUtf8), NULL, NULL);
|
2013-06-20 14:13:12 +08:00
|
|
|
IMEDispatcher::sharedDispatcher()->dispatchInsertText(szUtf8, nLen);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
if ( _lpfnAccelerometerKeyHook!=NULL )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
(*_lpfnAccelerometerKeyHook)( message,wParam,lParam );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_PAINT:
|
2012-06-01 13:44:28 +08:00
|
|
|
PAINTSTRUCT ps;
|
2013-06-15 14:03:30 +08:00
|
|
|
BeginPaint(_wnd, &ps);
|
|
|
|
EndPaint(_wnd, &ps);
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_CLOSE:
|
2013-06-20 14:13:12 +08:00
|
|
|
Director::sharedDirector()->end();
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_DESTROY:
|
2012-06-01 13:44:28 +08:00
|
|
|
destroyGL();
|
2012-04-19 14:35:52 +08:00
|
|
|
PostQuitMessage(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_wndproc)
|
2012-09-02 04:38:52 +08:00
|
|
|
{
|
2013-01-07 19:17:50 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_wndproc(message, wParam, lParam, &bProcessed);
|
2012-09-02 04:38:52 +08:00
|
|
|
if (bProcessed) break;
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
return DefWindowProc(_wnd, message, wParam, lParam);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-09-02 04:38:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_wndproc && !bProcessed)
|
2012-09-02 04:38:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_wndproc(message, wParam, lParam, &bProcessed);
|
2012-09-02 04:38:52 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void EGLView::setAccelerometerKeyHook( LPFN_ACCELEROMETER_KEYHOOK lpfnAccelerometerKeyHook )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_lpfnAccelerometerKeyHook=lpfnAccelerometerKeyHook;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool EGLView::isOpenGLReady()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return (_DC != NULL && _RC != NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void EGLView::end()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_wnd)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-10-18 09:54:24 +08:00
|
|
|
#if(_MSC_VER >= 1600)
|
2013-06-15 14:03:30 +08:00
|
|
|
if(_supportTouch)
|
2012-10-17 15:08:25 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
s_pfUnregisterTouchWindowFunction(_wnd);
|
2012-10-17 15:08:25 +08:00
|
|
|
}
|
2012-10-18 09:54:24 +08:00
|
|
|
#endif /* #if(_MSC_VER >= 1600) */
|
2013-06-15 14:03:30 +08:00
|
|
|
DestroyWindow(_wnd);
|
|
|
|
_wnd = NULL;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
s_pMainWindow = NULL;
|
|
|
|
UnregisterClass(kWindowClassName, GetModuleHandle(NULL));
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void EGLView::swapBuffers()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_DC != NULL)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
::SwapBuffers(_DC);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void EGLView::setIMEKeyboardState(bool /*bOpen*/)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-04-20 15:23:00 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void EGLView::setMenuResource(LPCWSTR menu)
|
2012-09-02 04:38:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_menu = menu;
|
|
|
|
if (_wnd != NULL)
|
2012-10-17 16:50:07 +08:00
|
|
|
{
|
|
|
|
HMENU hMenu = LoadMenu(GetModuleHandle(NULL), menu);
|
2013-06-15 14:03:30 +08:00
|
|
|
SetMenu(_wnd, hMenu);
|
2012-10-17 16:50:07 +08:00
|
|
|
}
|
2012-09-02 04:38:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void EGLView::setWndProc(CUSTOM_WND_PROC proc)
|
2012-09-02 04:38:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_wndproc = proc;
|
2012-09-02 04:38:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
HWND EGLView::getHWnd()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _wnd;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void EGLView::resize(int width, int height)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (! _wnd)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-03 00:58:42 +08:00
|
|
|
RECT rcWindow;
|
2013-06-15 14:03:30 +08:00
|
|
|
GetWindowRect(_wnd, &rcWindow);
|
2012-09-03 00:58:42 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
RECT rcClient;
|
2013-06-15 14:03:30 +08:00
|
|
|
GetClientRect(_wnd, &rcClient);
|
2012-09-03 00:58:42 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// calculate new window width and height
|
2012-09-03 00:58:42 +08:00
|
|
|
POINT ptDiff;
|
|
|
|
ptDiff.x = (rcWindow.right - rcWindow.left) - rcClient.right;
|
|
|
|
ptDiff.y = (rcWindow.bottom - rcWindow.top) - rcClient.bottom;
|
2012-04-19 14:35:52 +08:00
|
|
|
rcClient.right = rcClient.left + width;
|
|
|
|
rcClient.bottom = rcClient.top + height;
|
2012-09-03 00:58:42 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
const Size& frameSize = getFrameSize();
|
2012-09-03 00:58:42 +08:00
|
|
|
if (frameSize.width > 0)
|
|
|
|
{
|
2013-01-07 19:17:50 +08:00
|
|
|
WCHAR wszBuf[MAX_PATH] = {0};
|
2012-10-17 15:08:25 +08:00
|
|
|
#ifdef _DEBUG
|
2012-12-29 14:50:00 +08:00
|
|
|
char szBuf[MAX_PATH + 1];
|
|
|
|
memset(szBuf, 0, sizeof(szBuf));
|
|
|
|
snprintf(szBuf, MAX_PATH, "%s - %0.0fx%0.0f - %0.2f",
|
2013-06-15 14:03:30 +08:00
|
|
|
_viewName, frameSize.width, frameSize.height, _frameZoomFactor);
|
2012-12-29 14:50:00 +08:00
|
|
|
MultiByteToWideChar(CP_UTF8, 0, szBuf, -1, wszBuf, sizeof(wszBuf));
|
2013-01-07 19:17:50 +08:00
|
|
|
#else
|
2013-06-15 14:03:30 +08:00
|
|
|
MultiByteToWideChar(CP_UTF8, 0, _viewName, -1, wszBuf, sizeof(wszBuf));
|
2012-10-17 15:08:25 +08:00
|
|
|
#endif
|
2013-06-15 14:03:30 +08:00
|
|
|
SetWindowText(_wnd, wszBuf);
|
2012-09-03 00:58:42 +08:00
|
|
|
}
|
2012-09-14 01:22:03 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
AdjustWindowRectEx(&rcClient, GetWindowLong(_wnd, GWL_STYLE), FALSE, GetWindowLong(_wnd, GWL_EXSTYLE));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// change width and height
|
2013-06-15 14:03:30 +08:00
|
|
|
SetWindowPos(_wnd, 0, 0, 0, width + ptDiff.x, height + ptDiff.y,
|
2012-09-03 00:58:42 +08:00
|
|
|
SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER);
|
2012-05-02 17:50:26 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void EGLView::setFrameZoomFactor(float fZoomFactor)
|
2012-10-18 10:54:19 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_frameZoomFactor = fZoomFactor;
|
|
|
|
resize(_screenSize.width * fZoomFactor, _screenSize.height * fZoomFactor);
|
2012-10-18 10:54:19 +08:00
|
|
|
centerWindow();
|
2013-06-20 14:13:12 +08:00
|
|
|
Director::sharedDirector()->setProjection(Director::sharedDirector()->getProjection());
|
2012-10-18 10:54:19 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
float EGLView::getFrameZoomFactor()
|
2012-10-19 17:39:55 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _frameZoomFactor;
|
2012-10-19 17:39:55 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void EGLView::setFrameSize(float width, float height)
|
2012-05-02 17:50:26 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
EGLViewProtocol::setFrameSize(width, height);
|
2012-09-03 00:58:42 +08:00
|
|
|
|
|
|
|
resize(width, height); // adjust window size for menubar
|
|
|
|
centerWindow();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void EGLView::centerWindow()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (! _wnd)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RECT rcDesktop, rcWindow;
|
|
|
|
GetWindowRect(GetDesktopWindow(), &rcDesktop);
|
|
|
|
|
|
|
|
// substract the task bar
|
|
|
|
HWND hTaskBar = FindWindow(TEXT("Shell_TrayWnd"), NULL);
|
|
|
|
if (hTaskBar != NULL)
|
|
|
|
{
|
|
|
|
APPBARDATA abd;
|
|
|
|
|
|
|
|
abd.cbSize = sizeof(APPBARDATA);
|
|
|
|
abd.hWnd = hTaskBar;
|
|
|
|
|
|
|
|
SHAppBarMessage(ABM_GETTASKBARPOS, &abd);
|
|
|
|
SubtractRect(&rcDesktop, &rcDesktop, &abd.rc);
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
GetWindowRect(_wnd, &rcWindow);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-05-09 19:13:24 +08:00
|
|
|
int offsetX = rcDesktop.left + (rcDesktop.right - rcDesktop.left - (rcWindow.right - rcWindow.left)) / 2;
|
2012-04-19 14:35:52 +08:00
|
|
|
offsetX = (offsetX > 0) ? offsetX : rcDesktop.left;
|
2013-05-09 19:13:24 +08:00
|
|
|
int offsetY = rcDesktop.top + (rcDesktop.bottom - rcDesktop.top - (rcWindow.bottom - rcWindow.top)) / 2;
|
2012-04-19 14:35:52 +08:00
|
|
|
offsetY = (offsetY > 0) ? offsetY : rcDesktop.top;
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
SetWindowPos(_wnd, 0, offsetX, offsetY, 0, 0, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOZORDER);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void EGLView::setViewPortInPoints(float x , float y , float w , float h)
|
2012-10-19 17:39:55 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
glViewport((GLint)(x * _scaleX * _frameZoomFactor + _viewPortRect.origin.x * _frameZoomFactor),
|
|
|
|
(GLint)(y * _scaleY * _frameZoomFactor + _viewPortRect.origin.y * _frameZoomFactor),
|
|
|
|
(GLsizei)(w * _scaleX * _frameZoomFactor),
|
|
|
|
(GLsizei)(h * _scaleY * _frameZoomFactor));
|
2012-10-18 10:54:19 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void EGLView::setScissorInPoints(float x , float y , float w , float h)
|
2012-10-24 10:03:19 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
glScissor((GLint)(x * _scaleX * _frameZoomFactor + _viewPortRect.origin.x * _frameZoomFactor),
|
|
|
|
(GLint)(y * _scaleY * _frameZoomFactor + _viewPortRect.origin.y * _frameZoomFactor),
|
|
|
|
(GLsizei)(w * _scaleX * _frameZoomFactor),
|
|
|
|
(GLsizei)(h * _scaleY * _frameZoomFactor));
|
2012-10-24 10:03:19 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
EGLView* EGLView::sharedOpenGLView()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
static EGLView* s_pEglView = NULL;
|
2012-05-02 17:50:26 +08:00
|
|
|
if (s_pEglView == NULL)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
s_pEglView = new EGLView();
|
2012-10-09 00:38:04 +08:00
|
|
|
if(!s_pEglView->Create())
|
|
|
|
{
|
|
|
|
delete s_pEglView;
|
|
|
|
s_pEglView = NULL;
|
|
|
|
}
|
2012-05-02 17:50:26 +08:00
|
|
|
}
|
2012-10-09 00:38:04 +08:00
|
|
|
|
2012-08-21 14:58:31 +08:00
|
|
|
return s_pEglView;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|