From ede1427dfdab094edac0d55edb74f04dcf6b5036 Mon Sep 17 00:00:00 2001 From: Romain Moret Date: Fri, 20 Apr 2018 14:43:52 +0200 Subject: [PATCH] Added GLFW_MULTI key/button state for handling of double-click (win32) --- README.md | 3 +++ include/GLFW/glfw3.h | 7 +++++++ src/win32_window.c | 34 ++++++++++++++++++++++++++-------- src/window.c | 3 ++- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0573dcd93..1957a3441 100644 --- a/README.md +++ b/README.md @@ -178,6 +178,7 @@ information on what to include when reporting a bug. - Added `GLFW_OSMESA_CONTEXT_API` for creating OpenGL contexts with [OSMesa](https://www.mesa3d.org/osmesa.html) (#281) - Added `GenerateMappings.cmake` script for updating gamepad mappings +- Added `GLFW_MULTI` key/button state for handling of double-click/multi-press - Made `glfwCreateWindowSurface` emit an error when the window has a context (#1194,#1205) - Deprecated window parameter of clipboard string functions @@ -194,6 +195,7 @@ information on what to include when reporting a bug. - Bugfix: The scancode for synthetic key release events was always zero - Bugfix: The generated Doxyfile did not handle paths with spaces (#1081) - [Win32] Added system error strings to relevant GLFW error descriptions (#733) +- [Win32] Added 'WM_NBUTTONDBLCLK' message support - [Win32] Moved to `WM_INPUT` for disabled cursor mode motion input (#125) - [Win32] Removed XInput circular deadzone from joystick axis data (#1045) - [Win32] Bugfix: Undecorated windows could not be iconified by the user (#861) @@ -386,6 +388,7 @@ skills. - Jack Moffitt - Jeff Molofee - Pierre Morel + - Romain Moret - Jon Morton - Pierre Moulon - Martins Mozeiko diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index b6d9f341f..54b6251fb 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -310,6 +310,13 @@ extern "C" { * @ingroup input */ #define GLFW_REPEAT 2 +/*! @brief The key or mouse button was pressed multiple times (e.g. double-click). + * + * The key or mouse button was pressed multiple times (e.g. double-click). + * + * @ingroup input + */ +#define GLFW_MULTI 3 /*! @} */ /*! @defgroup hat_state Joystick hat states diff --git a/src/win32_window.c b/src/win32_window.c index 4506c8a72..c53c961a2 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -705,14 +705,21 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, case WM_RBUTTONUP: case WM_MBUTTONUP: case WM_XBUTTONUP: + case WM_LBUTTONDBLCLK: + case WM_RBUTTONDBLCLK: + case WM_MBUTTONDBLCLK: + case WM_XBUTTONDBLCLK: { int i, button, action; - if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP) + if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP || + uMsg == WM_LBUTTONDBLCLK) button = GLFW_MOUSE_BUTTON_LEFT; - else if (uMsg == WM_RBUTTONDOWN || uMsg == WM_RBUTTONUP) + else if (uMsg == WM_RBUTTONDOWN || uMsg == WM_RBUTTONUP || + uMsg == WM_RBUTTONDBLCLK) button = GLFW_MOUSE_BUTTON_RIGHT; - else if (uMsg == WM_MBUTTONDOWN || uMsg == WM_MBUTTONUP) + else if (uMsg == WM_MBUTTONDOWN || uMsg == WM_MBUTTONUP || + uMsg == WM_MBUTTONDBLCLK) button = GLFW_MOUSE_BUTTON_MIDDLE; else if (GET_XBUTTON_WPARAM(wParam) == XBUTTON1) button = GLFW_MOUSE_BUTTON_4; @@ -724,12 +731,20 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, { action = GLFW_PRESS; } - else + else if (uMsg == WM_LBUTTONUP || uMsg == WM_RBUTTONUP || + uMsg == WM_MBUTTONUP || uMsg == WM_XBUTTONUP) + { action = GLFW_RELEASE; + } + else + { + action = GLFW_MULTI; + } for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++) { - if (window->mouseButtons[i] == GLFW_PRESS) + if (window->mouseButtons[i] == GLFW_PRESS || + window->mouseButtons[i] == GLFW_MULTI) break; } @@ -740,14 +755,17 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++) { - if (window->mouseButtons[i] == GLFW_PRESS) + if (window->mouseButtons[i] == GLFW_PRESS || + window->mouseButtons[i] == GLFW_MULTI) break; } if (i > GLFW_MOUSE_BUTTON_LAST) ReleaseCapture(); - if (uMsg == WM_XBUTTONDOWN || uMsg == WM_XBUTTONUP) + if (uMsg == WM_XBUTTONDOWN || + uMsg == WM_XBUTTONUP || + uMsg == WM_XBUTTONDBLCLK) return TRUE; return 0; @@ -1151,7 +1169,7 @@ GLFWbool _glfwRegisterWindowClassWin32(void) ZeroMemory(&wc, sizeof(wc)); wc.cbSize = sizeof(wc); - wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; + wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS; wc.lpfnWndProc = (WNDPROC) windowProc; wc.hInstance = GetModuleHandleW(NULL); wc.hCursor = LoadCursorW(NULL, IDC_ARROW); diff --git a/src/window.c b/src/window.c index 38a8982bf..989b78b98 100644 --- a/src/window.c +++ b/src/window.c @@ -60,7 +60,8 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLFWbool focused) for (button = 0; button <= GLFW_MOUSE_BUTTON_LAST; button++) { - if (window->mouseButtons[button] == GLFW_PRESS) + if (window->mouseButtons[button] == GLFW_PRESS || + window->mouseButtons[button] == GLFW_MULTI) _glfwInputMouseClick(window, button, GLFW_RELEASE, 0); } }