[rcore] using win32_clipboard on platforms rlfw and rgfw
This commit is contained in:
parent
ba5045963e
commit
057f7dc98f
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -58,6 +58,7 @@
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
typedef void *PVOID;
|
typedef void *PVOID;
|
||||||
typedef PVOID HANDLE;
|
typedef PVOID HANDLE;
|
||||||
|
#include "../external/win32_clipboard.h"
|
||||||
typedef HANDLE HWND;
|
typedef HANDLE HWND;
|
||||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||||
#define GLFW_NATIVE_INCLUDE_NONE // To avoid some symbols re-definition in windows.h
|
#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);
|
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
|
// Show mouse cursor
|
||||||
void ShowCursor(void)
|
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
|
// EOF
|
||||||
|
|
|
||||||
|
|
@ -664,6 +664,43 @@ const char *GetClipboardText(void)
|
||||||
return RGFW_readClipboard(NULL);
|
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
|
// Show mouse cursor
|
||||||
void ShowCursor(void)
|
void ShowCursor(void)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -514,7 +514,7 @@ const char *TextFormat(const char *text, ...); // Formatting of tex
|
||||||
|
|
||||||
#if defined(SUPPORT_CLIPBOARD_IMAGE)
|
#if defined(SUPPORT_CLIPBOARD_IMAGE)
|
||||||
#if !defined(SUPPORT_FILEFORMAT_BMP) || !defined(STBI_REQUIRED) || !defined(SUPPORT_MODULE_RTEXTURES)
|
#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
|
||||||
#endif // SUPPORT_CLIPBOARD_IMAGE
|
#endif // SUPPORT_CLIPBOARD_IMAGE
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user