[rcore]: PLATFORM_SDL: improve clipboard data retrieval
This commit is contained in:
parent
729de10b1e
commit
4d5dfb150c
11
src/config.h
11
src/config.h
|
|
@ -283,14 +283,21 @@
|
||||||
#define STBI_REQUIRED
|
#define STBI_REQUIRED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SUPPORT_FILEFORMAT_BMP
|
#ifndef SUPPORT_FILEFORMAT_BMP // For clipboard image on Windows
|
||||||
#define SUPPORT_FILEFORMAT_BMP 1
|
#define SUPPORT_FILEFORMAT_BMP 1
|
||||||
#endif
|
#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
|
#ifndef SUPPORT_MODULE_RTEXTURES
|
||||||
#define SUPPORT_MODULE_RTEXTURES 1
|
#define SUPPORT_MODULE_RTEXTURES 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // CONFIG_H
|
#endif // CONFIG_H
|
||||||
|
|
|
||||||
|
|
@ -1086,20 +1086,39 @@ const char *GetClipboardText(void)
|
||||||
// Get clipboard image
|
// Get clipboard image
|
||||||
Image GetClipboardImage(void)
|
Image GetClipboardImage(void)
|
||||||
{
|
{
|
||||||
Image image = {0};
|
// Let's hope compiler put these arrays in static memory
|
||||||
|
const char *image_formats[] = {
|
||||||
|
"image/bmp",
|
||||||
|
"image/png",
|
||||||
|
"image/jpg",
|
||||||
|
"image/tiff",
|
||||||
|
};
|
||||||
|
const char *image_extensions[] = {
|
||||||
|
".bmp",
|
||||||
|
".png",
|
||||||
|
".jpg",
|
||||||
|
".tiff",
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Image image = {0};
|
||||||
size_t dataSize = 0;
|
size_t dataSize = 0;
|
||||||
// NOTE: This pointer should be free with SDL_free() at some point.
|
void *fileData = NULL;
|
||||||
// TODO: In case of failure let's try to cycle in to other mime types (formats)
|
for (int i = 0; i < SDL_arraysize(image_formats); ++i)
|
||||||
void* fileData = SDL_GetClipboardData("image/bmp", &dataSize); // returns NULL on failure;
|
|
||||||
if (fileData == NULL)
|
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data. %s", SDL_GetError());
|
// NOTE: This pointer should be free with SDL_free() at some point.
|
||||||
}
|
fileData = SDL_GetClipboardData(image_formats[i], &dataSize);
|
||||||
else
|
if (fileData) {
|
||||||
{
|
image = LoadImageFromMemory(image_extensions[i], fileData, dataSize);
|
||||||
image = LoadImageFromMemory(".bmp", fileData, dataSize);
|
if (IsImageValid(image))
|
||||||
|
{
|
||||||
|
TRACELOG(LOG_INFO, "Clipboard image: Got image from clipboard as a `%s` successfully", image_extensions[i]);
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data. %s", SDL_GetError());
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user