From 5f9d2a60329cf8ad35fe08d3091d01e44029f1af Mon Sep 17 00:00:00 2001 From: nill Date: Thu, 10 Sep 2015 17:26:49 +0800 Subject: [PATCH] +Win32 PointerInput API. +events example upgrade. --- include/GLFW/glfw3.h | 9 +++++++++ src/input.c | 18 ++++++++++++++++++ src/win32_platform.h | 19 ++++++++++++------- src/win32_window.c | 38 ++++++++++++++++++++++++++++++++++++++ tests/events.c | 20 ++++++++++++++++++++ 5 files changed, 97 insertions(+), 7 deletions(-) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 8b9c9e71d..01721d172 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -3330,6 +3330,15 @@ GLFWAPI int glfwExtensionSupported(const char* extension); */ GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname); +/************************************************************************* +* For win32 PointerInputer API +*************************************************************************/ + +typedef void(*GLFWpointerinputfun)(GLFWwindow*, unsigned int); +GLFWAPI GLFWpointerinputfun glfwSetPointerInputCallback(GLFWwindow* window, GLFWpointerinputfun cbfun); + +typedef void(*GLFWpointercapturechangefun)(GLFWwindow*, unsigned int); +GLFWAPI GLFWpointercapturechangefun glfwSetPointerCaptureChangeCallback(GLFWwindow* window, GLFWpointercapturechangefun cbfun); /************************************************************************* * Global definition cleanup diff --git a/src/input.c b/src/input.c index eefbf0860..2f192659d 100644 --- a/src/input.c +++ b/src/input.c @@ -612,3 +612,21 @@ GLFWAPI void glfwSetTime(double time) _glfwPlatformSetTime(time); } +GLFWAPI GLFWpointerinputfun glfwSetPointerInputCallback(GLFWwindow* handle, + GLFWpointerinputfun cbfun) +{ + _GLFWwindow* window = (_GLFWwindow*)handle; + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + _GLFW_SWAP_POINTERS(window->win32.pointerInput, cbfun); + return cbfun; +} + +GLFWAPI GLFWpointercapturechangefun glfwSetPointerCaptureChangeCallback(GLFWwindow* handle, + GLFWpointercapturechangefun cbfun) +{ + _GLFWwindow* window = (_GLFWwindow*)handle; + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + _GLFW_SWAP_POINTERS(window->win32.pointerCaptureChange, cbfun); + return cbfun; +} + diff --git a/src/win32_platform.h b/src/win32_platform.h index e8e32dfca..06dbc963c 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -51,14 +51,14 @@ #define UNICODE #endif -// GLFW requires Windows XP or later -#if WINVER < 0x0501 - #undef WINVER - #define WINVER 0x0501 +// GLFW requires Windows 8.1 or later, owing to Pointer Input API. +#if WINVER < 0x0602 +#undef WINVER +#define WINVER 0x0602 #endif -#if _WIN32_WINNT < 0x0501 - #undef _WIN32_WINNT - #define _WIN32_WINNT 0x0501 +#if _WIN32_WINNT < 0x0602 +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0602 #endif #include @@ -157,6 +157,11 @@ typedef struct _GLFWwindowWin32 // The last received cursor position, regardless of source int cursorPosX, cursorPosY; + // for pointer input events + UINT32 pointerFrameID; + GLFWpointerinputfun pointerInput; + GLFWpointercapturechangefun pointerCaptureChange; + } _GLFWwindowWin32; diff --git a/src/win32_window.c b/src/win32_window.c index 9d47c25a6..8c9ed4ced 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -627,6 +627,35 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, DragFinish(drop); return 0; } + + case WM_POINTERDOWN: + case WM_POINTERUPDATE: + case WM_POINTERUP: + case WM_POINTERWHEEL: + case WM_POINTERHWHEEL: + { + if (window->win32.pointerInput) + { + window->win32.pointerInput((GLFWwindow*)window, GET_POINTERID_WPARAM(wParam)); + return 0; + } + else + { + break; + } + } + case WM_POINTERCAPTURECHANGED: + { + if (window->win32.pointerCaptureChange) + { + window->win32.pointerCaptureChange((GLFWwindow*)window, GET_POINTERID_WPARAM(wParam)); + return 0; + } + else + { + break; + } + } } return DefWindowProc(hWnd, uMsg, wParam, lParam); @@ -727,6 +756,15 @@ static int createWindow(_GLFWwindow* window, if (!_glfwCreateContext(window, ctxconfig, fbconfig)) return GL_FALSE; + // Enable mouse to act as pointing device for this application + // if window. + if (!EnableMouseInPointer(TRUE)) + { + //HRESULT_FROM_WIN32(GetLastError()) + _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to enable MouseInPointer"); + return GL_FALSE; + } + return GL_TRUE; } diff --git a/tests/events.c b/tests/events.c index f40576d46..10af2a076 100644 --- a/tests/events.c +++ b/tests/events.c @@ -437,6 +437,21 @@ static void monitor_callback(GLFWmonitor* monitor, int event) } } +// for win32 PointInput API +static void pointer_input_callback(GLFWwindow* window, unsigned int point_id) +{ + Slot* slot = glfwGetWindowUserPointer(window); + printf("%08x to %i at %0.3f: point input, point ID: %i\n", + counter++, slot->number, glfwGetTime(), point_id); +} + +static void pointer_capture_change_callback(GLFWwindow* window, unsigned int point_id) +{ + Slot* slot = glfwGetWindowUserPointer(window); + printf("%08x to %i at %0.3f: point capture change, point ID: %i\n", + counter++, slot->number, glfwGetTime(), point_id); +} + int main(int argc, char** argv) { Slot* slots; @@ -551,6 +566,11 @@ int main(int argc, char** argv) glfwSetCharModsCallback(slots[i].window, char_mods_callback); glfwSetDropCallback(slots[i].window, drop_callback); + // if Uncomment, will response win32 PointInput events, + // but MouseButton, CursorPos event will not response. + glfwSetPointerInputCallback(slots[i].window, pointer_input_callback); + glfwSetPointerCaptureChangeCallback(slots[i].window, pointer_capture_change_callback); + glfwMakeContextCurrent(slots[i].window); glfwSwapInterval(1); }