mirror of
https://github.com/raysan5/raylib.git
synced 2026-05-25 14:10:27 -04:00
Compare commits
4 Commits
c04e57399a
...
b48933b096
| Author | SHA1 | Date | |
|---|---|---|---|
| b48933b096 | |||
| fd1dfd7d65 | |||
| be56f2c524 | |||
| d31c10a01e |
10
src/external/rprand.h
vendored
10
src/external/rprand.h
vendored
@ -1,6 +1,6 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* rprand v1.0 - A simple and easy-to-use pseudo-random numbers generator (PRNG)
|
||||
* rprand v1.1 - A simple and easy-to-use pseudo-random numbers generator (PRNG)
|
||||
*
|
||||
* FEATURES:
|
||||
* - Pseudo-random values generation, 32 bits: [0..4294967295]
|
||||
@ -118,6 +118,7 @@ extern "C" { // Prevents name mangling of functions
|
||||
//----------------------------------------------------------------------------------
|
||||
RPRANDAPI void rprand_set_seed(unsigned long long seed); // Set rprand_state for Xoshiro128**, seed is 64bit
|
||||
RPRANDAPI int rprand_get_value(int min, int max); // Get random value within a range, min and max included
|
||||
RPRANDAPI int rprand_get_value_raw(void); // Get random value, Xoshiro128** generator (uses global rprand_state)
|
||||
|
||||
RPRANDAPI int *rprand_load_sequence(unsigned int count, int min, int max); // Load pseudo-random numbers sequence with no duplicates
|
||||
RPRANDAPI void rprand_unload_sequence(int *sequence); // Unload pseudo-random numbers sequence
|
||||
@ -186,6 +187,13 @@ int rprand_get_value(int min, int max)
|
||||
return value;
|
||||
}
|
||||
|
||||
int rprand_get_value_raw(void)
|
||||
{
|
||||
int value = rprand_xoshiro();
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
// Load pseudo-random numbers sequence with no duplicates, min and max included
|
||||
int *rprand_load_sequence(unsigned int count, int min, int max)
|
||||
{
|
||||
|
||||
@ -1042,11 +1042,6 @@ const char *GetClipboardText(void)
|
||||
return glfwGetClipboardString(platform.handle);
|
||||
}
|
||||
|
||||
#if SUPPORT_CLIPBOARD_IMAGE && defined(__linux__) && defined(_GLFW_X11)
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
#endif
|
||||
|
||||
// Get clipboard image
|
||||
Image GetClipboardImage(void)
|
||||
{
|
||||
@ -1066,32 +1061,30 @@ Image GetClipboardImage(void)
|
||||
else image = LoadImageFromMemory(".bmp", (const unsigned char *)bmpData, (int)dataSize);
|
||||
|
||||
#elif defined(__linux__) && defined(_GLFW_X11)
|
||||
|
||||
// REF: https://github.com/ColleagueRiley/Clipboard-Copy-Paste/blob/main/x11.c
|
||||
Display *dpy = XOpenDisplay(NULL);
|
||||
if (!dpy) return image;
|
||||
|
||||
Window root = DefaultRootWindow(dpy);
|
||||
Window win = XCreateSimpleWindow(
|
||||
dpy, // The connection to the X Server
|
||||
root, // The 'Parent' window (usually the desktop/root)
|
||||
0, 0, // X and Y position on the screen
|
||||
1, 1, // Width and Height (1x1 pixel)
|
||||
0, // Border width
|
||||
0, // Border color
|
||||
0 // Background color
|
||||
);
|
||||
static Atom clipboard = 0;
|
||||
static Atom targetType = 0;
|
||||
static Atom property = 0;
|
||||
|
||||
Atom clipboard = XInternAtom(dpy, "CLIPBOARD", False);
|
||||
Atom targetType = XInternAtom(dpy, "image/png", False); // Ask for PNG
|
||||
Atom property = XInternAtom(dpy, "RAYLIB_CLIPBOARD_MANAGER", False);
|
||||
Display *display = glfwGetX11Display();
|
||||
XID window = glfwGetX11Window(platform.handle);
|
||||
|
||||
// Request the data: "Convert whatever is in CLIPBOARD to image/png and put it in RAYLIB_CLIPBOARD_MANAGER"
|
||||
XConvertSelection(dpy, clipboard, targetType, property, win, CurrentTime);
|
||||
// Lazy-load X11 atoms
|
||||
if(clipboard == 0)
|
||||
{
|
||||
clipboard = XInternAtom(display, "CLIPBOARD", False);
|
||||
targetType = XInternAtom(display, "image/png", False);
|
||||
property = XInternAtom(display, "RAYLIB_CLIPBOARD_MANAGER", False);
|
||||
}
|
||||
|
||||
XConvertSelection(display, clipboard, targetType, property, window, CurrentTime);
|
||||
XSync(display, 0);
|
||||
|
||||
// Wait for the SelectionNotify event
|
||||
XEvent ev = { 0 };
|
||||
XNextEvent(dpy, &ev);
|
||||
|
||||
// Keep calling until we get SelectionNotify
|
||||
while (XCheckTypedEvent(display, SelectionNotify, &ev) == False);
|
||||
|
||||
Atom actualType = { 0 };
|
||||
int actualFormat = 0;
|
||||
@ -1099,8 +1092,7 @@ Image GetClipboardImage(void)
|
||||
unsigned long bytesAfter = 0;
|
||||
unsigned char *data = NULL;
|
||||
|
||||
// Read the data from our ghost window's property
|
||||
XGetWindowProperty(dpy, win, property, 0, ~0L, False, AnyPropertyType,
|
||||
XGetWindowProperty(display, window, property, 0, ~0L, False, AnyPropertyType,
|
||||
&actualType, &actualFormat, &nitems, &bytesAfter, &data);
|
||||
|
||||
if (data != NULL)
|
||||
@ -1109,8 +1101,6 @@ Image GetClipboardImage(void)
|
||||
XFree(data);
|
||||
}
|
||||
|
||||
XDestroyWindow(dpy, win);
|
||||
XCloseDisplay(dpy);
|
||||
#else
|
||||
TRACELOG(LOG_WARNING, "GetClipboardImage() not implemented on target platform");
|
||||
#endif // _WIN32
|
||||
|
||||
@ -960,7 +960,7 @@ void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color co
|
||||
{
|
||||
// Calculate the maximum angle between segments based on the error rate (usually 0.5f)
|
||||
float th = acosf(2*powf(1 - SMOOTH_CIRCLE_ERROR_RATE/radius, 2) - 1);
|
||||
segments = (int)(ceilf(2*PI/th)/4.0f);
|
||||
segments = (int)(ceilf(2*PI/th)/2.0f);
|
||||
if (segments <= 0) segments = 4;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user