mirror of
https://github.com/glfw/glfw.git
synced 2025-10-04 05:36:35 +00:00
+Win32 PointerInput API.
+events example upgrade.
This commit is contained in:
parent
40da56fbf7
commit
5f9d2a6032
@ -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
|
||||
|
18
src/input.c
18
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;
|
||||
}
|
||||
|
||||
|
@ -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 <windows.h>
|
||||
@ -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;
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user