2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
2011-03-06 01:46:39 +01:00
|
|
|
// GLFW - An OpenGL library
|
2010-09-07 17:34:51 +02:00
|
|
|
// Platform: Win32/WGL
|
2010-09-07 17:41:26 +02:00
|
|
|
// API version: 3.0
|
2010-09-07 17:34:51 +02:00
|
|
|
// WWW: http://www.glfw.org/
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Copyright (c) 2002-2006 Marcus Geelnard
|
|
|
|
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
|
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
|
|
// arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it
|
|
|
|
// freely, subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
// claim that you wrote the original software. If you use this software
|
|
|
|
// in a product, an acknowledgment in the product documentation would
|
|
|
|
// be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such, and must not
|
|
|
|
// be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source
|
|
|
|
// distribution.
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
2010-09-14 01:05:03 +02:00
|
|
|
#include <stdlib.h>
|
2012-08-14 13:51:39 +02:00
|
|
|
#include <malloc.h>
|
2012-09-12 21:37:36 +02:00
|
|
|
#include <windowsx.h>
|
2010-09-13 23:50:04 +02:00
|
|
|
|
2011-10-05 00:47:39 +02:00
|
|
|
//========================================================================
|
|
|
|
// Hide mouse cursor
|
|
|
|
//========================================================================
|
|
|
|
|
2012-06-22 13:53:02 +02:00
|
|
|
static void hideCursor(_GLFWwindow* window)
|
2011-10-05 00:47:39 +02:00
|
|
|
{
|
2012-10-30 17:37:34 +01:00
|
|
|
UNREFERENCED_PARAMETER(window);
|
2011-10-05 00:47:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Capture mouse cursor
|
|
|
|
//========================================================================
|
|
|
|
|
2012-06-22 13:53:02 +02:00
|
|
|
static void captureCursor(_GLFWwindow* window)
|
2011-10-05 00:47:39 +02:00
|
|
|
{
|
|
|
|
RECT ClipWindowRect;
|
|
|
|
|
|
|
|
ShowCursor(FALSE);
|
|
|
|
|
|
|
|
// Clip cursor to the window
|
2013-01-02 01:40:42 +01:00
|
|
|
if (GetWindowRect(window->win32.handle, &ClipWindowRect))
|
2011-10-05 00:47:39 +02:00
|
|
|
ClipCursor(&ClipWindowRect);
|
|
|
|
|
|
|
|
// Capture cursor to user window
|
2013-01-02 01:40:42 +01:00
|
|
|
SetCapture(window->win32.handle);
|
2011-10-05 00:47:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Show mouse cursor
|
|
|
|
//========================================================================
|
|
|
|
|
2012-06-22 13:53:02 +02:00
|
|
|
static void showCursor(_GLFWwindow* window)
|
2011-10-05 00:47:39 +02:00
|
|
|
{
|
2012-10-30 17:37:34 +01:00
|
|
|
UNREFERENCED_PARAMETER(window);
|
|
|
|
|
2011-10-05 00:47:39 +02:00
|
|
|
// Un-capture cursor
|
|
|
|
ReleaseCapture();
|
|
|
|
|
|
|
|
// Release the cursor from the window
|
|
|
|
ClipCursor(NULL);
|
|
|
|
|
|
|
|
ShowCursor(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
|
|
|
// Translates a Windows key to the corresponding GLFW key
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 22:03:36 +02:00
|
|
|
static int translateKey(WPARAM wParam, LPARAM lParam)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
MSG next_msg;
|
|
|
|
DWORD msg_time;
|
|
|
|
DWORD scan_code;
|
|
|
|
|
2011-01-10 21:19:27 +01:00
|
|
|
// Check for numeric keypad keys.
|
|
|
|
// Note: This way we always force "NumLock = ON", which is intentional
|
|
|
|
// since the returned key code should correspond to a physical
|
|
|
|
// location.
|
2010-09-10 22:03:36 +02:00
|
|
|
int hiFlags = HIWORD(lParam);
|
|
|
|
if (!(hiFlags & 0x100))
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-10 22:03:36 +02:00
|
|
|
switch (MapVirtualKey(hiFlags & 0xFF, 1))
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
case VK_INSERT: return GLFW_KEY_KP_0;
|
|
|
|
case VK_END: return GLFW_KEY_KP_1;
|
|
|
|
case VK_DOWN: return GLFW_KEY_KP_2;
|
|
|
|
case VK_NEXT: return GLFW_KEY_KP_3;
|
|
|
|
case VK_LEFT: return GLFW_KEY_KP_4;
|
|
|
|
case VK_CLEAR: return GLFW_KEY_KP_5;
|
|
|
|
case VK_RIGHT: return GLFW_KEY_KP_6;
|
|
|
|
case VK_HOME: return GLFW_KEY_KP_7;
|
|
|
|
case VK_UP: return GLFW_KEY_KP_8;
|
|
|
|
case VK_PRIOR: return GLFW_KEY_KP_9;
|
|
|
|
case VK_DIVIDE: return GLFW_KEY_KP_DIVIDE;
|
|
|
|
case VK_MULTIPLY: return GLFW_KEY_KP_MULTIPLY;
|
|
|
|
case VK_SUBTRACT: return GLFW_KEY_KP_SUBTRACT;
|
|
|
|
case VK_ADD: return GLFW_KEY_KP_ADD;
|
|
|
|
case VK_DELETE: return GLFW_KEY_KP_DECIMAL;
|
2011-01-10 21:19:27 +01:00
|
|
|
default: break;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check which key was pressed or released
|
2010-09-10 22:03:36 +02:00
|
|
|
switch (wParam)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
// The SHIFT keys require special handling
|
|
|
|
case VK_SHIFT:
|
|
|
|
{
|
|
|
|
// Compare scan code for this key with that of VK_RSHIFT in
|
|
|
|
// order to determine which shift key was pressed (left or
|
|
|
|
// right)
|
2010-09-10 22:03:36 +02:00
|
|
|
scan_code = MapVirtualKey(VK_RSHIFT, 0);
|
|
|
|
if (((lParam & 0x01ff0000) >> 16) == scan_code)
|
2011-01-10 21:19:27 +01:00
|
|
|
return GLFW_KEY_RIGHT_SHIFT;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2011-01-10 21:19:27 +01:00
|
|
|
return GLFW_KEY_LEFT_SHIFT;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// The CTRL keys require special handling
|
|
|
|
case VK_CONTROL:
|
|
|
|
{
|
|
|
|
// Is this an extended key (i.e. right key)?
|
2010-09-10 22:03:36 +02:00
|
|
|
if (lParam & 0x01000000)
|
2011-01-10 21:38:08 +01:00
|
|
|
return GLFW_KEY_RIGHT_CONTROL;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
|
|
|
// Here is a trick: "Alt Gr" sends LCTRL, then RALT. We only
|
|
|
|
// want the RALT message, so we try to see if the next message
|
|
|
|
// is a RALT message. In that case, this is a false LCTRL!
|
|
|
|
msg_time = GetMessageTime();
|
2010-09-10 22:03:36 +02:00
|
|
|
if (PeekMessage(&next_msg, NULL, 0, 0, PM_NOREMOVE))
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-10 22:03:36 +02:00
|
|
|
if (next_msg.message == WM_KEYDOWN ||
|
|
|
|
next_msg.message == WM_SYSKEYDOWN)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-10 22:03:36 +02:00
|
|
|
if (next_msg.wParam == VK_MENU &&
|
2010-09-07 17:34:51 +02:00
|
|
|
(next_msg.lParam & 0x01000000) &&
|
2010-09-10 22:03:36 +02:00
|
|
|
next_msg.time == msg_time)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
// Next message is a RALT down message, which
|
|
|
|
// means that this is NOT a proper LCTRL message!
|
2011-01-10 21:19:27 +01:00
|
|
|
return -1;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-10 21:38:08 +01:00
|
|
|
return GLFW_KEY_LEFT_CONTROL;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// The ALT keys require special handling
|
|
|
|
case VK_MENU:
|
|
|
|
{
|
|
|
|
// Is this an extended key (i.e. right key)?
|
2010-09-10 22:03:36 +02:00
|
|
|
if (lParam & 0x01000000)
|
2011-01-10 21:19:27 +01:00
|
|
|
return GLFW_KEY_RIGHT_ALT;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2011-01-10 21:19:27 +01:00
|
|
|
return GLFW_KEY_LEFT_ALT;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// The ENTER keys require special handling
|
|
|
|
case VK_RETURN:
|
|
|
|
{
|
|
|
|
// Is this an extended key (i.e. right key)?
|
2010-09-10 22:03:36 +02:00
|
|
|
if (lParam & 0x01000000)
|
2010-09-07 17:34:51 +02:00
|
|
|
return GLFW_KEY_KP_ENTER;
|
|
|
|
|
|
|
|
return GLFW_KEY_ENTER;
|
|
|
|
}
|
|
|
|
|
2011-01-10 21:19:27 +01:00
|
|
|
// Funcion keys (non-printable keys)
|
|
|
|
case VK_ESCAPE: return GLFW_KEY_ESCAPE;
|
2010-09-07 17:34:51 +02:00
|
|
|
case VK_TAB: return GLFW_KEY_TAB;
|
|
|
|
case VK_BACK: return GLFW_KEY_BACKSPACE;
|
|
|
|
case VK_HOME: return GLFW_KEY_HOME;
|
|
|
|
case VK_END: return GLFW_KEY_END;
|
2011-01-10 21:19:27 +01:00
|
|
|
case VK_PRIOR: return GLFW_KEY_PAGE_UP;
|
|
|
|
case VK_NEXT: return GLFW_KEY_PAGE_DOWN;
|
2010-09-07 17:34:51 +02:00
|
|
|
case VK_INSERT: return GLFW_KEY_INSERT;
|
2011-01-10 21:19:27 +01:00
|
|
|
case VK_DELETE: return GLFW_KEY_DELETE;
|
2010-09-07 17:34:51 +02:00
|
|
|
case VK_LEFT: return GLFW_KEY_LEFT;
|
|
|
|
case VK_UP: return GLFW_KEY_UP;
|
|
|
|
case VK_RIGHT: return GLFW_KEY_RIGHT;
|
|
|
|
case VK_DOWN: return GLFW_KEY_DOWN;
|
|
|
|
case VK_F1: return GLFW_KEY_F1;
|
|
|
|
case VK_F2: return GLFW_KEY_F2;
|
|
|
|
case VK_F3: return GLFW_KEY_F3;
|
|
|
|
case VK_F4: return GLFW_KEY_F4;
|
|
|
|
case VK_F5: return GLFW_KEY_F5;
|
|
|
|
case VK_F6: return GLFW_KEY_F6;
|
|
|
|
case VK_F7: return GLFW_KEY_F7;
|
|
|
|
case VK_F8: return GLFW_KEY_F8;
|
|
|
|
case VK_F9: return GLFW_KEY_F9;
|
|
|
|
case VK_F10: return GLFW_KEY_F10;
|
|
|
|
case VK_F11: return GLFW_KEY_F11;
|
|
|
|
case VK_F12: return GLFW_KEY_F12;
|
|
|
|
case VK_F13: return GLFW_KEY_F13;
|
|
|
|
case VK_F14: return GLFW_KEY_F14;
|
|
|
|
case VK_F15: return GLFW_KEY_F15;
|
|
|
|
case VK_F16: return GLFW_KEY_F16;
|
|
|
|
case VK_F17: return GLFW_KEY_F17;
|
|
|
|
case VK_F18: return GLFW_KEY_F18;
|
|
|
|
case VK_F19: return GLFW_KEY_F19;
|
|
|
|
case VK_F20: return GLFW_KEY_F20;
|
|
|
|
case VK_F21: return GLFW_KEY_F21;
|
|
|
|
case VK_F22: return GLFW_KEY_F22;
|
|
|
|
case VK_F23: return GLFW_KEY_F23;
|
|
|
|
case VK_F24: return GLFW_KEY_F24;
|
2011-01-10 21:19:27 +01:00
|
|
|
case VK_NUMLOCK: return GLFW_KEY_NUM_LOCK;
|
|
|
|
case VK_CAPITAL: return GLFW_KEY_CAPS_LOCK;
|
|
|
|
case VK_SCROLL: return GLFW_KEY_SCROLL_LOCK;
|
|
|
|
case VK_PAUSE: return GLFW_KEY_PAUSE;
|
|
|
|
case VK_LWIN: return GLFW_KEY_LEFT_SUPER;
|
|
|
|
case VK_RWIN: return GLFW_KEY_RIGHT_SUPER;
|
|
|
|
case VK_APPS: return GLFW_KEY_MENU;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
|
|
|
// Numeric keypad
|
|
|
|
case VK_NUMPAD0: return GLFW_KEY_KP_0;
|
|
|
|
case VK_NUMPAD1: return GLFW_KEY_KP_1;
|
|
|
|
case VK_NUMPAD2: return GLFW_KEY_KP_2;
|
|
|
|
case VK_NUMPAD3: return GLFW_KEY_KP_3;
|
|
|
|
case VK_NUMPAD4: return GLFW_KEY_KP_4;
|
|
|
|
case VK_NUMPAD5: return GLFW_KEY_KP_5;
|
|
|
|
case VK_NUMPAD6: return GLFW_KEY_KP_6;
|
|
|
|
case VK_NUMPAD7: return GLFW_KEY_KP_7;
|
|
|
|
case VK_NUMPAD8: return GLFW_KEY_KP_8;
|
|
|
|
case VK_NUMPAD9: return GLFW_KEY_KP_9;
|
|
|
|
case VK_DIVIDE: return GLFW_KEY_KP_DIVIDE;
|
|
|
|
case VK_MULTIPLY: return GLFW_KEY_KP_MULTIPLY;
|
|
|
|
case VK_SUBTRACT: return GLFW_KEY_KP_SUBTRACT;
|
|
|
|
case VK_ADD: return GLFW_KEY_KP_ADD;
|
|
|
|
case VK_DECIMAL: return GLFW_KEY_KP_DECIMAL;
|
|
|
|
|
2011-01-10 21:19:27 +01:00
|
|
|
// Printable keys are mapped according to US layout
|
|
|
|
case VK_SPACE: return GLFW_KEY_SPACE;
|
|
|
|
case 0x30: return GLFW_KEY_0;
|
|
|
|
case 0x31: return GLFW_KEY_1;
|
|
|
|
case 0x32: return GLFW_KEY_2;
|
|
|
|
case 0x33: return GLFW_KEY_3;
|
|
|
|
case 0x34: return GLFW_KEY_4;
|
|
|
|
case 0x35: return GLFW_KEY_5;
|
|
|
|
case 0x36: return GLFW_KEY_6;
|
|
|
|
case 0x37: return GLFW_KEY_7;
|
|
|
|
case 0x38: return GLFW_KEY_8;
|
|
|
|
case 0x39: return GLFW_KEY_9;
|
|
|
|
case 0x41: return GLFW_KEY_A;
|
|
|
|
case 0x42: return GLFW_KEY_B;
|
|
|
|
case 0x43: return GLFW_KEY_C;
|
|
|
|
case 0x44: return GLFW_KEY_D;
|
|
|
|
case 0x45: return GLFW_KEY_E;
|
|
|
|
case 0x46: return GLFW_KEY_F;
|
|
|
|
case 0x47: return GLFW_KEY_G;
|
|
|
|
case 0x48: return GLFW_KEY_H;
|
|
|
|
case 0x49: return GLFW_KEY_I;
|
|
|
|
case 0x4A: return GLFW_KEY_J;
|
|
|
|
case 0x4B: return GLFW_KEY_K;
|
|
|
|
case 0x4C: return GLFW_KEY_L;
|
|
|
|
case 0x4D: return GLFW_KEY_M;
|
|
|
|
case 0x4E: return GLFW_KEY_N;
|
|
|
|
case 0x4F: return GLFW_KEY_O;
|
|
|
|
case 0x50: return GLFW_KEY_P;
|
|
|
|
case 0x51: return GLFW_KEY_Q;
|
|
|
|
case 0x52: return GLFW_KEY_R;
|
|
|
|
case 0x53: return GLFW_KEY_S;
|
|
|
|
case 0x54: return GLFW_KEY_T;
|
|
|
|
case 0x55: return GLFW_KEY_U;
|
|
|
|
case 0x56: return GLFW_KEY_V;
|
|
|
|
case 0x57: return GLFW_KEY_W;
|
|
|
|
case 0x58: return GLFW_KEY_X;
|
|
|
|
case 0x59: return GLFW_KEY_Y;
|
|
|
|
case 0x5A: return GLFW_KEY_Z;
|
|
|
|
case 0xBD: return GLFW_KEY_MINUS;
|
|
|
|
case 0xBB: return GLFW_KEY_EQUAL;
|
|
|
|
case 0xDB: return GLFW_KEY_LEFT_BRACKET;
|
|
|
|
case 0xDD: return GLFW_KEY_RIGHT_BRACKET;
|
|
|
|
case 0xDC: return GLFW_KEY_BACKSLASH;
|
|
|
|
case 0xBA: return GLFW_KEY_SEMICOLON;
|
|
|
|
case 0xDE: return GLFW_KEY_APOSTROPHE;
|
|
|
|
case 0xC0: return GLFW_KEY_GRAVE_ACCENT;
|
|
|
|
case 0xBC: return GLFW_KEY_COMMA;
|
|
|
|
case 0xBE: return GLFW_KEY_PERIOD;
|
|
|
|
case 0xBF: return GLFW_KEY_SLASH;
|
|
|
|
case 0xDF: return GLFW_KEY_WORLD_1;
|
|
|
|
case 0xE2: return GLFW_KEY_WORLD_2;
|
|
|
|
default: break;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
2011-01-10 21:19:27 +01:00
|
|
|
|
|
|
|
// No matching translation was found, so return -1
|
|
|
|
return -1;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Window callback function (handles window events)
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 22:03:36 +02:00
|
|
|
static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|
|
|
WPARAM wParam, LPARAM lParam)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-12 16:26:00 +02:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) GetWindowLongPtr(hWnd, 0);
|
|
|
|
|
2010-09-10 22:03:36 +02:00
|
|
|
switch (uMsg)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-14 01:05:03 +02:00
|
|
|
case WM_CREATE:
|
|
|
|
{
|
|
|
|
CREATESTRUCT* cs = (CREATESTRUCT*) lParam;
|
2010-09-14 02:17:18 +02:00
|
|
|
SetWindowLongPtr(hWnd, 0, (LONG_PTR) cs->lpCreateParams);
|
2010-09-14 01:05:03 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
case WM_ACTIVATE:
|
|
|
|
{
|
2012-11-22 17:04:44 +01:00
|
|
|
// Window was (de)focused and/or (de)iconified
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-11-22 17:04:44 +01:00
|
|
|
BOOL focused = LOWORD(wParam) != WA_INACTIVE;
|
2010-09-19 01:24:51 +02:00
|
|
|
BOOL iconified = HIWORD(wParam) ? TRUE : FALSE;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-11-22 17:04:44 +01:00
|
|
|
if (focused && iconified)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-19 02:49:42 +02:00
|
|
|
// This is a workaround for window iconification using the
|
2012-11-22 17:04:44 +01:00
|
|
|
// taskbar leading to windows being told they're focused and
|
|
|
|
// iconified and then never told they're defocused
|
|
|
|
focused = FALSE;
|
2010-09-19 02:49:42 +02:00
|
|
|
}
|
2010-09-19 01:24:51 +02:00
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (!focused && _glfw.focusedWindow == window)
|
2010-09-19 02:49:42 +02:00
|
|
|
{
|
2012-11-22 17:04:44 +01:00
|
|
|
// The window was defocused (or iconified, see above)
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2011-09-06 13:55:29 +02:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
2012-06-22 13:53:02 +02:00
|
|
|
showCursor(window);
|
2010-09-19 01:24:51 +02:00
|
|
|
|
2012-09-27 21:37:36 +02:00
|
|
|
if (window->monitor)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-10 22:03:36 +02:00
|
|
|
if (!iconified)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-19 01:24:51 +02:00
|
|
|
// Iconify the (on top, borderless, oddly positioned)
|
|
|
|
// window or the user will be annoyed
|
2010-09-20 01:57:50 +02:00
|
|
|
_glfwPlatformIconifyWindow(window);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (_glfw.win32.monitor.modeChanged)
|
2010-09-19 01:24:51 +02:00
|
|
|
{
|
|
|
|
_glfwRestoreVideoMode();
|
2013-01-02 01:40:42 +01:00
|
|
|
_glfw.win32.monitor.modeChanged = GL_FALSE;
|
2010-09-19 01:24:51 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
}
|
2013-01-02 01:40:42 +01:00
|
|
|
else if (focused && _glfw.focusedWindow != window)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2012-11-22 17:04:44 +01:00
|
|
|
// The window was focused
|
2010-09-19 02:49:42 +02:00
|
|
|
|
2011-09-06 13:55:29 +02:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
2012-06-22 13:53:02 +02:00
|
|
|
captureCursor(window);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-09-27 21:37:36 +02:00
|
|
|
if (window->monitor)
|
2010-09-19 01:24:51 +02:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
if (!_glfw.win32.monitor.modeChanged)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
_glfwSetVideoMode(&_glfw.win32.monitor.width,
|
|
|
|
&_glfw.win32.monitor.height,
|
|
|
|
&_glfw.win32.monitor.bitsPerPixel,
|
2010-09-19 01:24:51 +02:00
|
|
|
GL_TRUE);
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
_glfw.win32.monitor.modeChanged = GL_TRUE;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
}
|
2010-09-19 01:24:51 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-11-22 17:04:44 +01:00
|
|
|
_glfwInputWindowFocus(window, focused);
|
2011-10-09 17:10:40 +02:00
|
|
|
_glfwInputWindowIconify(window, iconified);
|
2010-09-07 17:34:51 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-21 21:18:09 +02:00
|
|
|
case WM_SHOWWINDOW:
|
|
|
|
{
|
|
|
|
_glfwInputWindowVisibility(window, wParam ? GL_TRUE : GL_FALSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
case WM_SYSCOMMAND:
|
|
|
|
{
|
2010-09-10 22:03:36 +02:00
|
|
|
switch (wParam & 0xfff0)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
case SC_SCREENSAVE:
|
|
|
|
case SC_MONITORPOWER:
|
|
|
|
{
|
2012-09-27 21:37:36 +02:00
|
|
|
if (window->monitor)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-10 22:03:36 +02:00
|
|
|
// We are running in fullscreen mode, so disallow
|
|
|
|
// screen saver and screen blanking
|
2010-09-07 17:34:51 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// User trying to access application menu using ALT?
|
|
|
|
case SC_KEYMENU:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_CLOSE:
|
|
|
|
{
|
2012-08-10 13:31:15 +02:00
|
|
|
_glfwInputWindowCloseRequest(window);
|
2010-09-07 17:34:51 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
{
|
2010-09-13 23:50:04 +02:00
|
|
|
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_PRESS);
|
2012-02-07 16:44:22 +01:00
|
|
|
break;
|
2010-11-15 20:21:09 +01:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-09-19 13:17:53 +02:00
|
|
|
case WM_CHAR:
|
|
|
|
{
|
|
|
|
_glfwInputChar(window, wParam);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
case WM_KEYUP:
|
|
|
|
case WM_SYSKEYUP:
|
|
|
|
{
|
|
|
|
// Special trick: release both shift keys on SHIFT up event
|
2010-09-10 22:03:36 +02:00
|
|
|
if (wParam == VK_SHIFT)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2011-01-10 21:19:27 +01:00
|
|
|
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, GLFW_RELEASE);
|
|
|
|
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, GLFW_RELEASE);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
else
|
2010-09-13 23:50:04 +02:00
|
|
|
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_RELEASE);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-02-07 16:44:22 +01:00
|
|
|
break;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case WM_LBUTTONDOWN:
|
2010-09-10 22:03:36 +02:00
|
|
|
{
|
2010-09-07 17:34:51 +02:00
|
|
|
SetCapture(hWnd);
|
2010-09-13 23:50:04 +02:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS);
|
2010-09-07 17:34:51 +02:00
|
|
|
return 0;
|
2010-09-10 22:03:36 +02:00
|
|
|
}
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
case WM_RBUTTONDOWN:
|
2010-09-10 22:03:36 +02:00
|
|
|
{
|
2010-09-07 17:34:51 +02:00
|
|
|
SetCapture(hWnd);
|
2010-09-13 23:50:04 +02:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS);
|
2010-09-07 17:34:51 +02:00
|
|
|
return 0;
|
2010-09-10 22:03:36 +02:00
|
|
|
}
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
case WM_MBUTTONDOWN:
|
2010-09-10 22:03:36 +02:00
|
|
|
{
|
2010-09-07 17:34:51 +02:00
|
|
|
SetCapture(hWnd);
|
2010-09-13 23:50:04 +02:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_MIDDLE, GLFW_PRESS);
|
2010-09-07 17:34:51 +02:00
|
|
|
return 0;
|
2010-09-10 22:03:36 +02:00
|
|
|
}
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
case WM_XBUTTONDOWN:
|
|
|
|
{
|
2010-09-10 22:03:36 +02:00
|
|
|
if (HIWORD(wParam) == XBUTTON1)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
SetCapture(hWnd);
|
2010-09-13 23:50:04 +02:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_4, GLFW_PRESS);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
2010-09-10 22:03:36 +02:00
|
|
|
else if (HIWORD(wParam) == XBUTTON2)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
SetCapture(hWnd);
|
2010-09-13 23:50:04 +02:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_5, GLFW_PRESS);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
2010-09-10 22:03:36 +02:00
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_LBUTTONUP:
|
2010-09-10 22:03:36 +02:00
|
|
|
{
|
2010-09-07 17:34:51 +02:00
|
|
|
ReleaseCapture();
|
2010-09-13 23:50:04 +02:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE);
|
2010-09-07 17:34:51 +02:00
|
|
|
return 0;
|
2010-09-10 22:03:36 +02:00
|
|
|
}
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
case WM_RBUTTONUP:
|
2010-09-10 22:03:36 +02:00
|
|
|
{
|
2010-09-07 17:34:51 +02:00
|
|
|
ReleaseCapture();
|
2010-09-13 23:50:04 +02:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE);
|
2010-09-07 17:34:51 +02:00
|
|
|
return 0;
|
2010-09-10 22:03:36 +02:00
|
|
|
}
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
case WM_MBUTTONUP:
|
2010-09-10 22:03:36 +02:00
|
|
|
{
|
2010-09-07 17:34:51 +02:00
|
|
|
ReleaseCapture();
|
2010-09-13 23:50:04 +02:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_MIDDLE, GLFW_RELEASE);
|
2010-09-07 17:34:51 +02:00
|
|
|
return 0;
|
2010-09-10 22:03:36 +02:00
|
|
|
}
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
case WM_XBUTTONUP:
|
|
|
|
{
|
2010-09-10 22:03:36 +02:00
|
|
|
if (HIWORD(wParam) == XBUTTON1)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
ReleaseCapture();
|
2010-09-13 23:50:04 +02:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_4, GLFW_RELEASE);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
2010-09-10 22:03:36 +02:00
|
|
|
else if (HIWORD(wParam) == XBUTTON2)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
ReleaseCapture();
|
2010-09-13 23:50:04 +02:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_5, GLFW_RELEASE);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
2010-09-10 22:03:36 +02:00
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
{
|
2012-06-22 13:53:02 +02:00
|
|
|
int newCursorX, newCursorY;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-06-22 13:53:02 +02:00
|
|
|
// Get signed (!) cursor position
|
2012-09-12 21:37:36 +02:00
|
|
|
newCursorX = GET_X_LPARAM(lParam);
|
|
|
|
newCursorY = GET_Y_LPARAM(lParam);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (newCursorX != window->win32.oldCursorX ||
|
|
|
|
newCursorY != window->win32.oldCursorY)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2011-10-09 17:10:40 +02:00
|
|
|
int x, y;
|
|
|
|
|
2011-09-06 13:55:29 +02:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
if (_glfw.focusedWindow != window)
|
2011-09-06 13:55:29 +02:00
|
|
|
return 0;
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
x = newCursorX - window->win32.oldCursorX;
|
|
|
|
y = newCursorY - window->win32.oldCursorY;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-22 13:53:02 +02:00
|
|
|
x = newCursorX;
|
|
|
|
y = newCursorY;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
2010-09-10 22:03:36 +02:00
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
window->win32.oldCursorX = newCursorX;
|
|
|
|
window->win32.oldCursorY = newCursorY;
|
|
|
|
window->win32.cursorCentered = GL_FALSE;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2011-10-09 17:10:40 +02:00
|
|
|
_glfwInputCursorMotion(window, x, y);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
2010-09-10 22:03:36 +02:00
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (!window->win32.cursorInside)
|
2012-03-22 13:17:44 +01:00
|
|
|
{
|
|
|
|
TRACKMOUSEEVENT tme;
|
|
|
|
ZeroMemory(&tme, sizeof(tme));
|
|
|
|
tme.cbSize = sizeof(tme);
|
|
|
|
tme.dwFlags = TME_LEAVE;
|
2013-01-02 01:40:42 +01:00
|
|
|
tme.hwndTrack = window->win32.handle;
|
2012-03-22 13:17:44 +01:00
|
|
|
TrackMouseEvent(&tme);
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
window->win32.cursorInside = GL_TRUE;
|
2012-03-22 13:17:44 +01:00
|
|
|
_glfwInputCursorEnter(window, GL_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOUSELEAVE:
|
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
window->win32.cursorInside = GL_FALSE;
|
2012-03-22 13:17:44 +01:00
|
|
|
_glfwInputCursorEnter(window, GL_FALSE);
|
2010-09-07 17:34:51 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
{
|
2012-03-28 21:54:09 +02:00
|
|
|
_glfwInputScroll(window, 0.0, (SHORT) HIWORD(wParam) / (double) WHEEL_DELTA);
|
2010-09-27 02:32:41 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2010-09-10 22:03:36 +02:00
|
|
|
|
2010-09-27 02:32:41 +02:00
|
|
|
case WM_MOUSEHWHEEL:
|
|
|
|
{
|
|
|
|
// This message is only sent on Windows Vista and later
|
2010-09-10 22:03:36 +02:00
|
|
|
|
2012-03-28 21:54:09 +02:00
|
|
|
_glfwInputScroll(window, (SHORT) HIWORD(wParam) / (double) WHEEL_DELTA, 0.0);
|
2010-09-12 16:26:00 +02:00
|
|
|
return 0;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case WM_SIZE:
|
|
|
|
{
|
2011-09-06 13:55:29 +02:00
|
|
|
// If window is in cursor capture mode, update clipping rect
|
|
|
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
RECT ClipWindowRect;
|
2013-01-02 01:40:42 +01:00
|
|
|
if (GetWindowRect(window->win32.handle, &ClipWindowRect))
|
2010-09-10 22:03:36 +02:00
|
|
|
ClipCursor(&ClipWindowRect);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2011-10-09 17:10:40 +02:00
|
|
|
_glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam));
|
2010-09-07 17:34:51 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOVE:
|
|
|
|
{
|
2011-09-06 13:55:29 +02:00
|
|
|
// If window is in cursor capture mode, update clipping rect
|
|
|
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
RECT ClipWindowRect;
|
2013-01-02 01:40:42 +01:00
|
|
|
if (GetWindowRect(window->win32.handle, &ClipWindowRect))
|
2010-09-10 22:03:36 +02:00
|
|
|
ClipCursor(&ClipWindowRect);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
2011-10-09 17:10:40 +02:00
|
|
|
|
|
|
|
_glfwInputWindowPos(window, LOWORD(lParam), HIWORD(lParam));
|
2010-09-07 17:34:51 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Was the window contents damaged?
|
|
|
|
case WM_PAINT:
|
|
|
|
{
|
2011-10-09 21:12:13 +02:00
|
|
|
_glfwInputWindowDamage(window);
|
2010-09-07 17:34:51 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_DISPLAYCHANGE:
|
|
|
|
{
|
|
|
|
// TODO: Do stuff here.
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2011-10-14 20:32:06 +02:00
|
|
|
|
|
|
|
case WM_DEVICECHANGE:
|
|
|
|
{
|
|
|
|
if (DBT_DEVNODES_CHANGED == wParam)
|
|
|
|
{
|
2012-09-12 19:35:52 +02:00
|
|
|
_glfwInputMonitorChange();
|
2011-10-14 20:32:06 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pass all unhandled messages to DefWindowProc
|
2010-09-10 22:03:36 +02:00
|
|
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Translate client window size to full window size (including window borders)
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 16:26:00 +02:00
|
|
|
static void getFullWindowSize(_GLFWwindow* window,
|
|
|
|
int clientWidth, int clientHeight,
|
2010-09-10 22:03:36 +02:00
|
|
|
int* fullWidth, int* fullHeight)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
RECT rect;
|
|
|
|
|
|
|
|
// Create a window rectangle
|
2010-09-10 22:03:36 +02:00
|
|
|
rect.left = (long) 0;
|
|
|
|
rect.right = (long) clientWidth - 1;
|
|
|
|
rect.top = (long) 0;
|
|
|
|
rect.bottom = (long) clientHeight - 1;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
|
|
|
// Adjust according to window styles
|
2013-01-02 01:40:42 +01:00
|
|
|
AdjustWindowRectEx(&rect, window->win32.dwStyle, FALSE, window->win32.dwExStyle);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
|
|
|
// Calculate width and height of full window
|
|
|
|
*fullWidth = rect.right - rect.left + 1;
|
|
|
|
*fullHeight = rect.bottom - rect.top + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Registers the GLFW window class
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 22:03:36 +02:00
|
|
|
static ATOM registerWindowClass(void)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
WNDCLASS wc;
|
2010-09-14 02:17:18 +02:00
|
|
|
ATOM classAtom;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
|
|
|
// Set window class parameters
|
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw on...
|
2010-09-12 16:26:00 +02:00
|
|
|
wc.lpfnWndProc = (WNDPROC) windowProc; // Message handler
|
2010-09-07 17:34:51 +02:00
|
|
|
wc.cbClsExtra = 0; // No extra class data
|
2010-09-12 16:26:00 +02:00
|
|
|
wc.cbWndExtra = sizeof(void*) + sizeof(int); // Make room for one pointer
|
2013-01-02 01:40:42 +01:00
|
|
|
wc.hInstance = _glfw.win32.instance; // Set instance
|
2010-09-12 16:26:00 +02:00
|
|
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load arrow pointer
|
2010-09-07 17:34:51 +02:00
|
|
|
wc.hbrBackground = NULL; // No background
|
|
|
|
wc.lpszMenuName = NULL; // No menu
|
|
|
|
wc.lpszClassName = _GLFW_WNDCLASSNAME; // Set class name
|
|
|
|
|
|
|
|
// Load user-provided icon if available
|
2013-01-02 01:40:42 +01:00
|
|
|
wc.hIcon = LoadIcon(_glfw.win32.instance, L"GLFW_ICON");
|
2010-09-10 22:03:36 +02:00
|
|
|
if (!wc.hIcon)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
// Load default icon
|
2010-09-10 22:03:36 +02:00
|
|
|
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 02:17:18 +02:00
|
|
|
classAtom = RegisterClass(&wc);
|
|
|
|
if (!classAtom)
|
|
|
|
{
|
2012-12-31 21:05:28 +01:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to register window class");
|
2010-09-14 02:17:18 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return classAtom;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Creates the GLFW window and rendering context
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 16:26:00 +02:00
|
|
|
static int createWindow(_GLFWwindow* window,
|
|
|
|
const _GLFWwndconfig* wndconfig,
|
2010-09-10 22:03:36 +02:00
|
|
|
const _GLFWfbconfig* fbconfig)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
DWORD dwStyle, dwExStyle;
|
2012-10-22 02:39:22 +02:00
|
|
|
int positionX, positionY, fullWidth, fullHeight;
|
2010-09-07 17:34:51 +02:00
|
|
|
POINT pos;
|
2012-02-03 20:34:24 +01:00
|
|
|
WCHAR* wideTitle;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
|
|
|
// Set common window styles
|
2012-08-28 21:37:07 +02:00
|
|
|
dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
|
2010-09-07 17:34:51 +02:00
|
|
|
dwExStyle = WS_EX_APPWINDOW;
|
|
|
|
|
|
|
|
// Set window style, depending on fullscreen mode
|
2012-09-27 21:37:36 +02:00
|
|
|
if (window->monitor)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
dwStyle |= WS_POPUP;
|
|
|
|
|
|
|
|
// Here's a trick for helping us getting window focus
|
|
|
|
// (SetForegroundWindow doesn't work properly under
|
|
|
|
// Win98/ME/2K/.NET/+)
|
|
|
|
/*
|
2013-01-02 01:40:42 +01:00
|
|
|
if (_glfw.Sys.WinVer != _GLFW_WIN_95 &&
|
|
|
|
_glfw.Sys.WinVer != _GLFW_WIN_NT4 &&
|
|
|
|
_glfw.Sys.WinVer != _GLFW_WIN_XP)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
dwStyle |= WS_MINIMIZE;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dwStyle |= WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
|
|
|
|
|
2011-11-02 16:56:34 +01:00
|
|
|
if (wndconfig->resizable)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-10 22:03:36 +02:00
|
|
|
dwStyle |= (WS_MAXIMIZEBOX | WS_SIZEBOX);
|
2010-09-07 17:34:51 +02:00
|
|
|
dwExStyle |= WS_EX_WINDOWEDGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remember window styles (used by getFullWindowSize)
|
2013-01-02 01:40:42 +01:00
|
|
|
window->win32.dwStyle = dwStyle;
|
|
|
|
window->win32.dwExStyle = dwExStyle;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
|
|
|
// Adjust window size for frame and title bar
|
2010-09-13 23:50:04 +02:00
|
|
|
getFullWindowSize(window, window->width, window->height, &fullWidth, &fullHeight);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-09-27 21:37:36 +02:00
|
|
|
if (window->monitor)
|
2012-10-05 04:10:42 +02:00
|
|
|
{
|
|
|
|
// Fullscreen windows are always opened in the upper left corner
|
|
|
|
// regardless of the desktop working area
|
2012-10-22 02:39:22 +02:00
|
|
|
positionX = wndconfig->monitor->positionX;
|
|
|
|
positionY = wndconfig->monitor->positionY;
|
2012-10-05 04:10:42 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
else
|
2012-10-05 04:10:42 +02:00
|
|
|
{
|
|
|
|
RECT wa;
|
2010-09-10 22:03:36 +02:00
|
|
|
SystemParametersInfo(SPI_GETWORKAREA, 0, &wa, 0);
|
|
|
|
|
2012-10-05 04:10:42 +02:00
|
|
|
// Adjust window position to working area
|
2012-11-27 16:55:04 +01:00
|
|
|
positionX = wndconfig->positionX + wa.left;
|
|
|
|
positionY = wndconfig->positionY + wa.top;
|
2012-10-05 04:10:42 +02:00
|
|
|
}
|
|
|
|
|
2012-02-05 02:07:50 +01:00
|
|
|
wideTitle = _glfwCreateWideStringFromUTF8(wndconfig->title);
|
2012-02-03 20:34:24 +01:00
|
|
|
if (!wideTitle)
|
|
|
|
{
|
2012-12-31 21:05:28 +01:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to convert title to wide string");
|
2012-02-07 16:21:19 +01:00
|
|
|
return GL_FALSE;
|
2012-02-03 20:34:24 +01:00
|
|
|
}
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
window->win32.handle = CreateWindowEx(window->win32.dwExStyle,
|
2010-09-12 16:26:00 +02:00
|
|
|
_GLFW_WNDCLASSNAME,
|
2012-02-03 20:34:24 +01:00
|
|
|
wideTitle,
|
2013-01-02 01:40:42 +01:00
|
|
|
window->win32.dwStyle,
|
2012-10-22 02:39:22 +02:00
|
|
|
positionX, positionY,
|
2010-09-12 16:26:00 +02:00
|
|
|
fullWidth, // Decorated window width
|
|
|
|
fullHeight, // Decorated window height
|
|
|
|
NULL, // No parent window
|
|
|
|
NULL, // No menu
|
2013-01-02 01:40:42 +01:00
|
|
|
_glfw.win32.instance,
|
2010-09-14 01:05:03 +02:00
|
|
|
window); // Pass GLFW window to WM_CREATE
|
2010-09-12 16:26:00 +02:00
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (!window->win32.handle)
|
2010-09-10 22:03:36 +02:00
|
|
|
{
|
2012-12-31 21:05:28 +01:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to create window");
|
2010-09-07 17:34:51 +02:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-02-07 14:58:58 +01:00
|
|
|
free(wideTitle);
|
2012-02-03 20:34:24 +01:00
|
|
|
|
2012-06-22 13:53:02 +02:00
|
|
|
// Initialize cursor position data
|
2010-09-10 22:03:36 +02:00
|
|
|
GetCursorPos(&pos);
|
2013-01-02 01:40:42 +01:00
|
|
|
ScreenToClient(window->win32.handle, &pos);
|
|
|
|
window->win32.oldCursorX = window->cursorPosX = pos.x;
|
|
|
|
window->win32.oldCursorY = window->cursorPosY = pos.y;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-07-31 22:48:28 +02:00
|
|
|
if (!_glfwCreateContext(window, wndconfig, fbconfig))
|
|
|
|
return GL_FALSE;
|
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Destroys the GLFW window and rendering context
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-13 23:50:04 +02:00
|
|
|
static void destroyWindow(_GLFWwindow* window)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2012-07-31 22:48:28 +02:00
|
|
|
_glfwDestroyContext(window);
|
2010-09-14 02:54:05 +02:00
|
|
|
|
2012-08-06 17:56:41 +02:00
|
|
|
// This is duplicated from glfwDestroyWindow
|
2010-09-14 02:54:05 +02:00
|
|
|
// TODO: Stop duplicating code
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window == _glfw.focusedWindow)
|
|
|
|
_glfw.focusedWindow = NULL;
|
2010-09-14 02:54:05 +02:00
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (window->win32.handle)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
DestroyWindow(window->win32.handle);
|
|
|
|
window->win32.handle = NULL;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-10 22:03:36 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-09-07 17:34:51 +02:00
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Here is where the window is created, and the OpenGL rendering context is
|
|
|
|
// created
|
|
|
|
//========================================================================
|
|
|
|
|
2012-08-06 17:56:41 +02:00
|
|
|
int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
|
|
|
const _GLFWwndconfig* wndconfig,
|
|
|
|
const _GLFWfbconfig* fbconfig)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2012-12-13 22:43:23 +01:00
|
|
|
int status;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
if (!_glfw.win32.classAtom)
|
2010-09-14 02:17:18 +02:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
_glfw.win32.classAtom = registerWindowClass();
|
|
|
|
if (!_glfw.win32.classAtom)
|
2010-09-14 02:17:18 +02:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-09-27 21:37:36 +02:00
|
|
|
if (window->monitor)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-13 23:50:04 +02:00
|
|
|
int bpp = fbconfig->redBits + fbconfig->greenBits + fbconfig->blueBits;
|
|
|
|
if (bpp < 15 || bpp >= 24)
|
|
|
|
bpp = 32;
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
_glfw.win32.monitor.width = window->width;
|
|
|
|
_glfw.win32.monitor.height = window->height;
|
|
|
|
_glfw.win32.monitor.bitsPerPixel = bpp;
|
2010-09-19 01:24:51 +02:00
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
_glfwSetVideoMode(&_glfw.win32.monitor.width,
|
|
|
|
&_glfw.win32.monitor.height,
|
|
|
|
&_glfw.win32.monitor.bitsPerPixel,
|
2010-09-19 01:24:51 +02:00
|
|
|
GL_FALSE);
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
_glfw.win32.monitor.modeChanged = GL_TRUE;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2010-09-12 16:26:00 +02:00
|
|
|
if (!createWindow(window, wndconfig, fbconfig))
|
2010-09-07 17:34:51 +02:00
|
|
|
return GL_FALSE;
|
|
|
|
|
2012-12-13 22:43:23 +01:00
|
|
|
status = _glfwAnalyzeContext(window, wndconfig, fbconfig);
|
2010-11-15 20:19:29 +01:00
|
|
|
|
2012-12-13 22:43:23 +01:00
|
|
|
if (status == _GLFW_RECREATION_IMPOSSIBLE)
|
|
|
|
return GL_FALSE;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-12-13 22:43:23 +01:00
|
|
|
if (status == _GLFW_RECREATION_REQUIRED)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
// Some window hints require us to re-create the context using WGL
|
|
|
|
// extensions retrieved through the current context, as we cannot check
|
|
|
|
// for WGL extensions or retrieve WGL entry points before we have a
|
|
|
|
// current context (actually until we have implicitly loaded the ICD)
|
|
|
|
|
|
|
|
// Yes, this is strange, and yes, this is the proper way on Win32
|
|
|
|
|
|
|
|
// As Windows only allows you to set the pixel format once for a
|
|
|
|
// window, we need to destroy the current window and create a new one
|
|
|
|
// to be able to use the new pixel format
|
|
|
|
|
|
|
|
// Technically, it may be possible to keep the old window around if
|
|
|
|
// we're just creating an OpenGL 3.0+ context with the same pixel
|
2011-09-06 14:52:42 +02:00
|
|
|
// format, but it's not worth the added code complexity
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-10-21 21:57:29 +02:00
|
|
|
// First we clear the current context (the one we just created)
|
|
|
|
// This is usually done by glfwDestroyWindow, but as we're not doing
|
|
|
|
// full window destruction, it's duplicated here
|
|
|
|
_glfwPlatformMakeContextCurrent(NULL);
|
|
|
|
|
|
|
|
// Next destroy the Win32 window and WGL context (without resetting or
|
|
|
|
// destroying the GLFW window object)
|
2010-09-13 23:50:04 +02:00
|
|
|
destroyWindow(window);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-10-21 21:57:29 +02:00
|
|
|
// ...and then create them again, this time with better APIs
|
2010-09-12 16:26:00 +02:00
|
|
|
if (!createWindow(window, wndconfig, fbconfig))
|
2010-09-07 17:34:51 +02:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-09-27 21:37:36 +02:00
|
|
|
if (window->monitor)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
// Place the window above all topmost windows
|
2012-09-23 15:08:43 +02:00
|
|
|
_glfwPlatformShowWindow(window);
|
2013-01-02 01:40:42 +01:00
|
|
|
SetWindowPos(window->win32.handle, HWND_TOPMOST, 0,0,0,0,
|
2010-09-10 22:03:36 +02:00
|
|
|
SWP_NOMOVE | SWP_NOSIZE);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Properly kill the window / video display
|
|
|
|
//========================================================================
|
|
|
|
|
2012-08-06 17:56:41 +02:00
|
|
|
void _glfwPlatformDestroyWindow(_GLFWwindow* window)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-13 23:50:04 +02:00
|
|
|
destroyWindow(window);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-09-27 21:37:36 +02:00
|
|
|
if (window->monitor)
|
2010-09-19 01:24:51 +02:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
if (_glfw.win32.monitor.modeChanged)
|
2010-09-19 01:24:51 +02:00
|
|
|
{
|
|
|
|
_glfwRestoreVideoMode();
|
2013-01-02 01:40:42 +01:00
|
|
|
_glfw.win32.monitor.modeChanged = GL_FALSE;
|
2010-09-19 01:24:51 +02:00
|
|
|
}
|
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Set the window title
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 16:26:00 +02:00
|
|
|
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2012-02-05 02:07:50 +01:00
|
|
|
WCHAR* wideTitle = _glfwCreateWideStringFromUTF8(title);
|
2012-02-03 20:34:24 +01:00
|
|
|
if (!wideTitle)
|
|
|
|
{
|
2012-12-31 21:05:28 +01:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to convert title to wide string");
|
2012-02-03 20:34:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
SetWindowText(window->win32.handle, wideTitle);
|
2012-02-03 20:34:24 +01:00
|
|
|
|
2012-02-07 14:58:58 +01:00
|
|
|
free(wideTitle);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Set the window size.
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 16:26:00 +02:00
|
|
|
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-13 23:50:04 +02:00
|
|
|
GLboolean sizeChanged = GL_FALSE;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2012-09-27 21:37:36 +02:00
|
|
|
if (window->monitor)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2010-09-13 23:50:04 +02:00
|
|
|
if (width > window->width || height > window->height)
|
|
|
|
{
|
|
|
|
// The new video mode is larger than the current one, so we resize
|
|
|
|
// the window before switch modes to avoid exposing whatever is
|
|
|
|
// underneath
|
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
SetWindowPos(window->win32.handle, HWND_TOP, 0, 0, width, height,
|
2010-09-13 23:50:04 +02:00
|
|
|
SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER);
|
|
|
|
sizeChanged = GL_TRUE;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
2010-09-13 23:50:04 +02:00
|
|
|
|
2012-03-25 20:45:06 +02:00
|
|
|
// TODO: Change video mode
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If we are in windowed mode, adjust the window size to
|
|
|
|
// compensate for window decorations
|
2010-09-13 23:50:04 +02:00
|
|
|
getFullWindowSize(window, width, height, &width, &height);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2010-09-13 23:50:04 +02:00
|
|
|
// Set window size (if we haven't already)
|
|
|
|
if (!sizeChanged)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
SetWindowPos(window->win32.handle, HWND_TOP, 0, 0, width, height,
|
2010-09-12 16:26:00 +02:00
|
|
|
SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Window iconification
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 16:26:00 +02:00
|
|
|
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
ShowWindow(window->win32.handle, SW_MINIMIZE);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Window un-iconification
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-12 16:26:00 +02:00
|
|
|
void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
ShowWindow(window->win32.handle, SW_RESTORE);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-21 20:01:57 +02:00
|
|
|
//========================================================================
|
|
|
|
// Show or hide window
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
void _glfwPlatformShowWindow(_GLFWwindow* window)
|
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
ShowWindow(window->win32.handle, SW_SHOWNORMAL);
|
|
|
|
BringWindowToTop(window->win32.handle);
|
|
|
|
SetForegroundWindow(window->win32.handle);
|
|
|
|
SetFocus(window->win32.handle);
|
2012-08-21 20:01:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
// Show or hide window
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
void _glfwPlatformHideWindow(_GLFWwindow* window)
|
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
ShowWindow(window->win32.handle, SW_HIDE);
|
2012-08-21 20:01:57 +02:00
|
|
|
}
|
|
|
|
|
2012-09-13 21:57:42 +02:00
|
|
|
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
|
|
|
// Poll for new window and input events
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 22:03:36 +02:00
|
|
|
void _glfwPlatformPollEvents(void)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
MSG msg;
|
2010-09-13 23:50:04 +02:00
|
|
|
_GLFWwindow* window;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
window = _glfw.focusedWindow;
|
2010-09-13 23:50:04 +02:00
|
|
|
if (window)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
window->win32.cursorCentered = GL_FALSE;
|
|
|
|
window->win32.oldCursorX = window->width / 2;
|
|
|
|
window->win32.oldCursorY = window->height / 2;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-02 01:40:42 +01:00
|
|
|
//window->win32.oldCursorX = window->cursorPosX;
|
|
|
|
//window->win32.oldCursorY = window->cursorPosY;
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2010-09-10 22:03:36 +02:00
|
|
|
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2012-09-19 13:17:53 +02:00
|
|
|
if (msg.message == WM_QUIT)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2012-09-19 13:17:53 +02:00
|
|
|
// Treat WM_QUIT as a close on all windows
|
2010-09-13 23:50:04 +02:00
|
|
|
|
2013-01-02 01:40:42 +01:00
|
|
|
window = _glfw.windowListHead;
|
2012-09-19 13:17:53 +02:00
|
|
|
while (window)
|
2010-09-10 22:03:36 +02:00
|
|
|
{
|
2012-09-19 13:17:53 +02:00
|
|
|
_glfwInputWindowCloseRequest(window);
|
|
|
|
window = window->next;
|
2010-09-10 22:03:36 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
2012-09-19 13:17:53 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// LSHIFT/RSHIFT fixup (keys tend to "stick" without this fix)
|
|
|
|
// This is the only async event handling in GLFW, but it solves some
|
|
|
|
// nasty problems.
|
2013-01-02 01:40:42 +01:00
|
|
|
window = _glfw.focusedWindow;
|
2010-09-13 23:50:04 +02:00
|
|
|
if (window)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
int lshift_down, rshift_down;
|
|
|
|
|
|
|
|
// Get current state of left and right shift keys
|
2010-09-10 22:03:36 +02:00
|
|
|
lshift_down = (GetAsyncKeyState(VK_LSHIFT) >> 15) & 1;
|
|
|
|
rshift_down = (GetAsyncKeyState(VK_RSHIFT) >> 15) & 1;
|
2010-09-07 17:34:51 +02:00
|
|
|
|
|
|
|
// See if this differs from our belief of what has happened
|
|
|
|
// (we only have to check for lost key up events)
|
2011-01-10 21:38:08 +01:00
|
|
|
if (!lshift_down && window->key[GLFW_KEY_LEFT_SHIFT] == 1)
|
|
|
|
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, GLFW_RELEASE);
|
2010-09-10 22:03:36 +02:00
|
|
|
|
2011-01-10 21:38:08 +01:00
|
|
|
if (!rshift_down && window->key[GLFW_KEY_RIGHT_SHIFT] == 1)
|
|
|
|
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, GLFW_RELEASE);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2012-11-22 17:04:44 +01:00
|
|
|
// Did the cursor move in an focused window that has captured the cursor
|
2013-01-02 01:40:42 +01:00
|
|
|
window = _glfw.focusedWindow;
|
2011-09-06 13:55:29 +02:00
|
|
|
if (window)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
2011-09-06 13:55:29 +02:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED &&
|
2013-01-02 01:40:42 +01:00
|
|
|
!window->win32.cursorCentered)
|
2011-09-06 13:55:29 +02:00
|
|
|
{
|
2012-06-22 13:53:02 +02:00
|
|
|
_glfwPlatformSetCursorPos(window,
|
|
|
|
window->width / 2,
|
|
|
|
window->height / 2);
|
2013-01-02 01:40:42 +01:00
|
|
|
window->win32.cursorCentered = GL_TRUE;
|
2011-09-06 13:55:29 +02:00
|
|
|
}
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2010-09-12 16:26:00 +02:00
|
|
|
// Wait for new window and input events
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 22:03:36 +02:00
|
|
|
void _glfwPlatformWaitEvents(void)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
WaitMessage();
|
|
|
|
|
|
|
|
_glfwPlatformPollEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
2012-06-22 13:53:02 +02:00
|
|
|
// Set physical cursor position
|
2010-09-07 17:34:51 +02:00
|
|
|
//========================================================================
|
|
|
|
|
2012-06-22 13:53:02 +02:00
|
|
|
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y)
|
2010-09-07 17:34:51 +02:00
|
|
|
{
|
|
|
|
POINT pos;
|
|
|
|
|
|
|
|
// Convert client coordinates to screen coordinates
|
|
|
|
pos.x = x;
|
|
|
|
pos.y = y;
|
2013-01-02 01:40:42 +01:00
|
|
|
ClientToScreen(window->win32.handle, &pos);
|
2010-09-07 17:34:51 +02:00
|
|
|
|
2010-09-10 22:03:36 +02:00
|
|
|
SetCursorPos(pos.x, pos.y);
|
2010-09-07 17:34:51 +02:00
|
|
|
}
|
|
|
|
|
2011-10-05 00:47:39 +02:00
|
|
|
|
2011-10-01 07:40:36 +02:00
|
|
|
//========================================================================
|
|
|
|
// Set physical mouse cursor mode
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
|
|
|
{
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case GLFW_CURSOR_NORMAL:
|
2012-06-22 13:53:02 +02:00
|
|
|
showCursor(window);
|
2011-10-01 07:40:36 +02:00
|
|
|
break;
|
|
|
|
case GLFW_CURSOR_HIDDEN:
|
2012-06-22 13:53:02 +02:00
|
|
|
hideCursor(window);
|
2011-10-01 07:40:36 +02:00
|
|
|
break;
|
|
|
|
case GLFW_CURSOR_CAPTURED:
|
2012-06-22 13:53:02 +02:00
|
|
|
captureCursor(window);
|
2011-10-01 07:40:36 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|