diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 5e6fad42..5c747ccf 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -5833,6 +5833,9 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state); */ GLFWAPI void glfwSetClipboardString(GLFWwindow* window, const char* string); +// hacky way for a screenshot +GLFWAPI void glfwSetClipboardBitmap(unsigned char * data, int width, int height); + /*! @brief Returns the contents of the clipboard as a string. * * This function returns the contents of the system clipboard, if it contains diff --git a/src/input.c b/src/input.c index b5bb69d6..2b699176 100644 --- a/src/input.c +++ b/src/input.c @@ -1464,6 +1464,12 @@ GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string) _glfw.platform.setClipboardString(string); } +GLFWAPI void glfwSetClipboardBitmap(unsigned char * data, int width, int height) +{ + _GLFW_REQUIRE_INIT(); + _glfw.platform.setClipboardBitmap(); +} + GLFWAPI const char* glfwGetClipboardString(GLFWwindow* handle) { _GLFW_REQUIRE_INIT_OR_RETURN(NULL); diff --git a/src/internal.h b/src/internal.h index fe0369aa..d15641e7 100644 --- a/src/internal.h +++ b/src/internal.h @@ -750,6 +750,7 @@ struct _GLFWplatform void (*getRequiredInstanceExtensions)(char**); GLFWbool (*getPhysicalDevicePresentationSupport)(VkInstance,VkPhysicalDevice,uint32_t); VkResult (*createWindowSurface)(VkInstance,_GLFWwindow*,const VkAllocationCallbacks*,VkSurfaceKHR*); + void (*setClipboardBitmap)(); }; // Library global data diff --git a/src/win32_init.c b/src/win32_init.c index 4cb01adb..189e41f5 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -675,6 +675,7 @@ GLFWbool _glfwConnectWin32(int platformID, _GLFWplatform* platform) _glfwGetRequiredInstanceExtensionsWin32, _glfwGetPhysicalDevicePresentationSupportWin32, _glfwCreateWindowSurfaceWin32, + _glfwSetClipboardBitmapWin32 }; *platform = win32; diff --git a/src/win32_platform.h b/src/win32_platform.h index 82b34bb9..de9ed1b8 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -591,6 +591,7 @@ GLFWbool _glfwCreateStandardCursorWin32(_GLFWcursor* cursor, int shape); void _glfwDestroyCursorWin32(_GLFWcursor* cursor); void _glfwSetCursorWin32(_GLFWwindow* window, _GLFWcursor* cursor); void _glfwSetClipboardStringWin32(const char* string); +void _glfwSetClipboardBitmapWin32(); const char* _glfwGetClipboardStringWin32(void); EGLenum _glfwGetEGLPlatformWin32(EGLint** attribs); diff --git a/src/win32_window.c b/src/win32_window.c index f7feb32d..ec28c68b 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -2289,6 +2289,24 @@ void _glfwSetCursorWin32(_GLFWwindow* window, _GLFWcursor* cursor) updateCursorImage(window); } +void _glfwSetClipboardBitmapWin32(unsigned char * data, int width, int height) { + HBITMAP fillBm = NULL; + fillBm = CreateBitmap(width, height, 1, 32, data); + + if (!OpenClipboard(_glfw.win32.helperWindowHandle)) { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, "Win32: Failed to open clipboard"); + return; + } + EmptyClipboard(); + + // place handle to clipboard + SetClipboardData(CF_BITMAP, fillBm); + + // Close the clipboard. + CloseClipboard(); + DeleteObject(fillBm); +} + void _glfwSetClipboardStringWin32(const char* string) { int characterCount, tries = 0;