mirror of
https://github.com/glfw/glfw.git
synced 2024-11-11 13:03:52 +00:00
Minor cleanup of Win32 window code.
This commit is contained in:
parent
e666835ca6
commit
941a671bfa
@ -68,12 +68,8 @@ static void showCursor(_GLFWwindow* window)
|
|||||||
{
|
{
|
||||||
UNREFERENCED_PARAMETER(window);
|
UNREFERENCED_PARAMETER(window);
|
||||||
|
|
||||||
// Un-capture cursor
|
|
||||||
ReleaseCapture();
|
ReleaseCapture();
|
||||||
|
|
||||||
// Release the cursor from the window
|
|
||||||
ClipCursor(NULL);
|
ClipCursor(NULL);
|
||||||
|
|
||||||
ShowCursor(TRUE);
|
ShowCursor(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,10 +81,9 @@ static int translateKey(WPARAM wParam, LPARAM lParam)
|
|||||||
DWORD msg_time;
|
DWORD msg_time;
|
||||||
DWORD scan_code;
|
DWORD scan_code;
|
||||||
|
|
||||||
// Check for numeric keypad keys.
|
// Check for numeric keypad keys
|
||||||
// Note: This way we always force "NumLock = ON", which is intentional
|
// NOTE: This way we always force "NumLock = ON", which is intentional since
|
||||||
// since the returned key code should correspond to a physical
|
// the returned key code should correspond to a physical location.
|
||||||
// location.
|
|
||||||
int hiFlags = HIWORD(lParam);
|
int hiFlags = HIWORD(lParam);
|
||||||
if (!(hiFlags & 0x100))
|
if (!(hiFlags & 0x100))
|
||||||
{
|
{
|
||||||
@ -506,11 +501,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||||||
|
|
||||||
case WM_MOUSEMOVE:
|
case WM_MOUSEMOVE:
|
||||||
{
|
{
|
||||||
int newCursorX, newCursorY;
|
const int newCursorX = GET_X_LPARAM(lParam);
|
||||||
|
const int newCursorY = GET_Y_LPARAM(lParam);
|
||||||
// Get signed (!) cursor position
|
|
||||||
newCursorX = GET_X_LPARAM(lParam);
|
|
||||||
newCursorY = GET_Y_LPARAM(lParam);
|
|
||||||
|
|
||||||
if (newCursorX != window->win32.oldCursorX ||
|
if (newCursorX != window->win32.oldCursorX ||
|
||||||
newCursorY != window->win32.oldCursorY)
|
newCursorY != window->win32.oldCursorY)
|
||||||
@ -592,20 +584,12 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Was the window contents damaged?
|
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
{
|
{
|
||||||
_glfwInputWindowDamage(window);
|
_glfwInputWindowDamage(window);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WM_DISPLAYCHANGE:
|
|
||||||
{
|
|
||||||
// TODO: Do stuff here.
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case WM_DEVICECHANGE:
|
case WM_DEVICECHANGE:
|
||||||
{
|
{
|
||||||
if (DBT_DEVNODES_CHANGED == wParam)
|
if (DBT_DEVNODES_CHANGED == wParam)
|
||||||
@ -617,7 +601,6 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass all unhandled messages to DefWindowProc
|
|
||||||
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -627,20 +610,14 @@ static void getFullWindowSize(_GLFWwindow* window,
|
|||||||
int clientWidth, int clientHeight,
|
int clientWidth, int clientHeight,
|
||||||
int* fullWidth, int* fullHeight)
|
int* fullWidth, int* fullHeight)
|
||||||
{
|
{
|
||||||
RECT rect;
|
RECT rect = { 0, 0, clientWidth, clientHeight };
|
||||||
|
|
||||||
// Create a window rectangle
|
|
||||||
rect.left = (long) 0;
|
|
||||||
rect.right = (long) clientWidth - 1;
|
|
||||||
rect.top = (long) 0;
|
|
||||||
rect.bottom = (long) clientHeight - 1;
|
|
||||||
|
|
||||||
// Adjust according to window styles
|
// Adjust according to window styles
|
||||||
AdjustWindowRectEx(&rect, window->win32.dwStyle, FALSE, window->win32.dwExStyle);
|
AdjustWindowRectEx(&rect, window->win32.dwStyle, FALSE, window->win32.dwExStyle);
|
||||||
|
|
||||||
// Calculate width and height of full window
|
// Calculate width and height of full window
|
||||||
*fullWidth = rect.right - rect.left + 1;
|
*fullWidth = rect.right - rect.left;
|
||||||
*fullHeight = rect.bottom - rect.top + 1;
|
*fullHeight = rect.bottom - rect.top;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Registers the GLFW window class
|
// Registers the GLFW window class
|
||||||
@ -665,7 +642,7 @@ static ATOM registerWindowClass(void)
|
|||||||
wc.hIcon = LoadIcon(GetModuleHandle(NULL), L"GLFW_ICON");
|
wc.hIcon = LoadIcon(GetModuleHandle(NULL), L"GLFW_ICON");
|
||||||
if (!wc.hIcon)
|
if (!wc.hIcon)
|
||||||
{
|
{
|
||||||
// Load default icon
|
// User-provided icon not found; load default icon
|
||||||
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
|
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -704,8 +681,7 @@ static int createWindow(_GLFWwindow* window,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
window->win32.dwStyle |= WS_OVERLAPPED | WS_CAPTION |
|
window->win32.dwStyle |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
|
||||||
WS_SYSMENU | WS_MINIMIZEBOX;
|
|
||||||
|
|
||||||
if (wndconfig->resizable)
|
if (wndconfig->resizable)
|
||||||
{
|
{
|
||||||
@ -738,7 +714,7 @@ static int createWindow(_GLFWwindow* window,
|
|||||||
NULL, // No parent window
|
NULL, // No parent window
|
||||||
NULL, // No window menu
|
NULL, // No window menu
|
||||||
GetModuleHandle(NULL),
|
GetModuleHandle(NULL),
|
||||||
window); // Pass GLFW window to WM_CREATE
|
window); // Pass GLFW window to WM_CREATE
|
||||||
|
|
||||||
free(wideTitle);
|
free(wideTitle);
|
||||||
|
|
||||||
@ -766,11 +742,6 @@ static void destroyWindow(_GLFWwindow* window)
|
|||||||
{
|
{
|
||||||
_glfwDestroyContext(window);
|
_glfwDestroyContext(window);
|
||||||
|
|
||||||
// This is duplicated from glfwDestroyWindow
|
|
||||||
// TODO: Stop duplicating code
|
|
||||||
if (window == _glfw.focusedWindow)
|
|
||||||
_glfw.focusedWindow = NULL;
|
|
||||||
|
|
||||||
if (window->win32.handle)
|
if (window->win32.handle)
|
||||||
{
|
{
|
||||||
DestroyWindow(window->win32.handle);
|
DestroyWindow(window->win32.handle);
|
||||||
@ -980,11 +951,6 @@ void _glfwPlatformPollEvents(void)
|
|||||||
window->win32.oldCursorX = width / 2;
|
window->win32.oldCursorX = width / 2;
|
||||||
window->win32.oldCursorY = height / 2;
|
window->win32.oldCursorY = height / 2;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
//window->win32.oldCursorX = window->cursorPosX;
|
|
||||||
//window->win32.oldCursorY = window->cursorPosY;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||||
{
|
{
|
||||||
@ -1006,31 +972,29 @@ void _glfwPlatformPollEvents(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
|
||||||
window = _glfw.focusedWindow;
|
window = _glfw.focusedWindow;
|
||||||
if (window)
|
if (window)
|
||||||
{
|
{
|
||||||
int lshift_down, rshift_down;
|
// 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
|
||||||
|
{
|
||||||
|
int lshift_down, rshift_down;
|
||||||
|
|
||||||
// Get current state of left and right shift keys
|
// Get current state of left and right shift keys
|
||||||
lshift_down = (GetAsyncKeyState(VK_LSHIFT) >> 15) & 1;
|
lshift_down = (GetAsyncKeyState(VK_LSHIFT) >> 15) & 1;
|
||||||
rshift_down = (GetAsyncKeyState(VK_RSHIFT) >> 15) & 1;
|
rshift_down = (GetAsyncKeyState(VK_RSHIFT) >> 15) & 1;
|
||||||
|
|
||||||
// See if this differs from our belief of what has happened
|
// See if this differs from our belief of what has happened
|
||||||
// (we only have to check for lost key up events)
|
// (we only have to check for lost key up events)
|
||||||
if (!lshift_down && window->key[GLFW_KEY_LEFT_SHIFT] == 1)
|
if (!lshift_down && window->key[GLFW_KEY_LEFT_SHIFT] == 1)
|
||||||
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, GLFW_RELEASE);
|
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, GLFW_RELEASE);
|
||||||
|
|
||||||
if (!rshift_down && window->key[GLFW_KEY_RIGHT_SHIFT] == 1)
|
if (!rshift_down && window->key[GLFW_KEY_RIGHT_SHIFT] == 1)
|
||||||
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, GLFW_RELEASE);
|
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, GLFW_RELEASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Did the cursor move in an focused window that has captured the cursor
|
// Did the cursor move in an focused window that has captured the cursor
|
||||||
window = _glfw.focusedWindow;
|
|
||||||
if (window)
|
|
||||||
{
|
|
||||||
if (window->cursorMode == GLFW_CURSOR_CAPTURED &&
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED &&
|
||||||
!window->win32.cursorCentered)
|
!window->win32.cursorCentered)
|
||||||
{
|
{
|
||||||
@ -1049,15 +1013,10 @@ void _glfwPlatformWaitEvents(void)
|
|||||||
_glfwPlatformPollEvents();
|
_glfwPlatformPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y)
|
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int xpos, int ypos)
|
||||||
{
|
{
|
||||||
POINT pos;
|
POINT pos = { xpos, ypos };
|
||||||
|
|
||||||
// Convert client coordinates to screen coordinates
|
|
||||||
pos.x = x;
|
|
||||||
pos.y = y;
|
|
||||||
ClientToScreen(window->win32.handle, &pos);
|
ClientToScreen(window->win32.handle, &pos);
|
||||||
|
|
||||||
SetCursorPos(pos.x, pos.y);
|
SetCursorPos(pos.x, pos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user