1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 10:48:51 -05:00

Minor cleanup of Win32 window code.

This commit is contained in:
Camilla Berglund 2013-02-20 17:44:16 +01:00
parent e666835ca6
commit 941a671bfa

View File

@ -68,12 +68,8 @@ static void showCursor(_GLFWwindow* window)
{
UNREFERENCED_PARAMETER(window);
// Un-capture cursor
ReleaseCapture();
// Release the cursor from the window
ClipCursor(NULL);
ShowCursor(TRUE);
}
@ -85,10 +81,9 @@ static int translateKey(WPARAM wParam, LPARAM lParam)
DWORD msg_time;
DWORD scan_code;
// 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.
// 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.
int hiFlags = HIWORD(lParam);
if (!(hiFlags & 0x100))
{
@ -506,11 +501,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_MOUSEMOVE:
{
int newCursorX, newCursorY;
// Get signed (!) cursor position
newCursorX = GET_X_LPARAM(lParam);
newCursorY = GET_Y_LPARAM(lParam);
const int newCursorX = GET_X_LPARAM(lParam);
const int newCursorY = GET_Y_LPARAM(lParam);
if (newCursorX != window->win32.oldCursorX ||
newCursorY != window->win32.oldCursorY)
@ -592,20 +584,12 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
return 0;
}
// Was the window contents damaged?
case WM_PAINT:
{
_glfwInputWindowDamage(window);
break;
}
case WM_DISPLAYCHANGE:
{
// TODO: Do stuff here.
break;
}
case WM_DEVICECHANGE:
{
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);
}
@ -627,20 +610,14 @@ static void getFullWindowSize(_GLFWwindow* window,
int clientWidth, int clientHeight,
int* fullWidth, int* fullHeight)
{
RECT rect;
// Create a window rectangle
rect.left = (long) 0;
rect.right = (long) clientWidth - 1;
rect.top = (long) 0;
rect.bottom = (long) clientHeight - 1;
RECT rect = { 0, 0, clientWidth, clientHeight };
// Adjust according to window styles
AdjustWindowRectEx(&rect, window->win32.dwStyle, FALSE, window->win32.dwExStyle);
// Calculate width and height of full window
*fullWidth = rect.right - rect.left + 1;
*fullHeight = rect.bottom - rect.top + 1;
*fullWidth = rect.right - rect.left;
*fullHeight = rect.bottom - rect.top;
}
// Registers the GLFW window class
@ -665,7 +642,7 @@ static ATOM registerWindowClass(void)
wc.hIcon = LoadIcon(GetModuleHandle(NULL), L"GLFW_ICON");
if (!wc.hIcon)
{
// Load default icon
// User-provided icon not found; load default icon
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
}
@ -704,8 +681,7 @@ static int createWindow(_GLFWwindow* window,
}
else
{
window->win32.dwStyle |= WS_OVERLAPPED | WS_CAPTION |
WS_SYSMENU | WS_MINIMIZEBOX;
window->win32.dwStyle |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
if (wndconfig->resizable)
{
@ -766,11 +742,6 @@ static void destroyWindow(_GLFWwindow* window)
{
_glfwDestroyContext(window);
// This is duplicated from glfwDestroyWindow
// TODO: Stop duplicating code
if (window == _glfw.focusedWindow)
_glfw.focusedWindow = NULL;
if (window->win32.handle)
{
DestroyWindow(window->win32.handle);
@ -980,11 +951,6 @@ void _glfwPlatformPollEvents(void)
window->win32.oldCursorX = width / 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))
{
@ -1006,11 +972,12 @@ 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;
if (window)
{
// 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;
@ -1028,9 +995,6 @@ void _glfwPlatformPollEvents(void)
}
// Did the cursor move in an focused window that has captured the cursor
window = _glfw.focusedWindow;
if (window)
{
if (window->cursorMode == GLFW_CURSOR_CAPTURED &&
!window->win32.cursorCentered)
{
@ -1049,15 +1013,10 @@ void _glfwPlatformWaitEvents(void)
_glfwPlatformPollEvents();
}
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y)
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int xpos, int ypos)
{
POINT pos;
// Convert client coordinates to screen coordinates
pos.x = x;
pos.y = y;
POINT pos = { xpos, ypos };
ClientToScreen(window->win32.handle, &pos);
SetCursorPos(pos.x, pos.y);
}