Browse Source

[rcore] using win32_clipboard on platforms rlfw and rgfw

pull/4459/head
evertonse 1 week ago
parent
commit
057f7dc98f
4 changed files with 70 additions and 35 deletions
  1. +0
    -34
      examples/core/core_clipboard_image.c
  2. +32
    -0
      src/platforms/rcore_desktop_glfw.c
  3. +37
    -0
      src/platforms/rcore_desktop_rgfw.c
  4. +1
    -1
      src/rcore.c

+ 0
- 34
examples/core/core_clipboard_image.c View File

@ -1,34 +0,0 @@
#include "raylib.h"
#include <stdio.h>
#include <stdlib.h>
static Image img = {0};
int main(int argc, char *argv[]) {
InitWindow(800, 450, "[core] raylib clipboard image");
SetTraceLogLevel(LOG_TRACE);
SetTargetFPS(60);
Texture tex = {0};
while(!WindowShouldClose()) {
if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_V)) {
#ifdef _WIN32
img = GetClipboardImage();
tex = LoadTextureFromImage(img);
if(!IsTextureValid(tex)) {
exit(98);
} else {
ExportImage(img, "Debug.bmp");
}
#endif
}
BeginDrawing();
ClearBackground(RAYWHITE);
if (IsTextureValid(tex)) {
DrawTexture(tex, 0, 10 + 21, WHITE);
}
DrawText("Print Screen and Crtl+V", 10, 10, 21, BLACK);
EndDrawing();
}
}

+ 32
- 0
src/platforms/rcore_desktop_glfw.c View File

@ -58,6 +58,7 @@
#if defined(_WIN32)
typedef void *PVOID;
typedef PVOID HANDLE;
#include "../external/win32_clipboard.h"
typedef HANDLE HWND;
#define GLFW_EXPOSE_NATIVE_WIN32
#define GLFW_NATIVE_INCLUDE_NONE // To avoid some symbols re-definition in windows.h
@ -966,6 +967,33 @@ const char *GetClipboardText(void)
return glfwGetClipboardString(platform.handle);
}
#if defined(SUPPORT_CLIPBOARD_IMAGE)
// Get clipboard image
Image GetClipboardImage(void)
{
Image image = {0};
unsigned long long int dataSize = 0;
void* fileData = NULL;
#ifdef _WIN32
int width, height;
fileData = (void*)Win32GetClipboardImageData(&width, &height, &dataSize);
#else
TRACELOG(LOG_WARNING, "Clipboard image: PLATFORM_GLFW doesn't implement `GetClipboardImage` for this OS");
#endif
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)
{
@ -1898,4 +1926,8 @@ static void JoystickCallback(int jid, int event)
}
}
#ifdef _WIN32
# define WIN32_CLIPBOARD_IMPLEMENTATION
# include "../external/win32_clipboard.h"
#endif
// EOF

+ 37
- 0
src/platforms/rcore_desktop_rgfw.c View File

@ -664,6 +664,43 @@ 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"
#endif
// Get clipboard image
Image GetClipboardImage(void)
{
Image image = {0};
unsigned long long int dataSize = 0;
void* fileData = NULL;
#ifdef _WIN32
int width, height;
fileData = (void*)Win32GetClipboardImageData(&width, &height, &dataSize);
#else
TRACELOG(LOG_WARNING, "Clipboard image: PLATFORM_GLFW doesn't implement `GetClipboardImage` for this OS");
#endif
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)
{

+ 1
- 1
src/rcore.c View File

@ -514,7 +514,7 @@ const char *TextFormat(const char *text, ...); // Formatting of tex
#if defined(SUPPORT_CLIPBOARD_IMAGE)
#if !defined(SUPPORT_FILEFORMAT_BMP) || !defined(STBI_REQUIRED) || !defined(SUPPORT_MODULE_RTEXTURES)
#error "To enabled SUPPORT_CLIPBOARD_IMAGE, it also needs SUPPORT_FILEFORMAT_BMP, SUPPORT_MODULE_RTEXTURES and STBI_REQUIRED to be defined"
#error "To enabled SUPPORT_CLIPBOARD_IMAGE, it also needs SUPPORT_FILEFORMAT_BMP, SUPPORT_MODULE_RTEXTURES and STBI_REQUIRED to be defined. It should have been defined earlier"
#endif
#endif // SUPPORT_CLIPBOARD_IMAGE

Loading…
Cancel
Save