2010-09-07 11:34:51 -04:00
|
|
|
//========================================================================
|
2015-06-01 16:55:06 -04:00
|
|
|
// GLFW 3.2 Win32 - www.glfw.org
|
2010-09-07 11:34:51 -04:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// 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-13 19:05:03 -04:00
|
|
|
#include <stdlib.h>
|
2012-08-14 07:51:39 -04:00
|
|
|
#include <malloc.h>
|
2014-09-09 10:26:57 -04:00
|
|
|
#include <string.h>
|
2012-09-12 15:37:36 -04:00
|
|
|
#include <windowsx.h>
|
2013-12-22 10:47:03 -05:00
|
|
|
#include <shellapi.h>
|
2010-09-13 17:50:04 -04:00
|
|
|
|
2013-05-30 11:19:12 -04:00
|
|
|
#define _GLFW_KEY_INVALID -2
|
|
|
|
|
2014-08-31 08:17:31 -04:00
|
|
|
#define _GLFW_WNDCLASSNAME L"GLFW30"
|
|
|
|
|
2013-02-20 11:29:06 -05:00
|
|
|
|
2015-06-02 15:12:37 -04:00
|
|
|
// Returns the window style for the specified window
|
|
|
|
//
|
2015-07-04 19:13:52 -04:00
|
|
|
static DWORD getWindowStyle(const _GLFWwindow* window)
|
2015-06-02 15:12:37 -04:00
|
|
|
{
|
|
|
|
DWORD style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
|
|
|
|
|
|
|
|
if (window->decorated && !window->monitor)
|
|
|
|
{
|
|
|
|
style |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
|
|
|
|
|
|
|
|
if (window->resizable)
|
|
|
|
style |= WS_MAXIMIZEBOX | WS_SIZEBOX;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
style |= WS_POPUP;
|
|
|
|
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the extended window style for the specified window
|
|
|
|
//
|
2015-07-04 19:13:52 -04:00
|
|
|
static DWORD getWindowExStyle(const _GLFWwindow* window)
|
2015-06-02 15:12:37 -04:00
|
|
|
{
|
|
|
|
DWORD style = WS_EX_APPWINDOW;
|
|
|
|
|
|
|
|
if (window->decorated && !window->monitor)
|
|
|
|
style |= WS_EX_WINDOWEDGE;
|
|
|
|
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
2015-10-18 11:01:14 -04:00
|
|
|
// Translate client window size to full window size according to styles
|
2014-02-12 20:57:59 -05:00
|
|
|
//
|
2015-10-18 11:01:14 -04:00
|
|
|
static void getFullWindowSize(DWORD style, DWORD exStyle,
|
2014-02-12 20:57:59 -05:00
|
|
|
int clientWidth, int clientHeight,
|
|
|
|
int* fullWidth, int* fullHeight)
|
|
|
|
{
|
|
|
|
RECT rect = { 0, 0, clientWidth, clientHeight };
|
2015-10-18 11:01:14 -04:00
|
|
|
AdjustWindowRectEx(&rect, style, FALSE, exStyle);
|
2014-02-12 20:57:59 -05:00
|
|
|
*fullWidth = rect.right - rect.left;
|
|
|
|
*fullHeight = rect.bottom - rect.top;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enforce the client rect aspect ratio based on which edge is being dragged
|
|
|
|
//
|
|
|
|
static void applyAspectRatio(_GLFWwindow* window, int edge, RECT* area)
|
|
|
|
{
|
|
|
|
int xoff, yoff;
|
|
|
|
const float ratio = (float) window->win32.numer /
|
|
|
|
(float) window->win32.denom;
|
|
|
|
|
2015-10-18 11:01:14 -04:00
|
|
|
getFullWindowSize(getWindowStyle(window), getWindowExStyle(window),
|
|
|
|
0, 0, &xoff, &yoff);
|
2014-02-12 20:57:59 -05:00
|
|
|
|
|
|
|
if (edge == WMSZ_LEFT || edge == WMSZ_BOTTOMLEFT ||
|
|
|
|
edge == WMSZ_RIGHT || edge == WMSZ_BOTTOMRIGHT)
|
|
|
|
{
|
|
|
|
area->bottom = area->top + yoff +
|
|
|
|
(int) ((area->right - area->left - xoff) / ratio);
|
|
|
|
}
|
|
|
|
else if (edge == WMSZ_TOPLEFT || edge == WMSZ_TOPRIGHT)
|
|
|
|
{
|
|
|
|
area->top = area->bottom - yoff -
|
|
|
|
(int) ((area->right - area->left - xoff) / ratio);
|
|
|
|
}
|
|
|
|
else if (edge == WMSZ_TOP || edge == WMSZ_BOTTOM)
|
|
|
|
{
|
|
|
|
area->right = area->left + xoff +
|
|
|
|
(int) ((area->bottom - area->top - yoff) * ratio);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-20 11:29:06 -05:00
|
|
|
// Updates the cursor clip rect
|
|
|
|
//
|
|
|
|
static void updateClipRect(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
RECT clipRect;
|
|
|
|
GetClientRect(window->win32.handle, &clipRect);
|
|
|
|
ClientToScreen(window->win32.handle, (POINT*) &clipRect.left);
|
|
|
|
ClientToScreen(window->win32.handle, (POINT*) &clipRect.right);
|
|
|
|
ClipCursor(&clipRect);
|
|
|
|
}
|
|
|
|
|
2014-09-02 10:52:16 -04:00
|
|
|
// Translates a GLFW standard cursor to a resource ID
|
|
|
|
//
|
|
|
|
static LPWSTR translateCursorShape(int shape)
|
|
|
|
{
|
|
|
|
switch (shape)
|
|
|
|
{
|
|
|
|
case GLFW_ARROW_CURSOR:
|
|
|
|
return IDC_ARROW;
|
|
|
|
case GLFW_IBEAM_CURSOR:
|
|
|
|
return IDC_IBEAM;
|
|
|
|
case GLFW_CROSSHAIR_CURSOR:
|
|
|
|
return IDC_CROSS;
|
|
|
|
case GLFW_HAND_CURSOR:
|
|
|
|
return IDC_HAND;
|
|
|
|
case GLFW_HRESIZE_CURSOR:
|
|
|
|
return IDC_SIZEWE;
|
|
|
|
case GLFW_VRESIZE_CURSOR:
|
|
|
|
return IDC_SIZENS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-12-09 13:19:00 -05:00
|
|
|
// Retrieves and translates modifier keys
|
|
|
|
//
|
|
|
|
static int getKeyMods(void)
|
|
|
|
{
|
|
|
|
int mods = 0;
|
|
|
|
|
|
|
|
if (GetKeyState(VK_SHIFT) & (1 << 31))
|
|
|
|
mods |= GLFW_MOD_SHIFT;
|
|
|
|
if (GetKeyState(VK_CONTROL) & (1 << 31))
|
2013-05-23 08:11:05 -04:00
|
|
|
mods |= GLFW_MOD_CONTROL;
|
2012-12-09 13:19:00 -05:00
|
|
|
if (GetKeyState(VK_MENU) & (1 << 31))
|
|
|
|
mods |= GLFW_MOD_ALT;
|
2013-05-23 07:22:27 -04:00
|
|
|
if ((GetKeyState(VK_LWIN) | GetKeyState(VK_RWIN)) & (1 << 31))
|
|
|
|
mods |= GLFW_MOD_SUPER;
|
2012-12-09 13:19:00 -05:00
|
|
|
|
|
|
|
return mods;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieves and translates modifier keys
|
|
|
|
//
|
|
|
|
static int getAsyncKeyMods(void)
|
|
|
|
{
|
|
|
|
int mods = 0;
|
|
|
|
|
|
|
|
if (GetAsyncKeyState(VK_SHIFT) & (1 << 31))
|
|
|
|
mods |= GLFW_MOD_SHIFT;
|
|
|
|
if (GetAsyncKeyState(VK_CONTROL) & (1 << 31))
|
2013-05-23 08:11:05 -04:00
|
|
|
mods |= GLFW_MOD_CONTROL;
|
2012-12-09 13:19:00 -05:00
|
|
|
if (GetAsyncKeyState(VK_MENU) & (1 << 31))
|
|
|
|
mods |= GLFW_MOD_ALT;
|
2013-05-23 07:22:27 -04:00
|
|
|
if ((GetAsyncKeyState(VK_LWIN) | GetAsyncKeyState(VK_RWIN)) & (1 << 31))
|
|
|
|
mods |= GLFW_MOD_SUPER;
|
2012-12-09 13:19:00 -05:00
|
|
|
|
|
|
|
return mods;
|
|
|
|
}
|
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
// Translates a Windows key to the corresponding GLFW key
|
2013-02-04 07:22:10 -05:00
|
|
|
//
|
2010-09-10 16:03:36 -04:00
|
|
|
static int translateKey(WPARAM wParam, LPARAM lParam)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2014-03-30 10:23:22 -04:00
|
|
|
if (wParam == VK_CONTROL)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
// The CTRL keys require special handling
|
2013-04-17 09:29:17 -04:00
|
|
|
|
2014-03-30 10:23:22 -04:00
|
|
|
MSG next;
|
|
|
|
DWORD time;
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2014-03-30 10:23:22 -04:00
|
|
|
// Is this an extended key (i.e. right key)?
|
|
|
|
if (lParam & 0x01000000)
|
|
|
|
return GLFW_KEY_RIGHT_CONTROL;
|
2013-04-17 09:29:17 -04:00
|
|
|
|
2014-03-30 10:23:22 -04: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!
|
|
|
|
time = GetMessageTime();
|
|
|
|
|
|
|
|
if (PeekMessageW(&next, NULL, 0, 0, PM_NOREMOVE))
|
|
|
|
{
|
|
|
|
if (next.message == WM_KEYDOWN ||
|
|
|
|
next.message == WM_SYSKEYDOWN ||
|
|
|
|
next.message == WM_KEYUP ||
|
|
|
|
next.message == WM_SYSKEYUP)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2014-03-30 10:23:22 -04:00
|
|
|
if (next.wParam == VK_MENU &&
|
|
|
|
(next.lParam & 0x01000000) &&
|
|
|
|
next.time == time)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2014-03-30 10:23:22 -04:00
|
|
|
// Next message is a RALT down message, which
|
|
|
|
// means that this is not a proper LCTRL message
|
|
|
|
return _GLFW_KEY_INVALID;
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-30 10:23:22 -04:00
|
|
|
return GLFW_KEY_LEFT_CONTROL;
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
2011-01-10 15:19:27 -05:00
|
|
|
|
2014-03-30 10:23:22 -04:00
|
|
|
return _glfw.win32.publicKeys[HIWORD(lParam) & 0x1FF];
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2015-01-05 15:55:15 -05:00
|
|
|
// Enter full screen mode
|
2014-09-10 07:40:40 -04:00
|
|
|
//
|
2015-08-23 13:30:04 -04:00
|
|
|
static GLFWbool enterFullscreenMode(_GLFWwindow* window)
|
2014-09-10 07:40:40 -04:00
|
|
|
{
|
|
|
|
GLFWvidmode mode;
|
2015-08-23 13:30:04 -04:00
|
|
|
GLFWbool status;
|
2014-09-10 07:40:40 -04:00
|
|
|
int xpos, ypos;
|
|
|
|
|
|
|
|
status = _glfwSetVideoMode(window->monitor, &window->videoMode);
|
|
|
|
|
|
|
|
_glfwPlatformGetVideoMode(window->monitor, &mode);
|
|
|
|
_glfwPlatformGetMonitorPos(window->monitor, &xpos, &ypos);
|
|
|
|
|
|
|
|
SetWindowPos(window->win32.handle, HWND_TOPMOST,
|
|
|
|
xpos, ypos, mode.width, mode.height, SWP_NOCOPYBITS);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2015-01-05 15:55:15 -05:00
|
|
|
// Leave full screen mode
|
2014-09-10 07:40:40 -04:00
|
|
|
//
|
|
|
|
static void leaveFullscreenMode(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
_glfwRestoreVideoMode(window->monitor);
|
|
|
|
}
|
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
// Window callback function (handles window events)
|
2013-02-04 07:22:10 -05:00
|
|
|
//
|
2010-09-10 16:03:36 -04:00
|
|
|
static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|
|
|
WPARAM wParam, LPARAM lParam)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2014-03-06 12:30:14 -05:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) GetWindowLongPtrW(hWnd, 0);
|
2010-09-12 10:26:00 -04:00
|
|
|
|
2010-09-10 16:03:36 -04:00
|
|
|
switch (uMsg)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2014-04-18 09:49:45 -04:00
|
|
|
case WM_NCCREATE:
|
2010-09-13 19:05:03 -04:00
|
|
|
{
|
2014-03-06 12:30:14 -05:00
|
|
|
CREATESTRUCTW* cs = (CREATESTRUCTW*) lParam;
|
|
|
|
SetWindowLongPtrW(hWnd, 0, (LONG_PTR) cs->lpCreateParams);
|
2010-09-13 19:05:03 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-12-26 06:25:48 -05:00
|
|
|
case WM_SETFOCUS:
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2015-07-02 07:04:56 -04:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
|
|
|
_glfwPlatformSetCursorMode(window, GLFW_CURSOR_DISABLED);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
_glfwInputWindowFocus(window, GLFW_TRUE);
|
2010-09-07 11:34:51 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-26 06:25:48 -05:00
|
|
|
case WM_KILLFOCUS:
|
2013-12-04 20:15:14 -05:00
|
|
|
{
|
2015-07-02 07:04:56 -04:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
|
|
|
_glfwPlatformSetCursorMode(window, GLFW_CURSOR_NORMAL);
|
2014-12-26 06:25:48 -05:00
|
|
|
|
|
|
|
if (window->monitor && window->autoIconify)
|
|
|
|
_glfwPlatformIconifyWindow(window);
|
2013-12-04 20:15:14 -05:00
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
_glfwInputWindowFocus(window, GLFW_FALSE);
|
2013-12-04 20:15:14 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
case WM_SYSCOMMAND:
|
|
|
|
{
|
2010-09-10 16:03:36 -04:00
|
|
|
switch (wParam & 0xfff0)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
case SC_SCREENSAVE:
|
|
|
|
case SC_MONITORPOWER:
|
|
|
|
{
|
2012-09-27 15:37:36 -04:00
|
|
|
if (window->monitor)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2015-01-05 15:55:15 -05:00
|
|
|
// We are running in full screen mode, so disallow
|
2010-09-10 16:03:36 -04:00
|
|
|
// screen saver and screen blanking
|
2010-09-07 11:34:51 -04: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 07:31:15 -04:00
|
|
|
_glfwInputWindowCloseRequest(window);
|
2010-09-07 11:34:51 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
{
|
2014-03-30 14:52:09 -04:00
|
|
|
const int scancode = (lParam >> 16) & 0x1ff;
|
2013-05-30 11:19:12 -04:00
|
|
|
const int key = translateKey(wParam, lParam);
|
|
|
|
if (key == _GLFW_KEY_INVALID)
|
|
|
|
break;
|
|
|
|
|
|
|
|
_glfwInputKey(window, key, scancode, GLFW_PRESS, getKeyMods());
|
2012-02-07 10:44:22 -05:00
|
|
|
break;
|
2010-11-15 14:21:09 -05:00
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2012-09-19 07:17:53 -04:00
|
|
|
case WM_CHAR:
|
2014-06-12 17:04:20 -04:00
|
|
|
{
|
2015-08-23 13:30:04 -04:00
|
|
|
_glfwInputChar(window, (unsigned int) wParam, getKeyMods(), GLFW_TRUE);
|
2014-06-12 17:04:20 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-19 07:08:35 -04:00
|
|
|
case WM_SYSCHAR:
|
2012-09-19 07:17:53 -04:00
|
|
|
{
|
2015-08-23 13:30:04 -04:00
|
|
|
_glfwInputChar(window, (unsigned int) wParam, getKeyMods(), GLFW_FALSE);
|
2012-09-19 07:17:53 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-10 18:59:21 -04:00
|
|
|
case WM_UNICHAR:
|
|
|
|
{
|
|
|
|
// This message is not sent by Windows, but is sent by some
|
|
|
|
// third-party input method engines
|
|
|
|
|
|
|
|
if (wParam == UNICODE_NOCHAR)
|
|
|
|
{
|
|
|
|
// Returning TRUE here announces support for this message
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
_glfwInputChar(window, (unsigned int) wParam, getKeyMods(), GLFW_TRUE);
|
2013-04-10 18:59:21 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
case WM_KEYUP:
|
|
|
|
case WM_SYSKEYUP:
|
|
|
|
{
|
2012-12-09 13:19:00 -05:00
|
|
|
const int mods = getKeyMods();
|
2014-03-30 14:52:09 -04:00
|
|
|
const int scancode = (lParam >> 16) & 0x1ff;
|
2013-05-30 11:19:12 -04:00
|
|
|
const int key = translateKey(wParam, lParam);
|
|
|
|
if (key == _GLFW_KEY_INVALID)
|
|
|
|
break;
|
2012-12-09 13:19:00 -05:00
|
|
|
|
2010-09-10 16:03:36 -04:00
|
|
|
if (wParam == VK_SHIFT)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2013-06-05 09:17:16 -04:00
|
|
|
// Release both Shift keys on Shift up event, as only one event
|
|
|
|
// is sent even if both keys are released
|
2013-05-30 11:19:12 -04:00
|
|
|
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, scancode, GLFW_RELEASE, mods);
|
|
|
|
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, scancode, GLFW_RELEASE, mods);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
2013-02-21 12:39:22 -05:00
|
|
|
else if (wParam == VK_SNAPSHOT)
|
|
|
|
{
|
|
|
|
// Key down is not reported for the print screen key
|
2013-05-30 11:19:12 -04:00
|
|
|
_glfwInputKey(window, key, scancode, GLFW_PRESS, mods);
|
|
|
|
_glfwInputKey(window, key, scancode, GLFW_RELEASE, mods);
|
2013-02-21 12:39:22 -05:00
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
else
|
2013-05-30 11:19:12 -04:00
|
|
|
_glfwInputKey(window, key, scancode, GLFW_RELEASE, mods);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2012-02-07 10:44:22 -05:00
|
|
|
break;
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
case WM_MBUTTONDOWN:
|
2013-04-16 14:57:51 -04:00
|
|
|
case WM_XBUTTONDOWN:
|
2010-09-10 16:03:36 -04:00
|
|
|
{
|
2012-12-09 13:19:00 -05:00
|
|
|
const int mods = getKeyMods();
|
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
SetCapture(hWnd);
|
2010-09-10 16:03:36 -04:00
|
|
|
|
2013-04-16 14:57:51 -04:00
|
|
|
if (uMsg == WM_LBUTTONDOWN)
|
2012-12-09 13:19:00 -05:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS, mods);
|
2013-04-16 14:57:51 -04:00
|
|
|
else if (uMsg == WM_RBUTTONDOWN)
|
2012-12-09 13:19:00 -05:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS, mods);
|
2013-04-16 14:57:51 -04:00
|
|
|
else if (uMsg == WM_MBUTTONDOWN)
|
2012-12-09 13:19:00 -05:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_MIDDLE, GLFW_PRESS, mods);
|
2013-04-16 14:57:51 -04:00
|
|
|
else
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2013-04-16 14:57:51 -04:00
|
|
|
if (HIWORD(wParam) == XBUTTON1)
|
2012-12-09 13:19:00 -05:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_4, GLFW_PRESS, mods);
|
2013-04-16 14:57:51 -04:00
|
|
|
else if (HIWORD(wParam) == XBUTTON2)
|
2012-12-09 13:19:00 -05:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_5, GLFW_PRESS, mods);
|
2010-09-10 16:03:36 -04:00
|
|
|
|
2013-04-16 14:57:51 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
|
|
|
|
return 0;
|
2010-09-10 16:03:36 -04:00
|
|
|
}
|
|
|
|
|
2013-04-16 14:57:51 -04:00
|
|
|
case WM_LBUTTONUP:
|
2010-09-07 11:34:51 -04:00
|
|
|
case WM_RBUTTONUP:
|
|
|
|
case WM_MBUTTONUP:
|
2013-04-16 14:57:51 -04:00
|
|
|
case WM_XBUTTONUP:
|
2010-09-10 16:03:36 -04:00
|
|
|
{
|
2012-12-09 13:19:00 -05:00
|
|
|
const int mods = getKeyMods();
|
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
ReleaseCapture();
|
2010-09-10 16:03:36 -04:00
|
|
|
|
2013-04-16 14:57:51 -04:00
|
|
|
if (uMsg == WM_LBUTTONUP)
|
2012-12-09 13:19:00 -05:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE, mods);
|
2013-04-16 14:57:51 -04:00
|
|
|
else if (uMsg == WM_RBUTTONUP)
|
2012-12-09 13:19:00 -05:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE, mods);
|
2013-04-16 14:57:51 -04:00
|
|
|
else if (uMsg == WM_MBUTTONUP)
|
2012-12-09 13:19:00 -05:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_MIDDLE, GLFW_RELEASE, mods);
|
2013-04-16 14:57:51 -04:00
|
|
|
else
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2013-04-16 14:57:51 -04:00
|
|
|
if (HIWORD(wParam) == XBUTTON1)
|
2012-12-09 13:19:00 -05:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_4, GLFW_RELEASE, mods);
|
2013-04-16 14:57:51 -04:00
|
|
|
else if (HIWORD(wParam) == XBUTTON2)
|
2012-12-09 13:19:00 -05:00
|
|
|
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_5, GLFW_RELEASE, mods);
|
2013-04-16 14:57:51 -04:00
|
|
|
|
|
|
|
return TRUE;
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
2010-09-10 16:03:36 -04:00
|
|
|
|
2013-04-16 14:57:51 -04:00
|
|
|
return 0;
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
{
|
2014-02-11 12:24:01 -05:00
|
|
|
const int x = GET_X_LPARAM(lParam);
|
|
|
|
const int y = GET_Y_LPARAM(lParam);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2014-02-11 12:24:01 -05:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2015-06-17 05:59:39 -04:00
|
|
|
if (_glfw.cursorWindow != window)
|
2014-02-11 12:24:01 -05:00
|
|
|
break;
|
2010-09-10 16:03:36 -04:00
|
|
|
|
2014-02-11 12:24:01 -05:00
|
|
|
_glfwInputCursorMotion(window,
|
2015-08-16 08:28:51 -04:00
|
|
|
x - window->win32.cursorPosX,
|
|
|
|
y - window->win32.cursorPosY);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
2014-02-11 12:24:01 -05:00
|
|
|
else
|
|
|
|
_glfwInputCursorMotion(window, x, y);
|
|
|
|
|
|
|
|
window->win32.cursorPosX = x;
|
|
|
|
window->win32.cursorPosY = y;
|
2010-09-10 16:03:36 -04:00
|
|
|
|
2015-07-07 05:45:53 -04:00
|
|
|
if (!window->win32.cursorTracked)
|
2012-03-22 08:17:44 -04:00
|
|
|
{
|
|
|
|
TRACKMOUSEEVENT tme;
|
|
|
|
ZeroMemory(&tme, sizeof(tme));
|
|
|
|
tme.cbSize = sizeof(tme);
|
|
|
|
tme.dwFlags = TME_LEAVE;
|
2013-01-01 19:40:42 -05:00
|
|
|
tme.hwndTrack = window->win32.handle;
|
2012-03-22 08:17:44 -04:00
|
|
|
TrackMouseEvent(&tme);
|
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
window->win32.cursorTracked = GLFW_TRUE;
|
|
|
|
_glfwInputCursorEnter(window, GLFW_TRUE);
|
2012-03-22 08:17:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOUSELEAVE:
|
|
|
|
{
|
2015-08-23 13:30:04 -04:00
|
|
|
window->win32.cursorTracked = GLFW_FALSE;
|
|
|
|
_glfwInputCursorEnter(window, GLFW_FALSE);
|
2010-09-07 11:34:51 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
{
|
2012-03-28 15:54:09 -04:00
|
|
|
_glfwInputScroll(window, 0.0, (SHORT) HIWORD(wParam) / (double) WHEEL_DELTA);
|
2010-09-26 20:32:41 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2010-09-10 16:03:36 -04:00
|
|
|
|
2010-09-26 20:32:41 -04:00
|
|
|
case WM_MOUSEHWHEEL:
|
|
|
|
{
|
|
|
|
// This message is only sent on Windows Vista and later
|
2014-10-26 13:29:34 -04:00
|
|
|
// NOTE: The X-axis is inverted for consistency with OS X and X11.
|
2014-10-26 08:53:45 -04:00
|
|
|
_glfwInputScroll(window, -((SHORT) HIWORD(wParam) / (double) WHEEL_DELTA), 0.0);
|
2010-09-12 10:26:00 -04:00
|
|
|
return 0;
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
case WM_SIZE:
|
|
|
|
{
|
2015-06-17 05:59:39 -04:00
|
|
|
if (_glfw.cursorWindow == window)
|
2013-10-07 09:30:57 -04:00
|
|
|
{
|
2014-01-15 07:21:13 -05:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
|
|
|
updateClipRect(window);
|
2013-10-07 09:30:57 -04:00
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2015-01-06 09:35:49 -05:00
|
|
|
if (!window->win32.iconified && wParam == SIZE_MINIMIZED)
|
|
|
|
{
|
2015-08-23 13:30:04 -04:00
|
|
|
window->win32.iconified = GLFW_TRUE;
|
2015-08-28 06:00:06 -04:00
|
|
|
if (window->monitor)
|
|
|
|
leaveFullscreenMode(window);
|
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
_glfwInputWindowIconify(window, GLFW_TRUE);
|
2015-01-06 09:35:49 -05:00
|
|
|
}
|
|
|
|
else if (window->win32.iconified &&
|
|
|
|
(wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED))
|
|
|
|
{
|
2015-08-23 13:30:04 -04:00
|
|
|
window->win32.iconified = GLFW_FALSE;
|
2015-08-28 06:00:06 -04:00
|
|
|
if (window->monitor)
|
|
|
|
enterFullscreenMode(window);
|
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
_glfwInputWindowIconify(window, GLFW_FALSE);
|
2015-01-06 09:35:49 -05:00
|
|
|
}
|
2014-12-31 14:25:54 -05:00
|
|
|
|
2013-06-03 06:51:57 -04:00
|
|
|
_glfwInputFramebufferSize(window, LOWORD(lParam), HIWORD(lParam));
|
2011-10-09 11:10:40 -04:00
|
|
|
_glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam));
|
2010-09-07 11:34:51 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOVE:
|
|
|
|
{
|
2015-06-17 05:59:39 -04:00
|
|
|
if (_glfw.cursorWindow == window)
|
2013-10-07 09:30:57 -04:00
|
|
|
{
|
2014-01-15 07:21:13 -05:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
|
|
|
updateClipRect(window);
|
2013-10-07 09:30:57 -04:00
|
|
|
}
|
2011-10-09 11:10:40 -04:00
|
|
|
|
2013-11-13 06:47:44 -05:00
|
|
|
// NOTE: This cannot use LOWORD/HIWORD recommended by MSDN, as
|
|
|
|
// those macros do not handle negative window positions correctly
|
2013-11-13 06:34:43 -05:00
|
|
|
_glfwInputWindowPos(window,
|
|
|
|
GET_X_LPARAM(lParam),
|
|
|
|
GET_Y_LPARAM(lParam));
|
2010-09-07 11:34:51 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-12 20:57:59 -05:00
|
|
|
case WM_SIZING:
|
|
|
|
{
|
|
|
|
if (window->win32.numer == GLFW_DONT_CARE ||
|
|
|
|
window->win32.denom == GLFW_DONT_CARE)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
applyAspectRatio(window, (int) wParam, (RECT*) lParam);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_GETMINMAXINFO:
|
|
|
|
{
|
|
|
|
int xoff, yoff;
|
|
|
|
MINMAXINFO* mmi = (MINMAXINFO*) lParam;
|
2015-10-18 12:50:38 -04:00
|
|
|
|
|
|
|
if (!window)
|
|
|
|
break;
|
|
|
|
|
2015-10-18 11:01:14 -04:00
|
|
|
getFullWindowSize(getWindowStyle(window), getWindowExStyle(window),
|
|
|
|
0, 0, &xoff, &yoff);
|
2014-02-12 20:57:59 -05:00
|
|
|
|
|
|
|
if (window->win32.minwidth != GLFW_DONT_CARE &&
|
|
|
|
window->win32.minheight != GLFW_DONT_CARE)
|
|
|
|
{
|
|
|
|
mmi->ptMinTrackSize.x = window->win32.minwidth + xoff;
|
|
|
|
mmi->ptMinTrackSize.y = window->win32.minheight + yoff;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->win32.maxwidth != GLFW_DONT_CARE &&
|
|
|
|
window->win32.maxheight != GLFW_DONT_CARE)
|
|
|
|
{
|
|
|
|
mmi->ptMaxTrackSize.x = window->win32.maxwidth + xoff;
|
|
|
|
mmi->ptMaxTrackSize.y = window->win32.maxheight + yoff;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-07 11:34:51 -04:00
|
|
|
case WM_PAINT:
|
|
|
|
{
|
2011-10-09 15:12:13 -04:00
|
|
|
_glfwInputWindowDamage(window);
|
2010-09-07 11:34:51 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-08 15:16:48 -04:00
|
|
|
case WM_ERASEBKGND:
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-03-11 17:57:39 -04:00
|
|
|
case WM_SETCURSOR:
|
|
|
|
{
|
2015-06-17 05:59:39 -04:00
|
|
|
if (_glfw.cursorWindow == window && LOWORD(lParam) == HTCLIENT)
|
2013-03-11 17:57:39 -04:00
|
|
|
{
|
2014-01-15 07:21:13 -05:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_HIDDEN ||
|
|
|
|
window->cursorMode == GLFW_CURSOR_DISABLED)
|
|
|
|
{
|
|
|
|
SetCursor(NULL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2013-12-04 08:19:22 -05:00
|
|
|
else if (window->cursor)
|
|
|
|
{
|
|
|
|
SetCursor(window->cursor->win32.handle);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2013-03-11 17:57:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-10-14 14:32:06 -04:00
|
|
|
case WM_DEVICECHANGE:
|
|
|
|
{
|
|
|
|
if (DBT_DEVNODES_CHANGED == wParam)
|
|
|
|
{
|
2012-09-12 13:35:52 -04:00
|
|
|
_glfwInputMonitorChange();
|
2011-10-14 14:32:06 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-03-11 15:54:32 -04:00
|
|
|
|
2013-07-10 05:42:14 -04:00
|
|
|
case WM_DROPFILES:
|
|
|
|
{
|
2015-08-09 07:58:50 -04:00
|
|
|
HDROP drop = (HDROP) wParam;
|
2013-12-22 10:38:56 -05:00
|
|
|
POINT pt;
|
2013-12-22 13:28:46 -05:00
|
|
|
int i;
|
|
|
|
|
2015-08-09 07:58:50 -04:00
|
|
|
const int count = DragQueryFileW(drop, 0xffffffff, NULL, 0);
|
2015-01-27 17:04:22 -05:00
|
|
|
char** paths = calloc(count, sizeof(char*));
|
2013-12-22 10:38:56 -05:00
|
|
|
|
|
|
|
// Move the mouse to the position of the drop
|
2015-08-09 07:58:50 -04:00
|
|
|
DragQueryPoint(drop, &pt);
|
2013-12-22 10:38:56 -05:00
|
|
|
_glfwInputCursorMotion(window, pt.x, pt.y);
|
|
|
|
|
2013-12-22 13:28:46 -05:00
|
|
|
for (i = 0; i < count; i++)
|
2013-12-22 10:38:56 -05:00
|
|
|
{
|
2015-08-09 07:58:50 -04:00
|
|
|
const UINT length = DragQueryFileW(drop, i, NULL, 0);
|
2013-12-22 13:28:46 -05:00
|
|
|
WCHAR* buffer = calloc(length + 1, sizeof(WCHAR));
|
2013-12-22 10:38:56 -05:00
|
|
|
|
2015-08-09 07:58:50 -04:00
|
|
|
DragQueryFileW(drop, i, buffer, length + 1);
|
2015-01-27 17:04:22 -05:00
|
|
|
paths[i] = _glfwCreateUTF8FromWideString(buffer);
|
2013-12-22 10:38:56 -05:00
|
|
|
|
2013-12-22 13:28:46 -05:00
|
|
|
free(buffer);
|
2013-12-22 10:38:56 -05:00
|
|
|
}
|
|
|
|
|
2015-01-27 17:04:22 -05:00
|
|
|
_glfwInputDrop(window, count, (const char**) paths);
|
2013-12-22 13:28:46 -05:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
2015-01-27 17:04:22 -05:00
|
|
|
free(paths[i]);
|
|
|
|
free(paths);
|
2013-12-22 13:28:46 -05:00
|
|
|
|
2015-08-09 07:58:50 -04:00
|
|
|
DragFinish(drop);
|
2014-02-10 18:56:52 -05:00
|
|
|
return 0;
|
2013-07-10 05:42:14 -04:00
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2010-09-10 16:03:36 -04:00
|
|
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creates the GLFW window and rendering context
|
2013-02-04 07:22:10 -05:00
|
|
|
//
|
2015-06-18 08:03:02 -04:00
|
|
|
static int createWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2013-02-20 10:00:53 -05:00
|
|
|
int xpos, ypos, fullWidth, fullHeight;
|
2012-02-03 14:34:24 -05:00
|
|
|
WCHAR* wideTitle;
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2015-06-08 10:12:47 -04:00
|
|
|
if (wndconfig->monitor)
|
2013-01-24 13:30:31 -05:00
|
|
|
{
|
2015-06-08 10:12:47 -04:00
|
|
|
GLFWvidmode mode;
|
|
|
|
|
2014-09-10 07:40:40 -04:00
|
|
|
// NOTE: This window placement is temporary and approximate, as the
|
|
|
|
// correct position and size cannot be known until the monitor
|
|
|
|
// video mode has been set
|
2013-02-20 10:00:53 -05:00
|
|
|
_glfwPlatformGetMonitorPos(wndconfig->monitor, &xpos, &ypos);
|
2015-06-08 10:12:47 -04:00
|
|
|
_glfwPlatformGetVideoMode(wndconfig->monitor, &mode);
|
|
|
|
fullWidth = mode.width;
|
|
|
|
fullHeight = mode.height;
|
2013-01-24 13:30:31 -05:00
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
else
|
|
|
|
{
|
2013-02-20 10:00:53 -05:00
|
|
|
xpos = CW_USEDEFAULT;
|
|
|
|
ypos = CW_USEDEFAULT;
|
2010-09-10 16:03:36 -04:00
|
|
|
|
2015-10-18 11:01:14 -04:00
|
|
|
getFullWindowSize(getWindowStyle(window), getWindowExStyle(window),
|
2015-01-05 14:24:48 -05:00
|
|
|
wndconfig->width, wndconfig->height,
|
|
|
|
&fullWidth, &fullHeight);
|
2012-10-04 22:10:42 -04:00
|
|
|
}
|
|
|
|
|
2012-02-04 20:07:50 -05:00
|
|
|
wideTitle = _glfwCreateWideStringFromUTF8(wndconfig->title);
|
2012-02-03 14:34:24 -05:00
|
|
|
if (!wideTitle)
|
|
|
|
{
|
2012-12-31 15:05:28 -05:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 14:51:14 -04:00
|
|
|
"Win32: Failed to convert window title to UTF-16");
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2012-02-03 14:34:24 -05:00
|
|
|
}
|
|
|
|
|
2015-06-02 15:12:37 -04:00
|
|
|
window->win32.handle = CreateWindowExW(getWindowExStyle(window),
|
2014-03-06 12:30:14 -05:00
|
|
|
_GLFW_WNDCLASSNAME,
|
|
|
|
wideTitle,
|
2015-06-02 15:12:37 -04:00
|
|
|
getWindowStyle(window),
|
2014-03-06 12:30:14 -05:00
|
|
|
xpos, ypos,
|
|
|
|
fullWidth, fullHeight,
|
|
|
|
NULL, // No parent window
|
|
|
|
NULL, // No window menu
|
|
|
|
GetModuleHandleW(NULL),
|
|
|
|
window); // Pass object to WM_CREATE
|
2010-09-12 10:26:00 -04:00
|
|
|
|
2013-01-22 17:28:41 -05:00
|
|
|
free(wideTitle);
|
2013-12-22 10:38:56 -05:00
|
|
|
|
2014-05-23 07:24:36 -04:00
|
|
|
if (!window->win32.handle)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to create window");
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2014-05-23 07:24:36 -04:00
|
|
|
}
|
|
|
|
|
2014-02-10 09:03:23 -05:00
|
|
|
if (_glfw_ChangeWindowMessageFilterEx)
|
|
|
|
{
|
|
|
|
_glfw_ChangeWindowMessageFilterEx(window->win32.handle,
|
2014-05-23 07:24:36 -04:00
|
|
|
WM_DROPFILES, MSGFLT_ALLOW, NULL);
|
2014-02-10 09:03:23 -05:00
|
|
|
_glfw_ChangeWindowMessageFilterEx(window->win32.handle,
|
2014-05-23 07:24:36 -04:00
|
|
|
WM_COPYDATA, MSGFLT_ALLOW, NULL);
|
2014-02-10 09:03:23 -05:00
|
|
|
_glfw_ChangeWindowMessageFilterEx(window->win32.handle,
|
2014-05-23 07:24:36 -04:00
|
|
|
WM_COPYGLOBALDATA, MSGFLT_ALLOW, NULL);
|
2014-02-10 09:03:23 -05:00
|
|
|
}
|
|
|
|
|
2014-05-23 08:01:02 -04:00
|
|
|
if (wndconfig->floating && !wndconfig->monitor)
|
|
|
|
{
|
|
|
|
SetWindowPos(window->win32.handle,
|
2015-08-30 20:52:32 -04:00
|
|
|
HWND_TOPMOST,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
|
2014-05-23 08:01:02 -04:00
|
|
|
}
|
|
|
|
|
2013-12-22 10:38:56 -05:00
|
|
|
DragAcceptFiles(window->win32.handle, TRUE);
|
2013-01-22 17:28:41 -05:00
|
|
|
|
2014-02-12 20:57:59 -05:00
|
|
|
window->win32.minwidth = GLFW_DONT_CARE;
|
|
|
|
window->win32.minheight = GLFW_DONT_CARE;
|
|
|
|
window->win32.maxwidth = GLFW_DONT_CARE;
|
|
|
|
window->win32.maxheight = GLFW_DONT_CARE;
|
|
|
|
window->win32.numer = GLFW_DONT_CARE;
|
|
|
|
window->win32.denom = GLFW_DONT_CARE;
|
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_TRUE;
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Destroys the GLFW window and rendering context
|
2013-02-04 07:22:10 -05:00
|
|
|
//
|
2010-09-13 17:50:04 -04:00
|
|
|
static void destroyWindow(_GLFWwindow* window)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2013-01-01 19:40:42 -05:00
|
|
|
if (window->win32.handle)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2013-01-01 19:40:42 -05:00
|
|
|
DestroyWindow(window->win32.handle);
|
|
|
|
window->win32.handle = NULL;
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-31 08:17:31 -04:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Registers the GLFW window class
|
|
|
|
//
|
2015-08-23 13:30:04 -04:00
|
|
|
GLFWbool _glfwRegisterWindowClass(void)
|
2014-08-31 08:17:31 -04:00
|
|
|
{
|
|
|
|
WNDCLASSW wc;
|
|
|
|
|
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
|
|
|
|
wc.lpfnWndProc = (WNDPROC) windowProc;
|
|
|
|
wc.cbClsExtra = 0; // No extra class data
|
|
|
|
wc.cbWndExtra = sizeof(void*) + sizeof(int); // Make room for one pointer
|
|
|
|
wc.hInstance = GetModuleHandleW(NULL);
|
|
|
|
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
|
|
|
|
wc.hbrBackground = NULL; // No background
|
|
|
|
wc.lpszMenuName = NULL; // No menu
|
|
|
|
wc.lpszClassName = _GLFW_WNDCLASSNAME;
|
|
|
|
|
|
|
|
// Load user-provided icon if available
|
2015-10-15 11:03:36 -04:00
|
|
|
wc.hIcon = LoadImageW(GetModuleHandleW(NULL),
|
|
|
|
L"GLFW_ICON", IMAGE_ICON,
|
|
|
|
0, 0, LR_DEFAULTSIZE | LR_SHARED);
|
2014-08-31 08:17:31 -04:00
|
|
|
if (!wc.hIcon)
|
|
|
|
{
|
|
|
|
// No user-provided icon found, load default icon
|
2015-10-15 11:03:36 -04:00
|
|
|
wc.hIcon = LoadImageW(NULL,
|
|
|
|
IDI_APPLICATION, IMAGE_ICON,
|
|
|
|
0, 0, LR_DEFAULTSIZE | LR_SHARED);
|
2014-08-31 08:17:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!RegisterClassW(&wc))
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to register window class");
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2014-08-31 08:17:31 -04:00
|
|
|
}
|
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_TRUE;
|
2014-08-31 08:17:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unregisters the GLFW window class
|
|
|
|
//
|
|
|
|
void _glfwUnregisterWindowClass(void)
|
|
|
|
{
|
|
|
|
UnregisterClassW(_GLFW_WNDCLASSNAME, GetModuleHandleW(NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-10 16:03:36 -04:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2012-08-06 11:56:41 -04:00
|
|
|
int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
|
|
|
const _GLFWwndconfig* wndconfig,
|
2014-03-06 14:05:32 -05:00
|
|
|
const _GLFWctxconfig* ctxconfig,
|
2012-08-06 11:56:41 -04:00
|
|
|
const _GLFWfbconfig* fbconfig)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2012-12-13 16:43:23 -05:00
|
|
|
int status;
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2015-06-18 08:03:02 -04:00
|
|
|
if (!createWindow(window, wndconfig))
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2015-06-18 08:03:02 -04:00
|
|
|
if (ctxconfig->api != GLFW_NO_API)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2015-06-18 08:03:02 -04:00
|
|
|
if (!_glfwCreateContext(window, ctxconfig, fbconfig))
|
|
|
|
return GLFW_FALSE;
|
2012-10-21 15:57:29 -04:00
|
|
|
|
2015-10-27 21:06:51 -04:00
|
|
|
#if defined(_GLFW_WGL)
|
2015-06-18 08:03:02 -04:00
|
|
|
status = _glfwAnalyzeContext(window, ctxconfig, fbconfig);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2015-06-18 08:03:02 -04:00
|
|
|
if (status == _GLFW_RECREATION_IMPOSSIBLE)
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2015-06-18 08:03:02 -04:00
|
|
|
|
|
|
|
if (status == _GLFW_RECREATION_REQUIRED)
|
|
|
|
{
|
|
|
|
// 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 vendor ICD)
|
|
|
|
|
2015-10-27 22:44:02 -04:00
|
|
|
// Yes, this is strange, and yes, this is the proper way on WGL
|
2015-06-18 08:03:02 -04:00
|
|
|
|
|
|
|
// 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
|
|
|
|
// format, but it's not worth the added code complexity
|
|
|
|
|
|
|
|
// First we clear the current context (the one we just created)
|
|
|
|
// This is usually done by glfwDestroyWindow, but as we're not doing
|
|
|
|
// full GLFW window destruction, it's duplicated here
|
|
|
|
_glfwPlatformMakeContextCurrent(NULL);
|
|
|
|
|
|
|
|
// Next destroy the Win32 window and WGL context (without resetting
|
|
|
|
// or destroying the GLFW window object)
|
|
|
|
_glfwDestroyContext(window);
|
|
|
|
destroyWindow(window);
|
|
|
|
|
|
|
|
// ...and then create them again, this time with better APIs
|
|
|
|
if (!createWindow(window, wndconfig))
|
|
|
|
return GLFW_FALSE;
|
|
|
|
if (!_glfwCreateContext(window, ctxconfig, fbconfig))
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
2015-10-27 22:42:47 -04:00
|
|
|
#endif // _GLFW_WGL
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2012-09-27 15:37:36 -04:00
|
|
|
if (window->monitor)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2012-09-23 09:08:43 -04:00
|
|
|
_glfwPlatformShowWindow(window);
|
2014-09-10 07:40:40 -04:00
|
|
|
if (!enterFullscreenMode(window))
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_TRUE;
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2012-08-06 11:56:41 -04:00
|
|
|
void _glfwPlatformDestroyWindow(_GLFWwindow* window)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2012-09-27 15:37:36 -04:00
|
|
|
if (window->monitor)
|
2014-09-10 07:40:40 -04:00
|
|
|
leaveFullscreenMode(window);
|
|
|
|
|
2015-06-18 08:03:02 -04:00
|
|
|
if (window->context.api != GLFW_NO_API)
|
|
|
|
_glfwDestroyContext(window);
|
|
|
|
|
2014-09-10 07:40:40 -04:00
|
|
|
destroyWindow(window);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2010-09-12 10:26:00 -04:00
|
|
|
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2012-02-04 20:07:50 -05:00
|
|
|
WCHAR* wideTitle = _glfwCreateWideStringFromUTF8(title);
|
2012-02-03 14:34:24 -05:00
|
|
|
if (!wideTitle)
|
|
|
|
{
|
2012-12-31 15:05:28 -05:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 14:51:14 -04:00
|
|
|
"Win32: Failed to convert window title to UTF-16");
|
2012-02-03 14:34:24 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-06 12:30:14 -05:00
|
|
|
SetWindowTextW(window->win32.handle, wideTitle);
|
2012-02-07 08:58:58 -05:00
|
|
|
free(wideTitle);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2013-01-24 13:30:31 -05:00
|
|
|
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos)
|
|
|
|
{
|
|
|
|
POINT pos = { 0, 0 };
|
|
|
|
ClientToScreen(window->win32.handle, &pos);
|
|
|
|
|
|
|
|
if (xpos)
|
|
|
|
*xpos = pos.x;
|
|
|
|
if (ypos)
|
|
|
|
*ypos = pos.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos)
|
|
|
|
{
|
|
|
|
RECT rect = { xpos, ypos, xpos, ypos };
|
2015-06-02 15:12:37 -04:00
|
|
|
AdjustWindowRectEx(&rect, getWindowStyle(window),
|
|
|
|
FALSE, getWindowExStyle(window));
|
2013-01-24 13:30:31 -05:00
|
|
|
SetWindowPos(window->win32.handle, NULL, rect.left, rect.top, 0, 0,
|
|
|
|
SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE);
|
|
|
|
}
|
|
|
|
|
2012-11-25 08:53:33 -05:00
|
|
|
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
|
|
|
|
{
|
|
|
|
RECT area;
|
|
|
|
GetClientRect(window->win32.handle, &area);
|
|
|
|
|
|
|
|
if (width)
|
|
|
|
*width = area.right;
|
|
|
|
if (height)
|
|
|
|
*height = area.bottom;
|
|
|
|
}
|
|
|
|
|
2010-09-12 10:26:00 -04:00
|
|
|
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2012-09-27 15:37:36 -04:00
|
|
|
if (window->monitor)
|
2014-09-10 07:40:40 -04:00
|
|
|
enterFullscreenMode(window);
|
2010-09-07 11:34:51 -04:00
|
|
|
else
|
|
|
|
{
|
2013-03-12 12:25:33 -04:00
|
|
|
int fullWidth, fullHeight;
|
2015-10-18 11:01:14 -04:00
|
|
|
getFullWindowSize(getWindowStyle(window), getWindowExStyle(window),
|
|
|
|
width, height, &fullWidth, &fullHeight);
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2013-03-12 12:25:33 -04:00
|
|
|
SetWindowPos(window->win32.handle, HWND_TOP,
|
|
|
|
0, 0, fullWidth, fullHeight,
|
2013-12-28 14:56:57 -05:00
|
|
|
SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-12 20:57:59 -05:00
|
|
|
void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window,
|
|
|
|
int minwidth, int minheight,
|
|
|
|
int maxwidth, int maxheight)
|
|
|
|
{
|
|
|
|
RECT area;
|
|
|
|
|
|
|
|
window->win32.minwidth = minwidth;
|
|
|
|
window->win32.minheight = minheight;
|
|
|
|
window->win32.maxwidth = maxwidth;
|
|
|
|
window->win32.maxheight = maxheight;
|
|
|
|
|
|
|
|
if ((minwidth == GLFW_DONT_CARE || minheight == GLFW_DONT_CARE) &&
|
|
|
|
(maxwidth == GLFW_DONT_CARE || maxheight == GLFW_DONT_CARE))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetWindowRect(window->win32.handle, &area);
|
|
|
|
MoveWindow(window->win32.handle,
|
|
|
|
area.left, area.top,
|
|
|
|
area.right - area.left,
|
|
|
|
area.bottom - area.top, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom)
|
|
|
|
{
|
|
|
|
RECT area;
|
|
|
|
|
|
|
|
window->win32.numer = numer;
|
|
|
|
window->win32.denom = denom;
|
|
|
|
|
|
|
|
if (numer == GLFW_DONT_CARE || denom == GLFW_DONT_CARE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GetWindowRect(window->win32.handle, &area);
|
|
|
|
applyAspectRatio(window, WMSZ_BOTTOMRIGHT, &area);
|
|
|
|
MoveWindow(window->win32.handle,
|
|
|
|
area.left, area.top,
|
|
|
|
area.right - area.left,
|
|
|
|
area.bottom - area.top, TRUE);
|
|
|
|
}
|
|
|
|
|
2013-06-03 06:51:57 -04:00
|
|
|
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height)
|
|
|
|
{
|
|
|
|
_glfwPlatformGetWindowSize(window, width, height);
|
|
|
|
}
|
|
|
|
|
2014-03-25 16:30:13 -04:00
|
|
|
void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
|
|
|
|
int* left, int* top,
|
|
|
|
int* right, int* bottom)
|
|
|
|
{
|
|
|
|
RECT rect;
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
_glfwPlatformGetWindowSize(window, &width, &height);
|
|
|
|
SetRect(&rect, 0, 0, width, height);
|
2015-06-02 15:12:37 -04:00
|
|
|
AdjustWindowRectEx(&rect, getWindowStyle(window),
|
|
|
|
FALSE, getWindowExStyle(window));
|
2014-03-25 16:30:13 -04:00
|
|
|
|
|
|
|
if (left)
|
|
|
|
*left = -rect.left;
|
|
|
|
if (top)
|
|
|
|
*top = -rect.top;
|
|
|
|
if (right)
|
|
|
|
*right = rect.right - width;
|
|
|
|
if (bottom)
|
|
|
|
*bottom = rect.bottom - height;
|
|
|
|
}
|
|
|
|
|
2010-09-12 10:26:00 -04:00
|
|
|
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2013-01-01 19:40:42 -05:00
|
|
|
ShowWindow(window->win32.handle, SW_MINIMIZE);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2010-09-12 10:26:00 -04:00
|
|
|
void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2013-01-01 19:40:42 -05:00
|
|
|
ShowWindow(window->win32.handle, SW_RESTORE);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2012-08-21 14:01:57 -04:00
|
|
|
void _glfwPlatformShowWindow(_GLFWwindow* window)
|
|
|
|
{
|
2014-05-19 05:54:54 -04:00
|
|
|
ShowWindow(window->win32.handle, SW_SHOW);
|
2013-01-01 19:40:42 -05:00
|
|
|
BringWindowToTop(window->win32.handle);
|
|
|
|
SetForegroundWindow(window->win32.handle);
|
|
|
|
SetFocus(window->win32.handle);
|
2012-08-21 14:01:57 -04:00
|
|
|
}
|
|
|
|
|
2014-06-20 07:39:06 -04:00
|
|
|
void _glfwPlatformUnhideWindow(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
ShowWindow(window->win32.handle, SW_SHOW);
|
|
|
|
}
|
|
|
|
|
2012-08-21 14:01:57 -04:00
|
|
|
void _glfwPlatformHideWindow(_GLFWwindow* window)
|
|
|
|
{
|
2013-01-01 19:40:42 -05:00
|
|
|
ShowWindow(window->win32.handle, SW_HIDE);
|
2012-08-21 14:01:57 -04:00
|
|
|
}
|
|
|
|
|
2014-12-26 06:25:48 -05:00
|
|
|
int _glfwPlatformWindowFocused(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
return window->win32.handle == GetActiveWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
int _glfwPlatformWindowIconified(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
return IsIconic(window->win32.handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
int _glfwPlatformWindowVisible(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
return IsWindowVisible(window->win32.handle);
|
|
|
|
}
|
|
|
|
|
2010-09-10 16:03:36 -04:00
|
|
|
void _glfwPlatformPollEvents(void)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
|
2014-03-06 12:30:14 -05:00
|
|
|
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2012-09-19 07:17:53 -04:00
|
|
|
if (msg.message == WM_QUIT)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2012-09-19 07:17:53 -04:00
|
|
|
// Treat WM_QUIT as a close on all windows
|
2014-12-16 19:31:36 -05:00
|
|
|
// While GLFW does not itself post WM_QUIT, other processes may post
|
|
|
|
// it to this one, for example Task Manager
|
2010-09-13 17:50:04 -04:00
|
|
|
|
2015-08-30 20:52:32 -04:00
|
|
|
_GLFWwindow* window = _glfw.windowListHead;
|
2012-09-19 07:17:53 -04:00
|
|
|
while (window)
|
2010-09-10 16:03:36 -04:00
|
|
|
{
|
2012-09-19 07:17:53 -04:00
|
|
|
_glfwInputWindowCloseRequest(window);
|
|
|
|
window = window->next;
|
2010-09-10 16:03:36 -04:00
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
2012-09-19 07:17:53 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
2014-03-06 12:30:14 -05:00
|
|
|
DispatchMessageW(&msg);
|
2012-09-19 07:17:53 -04:00
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2015-08-30 20:52:32 -04:00
|
|
|
if (_glfw.cursorWindow)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2015-08-30 20:52:32 -04:00
|
|
|
_GLFWwindow* window = _glfw.cursorWindow;
|
|
|
|
|
2013-02-20 11:44:16 -05: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
|
|
|
|
{
|
2012-12-09 13:19:00 -05:00
|
|
|
const int mods = getAsyncKeyMods();
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2013-02-20 11:44:16 -05:00
|
|
|
// Get current state of left and right shift keys
|
2012-12-09 13:19:00 -05:00
|
|
|
const int lshiftDown = (GetAsyncKeyState(VK_LSHIFT) >> 15) & 1;
|
|
|
|
const int rshiftDown = (GetAsyncKeyState(VK_RSHIFT) >> 15) & 1;
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2013-02-20 11:44:16 -05:00
|
|
|
// See if this differs from our belief of what has happened
|
|
|
|
// (we only have to check for lost key up events)
|
2014-05-18 15:28:11 -04:00
|
|
|
if (!lshiftDown && window->keys[GLFW_KEY_LEFT_SHIFT] == 1)
|
2013-05-30 11:19:12 -04:00
|
|
|
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, 0, GLFW_RELEASE, mods);
|
2010-09-10 16:03:36 -04:00
|
|
|
|
2014-05-18 15:28:11 -04:00
|
|
|
if (!rshiftDown && window->keys[GLFW_KEY_RIGHT_SHIFT] == 1)
|
2013-05-30 11:19:12 -04:00
|
|
|
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, 0, GLFW_RELEASE, mods);
|
2013-02-20 11:44:16 -05:00
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
|
2014-02-11 12:24:01 -05:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
2011-09-06 07:55:29 -04:00
|
|
|
{
|
2012-11-25 08:53:33 -05:00
|
|
|
int width, height;
|
|
|
|
_glfwPlatformGetWindowSize(window, &width, &height);
|
2015-08-16 07:55:44 -04:00
|
|
|
|
|
|
|
// NOTE: Re-center the cursor only if it has moved since the last
|
|
|
|
// call, to avoid breaking glfwWaitEvents with WM_MOUSEMOVE
|
|
|
|
if (window->win32.cursorPosX != width / 2 ||
|
|
|
|
window->win32.cursorPosY != height / 2)
|
|
|
|
{
|
|
|
|
_glfwPlatformSetCursorPos(window, width / 2, height / 2);
|
|
|
|
}
|
2011-09-06 07:55:29 -04:00
|
|
|
}
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-10 16:03:36 -04:00
|
|
|
void _glfwPlatformWaitEvents(void)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
|
|
|
WaitMessage();
|
|
|
|
|
|
|
|
_glfwPlatformPollEvents();
|
|
|
|
}
|
|
|
|
|
2014-02-10 12:16:58 -05:00
|
|
|
void _glfwPlatformPostEmptyEvent(void)
|
|
|
|
{
|
|
|
|
_GLFWwindow* window = _glfw.windowListHead;
|
|
|
|
PostMessage(window->win32.handle, WM_NULL, 0, 0);
|
|
|
|
}
|
|
|
|
|
2014-02-11 12:24:01 -05:00
|
|
|
void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos)
|
|
|
|
{
|
|
|
|
POINT pos;
|
|
|
|
|
|
|
|
if (GetCursorPos(&pos))
|
|
|
|
{
|
|
|
|
ScreenToClient(window->win32.handle, &pos);
|
|
|
|
|
|
|
|
if (xpos)
|
|
|
|
*xpos = pos.x;
|
|
|
|
if (ypos)
|
|
|
|
*ypos = pos.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-04 10:16:21 -04:00
|
|
|
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos)
|
2010-09-07 11:34:51 -04:00
|
|
|
{
|
2013-04-04 10:16:21 -04:00
|
|
|
POINT pos = { (int) xpos, (int) ypos };
|
2014-02-11 12:24:01 -05:00
|
|
|
|
|
|
|
// Store the new position so it can be recognized later
|
|
|
|
window->win32.cursorPosX = pos.x;
|
|
|
|
window->win32.cursorPosY = pos.y;
|
|
|
|
|
2013-01-01 19:40:42 -05:00
|
|
|
ClientToScreen(window->win32.handle, &pos);
|
2010-09-10 16:03:36 -04:00
|
|
|
SetCursorPos(pos.x, pos.y);
|
2010-09-07 11:34:51 -04:00
|
|
|
}
|
|
|
|
|
2015-07-02 07:04:56 -04:00
|
|
|
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
2011-10-01 01:40:36 -04:00
|
|
|
{
|
2015-07-02 07:04:56 -04:00
|
|
|
POINT pos;
|
|
|
|
|
|
|
|
if (mode == GLFW_CURSOR_DISABLED)
|
|
|
|
updateClipRect(window);
|
|
|
|
else
|
|
|
|
ClipCursor(NULL);
|
|
|
|
|
|
|
|
if (!GetCursorPos(&pos))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (WindowFromPoint(pos) != window->win32.handle)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mode == GLFW_CURSOR_NORMAL)
|
2011-10-01 01:40:36 -04:00
|
|
|
{
|
2015-07-02 07:04:56 -04:00
|
|
|
if (window->cursor)
|
|
|
|
SetCursor(window->cursor->win32.handle);
|
|
|
|
else
|
|
|
|
SetCursor(LoadCursorW(NULL, IDC_ARROW));
|
2011-10-01 01:40:36 -04:00
|
|
|
}
|
2015-07-02 07:04:56 -04:00
|
|
|
else
|
|
|
|
SetCursor(NULL);
|
2011-10-01 01:40:36 -04:00
|
|
|
}
|
|
|
|
|
2014-02-23 10:43:17 -05:00
|
|
|
int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
|
|
|
|
const GLFWimage* image,
|
|
|
|
int xhot, int yhot)
|
2013-12-04 08:19:22 -05:00
|
|
|
{
|
2014-01-23 09:24:57 -05:00
|
|
|
HDC dc;
|
|
|
|
HBITMAP bitmap, mask;
|
2013-12-04 08:19:22 -05:00
|
|
|
BITMAPV5HEADER bi;
|
|
|
|
ICONINFO ii;
|
2014-01-23 09:24:57 -05:00
|
|
|
DWORD* target = 0;
|
2014-02-23 10:43:17 -05:00
|
|
|
BYTE* source = (BYTE*) image->pixels;
|
2014-01-23 09:24:57 -05:00
|
|
|
int i;
|
2013-12-04 08:19:22 -05:00
|
|
|
|
2014-01-23 09:24:57 -05:00
|
|
|
ZeroMemory(&bi, sizeof(bi));
|
2013-12-04 08:19:22 -05:00
|
|
|
bi.bV5Size = sizeof(BITMAPV5HEADER);
|
2014-02-23 10:43:17 -05:00
|
|
|
bi.bV5Width = image->width;
|
|
|
|
bi.bV5Height = -image->height;
|
2013-12-04 08:19:22 -05:00
|
|
|
bi.bV5Planes = 1;
|
|
|
|
bi.bV5BitCount = 32;
|
|
|
|
bi.bV5Compression = BI_BITFIELDS;
|
2014-01-23 09:24:57 -05:00
|
|
|
bi.bV5RedMask = 0x00ff0000;
|
|
|
|
bi.bV5GreenMask = 0x0000ff00;
|
|
|
|
bi.bV5BlueMask = 0x000000ff;
|
|
|
|
bi.bV5AlphaMask = 0xff000000;
|
2013-12-04 08:19:22 -05:00
|
|
|
|
2014-01-23 09:24:57 -05:00
|
|
|
dc = GetDC(NULL);
|
|
|
|
bitmap = CreateDIBSection(dc, (BITMAPINFO*) &bi, DIB_RGB_COLORS,
|
|
|
|
(void**) &target, NULL, (DWORD) 0);
|
|
|
|
ReleaseDC(NULL, dc);
|
2013-12-04 08:19:22 -05:00
|
|
|
|
2014-01-23 09:24:57 -05:00
|
|
|
if (!bitmap)
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2013-12-04 08:19:22 -05:00
|
|
|
|
2014-02-23 10:43:17 -05:00
|
|
|
mask = CreateBitmap(image->width, image->height, 1, 1, NULL);
|
2014-01-23 09:24:57 -05:00
|
|
|
if (!mask)
|
2013-12-04 08:19:22 -05:00
|
|
|
{
|
2014-01-23 09:24:57 -05:00
|
|
|
DeleteObject(bitmap);
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2013-12-04 08:19:22 -05:00
|
|
|
}
|
|
|
|
|
2014-02-23 10:43:17 -05:00
|
|
|
for (i = 0; i < image->width * image->height; i++, target++, source += 4)
|
2014-03-20 06:17:55 -04:00
|
|
|
{
|
|
|
|
*target = (source[3] << 24) |
|
|
|
|
(source[0] << 16) |
|
|
|
|
(source[1] << 8) |
|
|
|
|
source[2];
|
|
|
|
}
|
2013-12-04 08:19:22 -05:00
|
|
|
|
2014-01-23 09:24:57 -05:00
|
|
|
ZeroMemory(&ii, sizeof(ii));
|
|
|
|
ii.fIcon = FALSE;
|
|
|
|
ii.xHotspot = xhot;
|
|
|
|
ii.yHotspot = yhot;
|
|
|
|
ii.hbmMask = mask;
|
|
|
|
ii.hbmColor = bitmap;
|
2013-12-04 08:19:22 -05:00
|
|
|
|
|
|
|
cursor->win32.handle = (HCURSOR) CreateIconIndirect(&ii);
|
|
|
|
|
2014-01-23 09:24:57 -05:00
|
|
|
DeleteObject(bitmap);
|
|
|
|
DeleteObject(mask);
|
2013-12-04 08:19:22 -05:00
|
|
|
|
2014-01-23 09:24:57 -05:00
|
|
|
if (!cursor->win32.handle)
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2013-12-04 08:19:22 -05:00
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_TRUE;
|
2013-12-04 08:19:22 -05:00
|
|
|
}
|
|
|
|
|
2014-09-02 10:52:16 -04:00
|
|
|
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
|
|
|
{
|
2015-03-10 14:51:14 -04:00
|
|
|
cursor->win32.handle =
|
|
|
|
CopyCursor(LoadCursorW(NULL, translateCursorShape(shape)));
|
2014-09-02 10:52:16 -04:00
|
|
|
if (!cursor->win32.handle)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 14:51:14 -04:00
|
|
|
"Win32: Failed to create standard cursor");
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_FALSE;
|
2014-09-02 10:52:16 -04:00
|
|
|
}
|
|
|
|
|
2015-08-23 13:30:04 -04:00
|
|
|
return GLFW_TRUE;
|
2014-09-02 10:52:16 -04:00
|
|
|
}
|
|
|
|
|
2013-12-04 08:19:22 -05:00
|
|
|
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
|
|
|
|
{
|
2014-01-23 09:24:57 -05:00
|
|
|
if (cursor->win32.handle)
|
|
|
|
DestroyIcon((HICON) cursor->win32.handle);
|
2013-12-04 08:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
|
|
|
|
{
|
2015-07-07 06:02:10 -04:00
|
|
|
POINT pos;
|
2013-12-04 08:19:22 -05:00
|
|
|
|
2015-07-07 06:02:10 -04:00
|
|
|
if (_glfw.cursorWindow != window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (window->cursorMode != GLFW_CURSOR_NORMAL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!GetCursorPos(&pos))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (WindowFromPoint(pos) != window->win32.handle)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (cursor)
|
|
|
|
SetCursor(cursor->win32.handle);
|
|
|
|
else
|
|
|
|
SetCursor(LoadCursorW(NULL, IDC_ARROW));
|
2013-12-04 08:19:22 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 10:26:57 -04:00
|
|
|
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
|
|
|
|
{
|
|
|
|
WCHAR* wideString;
|
|
|
|
HANDLE stringHandle;
|
|
|
|
size_t wideSize;
|
|
|
|
|
|
|
|
wideString = _glfwCreateWideStringFromUTF8(string);
|
|
|
|
if (!wideString)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2015-03-10 14:51:14 -04:00
|
|
|
"Win32: Failed to convert string to UTF-16");
|
2014-09-09 10:26:57 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wideSize = (wcslen(wideString) + 1) * sizeof(WCHAR);
|
|
|
|
|
|
|
|
stringHandle = GlobalAlloc(GMEM_MOVEABLE, wideSize);
|
|
|
|
if (!stringHandle)
|
|
|
|
{
|
|
|
|
free(wideString);
|
|
|
|
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to allocate global handle for clipboard");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(GlobalLock(stringHandle), wideString, wideSize);
|
|
|
|
GlobalUnlock(stringHandle);
|
|
|
|
|
|
|
|
if (!OpenClipboard(window->win32.handle))
|
|
|
|
{
|
|
|
|
GlobalFree(stringHandle);
|
|
|
|
free(wideString);
|
|
|
|
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to open clipboard");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EmptyClipboard();
|
|
|
|
SetClipboardData(CF_UNICODETEXT, stringHandle);
|
|
|
|
CloseClipboard();
|
|
|
|
|
|
|
|
free(wideString);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
HANDLE stringHandle;
|
|
|
|
|
|
|
|
if (!OpenClipboard(window->win32.handle))
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to open clipboard");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
stringHandle = GetClipboardData(CF_UNICODETEXT);
|
|
|
|
if (!stringHandle)
|
|
|
|
{
|
|
|
|
CloseClipboard();
|
|
|
|
|
2015-03-10 14:51:14 -04:00
|
|
|
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
|
|
|
|
"Win32: Failed to convert clipboard to string");
|
2014-09-09 10:26:57 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(_glfw.win32.clipboardString);
|
|
|
|
_glfw.win32.clipboardString =
|
|
|
|
_glfwCreateUTF8FromWideString(GlobalLock(stringHandle));
|
|
|
|
|
|
|
|
GlobalUnlock(stringHandle);
|
|
|
|
CloseClipboard();
|
|
|
|
|
|
|
|
if (!_glfw.win32.clipboardString)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to convert wide string to UTF-8");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _glfw.win32.clipboardString;
|
|
|
|
}
|
|
|
|
|
2013-04-17 09:29:17 -04:00
|
|
|
|
2013-01-15 16:38:14 -05:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW native API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle)
|
|
|
|
{
|
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
2013-02-19 18:28:08 -05:00
|
|
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
2013-01-15 16:38:14 -05:00
|
|
|
return window->win32.handle;
|
|
|
|
}
|
2011-10-01 01:40:36 -04:00
|
|
|
|