mirror of
https://github.com/raysan5/raylib.git
synced 2026-11-25 09:01:47 -05:00
Compare commits
3 Commits
fa14dc7792
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 7cbadefd06 | |||
| 9fcb245f28 | |||
| dd8e7491e2 |
10
src/config.h
10
src/config.h
@ -113,16 +113,6 @@
|
||||
// Enabling this flag allows manual control of the frame processes, use at your own risk
|
||||
#define SUPPORT_CUSTOM_FRAME_CONTROL 0 // Disabled by default
|
||||
#endif
|
||||
#ifndef SUPPORT_CLIPBOARD_IMAGE
|
||||
// Support for clipboard image loading
|
||||
// NOTE: Only working on SDL3, GLFW (Windows) and RGFW (Windows)
|
||||
// WARNING: It requires support for some additional flags:
|
||||
// - SUPPORT_MODULE_RTEXTURES
|
||||
// - SUPPORT_FILEFORMAT_BMP (Windows clipboard)
|
||||
// - SUPPORT_FILEFORMAT_PNG (Wayland clipboard)
|
||||
// - SUPPORT_FILEFORMAT_JPG
|
||||
#define SUPPORT_CLIPBOARD_IMAGE 1
|
||||
#endif
|
||||
|
||||
// rcore: Configuration values
|
||||
// NOTE: Below values are already defined inside [rcore.c] so there is no need to be
|
||||
|
||||
@ -721,7 +721,7 @@ Image GetClipboardImage(void)
|
||||
{
|
||||
Image image = { 0 };
|
||||
|
||||
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform");
|
||||
TRACELOG(LOG_WARNING, "Clipboard image retrieving not implemented");
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
@ -1080,7 +1080,7 @@ void SetClipboardText(const char *text)
|
||||
}
|
||||
|
||||
// Get clipboard text content
|
||||
// NOTE: returned string is allocated and freed by GLFW
|
||||
// NOTE: Returned string is allocated and freed by GLFW
|
||||
const char *GetClipboardText(void)
|
||||
{
|
||||
return glfwGetClipboardString(platform.handle);
|
||||
@ -1108,7 +1108,11 @@ Image GetClipboardImage(void)
|
||||
{
|
||||
Image image = { 0 };
|
||||
|
||||
#if SUPPORT_CLIPBOARD_IMAGE && SUPPORT_MODULE_RTEXTURES
|
||||
#if !SUPPORT_MODULE_RTEXTURES
|
||||
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
|
||||
return image;
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
unsigned int dataSize = 0;
|
||||
void *bmpData = NULL;
|
||||
@ -1163,11 +1167,8 @@ Image GetClipboardImage(void)
|
||||
XFree(data);
|
||||
}
|
||||
#else
|
||||
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform");
|
||||
TRACELOG(LOG_WARNING, "Clipboard image not implemented on target platform");
|
||||
#endif
|
||||
#else
|
||||
TRACELOG(LOG_WARNING, "Clipboard image: SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_MODULE_RTEXTURES to work properly");
|
||||
#endif // SUPPORT_CLIPBOARD_IMAGE
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
@ -168,6 +168,17 @@ extern "C" {
|
||||
#undef Size
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define WIN32_CLIPBOARD_IMPLEMENTATION
|
||||
#define WINUSER_ALREADY_INCLUDED
|
||||
#define WINBASE_ALREADY_INCLUDED
|
||||
#define WINGDI_ALREADY_INCLUDED
|
||||
#include "../external/win32_clipboard.h"
|
||||
#elif defined(__linux__) && defined(DRGFW_X11)
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
@ -1307,26 +1318,17 @@ const char *GetClipboardText(void)
|
||||
return RGFW_readClipboard(NULL);
|
||||
}
|
||||
|
||||
#if SUPPORT_CLIPBOARD_IMAGE
|
||||
#if defined(_WIN32)
|
||||
#define WIN32_CLIPBOARD_IMPLEMENTATION
|
||||
#define WINUSER_ALREADY_INCLUDED
|
||||
#define WINBASE_ALREADY_INCLUDED
|
||||
#define WINGDI_ALREADY_INCLUDED
|
||||
#include "../external/win32_clipboard.h"
|
||||
#elif defined(__linux__) && defined(DRGFW_X11)
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Get clipboard image
|
||||
Image GetClipboardImage(void)
|
||||
{
|
||||
Image image = { 0 };
|
||||
|
||||
#if SUPPORT_CLIPBOARD_IMAGE && SUPPORT_MODULE_RTEXTURES
|
||||
#if defined(_WIN32
|
||||
#if !SUPPORT_MODULE_RTEXTURES
|
||||
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
|
||||
return image;
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
unsigned int dataSize = 0;
|
||||
void *fileData = NULL;
|
||||
|
||||
@ -1386,11 +1388,8 @@ Image GetClipboardImage(void)
|
||||
XDestroyWindow(dpy, win);
|
||||
XCloseDisplay(dpy);
|
||||
#else
|
||||
TRACELOG(LOG_WARNING, "Clipboard image: PLATFORM_DESKTOP_RGFW doesn't implement GetClipboardImage() for this OS");
|
||||
#endif // _WIN32
|
||||
#else
|
||||
TRACELOG(LOG_WARNING, "Clipboard image: SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_MODULE_RTEXTURES to work properly");
|
||||
#endif // SUPPORT_CLIPBOARD_IMAGE
|
||||
TRACELOG(LOG_WARNING, "Clipboard image not implemented on target platform");
|
||||
#endif
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
@ -1215,22 +1215,22 @@ Image GetClipboardImage(void)
|
||||
{
|
||||
Image image = { 0 };
|
||||
|
||||
#if SUPPORT_CLIPBOARD_IMAGE
|
||||
#if !SUPPORT_MODULE_RTEXTURES
|
||||
TRACELOG(LOG_WARNING, "Enabling SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_MODULE_RTEXTURES to work properly");
|
||||
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
|
||||
return image;
|
||||
#endif
|
||||
|
||||
// It's nice to have support Bitmap on Linux as well, but not as necessary as Windows
|
||||
#if !SUPPORT_FILEFORMAT_BMP && defined(_WIN32)
|
||||
TRACELOG(LOG_WARNING, "WARNING: Enabling SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_FILEFORMAT_BMP, specially on Windows");
|
||||
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_FILEFORMAT_BMP on Windows");
|
||||
return image;
|
||||
#endif
|
||||
|
||||
// From what I've tested applications on Wayland saves images on clipboard as PNG
|
||||
#if (!SUPPORT_FILEFORMAT_PNG || !SUPPORT_FILEFORMAT_JPG) && !defined(_WIN32)
|
||||
TRACELOG(LOG_WARNING, "WARNING: Getting image from the clipboard might not work without SUPPORT_FILEFORMAT_PNG or SUPPORT_FILEFORMAT_JPG");
|
||||
TRACELOG(LOG_WARNING, "Clipboard image might require SUPPORT_FILEFORMAT_PNG or SUPPORT_FILEFORMAT_JPG");
|
||||
#endif
|
||||
|
||||
// Let's hope compiler put these arrays in static memory
|
||||
const char *imageFormats[] = {
|
||||
"image/bmp",
|
||||
@ -1238,6 +1238,7 @@ Image GetClipboardImage(void)
|
||||
"image/jpg",
|
||||
"image/tiff",
|
||||
};
|
||||
|
||||
const char *imageExtensions[] = {
|
||||
".bmp",
|
||||
".png",
|
||||
@ -1246,7 +1247,7 @@ Image GetClipboardImage(void)
|
||||
};
|
||||
|
||||
size_t dataSize = 0;
|
||||
void *fileData = NULL;
|
||||
void *fileData = NULL;
|
||||
|
||||
for (int i = 0; i < SDL_arraysize(imageFormats); i++)
|
||||
{
|
||||
@ -1259,14 +1260,13 @@ Image GetClipboardImage(void)
|
||||
|
||||
if (IsImageValid(image))
|
||||
{
|
||||
TRACELOG(LOG_INFO, "Clipboard: Got image from clipboard successfully: %s", imageExtensions[i]);
|
||||
TRACELOG(LOG_INFO, "Clipboard image retrieved successfully (%s image data)", imageExtensions[i]);
|
||||
return image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!IsImageValid(image)) TRACELOG(LOG_WARNING, "Clipboard: Couldn't get clipboard data. ERROR: %s", SDL_GetError());
|
||||
#endif // SUPPORT_CLIPBOARD_IMAGE
|
||||
if (!IsImageValid(image)) TRACELOG(LOG_WARNING, "Clipboard image data can not be retrieved, ERROR: %s", SDL_GetError());
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
@ -91,13 +91,11 @@ typedef enum MONITOR_DPI_TYPE {
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
#if SUPPORT_CLIPBOARD_IMAGE && SUPPORT_MODULE_RTEXTURES
|
||||
#define WIN32_CLIPBOARD_IMPLEMENTATION
|
||||
#define WINUSER_ALREADY_INCLUDED
|
||||
#define WINBASE_ALREADY_INCLUDED
|
||||
#define WINGDI_ALREADY_INCLUDED
|
||||
#include "../external/win32_clipboard.h"
|
||||
#endif
|
||||
#define WIN32_CLIPBOARD_IMPLEMENTATION
|
||||
#define WINUSER_ALREADY_INCLUDED
|
||||
#define WINBASE_ALREADY_INCLUDED
|
||||
#define WINGDI_ALREADY_INCLUDED
|
||||
#include "../external/win32_clipboard.h"
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
@ -1484,8 +1482,12 @@ bool SetClipboardImage(Image image)
|
||||
Image GetClipboardImage(void)
|
||||
{
|
||||
Image image = { 0 };
|
||||
|
||||
#if !SUPPORT_MODULE_RTEXTURES
|
||||
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
|
||||
return image;
|
||||
#endif
|
||||
|
||||
#if SUPPORT_CLIPBOARD_IMAGE && SUPPORT_MODULE_RTEXTURES
|
||||
unsigned int dataSize = 0;
|
||||
void *fileData = NULL;
|
||||
int width = 0;
|
||||
@ -1496,12 +1498,10 @@ Image GetClipboardImage(void)
|
||||
if (fileData == NULL) TRACELOG(LOG_WARNING, "Clipboard image: Couldn't get clipboard data.");
|
||||
else
|
||||
{
|
||||
// TODO: Support additional image file-formats
|
||||
image = LoadImageFromMemory(".bmp", (const unsigned char*)fileData, (int)dataSize);
|
||||
RL_FREE(fileData);
|
||||
}
|
||||
#else
|
||||
TRACELOG(LOG_WARNING, "Clipboard image: SUPPORT_CLIPBOARD_IMAGE requires SUPPORT_MODULE_RTEXTURES to work properly");
|
||||
#endif
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
@ -570,7 +570,7 @@ Image GetClipboardImage(void)
|
||||
{
|
||||
Image image = { 0 };
|
||||
|
||||
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform");
|
||||
TRACELOG(LOG_WARNING, "Clipboard image retrieving not implemented");
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
@ -323,7 +323,7 @@ Image GetClipboardImage(void)
|
||||
{
|
||||
Image image = { 0 };
|
||||
|
||||
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform");
|
||||
TRACELOG(LOG_WARNING, "Clipboard image retrieving not implemented");
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
@ -302,7 +302,7 @@ Image GetClipboardImage(void)
|
||||
{
|
||||
Image image = { 0 };
|
||||
|
||||
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform");
|
||||
TRACELOG(LOG_WARNING, "Clipboard image retrieving not implemented");
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
@ -901,11 +901,16 @@ bool SetClipboardImage(Image image)
|
||||
Image GetClipboardImage(void)
|
||||
{
|
||||
Image image = { 0 };
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
#if !SUPPORT_MODULE_RTEXTURES
|
||||
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
|
||||
return image;
|
||||
#endif
|
||||
|
||||
RequestClipboardData();
|
||||
|
||||
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
unsigned char *data = GetLastPastedImage(&width, &height);
|
||||
|
||||
if (data != NULL)
|
||||
@ -1703,7 +1708,6 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
|
||||
// Gesture data is sent to gestures-system for processing
|
||||
// Prevent calling ProcessGestureEvent() when Emscripten is present and there's a touch gesture, so EmscriptenTouchCallback() can handle it itself
|
||||
if (GetMouseX() != 0 || GetMouseY() != 0) ProcessGestureEvent(gestureEvent);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -864,12 +864,15 @@ EM_ASYNC_JS(void, RequestClipboardData, (void), {
|
||||
EM_JS(char *, GetLastPastedText, (void), {
|
||||
var str = window._lastClipboardString || "";
|
||||
var length = lengthBytesUTF8(str) + 1;
|
||||
|
||||
if (length > 1)
|
||||
{
|
||||
var ptr = _malloc(length);
|
||||
stringToUTF8(str, ptr, length);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
@ -885,7 +888,7 @@ EM_JS(unsigned char *, GetLastPastedImage, (int *width, int *height), {
|
||||
|
||||
// Set the width and height via the pointers passed from C
|
||||
// HEAP32 handles the 4-byte integers
|
||||
if (width) setValue(width, window._lastImgWidth, 'i32');
|
||||
if (width) setValue(width, window._lastImgWidth, 'i32');
|
||||
if (height) setValue(height, window._lastImgHeight, 'i32');
|
||||
|
||||
// Clear the JS buffer so there is no need to fetch the same image twice
|
||||
@ -921,10 +924,16 @@ bool SetClipboardImage(Image image)
|
||||
Image GetClipboardImage(void)
|
||||
{
|
||||
Image image = { 0 };
|
||||
|
||||
#if !SUPPORT_MODULE_RTEXTURES
|
||||
TRACELOG(LOG_WARNING, "Clipboard image requires SUPPORT_MODULE_RTEXTURES to work");
|
||||
return image;
|
||||
#endif
|
||||
|
||||
RequestClipboardData();
|
||||
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
RequestClipboardData();
|
||||
unsigned char *data = GetLastPastedImage(&width, &height);
|
||||
|
||||
if (data != NULL)
|
||||
|
||||
23
src/rcore.c
23
src/rcore.c
@ -322,11 +322,9 @@ typedef struct CoreData {
|
||||
|
||||
char **dropFilepaths; // Store dropped files paths pointers (provided by GLFW)
|
||||
unsigned int dropFileCount; // Count dropped files strings
|
||||
|
||||
} Window;
|
||||
struct {
|
||||
const char *basePath; // Base path for data storage
|
||||
|
||||
} Storage;
|
||||
struct {
|
||||
struct {
|
||||
@ -343,7 +341,6 @@ typedef struct CoreData {
|
||||
|
||||
int charPressedQueue[MAX_CHAR_PRESSED_QUEUE]; // Input characters queue (unicode)
|
||||
int charPressedQueueCount; // Input characters queue count
|
||||
|
||||
} Keyboard;
|
||||
struct {
|
||||
Vector2 offset; // Mouse offset
|
||||
@ -361,7 +358,6 @@ typedef struct CoreData {
|
||||
char previousButtonState[MAX_MOUSE_BUTTONS]; // Registers previous mouse button state
|
||||
Vector2 currentWheelMove; // Registers current mouse wheel variation
|
||||
Vector2 previousWheelMove; // Registers previous mouse wheel variation
|
||||
|
||||
} Mouse;
|
||||
struct {
|
||||
int pointCount; // Number of touch points active
|
||||
@ -370,7 +366,6 @@ typedef struct CoreData {
|
||||
Vector2 previousPosition[MAX_TOUCH_POINTS]; // Previous touch position on screen
|
||||
char currentTouchState[MAX_TOUCH_POINTS]; // Registers current touch state
|
||||
char previousTouchState[MAX_TOUCH_POINTS]; // Registers previous touch state
|
||||
|
||||
} Touch;
|
||||
struct {
|
||||
int lastButtonPressed; // Register last gamepad button pressed
|
||||
@ -380,9 +375,7 @@ typedef struct CoreData {
|
||||
char currentButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state
|
||||
char previousButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state
|
||||
float axisState[MAX_GAMEPADS][MAX_GAMEPAD_AXES]; // Gamepad axes state
|
||||
|
||||
} Gamepad;
|
||||
|
||||
} Input;
|
||||
struct {
|
||||
double current; // Current time measure (seconds)
|
||||
@ -393,7 +386,6 @@ typedef struct CoreData {
|
||||
double target; // Desired time for one frame, if 0 not applied (seconds)
|
||||
unsigned long long base; // Base time measure for hi-res timer (ticks or nanoseconds)
|
||||
unsigned int frameCounter; // Frame counter (frames)
|
||||
|
||||
} Time;
|
||||
} CoreData;
|
||||
|
||||
@ -579,6 +571,13 @@ const char *TextFormat(const char *text, ...); // Formatting of text with variab
|
||||
//Vector2 GetMonitorPosition(int monitor)
|
||||
//const char *GetMonitorName(int monitor)
|
||||
|
||||
// Clipboard interaction support
|
||||
// NOTE: Only working on SDL3, GLFW (Windows) and RGFW (Windows)
|
||||
// WARNING: It requires support for some additional flags:
|
||||
// - SUPPORT_MODULE_RTEXTURES
|
||||
// - SUPPORT_FILEFORMAT_BMP (Windows clipboard)
|
||||
// - SUPPORT_FILEFORMAT_PNG (Wayland clipboard)
|
||||
// - SUPPORT_FILEFORMAT_JPG
|
||||
//void SetClipboardText(const char *text)
|
||||
//const char *GetClipboardText(void)
|
||||
//bool SetClipboardImage(Image image)
|
||||
@ -2694,9 +2693,7 @@ const char *GetApplicationDirectory(void)
|
||||
appDir[0] = '.';
|
||||
appDir[1] = '\\';
|
||||
}
|
||||
|
||||
#elif defined(__linux__)
|
||||
|
||||
unsigned int size = sizeof(appDir);
|
||||
ssize_t len = readlink("/proc/self/exe", appDir, size);
|
||||
|
||||
@ -2716,9 +2713,7 @@ const char *GetApplicationDirectory(void)
|
||||
appDir[0] = '.';
|
||||
appDir[1] = '/';
|
||||
}
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
uint32_t size = sizeof(appDir);
|
||||
|
||||
if (_NSGetExecutablePath(appDir, &size) == 0)
|
||||
@ -2738,9 +2733,7 @@ const char *GetApplicationDirectory(void)
|
||||
appDir[0] = '.';
|
||||
appDir[1] = '/';
|
||||
}
|
||||
|
||||
#elif defined(__FreeBSD__)
|
||||
|
||||
size_t size = sizeof(appDir);
|
||||
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
|
||||
|
||||
@ -2761,9 +2754,7 @@ const char *GetApplicationDirectory(void)
|
||||
appDir[0] = '.';
|
||||
appDir[1] = '/';
|
||||
}
|
||||
|
||||
#elif defined(__wasm__)
|
||||
|
||||
appDir[0] = '/';
|
||||
#endif
|
||||
|
||||
|
||||
@ -1079,7 +1079,6 @@ typedef struct rlglData {
|
||||
|
||||
int framebufferWidth; // Current framebuffer width
|
||||
int framebufferHeight; // Current framebuffer height
|
||||
|
||||
} State; // Renderer state
|
||||
struct {
|
||||
bool vao; // VAO support (OpenGL ES2 could not support VAO extension) (GL_ARB_vertex_array_object)
|
||||
@ -1101,7 +1100,6 @@ typedef struct rlglData {
|
||||
|
||||
float maxAnisotropyLevel; // Maximum anisotropy level supported (minimum is 2.0f)
|
||||
int maxDepthBits; // Maximum bits for depth component
|
||||
|
||||
} ExtSupported; // Extensions supported flags
|
||||
} rlglData;
|
||||
|
||||
|
||||
@ -6808,10 +6808,9 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, int *animCo
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "MODEL: [%s] Expected one unique skin to load animation data from, but found %i", fileName, data->skins_count);
|
||||
}
|
||||
|
||||
cgltf_free(data);
|
||||
}
|
||||
|
||||
cgltf_free(data);
|
||||
UnloadFileData(fileData);
|
||||
|
||||
return animations;
|
||||
|
||||
Reference in New Issue
Block a user