From c78757a95957adb3c3b3437d99e31273c1e361ea Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 19 Nov 2024 12:31:49 +0100 Subject: [PATCH] REVIEWED: `GetClipboardImage()`, make symbol available on all platforms --- src/config.h | 51 ++++++++++++++---------------- src/platforms/rcore_android.c | 10 ++++++ src/platforms/rcore_desktop_glfw.c | 29 ++++++++--------- src/platforms/rcore_desktop_rgfw.c | 43 ++++++++++++------------- src/platforms/rcore_drm.c | 10 ++++++ src/platforms/rcore_template.c | 10 ++++++ src/platforms/rcore_web.c | 10 ++++++ 7 files changed, 97 insertions(+), 66 deletions(-) diff --git a/src/config.h b/src/config.h index e3749c560..d8f7112eb 100644 --- a/src/config.h +++ b/src/config.h @@ -71,6 +71,30 @@ // Enabling this flag allows manual control of the frame processes, use at your own risk //#define SUPPORT_CUSTOM_FRAME_CONTROL 1 +// Support for clipboard image loading +// NOTE: Only working on SDL3, GLFW (Windows) and RGFW (Windows) +#define SUPPORT_CLIPBOARD_IMAGE 1 + +// NOTE: Clipboard image loading requires support for some image file formats +// TODO: Those defines should probably be removed from here, I prefer to let the user manage them +#if defined(SUPPORT_CLIPBOARD_IMAGE) + #ifndef SUPPORT_MODULE_RTEXTURES + #define SUPPORT_MODULE_RTEXTURES 1 + #endif + #ifndef STBI_REQUIRED + #define STBI_REQUIRED + #endif + #ifndef SUPPORT_FILEFORMAT_BMP // For clipboard image on Windows + #define SUPPORT_FILEFORMAT_BMP 1 + #endif + #ifndef SUPPORT_FILEFORMAT_PNG // Wayland uses png for prints, at least it was on 22 LTS ubuntu + #define SUPPORT_FILEFORMAT_PNG 1 + #endif + #ifndef SUPPORT_FILEFORMAT_JPG + #define SUPPORT_FILEFORMAT_JPG 1 + #endif +#endif + // rcore: Configuration values //------------------------------------------------------------------------------------ @@ -273,31 +297,4 @@ //------------------------------------------------------------------------------------ #define MAX_TRACELOG_MSG_LENGTH 256 // Max length of one trace-log message - -// Enable partial support for clipboard image, only working on SDL3 or -// being on both Windows OS + GLFW or Windows OS + RGFW -#define SUPPORT_CLIPBOARD_IMAGE 1 - -#if defined(SUPPORT_CLIPBOARD_IMAGE) - #ifndef STBI_REQUIRED - #define STBI_REQUIRED - #endif - - #ifndef SUPPORT_FILEFORMAT_BMP // For clipboard image on Windows - #define SUPPORT_FILEFORMAT_BMP 1 - #endif - - #ifndef SUPPORT_FILEFORMAT_PNG // Wayland uses png for prints, at least it was on 22 LTS ubuntu - #define SUPPORT_FILEFORMAT_PNG 1 - #endif - - #ifndef SUPPORT_FILEFORMAT_JPG - #define SUPPORT_FILEFORMAT_JPG 1 - #endif - - #ifndef SUPPORT_MODULE_RTEXTURES - #define SUPPORT_MODULE_RTEXTURES 1 - #endif -#endif - #endif // CONFIG_H diff --git a/src/platforms/rcore_android.c b/src/platforms/rcore_android.c index 85ce82a3a..401e2a067 100644 --- a/src/platforms/rcore_android.c +++ b/src/platforms/rcore_android.c @@ -515,6 +515,16 @@ const char *GetClipboardText(void) return NULL; } +// Get clipboard image +Image GetClipboardImage(void) +{ + Image image = { 0 }; + + TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform"); + + return image; +} + // Show mouse cursor void ShowCursor(void) { diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index baf2967fe..839852d9f 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -967,32 +967,29 @@ const char *GetClipboardText(void) return glfwGetClipboardString(platform.handle); } -#if defined(SUPPORT_CLIPBOARD_IMAGE) // Get clipboard image Image GetClipboardImage(void) { - Image image = {0}; + Image image = { 0 }; + +#if defined(SUPPORT_CLIPBOARD_IMAGE) +#if defined(_WIN32) unsigned long long int dataSize = 0; - void* fileData = NULL; - -#ifdef _WIN32 - int width, height; + void *fileData = NULL; + int width = 0; + int height = 0; + fileData = (void*)Win32GetClipboardImageData(&width, &height, &dataSize); + + if (fileData == NULL) TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data."); + else image = LoadImageFromMemory(".bmp", fileData, (int)dataSize); #else - TRACELOG(LOG_WARNING, "Clipboard image: PLATFORM_DESKTOP_GLFW doesn't implement `GetClipboardImage` for this OS"); + TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform"); #endif +#endif // SUPPORT_CLIPBOARD_IMAGE - if (fileData == NULL) - { - TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data."); - } - else - { - image = LoadImageFromMemory(".bmp", fileData, (int)dataSize); - } return image; } -#endif // SUPPORT_CLIPBOARD_IMAGE // Show mouse cursor void ShowCursor(void) diff --git a/src/platforms/rcore_desktop_rgfw.c b/src/platforms/rcore_desktop_rgfw.c index f3f26e3e8..7a2ea9c0d 100644 --- a/src/platforms/rcore_desktop_rgfw.c +++ b/src/platforms/rcore_desktop_rgfw.c @@ -664,42 +664,39 @@ const char *GetClipboardText(void) return RGFW_readClipboard(NULL); } - #if defined(SUPPORT_CLIPBOARD_IMAGE) - -#ifdef _WIN32 -# define WIN32_CLIPBOARD_IMPLEMENTATION -# define WINUSER_ALREADY_INCLUDED -# define WINBASE_ALREADY_INCLUDED -# define WINGDI_ALREADY_INCLUDED -# include "../external/win32_clipboard.h" +#if defined(_WIN32) + #define WIN32_CLIPBOARD_IMPLEMENTATION + #define WINUSER_ALREADY_INCLUDED + #define WINBASE_ALREADY_INCLUDED + #define WINGDI_ALREADY_INCLUDED + #include "../external/win32_clipboard.h" #endif +#endif // SUPPORT_CLIPBOARD_IMAGE // Get clipboard image Image GetClipboardImage(void) { - Image image = {0}; + Image image = { 0 }; + +#if defined(SUPPORT_CLIPBOARD_IMAGE) +#if defined(_WIN32) unsigned long long int dataSize = 0; - void* fileData = NULL; - -#ifdef _WIN32 - int width, height; + void *fileData = NULL; + int width = 0; + int height = 0; + fileData = (void*)Win32GetClipboardImageData(&width, &height, &dataSize); + + if (fileData == NULL) TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data."); + else image = LoadImageFromMemory(".bmp", fileData, (int)dataSize); #else - TRACELOG(LOG_WARNING, "Clipboard image: PLATFORM_DESKTOP_RGFW doesn't implement `GetClipboardImage` for this OS"); + TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform"); #endif +#endif // SUPPORT_CLIPBOARD_IMAGE - if (fileData == NULL) - { - TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data."); - } - else - { - image = LoadImageFromMemory(".bmp", fileData, dataSize); - } return image; } -#endif // SUPPORT_CLIPBOARD_IMAGE // Show mouse cursor void ShowCursor(void) diff --git a/src/platforms/rcore_drm.c b/src/platforms/rcore_drm.c index eb8ef0103..e53f6e86d 100644 --- a/src/platforms/rcore_drm.c +++ b/src/platforms/rcore_drm.c @@ -509,6 +509,16 @@ const char *GetClipboardText(void) return NULL; } +// Get clipboard image +Image GetClipboardImage(void) +{ + Image image = { 0 }; + + TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform"); + + return image; +} + // Show mouse cursor void ShowCursor(void) { diff --git a/src/platforms/rcore_template.c b/src/platforms/rcore_template.c index 6bc3432eb..83994e30f 100644 --- a/src/platforms/rcore_template.c +++ b/src/platforms/rcore_template.c @@ -292,6 +292,16 @@ const char *GetClipboardText(void) return NULL; } +// Get clipboard image +Image GetClipboardImage(void) +{ + Image image = { 0 }; + + TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform"); + + return image; +} + // Show mouse cursor void ShowCursor(void) { diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index f9d93e5a3..aea9fef83 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -805,6 +805,16 @@ const char *GetClipboardText(void) return NULL; } +// Get clipboard image +Image GetClipboardImage(void) +{ + Image image = { 0 }; + + TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform"); + + return image; +} + // Show mouse cursor void ShowCursor(void) {