From 37f60e75e72eebd5ff687b8857bf9043d291b0df Mon Sep 17 00:00:00 2001 From: MichaelFiber <42419558+michaelfiber@users.noreply.github.com> Date: Sat, 9 Sep 2023 03:47:07 -0400 Subject: [PATCH 01/11] Remove unneeded #if (#3301) Co-authored-by: MichaelFiber --- src/rcore.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/rcore.c b/src/rcore.c index 2f112aee5..8df087f83 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -265,11 +265,9 @@ #include // Linux: Keycodes constants definition (KEY_A, ...) #include // Linux: Joystick support library -#if defined(PLATFORM_DRM) #include // Generic Buffer Management (native platform for EGL on DRM) #include // Direct Rendering Manager user-level library interface #include // Direct Rendering Manager mode setting (KMS) interface -#endif #include "EGL/egl.h" // Native platform windowing system interface #include "EGL/eglext.h" // EGL extensions From b8cd10264b6d34ff4b09ccdd0b0f7b254cf3b122 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Sat, 9 Sep 2023 11:32:28 -0400 Subject: [PATCH 02/11] Revert "Disable UBSAN in zig builds. (#3292)" (#3303) This reverts commit a316f9e7fc7f8e06852a40544e57f89018672ee4. Issue #1891 was fixed again, so this is no longer needed. --- src/build.zig | 1 - 1 file changed, 1 deletion(-) diff --git a/src/build.zig b/src/build.zig index 09d954bf5..27250f5ff 100644 --- a/src/build.zig +++ b/src/build.zig @@ -6,7 +6,6 @@ pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.built "-std=gnu99", "-D_GNU_SOURCE", "-DGL_SILENCE_DEPRECATION=199309L", - "-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/1891 }; const raylib = b.addStaticLibrary(.{ From 30f8dd6e377ba022a70ebdbac78a10f5b27af0eb Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Mon, 11 Sep 2023 13:00:30 -0400 Subject: [PATCH 03/11] rtextures: Fix ImageDraw() source clipping when drawing beyond top left (#3306) --- src/rtextures.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rtextures.c b/src/rtextures.c index 4e2fdbd91..c86ebac39 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -3481,7 +3481,7 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color // Destination rectangle out-of-bounds security checks if (dstRec.x < 0) { - srcRec.x = -dstRec.x; + srcRec.x -= dstRec.x; srcRec.width += dstRec.x; dstRec.x = 0; } @@ -3489,7 +3489,7 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color if (dstRec.y < 0) { - srcRec.y = -dstRec.y; + srcRec.y -= dstRec.y; srcRec.height += dstRec.y; dstRec.y = 0; } From e75f85ce58ccc73a54ec8116f4890247587727ab Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 11 Sep 2023 19:01:24 +0200 Subject: [PATCH 04/11] REVIEWED: `TextToPascal()` issue when first char is uppercase --- src/rtext.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rtext.c b/src/rtext.c index 146fc68f4..fb8440131 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -1676,6 +1676,7 @@ const char *TextToPascal(const char *text) { // Upper case first character if ((text[0] >= 'a') && (text[0] <= 'z')) buffer[0] = text[0] - 32; + else buffer[0] = text[0]; // Check for next separator to upper case another character for (int i = 1, j = 1; (i < MAX_TEXT_BUFFER_LENGTH - 1) && (text[j] != '\0'); i++, j++) From 9d230d753b5dfb9c4f56b065833ac5ddaf265d8c Mon Sep 17 00:00:00 2001 From: Peter0x44 Date: Mon, 11 Sep 2023 17:03:33 +0000 Subject: [PATCH 05/11] Implement FLAG_WINDOW_RESIZABLE for web (#3305) Fixes #3231 --- src/rcore.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/rcore.c b/src/rcore.c index 8df087f83..beb611040 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -914,9 +914,9 @@ void InitWindow(int width, int height, const char *title) // Check fullscreen change events(note this is done on the window since most browsers don't support this on #canvas) //emscripten_set_fullscreenchange_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenResizeCallback); // Check Resize event (note this is done on the window since most browsers don't support this on #canvas) - //emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenResizeCallback); + emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, NULL, 1, EmscriptenResizeCallback); // Trigger this once to get initial window sizing - //EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL); + EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL); // Support keyboard events -> Not used, GLFW.JS takes care of that //emscripten_set_keypress_callback("#canvas", NULL, 1, EmscriptenKeyboardCallback); @@ -6165,8 +6165,8 @@ static EM_BOOL EmscriptenWindowResizedCallback(int eventType, const EmscriptenUi return 1; // The event was consumed by the callback handler } -EM_JS(int, GetCanvasWidth, (), { return canvas.clientWidth; }); -EM_JS(int, GetCanvasHeight, (), { return canvas.clientHeight; }); +EM_JS(int, GetWindowInnerWidth, (), { return window.innerWidth; }); +EM_JS(int, GetWindowInnerHeight, (), { return window.innerHeight; }); // Register DOM element resize event static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent *event, void *userData) @@ -6176,8 +6176,8 @@ static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent * // This event is called whenever the window changes sizes, // so the size of the canvas object is explicitly retrieved below - int width = GetCanvasWidth(); - int height = GetCanvasHeight(); + int width = GetWindowInnerWidth(); + int height = GetWindowInnerHeight(); emscripten_set_canvas_element_size("#canvas",width,height); SetupViewport(width, height); // Reset viewport and projection matrix for new size From 3ab7f70e3129be963812a9b4133278e8a5e41797 Mon Sep 17 00:00:00 2001 From: Kenta <106167071+Its-Kenta@users.noreply.github.com> Date: Mon, 11 Sep 2023 22:19:43 +0100 Subject: [PATCH 06/11] Update BINDINGS.md (#3307) Fix Kaylib binding. Reroute to a new repository. Binding renamed. --- BINDINGS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BINDINGS.md b/BINDINGS.md index bdd5e2558..c26fa873e 100644 --- a/BINDINGS.md +++ b/BINDINGS.md @@ -37,7 +37,7 @@ Some people ported raylib to other languages in form of bindings or wrappers to | raylib-j | 4.0 | [Java](https://en.wikipedia.org/wiki/Java_(programming_language)) | Zlib | https://github.com/CreedVI/Raylib-J | | raylib.jl | 4.2 | [Julia](https://julialang.org/) | Zlib | https://github.com/irishgreencitrus/raylib.jl | | kaylib | 3.7 | [Kotlin/native](https://kotlinlang.org) | ? | https://github.com/electronstudio/kaylib | -| kaylib | **4.5**| [Kotlin/native](https://kotlinlang.org) | Zlib | https://codeberg.org/Soutaisei/Kaylib | +| KaylibKit | **4.5**| [Kotlin/native](https://kotlinlang.org) | Zlib | https://codeberg.org/Kenta/KaylibKit | | raylib-lua | **4.5** | [Lua](http://www.lua.org/) | ISC | https://github.com/TSnake41/raylib-lua | | raylua | 4.0 | [Lua](http://www.lua.org/) | MIT | https://github.com/Rabios/raylua | | nelua-raylib | 4.0 | [nelua](https://nelua.io/) | MIT | https://github.com/AKDev21/nelua-raylib | From 2e7a7877a51ca33487642bd7ed0367b017b54486 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 12 Sep 2023 15:11:16 +0200 Subject: [PATCH 07/11] Update webassembly.yml --- .github/workflows/webassembly.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/webassembly.yml b/.github/workflows/webassembly.yml index b50cd8c46..9374cb9eb 100644 --- a/.github/workflows/webassembly.yml +++ b/.github/workflows/webassembly.yml @@ -27,7 +27,7 @@ jobs: uses: actions/checkout@master - name: Setup emsdk - uses: mymindstorm/setup-emsdk@v11 + uses: mymindstorm/setup-emsdk@v12 with: version: 3.1.30 actions-cache-folder: 'emsdk-cache' From 2b1849e57d23f3ba53a8ee5200303694f7a3a63a Mon Sep 17 00:00:00 2001 From: bohonghuang <1281299809@qq.com> Date: Wed, 13 Sep 2023 22:35:37 +0800 Subject: [PATCH 08/11] Add claw-raylib to BINDINGS.md (#3310) --- BINDINGS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/BINDINGS.md b/BINDINGS.md index c26fa873e..28e2c542e 100644 --- a/BINDINGS.md +++ b/BINDINGS.md @@ -12,6 +12,7 @@ Some people ported raylib to other languages in form of bindings or wrappers to | Raylib-CsLo | 4.2 | [C#](https://en.wikipedia.org/wiki/C_Sharp_(programming_language)) | MPL-2.0 | https://github.com/NotNotTech/Raylib-CsLo | | cl-raylib | 4.0 | [Common Lisp](https://common-lisp.net/) | MIT | https://github.com/longlene/cl-raylib | | claylib/wrap | **4.5** | [Common Lisp](https://common-lisp.net/) | Zlib | https://github.com/defun-games/claylib | +| claw-raylib | **auto** | [Common Lisp](https://common-lisp.net/) | Apache-2.0 | https://github.com/bohonghuang/claw-raylib | | chez-raylib | **auto** | [Chez Scheme](https://cisco.github.io/ChezScheme/) | GPLv3 | https://github.com/Yunoinsky/chez-raylib | | raylib-cr | **4.6-dev (5e1a81)** | [Crystal](https://crystal-lang.org/) | Apache-2.0 | https://github.com/sol-vin/raylib-cr | | ray-cyber | 4.5 | [Cyber](https://cyberscript.dev) | MIT | https://github.com/fubark/ray-cyber | From 719365f209d046f3fccefce2974b3dcb2e75cc8f Mon Sep 17 00:00:00 2001 From: ubkp <118854183+ubkp@users.noreply.github.com> Date: Wed, 13 Sep 2023 11:37:11 -0300 Subject: [PATCH 09/11] Add SetWindowMaxSize for desktop and web (#3309) * Add SetWindowMaxSize for desktop and web * Remove SizeInt and respective adjustments --- src/raylib.h | 1 + src/rcore.c | 72 +++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 58 insertions(+), 15 deletions(-) diff --git a/src/raylib.h b/src/raylib.h index 4f3e35380..94e79a5f7 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -961,6 +961,7 @@ RLAPI void SetWindowTitle(const char *title); // Set title f RLAPI void SetWindowPosition(int x, int y); // Set window position on screen (only PLATFORM_DESKTOP) RLAPI void SetWindowMonitor(int monitor); // Set monitor for the current window RLAPI void SetWindowMinSize(int width, int height); // Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE) +RLAPI void SetWindowMaxSize(int width, int height); // Set window maximum dimensions (for FLAG_WINDOW_RESIZABLE) RLAPI void SetWindowSize(int width, int height); // Set window dimensions RLAPI void SetWindowOpacity(float opacity); // Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP) RLAPI void SetWindowFocused(void); // Set window focused (only PLATFORM_DESKTOP) diff --git a/src/rcore.c b/src/rcore.c index beb611040..771a8380d 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -395,9 +395,11 @@ typedef struct CoreData { Size currentFbo; // Current render width and height (depends on active fbo) Size render; // Framebuffer width and height (render area, including black bars if required) Point renderOffset; // Offset from render area (must be divided by 2) + Size windowMin; // Window minimum width and height (for resizable window) + Size windowMax; // Window maximum width and height (for resizable window) Matrix screenScale; // Matrix to scale screen (framebuffer rendering) - char **dropFilepaths; // Store dropped files paths pointers (provided by GLFW) + char **dropFilepaths; // Store dropped files paths pointers (provided by GLFW) unsigned int dropFileCount; // Count dropped files strings } Window; @@ -1787,9 +1789,36 @@ void SetWindowMonitor(int monitor) // Set window minimum dimensions (FLAG_WINDOW_RESIZABLE) void SetWindowMinSize(int width, int height) { + CORE.Window.windowMin.width = width; + CORE.Window.windowMin.height = height; #if defined(PLATFORM_DESKTOP) - const GLFWvidmode *mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); - glfwSetWindowSizeLimits(CORE.Window.handle, width, height, mode->width, mode->height); + int minWidth = (CORE.Window.windowMin.width == 0) ? GLFW_DONT_CARE : CORE.Window.windowMin.width; + int minHeight = (CORE.Window.windowMin.height == 0) ? GLFW_DONT_CARE : CORE.Window.windowMin.height; + int maxWidth = (CORE.Window.windowMax.width == 0) ? GLFW_DONT_CARE : CORE.Window.windowMax.width; + int maxHeight = (CORE.Window.windowMax.height == 0) ? GLFW_DONT_CARE : CORE.Window.windowMax.height; + glfwSetWindowSizeLimits(CORE.Window.handle, minWidth, minHeight, maxWidth, maxHeight); +#endif +#if defined(PLATFORM_WEB) + // Trigger the resize event once to update the window minimum width and height + if ((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) != 0) EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL); +#endif +} + +// Set window maximum dimensions (FLAG_WINDOW_RESIZABLE) +void SetWindowMaxSize(int width, int height) +{ + CORE.Window.windowMax.width = width; + CORE.Window.windowMax.height = height; +#if defined(PLATFORM_DESKTOP) + int minWidth = (CORE.Window.windowMin.width == 0) ? GLFW_DONT_CARE : CORE.Window.windowMin.width; + int minHeight = (CORE.Window.windowMin.height == 0) ? GLFW_DONT_CARE : CORE.Window.windowMin.height; + int maxWidth = (CORE.Window.windowMax.width == 0) ? GLFW_DONT_CARE : CORE.Window.windowMax.width; + int maxHeight = (CORE.Window.windowMax.height == 0) ? GLFW_DONT_CARE : CORE.Window.windowMax.height; + glfwSetWindowSizeLimits(CORE.Window.handle, minWidth, minHeight, maxWidth, maxHeight); +#endif +#if defined(PLATFORM_WEB) + // Trigger the resize event once to update the window maximum width and height + if ((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) != 0) EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL); #endif } @@ -3182,7 +3211,7 @@ bool DirectoryExists(const char *dirPath) int GetFileLength(const char *fileName) { int size = 0; - + // NOTE: On Unix-like systems, it can by used the POSIX system call: stat(), // but depending on the platform that call could not be available //struct stat result = { 0 }; @@ -3195,11 +3224,11 @@ int GetFileLength(const char *fileName) { fseek(file, 0L, SEEK_END); long int fileSize = ftell(file); - + // Check for size overflow (INT_MAX) if (fileSize > 2147483647) TRACELOG(LOG_WARNING, "[%s] File size overflows expected limit, do not use GetFileLength()", fileName); else size = (int)fileSize; - + fclose(file); } @@ -3765,12 +3794,12 @@ bool IsKeyPressed(int key) bool IsKeyPressedRepeat(int key) { bool repeat = false; - + if ((key > 0) && (key < MAX_KEYBOARD_KEYS)) { if (CORE.Input.Keyboard.keyRepeatInFrame[key] == 1) repeat = true; } - + return repeat; } @@ -3778,12 +3807,12 @@ bool IsKeyPressedRepeat(int key) bool IsKeyDown(int key) { bool down = false; - + if ((key > 0) && (key < MAX_KEYBOARD_KEYS)) { if (CORE.Input.Keyboard.currentKeyState[key] == 1) down = true; } - + return down; } @@ -3791,7 +3820,7 @@ bool IsKeyDown(int key) bool IsKeyReleased(int key) { bool released = false; - + if ((key > 0) && (key < MAX_KEYBOARD_KEYS)) { if ((CORE.Input.Keyboard.previousKeyState[key] == 1) && (CORE.Input.Keyboard.currentKeyState[key] == 0)) released = true; @@ -3804,12 +3833,12 @@ bool IsKeyReleased(int key) bool IsKeyUp(int key) { bool up = false; - + if ((key > 0) && (key < MAX_KEYBOARD_KEYS)) { if (CORE.Input.Keyboard.currentKeyState[key] == 0) up = true; } - + return up; } @@ -3887,7 +3916,7 @@ const char *GetGamepadName(int gamepad) if (CORE.Input.Gamepad.ready[gamepad]) name = glfwGetJoystickName(gamepad); #endif #if defined(PLATFORM_DRM) - if (CORE.Input.Gamepad.ready[gamepad]) + if (CORE.Input.Gamepad.ready[gamepad]) { ioctl(CORE.Input.Gamepad.streamId[gamepad], JSIOCGNAME(64), &CORE.Input.Gamepad.name[gamepad]); name = CORE.Input.Gamepad.name[gamepad]; @@ -4061,7 +4090,7 @@ int GetMouseY(void) Vector2 GetMousePosition(void) { Vector2 position = { 0 }; - + // TODO: Review touch position on PLATFORM_WEB #if defined(PLATFORM_ANDROID) //|| defined(PLATFORM_WEB) @@ -4220,6 +4249,12 @@ static bool InitGraphicsDevice(int width, int height) CORE.Window.screen.height = height; // User desired height CORE.Window.screenScale = MatrixIdentity(); // No draw scaling required by default + // Set the window minimum and maximum default values to 0 + CORE.Window.windowMin.width = 0; + CORE.Window.windowMin.height = 0; + CORE.Window.windowMax.width = 0; + CORE.Window.windowMax.height = 0; + // NOTE: Framebuffer (render area - CORE.Window.render.width, CORE.Window.render.height) could include black bars... // ...in top-down or left-right to match display aspect ratio (no weird scaling) @@ -6178,6 +6213,13 @@ static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent * // so the size of the canvas object is explicitly retrieved below int width = GetWindowInnerWidth(); int height = GetWindowInnerHeight(); + + if (width < CORE.Window.windowMin.width) width = CORE.Window.windowMin.width; + else if (width > CORE.Window.windowMax.width && CORE.Window.windowMax.width > 0) width = CORE.Window.windowMax.width; + + if (height < CORE.Window.windowMin.height) height = CORE.Window.windowMin.height; + else if (height > CORE.Window.windowMax.height && CORE.Window.windowMax.height > 0) height = CORE.Window.windowMax.height; + emscripten_set_canvas_element_size("#canvas",width,height); SetupViewport(width, height); // Reset viewport and projection matrix for new size From 528b8799550f8a9d759ef5db8c86d19923a79794 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 13 Sep 2023 17:05:22 +0200 Subject: [PATCH 10/11] Update rtextures.c --- src/rtextures.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rtextures.c b/src/rtextures.c index c86ebac39..a6741ee2a 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -322,9 +322,10 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int Image LoadImageSvg(const char *fileNameOrString, int width, int height) { Image image = { 0 }; + +#if defined(SUPPORT_FILEFORMAT_SVG) bool isSvgStringValid = false; -#if defined(SUPPORT_FILEFORMAT_SVG) // Validate fileName or string if (fileNameOrString != NULL) { From 97ef81914ce5fe34b79e263814b65292a31edf42 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 13 Sep 2023 17:05:38 +0200 Subject: [PATCH 11/11] Reviewed parameters for consistency --- src/raylib.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/raylib.h b/src/raylib.h index 94e79a5f7..07b64aeb6 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -918,8 +918,8 @@ typedef enum { // Callbacks to hook some internal functions // WARNING: These callbacks are intended for advance users typedef void (*TraceLogCallback)(int logLevel, const char *text, va_list args); // Logging: Redirect trace log messages -typedef unsigned char *(*LoadFileDataCallback)(const char *fileName, unsigned int *bytesRead); // FileIO: Load binary data -typedef bool (*SaveFileDataCallback)(const char *fileName, void *data, unsigned int bytesToWrite); // FileIO: Save binary data +typedef unsigned char *(*LoadFileDataCallback)(const char *fileName, int *dataSize); // FileIO: Load binary data +typedef bool (*SaveFileDataCallback)(const char *fileName, void *data, int dataSize); // FileIO: Save binary data typedef char *(*LoadFileTextCallback)(const char *fileName); // FileIO: Load text data typedef bool (*SaveFileTextCallback)(const char *fileName, char *text); // FileIO: Save text data