From 7bb36286a6d7e35af445dbe2c7319e27f9563b6a Mon Sep 17 00:00:00 2001 From: Antonis Geralis Date: Sun, 16 Jun 2024 16:50:26 +0300 Subject: [PATCH] update upstream --- src/raylib/CMakeLists.txt | 2 +- src/raylib/Makefile | 4 +- src/raylib/build.zig | 2 + src/raylib/external/RGFW.h | 872 ++++++++++++++-------- src/raylib/external/jar_xm.h | 60 +- src/raylib/platforms/rcore_android.c | 10 +- src/raylib/platforms/rcore_desktop.c | 2 +- src/raylib/platforms/rcore_desktop_rgfw.c | 8 +- src/raylib/platforms/rcore_desktop_sdl.c | 2 +- src/raylib/platforms/rcore_drm.c | 4 +- src/raylib/platforms/rcore_template.c | 2 +- src/raylib/platforms/rcore_web.c | 2 +- src/raylib/raudio.c | 8 +- src/raylib/raylib.h | 100 +-- src/raylib/rcore.c | 14 +- src/raylib/rlgl.h | 4 +- src/raylib/rmodels.c | 28 +- src/raylib/rshapes.c | 117 +-- src/raylib/rtext.c | 69 +- src/raylib/rtextures.c | 58 +- update_bindings.nims | 2 +- 21 files changed, 806 insertions(+), 564 deletions(-) diff --git a/src/raylib/CMakeLists.txt b/src/raylib/CMakeLists.txt index 3876657..bfb4b05 100644 --- a/src/raylib/CMakeLists.txt +++ b/src/raylib/CMakeLists.txt @@ -69,7 +69,7 @@ else() endif() if (${PLATFORM} MATCHES "Web") - target_link_options(raylib PRIVATE "-sUSE_GLFW=3") + target_link_options(raylib PUBLIC "-sUSE_GLFW=3") endif() set_target_properties(raylib PROPERTIES diff --git a/src/raylib/Makefile b/src/raylib/Makefile index 2374256..19251b9 100644 --- a/src/raylib/Makefile +++ b/src/raylib/Makefile @@ -316,7 +316,7 @@ endif # -D_GNU_SOURCE access to lots of nonstandard GNU/Linux extension functions # -Werror=pointer-arith catch unportable code that does direct arithmetic on void pointers # -fno-strict-aliasing jar_xm.h does shady stuff (breaks strict aliasing) -CFLAGS = -Wall -D_GNU_SOURCE -D$(PLATFORM) -D$(GRAPHICS) -Wno-missing-braces -Werror=pointer-arith -fno-strict-aliasing $(CUSTOM_CFLAGS) +CFLAGS = -Wall -D_GNU_SOURCE -D$(PLATFORM) -D$(GRAPHICS) -Wno-missing-braces -Werror=pointer-arith -fno-strict-aliasing ifneq ($(RAYLIB_CONFIG_FLAGS), NONE) CFLAGS += -DEXTERNAL_CONFIG_FLAGS $(RAYLIB_CONFIG_FLAGS) @@ -449,6 +449,8 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) endif endif +CFLAGS += $(CUSTOM_CFLAGS) + # Define include paths for required headers: INCLUDE_PATHS # NOTE: Several external required libraries (stb and others) #------------------------------------------------------------------------------------------------ diff --git a/src/raylib/build.zig b/src/raylib/build.zig index 51a8ab7..81d4a76 100644 --- a/src/raylib/build.zig +++ b/src/raylib/build.zig @@ -22,6 +22,7 @@ pub fn addRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. .platform_drm = options.platform_drm, .shared = options.shared, .linux_display_backend = options.linux_display_backend, + .opengl_version = options.opengl_version, }); const raylib = raylib_dep.artifact("raylib"); @@ -216,6 +217,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. }, } + raylib.addIncludePath(b.path("src")); raylib.root_module.addCSourceFiles(.{ .root = b.path("src"), .files = c_source_files.items, diff --git a/src/raylib/external/RGFW.h b/src/raylib/external/RGFW.h index 67c67e9..a0ca21c 100644 --- a/src/raylib/external/RGFW.h +++ b/src/raylib/external/RGFW.h @@ -34,7 +34,9 @@ #define RGFW_BUFFER - (optional) just draw directly to (RGFW) window pixel buffer that is drawn to screen (the buffer is in the RGBA format) #define RGFW_EGL - (optional) use EGL for loading an OpenGL context (instead of the system's opengl api) #define RGFW_OPENGL_ES1 - (optional) use EGL to load and use Opengl ES (version 1) for backend rendering (instead of the system's opengl api) + This version doesn't work for desktops (I'm pretty sure) #define RGFW_OPENGL_ES2 - (optional) use OpenGL ES (version 2) + #define RGFW_OPENGL_ES3 - (optional) use OpenGL ES (version 3) #define RGFW_VULKAN - (optional) use vulkan for the rendering backend (rather than opengl) #define RGFW_DIRECTX - (optional) use directX for the rendering backend (rather than opengl) (windows only, defaults to opengl for unix) #define RGFW_NO_API - (optional) don't use any rendering API (no opengl, no vulkan, no directX) @@ -90,12 +92,16 @@ #ifndef RGFWDEF #ifdef __APPLE__ -#define RGFWDEF extern inline +#define RGFWDEF static inline #else #define RGFWDEF inline #endif #endif +#ifndef RGFW_UNUSED +#define RGFW_UNUSED(x) if (x){} +#endif + #ifdef __cplusplus extern "C" { #endif @@ -106,7 +112,7 @@ extern "C" { #define RGFW_HEADER #if !defined(u8) -#include + #include typedef uint8_t u8; typedef int8_t i8; @@ -130,12 +136,16 @@ extern "C" { #define RGFW_WINDOWS -#if defined(_WIN32) +#if defined(_WIN32) && !defined(WIN32) #define WIN32 #endif #if defined(_WIN64) + +#ifndef WIN64 #define WIN64 +#endif + #define _AMD64_ #undef _X86_ #else @@ -163,7 +173,7 @@ extern "C" { #define RGFW_MACOS #endif -#if (defined(RGFW_OPENGL_ES1) || defined(RGFW_OPENGL_ES2)) && !defined(RGFW_EGL) +#if (defined(RGFW_OPENGL_ES1) || defined(RGFW_OPENGL_ES2) || defined(RGFW_OPENGL_ES3)) && !defined(RGFW_EGL) #define RGFW_EGL #endif #if defined(RGFW_EGL) && defined(__APPLE__) @@ -193,7 +203,7 @@ extern "C" { #include #endif -#if defined(RGFW_X11) && defined(RGFW_OPENGL) +#if defined(RGFW_X11) && (defined(RGFW_OPENGL)) #ifndef GLX_MESA_swap_control #define GLX_MESA_swap_control #endif @@ -384,10 +394,10 @@ typedef struct { i32 x, y; } RGFW_vector; RGFW_vector point; /*!< mouse x, y of event (or drop point) */ u32 keyCode; /*!< keycode of event !!Keycodes defined at the bottom of the header file!! */ - u32 inFocus; /*if the window is in focus or not*/ - u32 fps; /*the current fps of the window [the fps is checked when events are checked]*/ - u32 current_ticks, frames; /* this is used for counting the fps */ + u64 frameTime, frameTime2; /* this is used for counting the fps */ + + u8 inFocus; /*if the window is in focus or not*/ u8 lockState; @@ -416,9 +426,10 @@ typedef struct { i32 x, y; } RGFW_vector; u32 display; void* displayLink; void* window; + u8 dndPassed; #endif -#if defined(RGFW_OPENGL) && !defined(RGFW_OSMESA) +#if (defined(RGFW_OPENGL)) && !defined(RGFW_OSMESA) #ifdef RGFW_MACOS void* rSurf; /*!< source graphics context */ #endif @@ -460,6 +471,7 @@ typedef struct { i32 x, y; } RGFW_vector; #ifdef RGFW_EGL EGLSurface EGL_surface; EGLDisplay EGL_display; + EGLContext EGL_context; #endif #if defined(RGFW_OSMESA) || defined(RGFW_BUFFER) @@ -508,7 +520,7 @@ typedef struct { i32 x, y; } RGFW_vector; RGFW_rect r; /* the x, y, w and h of the struct */ - u8 fpsCap; /*!< the fps cap of the window should run at (change this var to change the fps cap, 0 = no limit)*/ + u32 fpsCap; /*!< the fps cap of the window should run at (change this var to change the fps cap, 0 = no limit)*/ /*[the fps is capped when events are checked]*/ } RGFW_window; /*!< Window structure for managing the window */ @@ -627,7 +639,6 @@ typedef struct { i32 x, y; } RGFW_vector; this is run by default if the user uses the arg `RGFW_SCALE_TO_MONITOR` during window creation */ RGFWDEF void RGFW_window_scaleToMonitor(RGFW_window* win); - /* get the struct of the window's monitor */ RGFWDEF RGFW_monitor RGFW_window_getMonitor(RGFW_window* win); @@ -635,11 +646,16 @@ typedef struct { i32 x, y; } RGFW_vector; RGFWDEF void RGFW_window_makeCurrent(RGFW_window* win); /*error handling*/ - RGFWDEF u8 RGFW_Error(); /* returns true if an error has occurred (doesn't print errors itself) */ + RGFWDEF u8 RGFW_Error(void); /* returns true if an error has occurred (doesn't print errors itself) */ /*!< if window == NULL, it checks if the key is pressed globally. Otherwise, it checks only if the key is pressed while the window in focus.*/ RGFWDEF u8 RGFW_isPressedI(RGFW_window* win, u32 key); /*!< if key is pressed (key code)*/ + RGFWDEF u8 RGFW_wasPressedI(RGFW_window* win, u32 key); /*!< if key was pressed (checks prev keymap only) (key code)*/ + + RGFWDEF u8 RGFW_isHeldI(RGFW_window* win, u32 key); /*!< if key is held (key code)*/ + RGFWDEF u8 RGFW_isReleasedI(RGFW_window* win, u32 key); /*!< if key is released (key code)*/ + /* !!Keycodes defined at the bottom of the header file!! */ @@ -676,7 +692,14 @@ typedef struct { i32 x, y; } RGFW_vector; if you're going to use sili which is a good idea generally */ - RGFWDEF RGFW_thread RGFW_createThread(void* (*function_ptr)(void*), void* args); /*!< create a thread*/ + + #if defined(__unix__) || defined(__APPLE__) + typedef void* (* RGFW_threadFunc_ptr)(void*); + #else + typedef DWORD (* RGFW_threadFunc_ptr)(void*); + #endif + + RGFWDEF RGFW_thread RGFW_createThread(RGFW_threadFunc_ptr ptr, void* args); /*!< create a thread*/ RGFWDEF void RGFW_cancelThread(RGFW_thread thread); /*!< cancels a thread*/ RGFWDEF void RGFW_joinThread(RGFW_thread thread); /*!< join thread to current thread */ RGFWDEF void RGFW_setThreadPriority(RGFW_thread thread, u8 priority); /*!< sets the priority priority */ @@ -694,7 +717,7 @@ typedef struct { i32 x, y; } RGFW_vector; /*! native opengl functions */ #ifdef RGFW_OPENGL /*! Get max OpenGL version */ - RGFWDEF u8* RGFW_getMaxGLVersion(); + RGFWDEF u8* RGFW_getMaxGLVersion(void); /* OpenGL init hints */ RGFWDEF void RGFW_setGLStencil(i32 stencil); /* set stencil buffer bit size (8 by default) */ RGFWDEF void RGFW_setGLSamples(i32 samples); /* set number of sampiling buffers (4 by default) */ @@ -754,8 +777,8 @@ typedef struct { i32 x, y; } RGFW_vector; RGFWDEF void RGFW_createSurface(VkInstance instance, RGFW_window* win); int RGFW_deviceInitialization(RGFW_window* win); int RGFW_createSwapchain(RGFW_window* win); - RGFWDEF int RGFW_createRenderPass(); - int RGFW_createCommandPool(); + RGFWDEF int RGFW_createRenderPass(void); + int RGFW_createCommandPool(void); int RGFW_createCommandBuffers(RGFW_window* win); int RGFW_createSyncObjects(RGFW_window* win); RGFWDEF int RGFW_createFramebuffers(RGFW_window* win); @@ -780,8 +803,7 @@ typedef struct { i32 x, y; } RGFW_vector; RGFWDEF void RGFW_window_checkFPS(RGFW_window* win); /*!< updates fps / sets fps to cap (ran by RGFW_window_checkEvent)*/ RGFWDEF u64 RGFW_getTime(void); /* get time in seconds */ RGFWDEF u64 RGFW_getTimeNS(void); /* get time in nanoseconds */ - RGFWDEF u32 RGFW_getFPS(void); /* get current FPS (win->event.fps) */ - RGFWDEF void RGFW_sleep(u32 microsecond); /* sleep for a set time */ + RGFWDEF void RGFW_sleep(u64 microsecond); /* sleep for a set time */ #endif /* RGFW_HEADER */ /* @@ -859,20 +881,19 @@ typedef struct { i32 x, y; } RGFW_vector; #ifdef RGFW_WINDOWS -#define WIN32_LEAN_AND_MEAN - #include #endif #ifdef RGFW_MACOS -#include - /* based on silicon.h */ +#ifndef GL_SILENCE_DEPRECATION #define GL_SILENCE_DEPRECATION +#endif + #include #include #include @@ -914,7 +935,7 @@ typedef struct { i32 x, y; } RGFW_vector; #define abi_objc_msgSend_fpret objc_msgSend_fpret #endif -#define NSAlloc(nsclass) objc_msgSend_id(nsclass, sel_registerName("alloc")) +#define NSAlloc(nsclass) objc_msgSend_id((id)nsclass, sel_registerName("alloc")) #define objc_msgSend_bool ((BOOL (*)(id, SEL))objc_msgSend) #define objc_msgSend_void ((void (*)(id, SEL))objc_msgSend) #define objc_msgSend_void_id ((void (*)(id, SEL, id))objc_msgSend) @@ -948,7 +969,7 @@ typedef struct { i32 x, y; } RGFW_vector; loadFunc("stringWithUTF8String:"); return ((id(*)(id, SEL, const char*))objc_msgSend) - (objc_getClass("NSString"), func, str); + ((id)objc_getClass("NSString"), func, str); } const char* NSString_to_char(NSString* str) { @@ -1053,7 +1074,7 @@ typedef struct { i32 x, y; } RGFW_vector; void* func = sel_registerName("initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:"); return (NSBitmapImageRep*) ((id(*)(id, SEL, unsigned char**, NSInteger, NSInteger, NSInteger, NSInteger, bool, bool, const char*, NSBitmapFormat, NSInteger, NSInteger))objc_msgSend) - (NSAlloc(objc_getClass("NSBitmapImageRep")), func, planes, width, height, bps, spp, alpha, isPlanar, NSString_stringWithUTF8String(colorSpaceName), bitmapFormat, rowBytes, pixelBits); + (NSAlloc((id)objc_getClass("NSBitmapImageRep")), func, planes, width, height, bps, spp, alpha, isPlanar, NSString_stringWithUTF8String(colorSpaceName), bitmapFormat, rowBytes, pixelBits); } NSColor* NSColor_colorWithSRGB(CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha) { @@ -1079,7 +1100,7 @@ typedef struct { i32 x, y; } RGFW_vector; NSImage* NSImage_initWithSize(NSSize size) { void* func = sel_registerName("initWithSize:"); return ((id(*)(id, SEL, NSSize))objc_msgSend) - (NSAlloc(objc_getClass("NSImage")), func, size); + (NSAlloc((id)objc_getClass("NSImage")), func, size); } #define NS_OPENGL_ENUM_DEPRECATED(minVers, maxVers) API_AVAILABLE(macos(minVers)) typedef NS_ENUM(NSInteger, NSOpenGLContextParameter) { @@ -1111,13 +1132,13 @@ typedef struct { i32 x, y; } RGFW_vector; void* NSOpenGLPixelFormat_initWithAttributes(const uint32_t* attribs) { void* func = sel_registerName("initWithAttributes:"); return (void*) ((id(*)(id, SEL, const uint32_t*))objc_msgSend) - (NSAlloc(objc_getClass("NSOpenGLPixelFormat")), func, attribs); + (NSAlloc((id)objc_getClass("NSOpenGLPixelFormat")), func, attribs); } NSOpenGLView* NSOpenGLView_initWithFrame(NSRect frameRect, uint32_t* format) { void* func = sel_registerName("initWithFrame:pixelFormat:"); return (NSOpenGLView*) ((id(*)(id, SEL, NSRect, uint32_t*))objc_msgSend) - (NSAlloc(objc_getClass("NSOpenGLView")), func, frameRect, format); + (NSAlloc((id)objc_getClass("NSOpenGLView")), func, frameRect, format); } void NSCursor_performSelector(NSCursor* cursor, void* selector) { @@ -1126,7 +1147,7 @@ typedef struct { i32 x, y; } RGFW_vector; } NSPasteboard* NSPasteboard_generalPasteboard(void) { - return (NSPasteboard*) objc_msgSend_id(objc_getClass("NSPasteboard"), sel_registerName("generalPasteboard")); + return (NSPasteboard*) objc_msgSend_id((id)objc_getClass("NSPasteboard"), sel_registerName("generalPasteboard")); } NSString** cstrToNSStringArray(char** strs, size_t len) { @@ -1144,27 +1165,22 @@ typedef struct { i32 x, y; } RGFW_vector; } NSArray* c_array_to_NSArray(void* array, size_t len) { - void* func = sel_registerName("initWithObjects:count:"); + SEL func = sel_registerName("initWithObjects:count:"); void* nsclass = objc_getClass("NSArray"); - - return ((id(*)(id, SEL, void*, NSUInteger))objc_msgSend) - (NSAlloc(nsclass), func, array, len); + return ((id (*)(id, SEL, void*, NSUInteger))objc_msgSend) + (NSAlloc(nsclass), func, array, len); } - + void NSregisterForDraggedTypes(void* view, NSPasteboardType* newTypes, size_t len) { - NSString** ntypes = cstrToNSStringArray(newTypes, len); - - void* func = sel_registerName("registerForDraggedTypes:"); + NSString** ntypes = cstrToNSStringArray((char**)newTypes, len); NSArray* array = c_array_to_NSArray(ntypes, len); - objc_msgSend_void_id(view, sel_registerName("registerForDraggedTypes:"), array); - NSRelease(array); } NSInteger NSPasteBoard_declareTypes(NSPasteboard* pasteboard, NSPasteboardType* newTypes, size_t len, void* owner) { - NSString** ntypes = cstrToNSStringArray(newTypes, len); + NSString** ntypes = cstrToNSStringArray((char**)newTypes, len); void* func = sel_registerName("declareTypes:owner:"); @@ -1252,13 +1268,17 @@ typedef struct { i32 x, y; } RGFW_vector; (pasteboard, func, array, options); NSRelease(array); - NSUInteger count = NSArray_count(output); const char** res = si_array_init_reserve(sizeof(const char*), count); - for (NSUInteger i = 0; i < count; i++) - res[i] = NSString_to_char(NSArray_objectAtIndex(output, i)); + void* path_func = sel_registerName("path"); + + for (NSUInteger i = 0; i < count; i++) { + void* url = NSArray_objectAtIndex(output, i); + NSString* url_str = ((id(*)(id, SEL))objc_msgSend)(url, path_func); + res[i] = NSString_to_char(url_str); + } return res; } @@ -1301,12 +1321,20 @@ typedef struct { i32 x, y; } RGFW_vector; } #endif + #ifdef RGFW_WINDOWS + __declspec(dllimport) u32 __stdcall timeBeginPeriod(u32 uPeriod); + #endif + RGFWDEF RGFW_window* RGFW_window_basic_init(RGFW_rect rect, u16 args); RGFWDEF void RGFW_init_buffer(RGFW_window* win); RGFW_window* RGFW_window_basic_init(RGFW_rect rect, u16 args) { RGFW_window* win = (RGFW_window*) RGFW_MALLOC(sizeof(RGFW_window)); /* make a new RGFW struct */ + #ifdef RGFW_WINDOWS + timeBeginPeriod(1); + #endif + #ifdef RGFW_ALLOC_DROPFILES win->event.droppedFiles = (char**) RGFW_MALLOC(sizeof(char*) * RGFW_MAX_DROPS); u32 i; @@ -1406,6 +1434,8 @@ typedef struct { i32 x, y; } RGFW_vector; win->src.hdcMem = CreateCompatibleDC(win->src.hdc); #endif +#else +RGFW_UNUSED(win); /* if buffer rendering is not being used */ #endif } @@ -1827,9 +1857,18 @@ typedef struct { i32 x, y; } RGFW_vector; #endif #if defined(RGFW_MACOS) - u8 RGFW_keyMap[128] = { 0 }; + u8 RGFW_keyBoard[128] = { 0 }; + u8 RGFW_keyBoard_prev[128]; #endif + u8 RGFW_isHeldI(RGFW_window* win, u32 key) { + return (RGFW_isPressedI(win, key) && RGFW_wasPressedI(win, key)); + } + + u8 RGFW_isReleasedI(RGFW_window* win, u32 key) { + return (!RGFW_isPressedI(win, key) && RGFW_wasPressedI(win, key)); + } + char* RGFW_keyCodeTokeyStr(u64 key) { #if defined(RGFW_MACOS) static char* keyStrs[128] = { "a", "s", "d", "f", "h", "g", "z", "x", "c", "v", "0", "b", "q", "w", "e", "r", "y", "t", "1", "2", "3", "4", "6", "5", "Equals", "9", "7", "Minus", "8", "0", "CloseBracket", "o", "u", "Bracket", "i", "p", "Return", "l", "j", "Apostrophe", "k", "Semicolon", "BackSlash", "Comma", "Slash", "n", "m", "Period", "Tab", "Space", "Backtick", "BackSpace", "0", "Escape", "0", "Super", "Shift", "CapsLock", "Alt", "Control", "0", "0", "0", "0", "0", "KP_Period", "0", "KP_Minus", "0", "0", "0", "0", "Numlock", "0", "0", "0", "KP_Multiply", "KP_Return", "0", "0", "0", "0", "KP_Slash", "KP_0", "KP_1", "KP_2", "KP_3", "KP_4", "KP_5", "KP_6", "KP_7", "0", "KP_8", "KP_9", "0", "0", "0", "F5", "F6", "F7", "F3", "F8", "F9", "0", "F11", "0", "F13", "0", "F14", "0", "F10", "0", "F12", "0", "F15", "Insert", "Home", "PageUp", "Delete", "F4", "End", "F2", "PageDown", "Left", "Right", "Down", "Up", "F1" }; @@ -1998,12 +2037,14 @@ typedef struct { i32 x, y; } RGFW_vector; u32 RGFW_isPressedJS(RGFW_window* win, u16 c, u8 button) { return win->src.jsPressed[c][button]; } #else - typedef DWORD (WINAPI * PFN_XInputGetState)(DWORD,XINPUT_STATE*); + typedef u64 (WINAPI * PFN_XInputGetState)(DWORD,XINPUT_STATE*); PFN_XInputGetState XInputGetStateSRC = NULL; #define XInputGetState XInputGetStateSRC static HMODULE RGFW_XInput_dll = NULL; u32 RGFW_isPressedJS(RGFW_window* win, u16 c, u8 button) { + RGFW_UNUSED(win) + XINPUT_STATE state; if (XInputGetState == NULL || XInputGetState(c, &state) == ERROR_DEVICE_NOT_CONNECTED) return 0; @@ -2027,9 +2068,15 @@ typedef struct { i32 x, y; } RGFW_vector; } #endif -#ifdef RGFW_OPENGL +#if defined(RGFW_OPENGL) || defined(RGFW_EGL) i32 RGFW_majorVersion = 0, RGFW_minorVersion = 0; + + #ifndef RGFW_EGL i32 RGFW_STENCIL = 8, RGFW_SAMPLES = 4, RGFW_STEREO = GL_FALSE, RGFW_AUX_BUFFERS = 0; + #else + i32 RGFW_STENCIL = 0, RGFW_SAMPLES = 0, RGFW_STEREO = GL_FALSE, RGFW_AUX_BUFFERS = 0; + #endif + void RGFW_setGLStencil(i32 stencil) { RGFW_STENCIL = stencil; } void RGFW_setGLSamples(i32 samples) { RGFW_SAMPLES = samples; } @@ -2041,7 +2088,7 @@ typedef struct { i32 x, y; } RGFW_vector; RGFW_minorVersion = minor; } - u8* RGFW_getMaxGLVersion() { + u8* RGFW_getMaxGLVersion(void) { RGFW_window* dummy = RGFW_createWindow("dummy", RGFW_RECT(0, 0, 1, 1), 0); const char* versionStr = (const char*) glGetString(GL_VERSION); @@ -2055,6 +2102,8 @@ typedef struct { i32 x, y; } RGFW_vector; return version; } +#ifndef RGFW_EGL + #define RGFW_GL_RENDER_TYPE RGFW_OS_BASED_VALUE(GLX_X_VISUAL_TYPE, 0x2003, 73) #define RGFW_GL_ALPHA_SIZE RGFW_OS_BASED_VALUE(GLX_ALPHA_SIZE, 0x201b, 11) #define RGFW_GL_DEPTH_SIZE RGFW_OS_BASED_VALUE(GLX_DEPTH_SIZE, 0x2022, 12) @@ -2087,6 +2136,7 @@ typedef struct { i32 x, y; } RGFW_vector; #endif static u32* RGFW_initAttribs(u32 useSoftware) { + RGFW_UNUSED(useSoftware); static u32 attribs[] = { #ifndef RGFW_MACOS RGFW_GL_RENDER_TYPE, @@ -2165,9 +2215,9 @@ typedef struct { i32 x, y; } RGFW_vector; return attribs; } -#endif +#else -#ifdef RGFW_EGL +#include #if defined(RGFW_LINK_EGL) typedef EGLBoolean(EGLAPIENTRY* PFN_eglInitialize)(EGLDisplay, EGLint*, EGLint*); @@ -2202,8 +2252,8 @@ typedef struct { i32 x, y; } RGFW_vector; #endif -#define EGL_CONTEXT_MAJOR_VERSION_KHR 0x3098 -#define EGL_CONTEXT_MINOR_VERSION_KHR 0x30fb +#define EGL_SURFACE_MAJOR_VERSION_KHR 0x3098 +#define EGL_SURFACE_MINOR_VERSION_KHR 0x30fb #ifndef RGFW_GL_ADD_ATTRIB #define RGFW_GL_ADD_ATTRIB(attrib, attVal) \ @@ -2214,9 +2264,8 @@ typedef struct { i32 x, y; } RGFW_vector; } #endif - void RGFW_createOpenGLContext(RGFW_window* win) { - static EGLContext globalCtx = EGL_NO_CONTEXT; + void RGFW_createOpenGLContext(RGFW_window* win) { #if defined(RGFW_LINK_EGL) eglInitializeSource = (PFNEGLINITIALIZEPROC) eglGetProcAddress("eglInitialize"); eglGetConfigsSource = (PFNEGLGETCONFIGSPROC) eglGetProcAddress("eglGetConfigs"); @@ -2233,69 +2282,101 @@ typedef struct { i32 x, y; } RGFW_vector; eglDestroySurfaceSource = (PFNEGLDESTROYSURFACEPROC) eglGetProcAddress("eglDestroySurface"); #endif /* RGFW_LINK_EGL */ + #ifdef RGFW_WINDOWS + win->src.EGL_display = eglGetDisplay((EGLNativeDisplayType) win->src.hdc); + #else win->src.EGL_display = eglGetDisplay((EGLNativeDisplayType) win->src.display); + #endif EGLint major, minor; eglInitialize(win->src.EGL_display, &major, &minor); - EGLint config_attribs[] = { + #ifndef EGL_OPENGL_ES1_BIT + #define EGL_OPENGL_ES1_BIT 0x1 + #endif + + EGLint egl_config[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, #ifdef RGFW_OPENGL_ES1 EGL_OPENGL_ES1_BIT, - #endif - #ifdef RGFW_OPENGL_ES2 + #elif defined(RGFW_OPENGL_ES3) + EGL_OPENGL_ES3_BIT, + #elif defined(RGFW_OPENGL_ES2) EGL_OPENGL_ES2_BIT, #else EGL_OPENGL_BIT, #endif - EGL_NONE + EGL_NONE, EGL_NONE }; EGLConfig config; - EGLint num_configs; - eglChooseConfig(win->src.EGL_display, config_attribs, &config, 1, &num_configs); + EGLint numConfigs; + eglChooseConfig(win->src.EGL_display, egl_config, &config, 1, &numConfigs); -#if defined(RGFW_OPENGL_ES2) || defined(RGFW_OPENGL_ES1) - eglBindAPI(EGL_OPENGL_ES_API); -#else - eglBindAPI(EGL_OPENGL_API); -#endif - EGLint attribs[]{ - EGL_CONTEXT_OPENGL_PROFILE_MASK, EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT, - 0, 0, 0, 0 + win->src.EGL_surface = eglCreateWindowSurface(win->src.EGL_display, config, (EGLNativeWindowType) win->src.window, NULL); + + EGLint attribs[] = { + EGL_CONTEXT_CLIENT_VERSION, + #ifdef RGFW_OPENGL_ES1 + 1, + #else + 2, + #endif + EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE, EGL_NONE }; - size_t index = 2; + size_t index = 4; RGFW_GL_ADD_ATTRIB(EGL_STENCIL_SIZE, RGFW_STENCIL); RGFW_GL_ADD_ATTRIB(EGL_SAMPLES, RGFW_SAMPLES); - RGFW_GL_ADD_ATTRIB(EGL_CONTEXT_MAJOR_VERSION, RGFW_majorVersion); - RGFW_GL_ADD_ATTRIB(EGL_CONTEXT_MINOR_VERSION, RGFW_minorVersion); - win->src.rSurf = eglCreateContext(win->src.EGL_display, config, globalCtx, attribs); - win->src.EGL_surface = eglCreateWindowSurface(win->src.EGL_display, config, (EGLNativeWindowType) win->src.window, NULL); + if (RGFW_majorVersion) { + attribs[1] = RGFW_majorVersion; + RGFW_GL_ADD_ATTRIB(EGL_CONTEXT_OPENGL_PROFILE_MASK, EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT); + RGFW_GL_ADD_ATTRIB(EGL_CONTEXT_MAJOR_VERSION, RGFW_majorVersion); + RGFW_GL_ADD_ATTRIB(EGL_CONTEXT_MINOR_VERSION, RGFW_minorVersion); + } - if (globalCtx == EGL_NO_CONTEXT) - RGFW_EGLglobalContext = win->src.rSurf; + #if defined(RGFW_OPENGL_ES1) || defined(RGFW_OPENGL_ES2) || defined(RGFW_OPENGL_ES3) + eglBindAPI(EGL_OPENGL_ES_API); + #else + eglBindAPI(EGL_OPENGL_API); + #endif - eglMakeCurrent(win->src.EGL_display, win->src.EGL_surface, win->src.EGL_surface, win->src.rSurf); - eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface); + win->src.EGL_context = eglCreateContext(win->src.EGL_display, config, EGL_NO_CONTEXT, attribs); - eglSwapInterval(win->src.EGL_display, 1); + eglMakeCurrent(win->src.EGL_display, win->src.EGL_surface, win->src.EGL_surface, win->src.EGL_context); + eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface); } - void* RGFW_getProcAddress(const char* procname) { return (void*) eglGetProcAddress(procname); } + #ifdef RGFW_APPLE + void* RGFWnsglFramework = NULL; + #elif defined(RGFW_WINDOWS) + static HMODULE wglinstance = NULL; + #endif + + void* RGFW_getProcAddress(const char* procname) { + #if defined(RGFW_WINDOWS) + void* proc = (void*) GetProcAddress(wglinstance, procname); + + if (proc) + return proc; + #endif + + return (void*) eglGetProcAddress(procname); + } void RGFW_closeEGL(RGFW_window* win) { eglDestroySurface(win->src.EGL_display, win->src.EGL_surface); - eglDestroyContext(win->src.EGL_display, win->src.rSurf); + eglDestroyContext(win->src.EGL_display, win->src.EGL_context); eglTerminate(win->src.EGL_display); } #endif /* RGFW_EGL */ +#endif /* RGFW_GL stuff? */ /* This is where OS specific stuff starts @@ -2388,7 +2469,7 @@ typedef struct { i32 x, y; } RGFW_vector; } u32 i; - for (i = 0; i < fbcount; i++) { + for (i = 0; i < (u32)fbcount; i++) { XVisualInfo* vi = glXGetVisualFromFBConfig((Display*) win->src.display, fbc[i]); if (vi == NULL) continue; @@ -2398,8 +2479,9 @@ typedef struct { i32 x, y; } RGFW_vector; i32 samp_buf, samples; glXGetFBConfigAttrib((Display*) win->src.display, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf); glXGetFBConfigAttrib((Display*) win->src.display, fbc[i], GLX_SAMPLES, &samples); - if ((best_fbc < 0 || samp_buf) && (samples == RGFW_SAMPLES)) + if ((best_fbc < 0 || samp_buf) && (samples == RGFW_SAMPLES || best_fbc == -1)) { best_fbc = i; + } } if (best_fbc == -1) { @@ -2471,11 +2553,6 @@ typedef struct { i32 x, y; } RGFW_vector; win->src.rSurf = glXCreateContextAttribsARB((Display*) win->src.display, bestFbc, ctx, True, context_attribs); #endif - -#ifdef RGFW_EGL - RGFW_createOpenGLContext(win); -#endif - if (RGFW_root == NULL) RGFW_root = win; @@ -2558,6 +2635,10 @@ typedef struct { i32 x, y; } RGFW_vector; PropModeReplace, (u8*) &version, 1); /* turns on drag and drop */ } + #ifdef RGFW_EGL + RGFW_createOpenGLContext(win); + #endif + RGFW_window_setMouseDefault(win); RGFW_windowsOpen++; @@ -2593,9 +2674,11 @@ typedef struct { i32 x, y; } RGFW_vector; int xAxis = 0, yAxis = 0; + char RGFW_keyboard[32]; + char RGFW_keyboard_prev[32]; + RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { assert(win != NULL); - win->event.type = 0; #ifdef __linux__ @@ -2650,13 +2733,6 @@ typedef struct { i32 x, y; } RGFW_vector; } u32 i; - - if (win->event.droppedFilesCount) { - for (i = 0; i < win->event.droppedFilesCount; i++) - win->event.droppedFiles[i][0] = '\0'; - } - - win->event.droppedFilesCount = 0; win->event.type = 0; @@ -2676,6 +2752,11 @@ typedef struct { i32 x, y; } RGFW_vector; win->event.keyCode = XkbKeycodeToKeysym((Display*) win->src.display, E.xkey.keycode, 0, E.xkey.state & ShiftMask ? 1 : 0); win->event.keyName = XKeysymToString(win->event.keyCode); /* convert to string */ + if (RGFW_isPressedI(win, win->event.keyCode)) + RGFW_keyboard_prev[E.xkey.keycode >> 3] |= (1 << (E.xkey.keycode & 7)); + else + RGFW_keyboard_prev[E.xkey.keycode >> 3] |= 0; + /* get keystate data */ win->event.type = (E.type == KeyPress) ? RGFW_keyPressed : RGFW_keyReleased; @@ -2690,6 +2771,8 @@ typedef struct { i32 x, y; } RGFW_vector; else if (win->event.keyCode == XK_Num_Lock) win->event.lockState |= RGFW_NUMLOCK; } + + XQueryKeymap(win->src.display, RGFW_keyboard); /* query the keymap */ break; case ButtonPress: @@ -2718,6 +2801,14 @@ typedef struct { i32 x, y; } RGFW_vector; win->event.type = RGFW_quit; break; } + + /* reset DND values */ + if (win->event.droppedFilesCount) { + for (i = 0; i < win->event.droppedFilesCount; i++) + win->event.droppedFiles[i][0] = '\0'; + } + + win->event.droppedFilesCount = 0; /* much of this event (drag and drop code) is source from glfw @@ -3002,13 +3093,13 @@ typedef struct { i32 x, y; } RGFW_vector; win->src.winArgs &= ~RGFW_MOUSE_CHANGED; } - if (win->src.winArgs & RGFW_HOLD_MOUSE && win->event.inFocus && win->event.type == RGFW_mousePosChanged) { - RGFW_window_moveMouse(win, RGFW_VECTOR(win->r.x + (win->r.w / 2), win->r.y + (win->r.h / 2))); - - if (XEventsQueued((Display*) win->src.display, QueuedAfterReading) <= 1) - XSync(win->src.display, True); - } + if (win->src.winArgs & RGFW_HOLD_MOUSE && win->event.inFocus && win->event.type == RGFW_mousePosChanged) { + RGFW_window_moveMouse(win, RGFW_VECTOR(win->r.x + (win->r.w / 2), win->r.y + (win->r.h / 2))); + if (XEventsQueued((Display*) win->src.display, QueuedAfterReading) <= 1) + XSync(win->src.display, True); + } + XFlush((Display*) win->src.display); @@ -3022,7 +3113,7 @@ typedef struct { i32 x, y; } RGFW_vector; assert(win != NULL); #ifdef RGFW_VULKAN - for (int i = 0; i < win->src.image_count; i++) { + for (u32 i = 0; i < win->src.image_count; i++) { vkDestroyImageView(RGFW_vulkan_info.device, win->src.swapchain_image_views[i], NULL); } @@ -3212,7 +3303,7 @@ typedef struct { i32 x, y; } RGFW_vector; #ifndef RGFW_NO_X11_CURSOR /* free the previous cursor */ - if (win->src.cursor && win->src.cursor != -1) + if (win->src.cursor) XFreeCursor((Display*) win->src.display, (Cursor) win->src.cursor); XcursorImage* native = XcursorImageCreate(a.w, a.h); @@ -3235,6 +3326,8 @@ typedef struct { i32 x, y; } RGFW_vector; win->src.cursor = XcursorImageLoadCursor((Display*) win->src.display, native); XcursorImageDestroy(native); +#else + RGFW_UNUSED(image) RGFW_UNUSED(a.w) RGFW_UNUSED(channels) #endif } @@ -3256,7 +3349,7 @@ typedef struct { i32 x, y; } RGFW_vector; } RGFWDEF void RGFW_window_disableMouse(RGFW_window* win) { - + RGFW_UNUSED(win); } void RGFW_window_setMouseDefault(RGFW_window* win) { @@ -3267,7 +3360,7 @@ typedef struct { i32 x, y; } RGFW_vector; assert(win != NULL); /* free the previous cursor */ - if (win->src.cursor && win->src.cursor != -1) + if (win->src.cursor) XFreeCursor((Display*) win->src.display, (Cursor) win->src.cursor); win->src.winArgs |= RGFW_MOUSE_CHANGED; @@ -3615,7 +3708,7 @@ typedef struct { i32 x, y; } RGFW_vector; monitor.physW = (monitor.rect.w * 25.4f / 96.f); monitor.physH = (monitor.rect.h * 25.4f / 96.f); - strncpy(monitor.name, DisplayString(display), 128); + strcpy(monitor.name, DisplayString(display)); XGetSystemContentScale(display, &monitor.scaleX, &monitor.scaleY); @@ -3648,7 +3741,7 @@ typedef struct { i32 x, y; } RGFW_vector; RGFW_monitor RGFW_monitors[6]; RGFW_monitor* RGFW_getMonitors(void) { size_t i; - for (i = 0; i < ScreenCount(RGFW_root->src.display) && i < 6; i++) + for (i = 0; i < (size_t)ScreenCount(RGFW_root->src.display) && i < 6; i++) RGFW_monitors[i] = RGFW_XCreateMonitor(i); return RGFW_monitors; @@ -3684,9 +3777,7 @@ typedef struct { i32 x, y; } RGFW_vector; RGFW_monitor RGFW_window_getMonitor(RGFW_window* win) { return RGFW_XCreateMonitor(DefaultScreen(win->src.display)); } - - char keyboard[32]; - + u8 RGFW_isPressedI(RGFW_window* win, u32 key) { Display* d; if (win == (RGFW_window*) 0) @@ -3695,11 +3786,22 @@ typedef struct { i32 x, y; } RGFW_vector; return 0; else d = (Display*) win->src.display; + + KeyCode kc2 = XKeysymToKeycode(d, key); /* convert the key to a keycode */ + return (RGFW_keyboard[kc2 >> 3] & (1 << (kc2 & 7))); /* check if the key is pressed */ + } - XQueryKeymap(d, keyboard); /* query the keymap */ - + u8 RGFW_wasPressedI(RGFW_window* win, u32 key) { + Display* d; + if (win == (RGFW_window*) 0) + d = RGFW_root->src.display; + else if (!win->event.inFocus) + return 0; + else + d = (Display*) win->src.display; + KeyCode kc2 = XKeysymToKeycode(d, key); /* convert the key to a keycode */ - return !!(keyboard[kc2 >> 3] & (1 << (kc2 & 7))); /* check if the key is pressed */ + return !!(RGFW_keyboard_prev[kc2 >> 3] & (1 << (kc2 & 7))); /* check if the key is pressed */ } #endif @@ -3742,8 +3844,8 @@ typedef struct { i32 x, y; } RGFW_vector; void* RGFWjoystickApi = NULL; /* these two wgl functions need to be preloaded */ - typedef HGLRC(WINAPI* wglCreateContextAttribsARB_type)(HDC hdc, HGLRC hShareContext, - const i32* attribList); + typedef long long int (WINAPI* wglCreateContextAttribsARB_type)(HDC hdc, HGLRC hShareContext, + const int* attribList); wglCreateContextAttribsARB_type wglCreateContextAttribsARB = NULL; /* defines for creating ARB attributes */ @@ -3785,7 +3887,9 @@ typedef struct { i32 x, y; } RGFW_vector; #define WGL_SAMPLES_ARB 0x2042 #define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20a9 +#ifndef RGFW_EGL static HMODULE wglinstance = NULL; +#endif #ifdef RGFW_WGL_LOAD typedef HGLRC(WINAPI* PFN_wglCreateContext)(HDC); @@ -3802,13 +3906,13 @@ static HMODULE wglinstance = NULL; PFN_wglGetCurrentDC wglGetCurrentDCSRC; PFN_wglGetCurrentContext wglGetCurrentContextSRC; -#define wglCreateContext wglCreateContextSRC -#define wglDeleteContext wglDeleteContextSRC -#define wglGetProcAddress wglGetProcAddressSRC -#define wglMakeCurrent wglMakeCurrentSRC + #define wglCreateContext wglCreateContextSRC + #define wglDeleteContext wglDeleteContextSRC + #define wglGetProcAddress wglGetProcAddressSRC + #define wglMakeCurrent wglMakeCurrentSRC -#define wglGetCurrentDC wglGetCurrentDCSRC -#define wglGetCurrentContext wglGetCurrentContextSRC + #define wglGetCurrentDC wglGetCurrentDCSRC + #define wglGetCurrentContext wglGetCurrentContextSRC #endif #ifdef RGFW_OPENGL @@ -3820,11 +3924,11 @@ static HMODULE wglinstance = NULL; return (void*) GetProcAddress(wglinstance, procname); } - typedef BOOL(APIENTRY* PFNWGLCHOOSEPIXELFORMATARBPROC)(HDC hdc, const int* piAttribIList, const FLOAT* pfAttribFList, UINT nMaxFormats, int* piFormats, UINT* nNumFormats); + typedef u64 (APIENTRY* PFNWGLCHOOSEPIXELFORMATARBPROC)(HDC hdc, const int* piAttribIList, const FLOAT* pfAttribFList, UINT nMaxFormats, int* piFormats, UINT* nNumFormats); static PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = NULL; #endif - RGFW_window RGFW_eventWindow = { {NULL} }; + RGFW_window RGFW_eventWindow; LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { @@ -3845,7 +3949,7 @@ static HMODULE wglinstance = NULL; #ifndef RGFW_NO_DPI static HMODULE RGFW_Shcore_dll = NULL; - typedef HRESULT (WINAPI * PFN_GetDpiForMonitor)(HMONITOR,MONITOR_DPI_TYPE,UINT*,UINT*); + typedef u64 (WINAPI * PFN_GetDpiForMonitor)(HMONITOR,MONITOR_DPI_TYPE,UINT*,UINT*); PFN_GetDpiForMonitor GetDpiForMonitorSRC = NULL; #define GetDpiForMonitor GetDpiForMonitorSRC #endif @@ -3898,6 +4002,7 @@ static HMODULE wglinstance = NULL; if (name[0] == 0) name = (char*) " "; RGFW_eventWindow.r = RGFW_RECT(-1, -1, -1, -1); + RGFW_eventWindow.src.window = NULL; RGFW_window* win = RGFW_window_basic_init(rect, args); @@ -4036,7 +4141,7 @@ static HMODULE wglinstance = NULL; ReleaseDC(dummyWin, dummy_dc); if (wglCreateContextAttribsARB != NULL) { - PIXELFORMATDESCRIPTOR pfd = { sizeof(pfd), 1, PFD_TYPE_RGBA, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, 32, 8, PFD_MAIN_PLANE, 24, 8 }; + PIXELFORMATDESCRIPTOR pfd = (PIXELFORMATDESCRIPTOR){ sizeof(pfd), 1, PFD_TYPE_RGBA, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, 32, 8, PFD_MAIN_PLANE, 24, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; if (args & RGFW_OPENGL_SOFTWARE) pfd.dwFlags |= PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED; @@ -4059,15 +4164,15 @@ static HMODULE wglinstance = NULL; u32 index = 0; i32 attribs[40]; -#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 - SET_ATTRIB(WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB); + + SET_ATTRIB(WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB); if (RGFW_majorVersion || RGFW_minorVersion) { SET_ATTRIB(WGL_CONTEXT_MAJOR_VERSION_ARB, RGFW_majorVersion); SET_ATTRIB(WGL_CONTEXT_MINOR_VERSION_ARB, RGFW_minorVersion); } - SET_ATTRIB(WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB); + SET_ATTRIB(WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB); if (RGFW_majorVersion || RGFW_minorVersion) { SET_ATTRIB(WGL_CONTEXT_MAJOR_VERSION_ARB, RGFW_majorVersion); @@ -4076,7 +4181,7 @@ static HMODULE wglinstance = NULL; SET_ATTRIB(0, 0); - win->src.rSurf = wglCreateContextAttribsARB(win->src.hdc, NULL, attribs); + win->src.rSurf = (HGLRC)wglCreateContextAttribsARB(win->src.hdc, NULL, attribs); } else { fprintf(stderr, "Failed to create an accelerated OpenGL Context\n"); @@ -4293,6 +4398,9 @@ static HMODULE wglinstance = NULL; return 0; } + BYTE RGFW_keyBoard[256]; + BYTE RGFW_keyBoard_prev[256]; + RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { assert(win != NULL); @@ -4317,14 +4425,6 @@ static HMODULE wglinstance = NULL; return &win->event; } - if (win->event.droppedFilesCount) { - u32 i; - for (i = 0; i < win->event.droppedFilesCount; i++) - win->event.droppedFiles[i][0] = '\0'; - } - - win->event.droppedFilesCount = 0; - win->event.inFocus = (GetForegroundWindow() == win->src.window); if (RGFW_checkXInput(&win->event)) @@ -4334,7 +4434,6 @@ static HMODULE wglinstance = NULL; return NULL; static BYTE keyboardState[256]; - GetKeyboardState(keyboardState); if (PeekMessageA(&msg, win->src.window, 0u, 0u, PM_REMOVE)) { switch (msg.message) { @@ -4345,24 +4444,37 @@ static HMODULE wglinstance = NULL; case WM_KEYUP: win->event.keyCode = (u32) msg.wParam; + if (RGFW_isPressedI(win, win->event.keyCode)) + RGFW_keyBoard_prev[win->event.keyCode] |= 0x80; + else + RGFW_keyBoard_prev[win->event.keyCode] = 0; + strncpy(win->event.keyName, RGFW_keyCodeTokeyStr(msg.lParam), 16); - if (GetKeyState(VK_SHIFT) & 0x8000) { + if (RGFW_isPressedI(win, VK_SHIFT)) { ToAscii((UINT) msg.wParam, MapVirtualKey((UINT) msg.wParam, MAPVK_VK_TO_CHAR), keyboardState, (LPWORD) win->event.keyName, 0); } win->event.type = RGFW_keyReleased; + GetKeyboardState(RGFW_keyBoard); break; case WM_KEYDOWN: win->event.keyCode = (u32) msg.wParam; + + if (RGFW_isPressedI(win, win->event.keyCode)) + RGFW_keyBoard_prev[win->event.keyCode] |= 0x80; + else + RGFW_keyBoard_prev[win->event.keyCode] = 0; + strncpy(win->event.keyName, RGFW_keyCodeTokeyStr(msg.lParam), 16); - if (GetKeyState(VK_SHIFT) & 0x8000) { + if (RGFW_isPressedI(win, VK_SHIFT) & 0x8000) { ToAscii((UINT) msg.wParam, MapVirtualKey((UINT) msg.wParam, MAPVK_VK_TO_CHAR), keyboardState, (LPWORD) win->event.keyName, 0); } win->event.type = RGFW_keyPressed; + GetKeyboardState(RGFW_keyBoard); break; case WM_MOUSEMOVE: @@ -4413,6 +4525,15 @@ static HMODULE wglinstance = NULL; much of this event is source from glfw */ case WM_DROPFILES: { + + if (win->event.droppedFilesCount) { + u32 i; + for (i = 0; i < win->event.droppedFilesCount; i++) + win->event.droppedFiles[i][0] = '\0'; + } + + win->event.droppedFilesCount = 0; + win->event.type = RGFW_dnd; HDROP drop = (HDROP) msg.wParam; @@ -4522,6 +4643,9 @@ static HMODULE wglinstance = NULL; typedef struct { int iIndex; HMONITOR hMonitor; } RGFW_mInfo; BOOL CALLBACK GetMonitorByHandle(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { + RGFW_UNUSED(hdcMonitor) + RGFW_UNUSED(lprcMonitor) + RGFW_mInfo* info = (RGFW_mInfo*) dwData; if (info->hMonitor == hMonitor) return FALSE; @@ -4586,6 +4710,9 @@ static HMODULE wglinstance = NULL; RGFW_monitor RGFW_monitors[6]; BOOL CALLBACK GetMonitorHandle(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { + RGFW_UNUSED(hdcMonitor) + RGFW_UNUSED(lprcMonitor) + RGFW_mInfo* info = (RGFW_mInfo*) dwData; if (info->iIndex >= 6) @@ -4618,9 +4745,20 @@ static HMODULE wglinstance = NULL; if (win != NULL && !win->event.inFocus) return 0; - if (GetAsyncKeyState(key) & 0x8000) + if (RGFW_keyBoard[key] & 0x80) return 1; - else return 0; + + return 0; + } + + u8 RGFW_wasPressedI(RGFW_window* win, u32 key) { + if (win != NULL && !win->event.inFocus) + return 0; + + if (RGFW_keyBoard_prev[key] & 0x80) + return 1; + + return 0; } HICON RGFW_loadHandleImage(RGFW_window* win, u8* src, RGFW_area a, BOOL icon) { @@ -4684,6 +4822,7 @@ static HMODULE wglinstance = NULL; void RGFW_window_setMouse(RGFW_window* win, u8* image, RGFW_area a, i32 channels) { assert(win != NULL); + RGFW_UNUSED(channels) HCURSOR cursor = (HCURSOR) RGFW_loadHandleImage(win, image, a, FALSE); SetClassLongPtrA(win->src.window, GCLP_HCURSOR, (LPARAM) cursor); @@ -4824,6 +4963,7 @@ static HMODULE wglinstance = NULL; /* much of this function is sourced from GLFW */ void RGFW_window_setIcon(RGFW_window* win, u8* src, RGFW_area a, i32 channels) { assert(win != NULL); + RGFW_UNUSED(channels) HICON handle = RGFW_loadHandleImage(win, src, a, TRUE); @@ -4900,12 +5040,14 @@ static HMODULE wglinstance = NULL; u16 RGFW_registerJoystick(RGFW_window* win, i32 jsNumber) { assert(win != NULL); + RGFW_UNUSED(jsNumber) + return RGFW_registerJoystickF(win, (char*) ""); } u16 RGFW_registerJoystickF(RGFW_window* win, char* file) { assert(win != NULL); - + RGFW_UNUSED(file) return win->src.joystickCount - 1; } @@ -4936,7 +5078,7 @@ static HMODULE wglinstance = NULL; } #ifndef RGFW_NO_THREADS - RGFW_thread RGFW_createThread(void* (*function_ptr)(void*), void* args) { return CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) *function_ptr, args, 0, NULL); } + RGFW_thread RGFW_createThread(RGFW_threadFunc_ptr ptr, void* args) { return CreateThread(NULL, 0, ptr, args, 0, NULL); } void RGFW_cancelThread(RGFW_thread thread) { CloseHandle((HANDLE) thread); } void RGFW_joinThread(RGFW_thread thread) { WaitForSingleObject((HANDLE) thread, INFINITE); } void RGFW_setThreadPriority(RGFW_thread thread, u8 priority) { SetThreadPriority((HANDLE) thread, priority); } @@ -4962,7 +5104,10 @@ static HMODULE wglinstance = NULL; } #endif - CVReturn displayCallback(CVDisplayLinkRef displayLink, const CVTimeStamp* inNow, const CVTimeStamp* inOutputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void* displayLinkContext) { return kCVReturnSuccess; } + CVReturn displayCallback(CVDisplayLinkRef displayLink, const CVTimeStamp* inNow, const CVTimeStamp* inOutputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void* displayLinkContext) { + RGFW_UNUSED(displayLink) RGFW_UNUSED(inNow) RGFW_UNUSED(inOutputTime) RGFW_UNUSED(flagsIn) RGFW_UNUSED(flagsOut) RGFW_UNUSED(displayLinkContext) + return kCVReturnSuccess; + } RGFW_window* RGFW_windows[10]; u32 RGFW_windows_size = 0; @@ -4983,17 +5128,25 @@ static HMODULE wglinstance = NULL; } /* NOTE(EimaMei): Fixes the constant clicking when the app is running under a terminal. */ - bool acceptsFirstResponder() { return true; } - bool performKeyEquivalent(NSEvent* event) { return true; } + bool acceptsFirstResponder(void) { return true; } + bool performKeyEquivalent(NSEvent* event) { RGFW_UNUSED(event); return true; } - NSDragOperation draggingEntered(id self, SEL sel, id sender) { return NSDragOperationCopy; } - NSDragOperation draggingUpdated(id self, SEL sel, id sender) { return NSDragOperationCopy; } + NSDragOperation draggingEntered(id self, SEL sel, id sender) { + RGFW_UNUSED(sender); RGFW_UNUSED(self); RGFW_UNUSED(sel); + return NSDragOperationCopy; + } + NSDragOperation draggingUpdated(id self, SEL sel, id sender) { + RGFW_UNUSED(sender); RGFW_UNUSED(self); RGFW_UNUSED(sel); + return NSDragOperationCopy; + } bool prepareForDragOperation(void) { return true; } - void RGFW__osxDraggingEnded(id self, SEL sel, id sender) { return; } + void RGFW__osxDraggingEnded(id self, SEL sel, id sender) { RGFW_UNUSED(sender); RGFW_UNUSED(self); RGFW_UNUSED(sel); return; } /* NOTE(EimaMei): Usually, you never need 'id self, SEL cmd' for C -> Obj-C methods. This isn't the case. */ bool performDragOperation(id self, SEL sel, id sender) { + RGFW_UNUSED(sender); RGFW_UNUSED(self); RGFW_UNUSED(sel); + NSWindow* window = objc_msgSend_id(sender, sel_registerName("draggingDestinationWindow")); u32 i; bool found = false; @@ -5007,10 +5160,10 @@ static HMODULE wglinstance = NULL; if (!found) i = 0; - Class* array[] = { objc_getClass("NSURL"), NULL }; - char** droppedFiles = (char**) NSPasteboard_readObjectsForClasses( - (NSPasteboard*) objc_msgSend_id(sender, sel_registerName("draggingPasteboard")), - array, 1, NULL); + Class array[] = { objc_getClass("NSURL"), NULL }; + NSPasteboard* pasteBoard = objc_msgSend_id(sender, sel_registerName("draggingPasteboard")); + + char** droppedFiles = (char**) NSPasteboard_readObjectsForClasses(pasteBoard, array, 1, NULL); RGFW_windows[i]->event.droppedFilesCount = si_array_len(droppedFiles); @@ -5020,11 +5173,12 @@ static HMODULE wglinstance = NULL; strcpy(RGFW_windows[i]->event.droppedFiles[y], droppedFiles[y]); RGFW_windows[i]->event.type = RGFW_dnd; + RGFW_windows[i]->src.dndPassed = false; - NSPoint p = *(NSPoint*) objc_msgSend_id(sender, sel_registerName("draggingLocation")); - RGFW_windows[i]->event.point.x = p.x; - RGFW_windows[i]->event.point.x = p.y; + NSPoint p = ((NSPoint(*)(id, SEL)) objc_msgSend)(sender, sel_registerName("draggingLocation")); + RGFW_windows[i]->event.point.x = (i32)p.x; + RGFW_windows[i]->event.point.x = (i32)p.y; return true; } @@ -5059,6 +5213,8 @@ static HMODULE wglinstance = NULL; NSSize RGFW__osxWindowResize(void* self, SEL sel, NSSize frameSize) { + RGFW_UNUSED(sel); + u32 i; for (i = 0; i < RGFW_windows_size; i++) { if (RGFW_windows[i] && NSWindow_delegate(RGFW_windows[i]) == self) { @@ -5074,6 +5230,8 @@ static HMODULE wglinstance = NULL; } void RGFW__osxWindowMove(void* self, SEL sel) { + RGFW_UNUSED(sel); + u32 i; for (i = 0; i < RGFW_windows_size; i++) { if (RGFW_windows[i] && NSWindow_delegate(RGFW_windows[i]) == self) { @@ -5093,8 +5251,8 @@ static HMODULE wglinstance = NULL; #define APPKIT_EXTERN extern #endif - APPKIT_EXTERN NSPasteboardType const NSPasteboardTypeURL = "public.url"; API_AVAILABLE(macos(10.13)); // Equivalent to kUTTypeURL - APPKIT_EXTERN NSPasteboardType const NSPasteboardTypeFileURL = "public.file-url"; API_AVAILABLE(macos(10.13)); // Equivalent to kUTTypeFileURL + NSPasteboardType const NSPasteboardTypeURL = "public.url"; + NSPasteboardType const NSPasteboardTypeFileURL = "public.file-url"; RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { static u8 RGFW_loaded = 0; @@ -5109,7 +5267,7 @@ static HMODULE wglinstance = NULL; si_func_to_SEL("NSWindow", performKeyEquivalent); if (NSApp == NULL) { - NSApp = objc_msgSend_id(objc_getClass("NSApplication"), sel_registerName("sharedApplication")); + NSApp = objc_msgSend_id((id)objc_getClass("NSApplication"), sel_registerName("sharedApplication")); ((void (*)(id, SEL, NSUInteger))objc_msgSend) (NSApp, sel_registerName("setActivationPolicy:"), NSApplicationActivationPolicyRegular); @@ -5164,7 +5322,7 @@ static HMODULE wglinstance = NULL; #else NSRect contentRect = NSMakeRect(0, 0, win->r.w, win->r.h); win->src.view = ((id(*)(id, SEL, NSRect))objc_msgSend) - (NSAlloc(objc_getClass("NSView")), sel_registerName("initWithFrame:"), + (NSAlloc((id)objc_getClass("NSView")), sel_registerName("initWithFrame:"), contentRect); #endif @@ -5193,7 +5351,7 @@ static HMODULE wglinstance = NULL; } win->src.display = CGMainDisplayID(); - CVDisplayLinkCreateWithCGDisplay(win->src.display, &win->src.displayLink); + CVDisplayLinkCreateWithCGDisplay(win->src.display, (CVDisplayLinkRef*)&win->src.displayLink); CVDisplayLinkSetOutputCallback(win->src.displayLink, displayCallback, win); CVDisplayLinkStart(win->src.displayLink); @@ -5213,35 +5371,17 @@ static HMODULE wglinstance = NULL; NSMoveToResourceDir(); Class delegateClass = objc_allocateClassPair(objc_getClass("NSObject"), "WindowDelegate", 0); + + class_addMethod(delegateClass, sel_registerName("windowWillResize:toSize:"), (IMP) RGFW__osxWindowResize, "{NSSize=ff}@:{NSSize=ff}"); class_addMethod(delegateClass, sel_registerName("windowWillMove:"), (IMP) RGFW__osxWindowMove, ""); class_addMethod(delegateClass, sel_registerName("windowDidMove:"), (IMP) RGFW__osxWindowMove, ""); - - - if (args & RGFW_ALLOW_DND) { - win->src.winArgs |= RGFW_ALLOW_DND; - -/* - NSPasteboardType types[] = {NSPasteboardTypeURL, NSPasteboardTypeFileURL, NSPasteboardTypeString}; - - siArray(NSPasteboardType) array = sic_arrayInit(types, sizeof(id), countof(types)); - NSWindow_registerForDraggedTypes(win->hwnd, array); - - win->dndHead = win->dndPrev = out; -*/ - - NSPasteboardType array[] = {NSPasteboardTypeURL, NSPasteboardTypeFileURL, NSPasteboardTypeString}; - NSregisterForDraggedTypes(win->src.window, array, 3); - - /* NOTE(EimaMei): Drag 'n Drop requires too many damn functions for just a Drag 'n Drop event. */ - class_addMethod(delegateClass, "draggingEntered:", draggingEntered, "l@:@"); - class_addMethod(delegateClass, "draggingUpdated:", draggingUpdated, "l@:@"); - class_addMethod(delegateClass, "draggingExited:", RGFW__osxDraggingEnded, "v@:@"); - class_addMethod(delegateClass, "draggingEnded:", RGFW__osxDraggingEnded, "v@:@"); - class_addMethod(delegateClass, "prepareForDragOperation:", prepareForDragOperation, "B@:@"); - class_addMethod(delegateClass, "performDragOperation:", performDragOperation, "B@:@"); - - } + class_addMethod(delegateClass, sel_registerName("draggingEntered:"), (IMP)draggingEntered, "l@:@"); + class_addMethod(delegateClass, sel_registerName("draggingUpdated:"), (IMP)draggingUpdated, "l@:@"); + class_addMethod(delegateClass, sel_registerName("draggingExited:"), (IMP)RGFW__osxDraggingEnded, "v@:@"); + class_addMethod(delegateClass, sel_registerName("draggingEnded:"), (IMP)RGFW__osxDraggingEnded, "v@:@"); + class_addMethod(delegateClass, sel_registerName("prepareForDragOperation:"), (IMP)prepareForDragOperation, "B@:@"); + class_addMethod(delegateClass, sel_registerName("performDragOperation:"), (IMP)performDragOperation, "B@:@"); id delegate = objc_msgSend_id(NSAlloc(delegateClass), sel_registerName("init")); @@ -5249,6 +5389,13 @@ static HMODULE wglinstance = NULL; objc_msgSend_void_id(win->src.window, sel_registerName("setDelegate:"), delegate); + if (args & RGFW_ALLOW_DND) { + win->src.winArgs |= RGFW_ALLOW_DND; + + NSPasteboardType types[] = {NSPasteboardTypeURL, NSPasteboardTypeFileURL, NSPasteboardTypeString}; + NSregisterForDraggedTypes(win->src.window, types, 3); + } + // Show the window ((id(*)(id, SEL, SEL))objc_msgSend)(win->src.window, sel_registerName("makeKeyAndOrderFront:"), NULL); objc_msgSend_void_bool(win->src.window, sel_registerName("setIsVisible:"), true); @@ -5259,6 +5406,8 @@ static HMODULE wglinstance = NULL; RGFW_loaded = 1; } + objc_msgSend_void(win->src.window, sel_registerName("makeKeyWindow")); + NSApplication_finishLaunching(NSApp); RGFW_windows_size++; @@ -5385,12 +5534,25 @@ static HMODULE wglinstance = NULL; }; + typedef enum NSEventModifierFlags { + NSEventModifierFlagCapsLock = 1 << 16, + NSEventModifierFlagShift = 1 << 17, + NSEventModifierFlagControl = 1 << 18, + NSEventModifierFlagOption = 1 << 19, + NSEventModifierFlagCommand = 1 << 20 + } NSEventModifierFlags; + RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) { assert(win != NULL); if (win->event.type == RGFW_quit) return &win->event; + if (win->event.type == RGFW_dnd && win->src.dndPassed == 0) { + win->src.dndPassed = 1; + return &win->event; + } + static void* eventFunc = NULL; if (eventFunc == NULL) eventFunc = sel_registerName("nextEventMatchingMask:untilDate:inMode:dequeue:"); @@ -5426,85 +5588,156 @@ static HMODULE wglinstance = NULL; win->event.inFocus = (bool) objc_msgSend_bool(win->src.window, sel_registerName("isKeyWindow")); switch (objc_msgSend_uint(e, sel_registerName("type"))) { - case NSEventTypeKeyDown: - win->event.type = RGFW_keyPressed; - win->event.keyCode = (u16) objc_msgSend_uint(e, sel_registerName("keyCode")); - win->event.keyName = (const char*) NSString_to_char(objc_msgSend_id(e, sel_registerName("characters"))); + case NSEventTypeKeyDown: + win->event.keyCode = (u16) objc_msgSend_uint(e, sel_registerName("keyCode")); + RGFW_keyBoard_prev[win->event.keyCode] = RGFW_keyBoard[win->event.keyCode]; - RGFW_keyMap[win->event.keyCode] = 1; - break; + win->event.type = RGFW_keyPressed; + win->event.keyName = (char*)(const char*) NSString_to_char(objc_msgSend_id(e, sel_registerName("characters"))); - case NSEventTypeKeyUp: - win->event.type = RGFW_keyReleased; - win->event.keyCode = (u16) objc_msgSend_uint(e, sel_registerName("keyCode")); - win->event.keyName = (const char*) NSString_to_char(objc_msgSend_id(e, sel_registerName("characters"))); + RGFW_keyBoard[win->event.keyCode] = 1; + break; - RGFW_keyMap[win->event.keyCode] = 0; - break; + case NSEventTypeKeyUp: + win->event.keyCode = (u16) objc_msgSend_uint(e, sel_registerName("keyCode")); - case NSEventTypeLeftMouseDragged: - case NSEventTypeOtherMouseDragged: - case NSEventTypeRightMouseDragged: - case NSEventTypeMouseMoved: - win->event.type = RGFW_mousePosChanged; - NSPoint p = ((NSPoint(*)(id, SEL)) objc_msgSend)(e, sel_registerName("locationInWindow")); + RGFW_keyBoard_prev[win->event.keyCode] = RGFW_keyBoard[win->event.keyCode]; + + win->event.type = RGFW_keyReleased; + win->event.keyName = (char*)(const char*) NSString_to_char(objc_msgSend_id(e, sel_registerName("characters"))); + + RGFW_keyBoard[win->event.keyCode] = 0; + break; + + case NSEventTypeFlagsChanged: { + u32 flags = objc_msgSend_uint(e, sel_registerName("modifierFlags")); + memcpy(RGFW_keyBoard_prev + 55, RGFW_keyBoard + 55, 5); - win->event.point = RGFW_VECTOR((u32) p.x, (u32) (win->r.h - p.y)); + if ((flags & NSEventModifierFlagCapsLock) && !RGFW_wasPressedI(win, 57)) { + RGFW_keyBoard[57] = 1; + win->event.type = RGFW_keyPressed; + win->event.keyCode = 57; + break; + } if (!(flags & NSEventModifierFlagCapsLock) && RGFW_wasPressedI(win, 57)) { + RGFW_keyBoard[57] = 0; + win->event.type = RGFW_keyReleased; + win->event.keyCode = 57; + break; + } + + if ((flags & NSEventModifierFlagOption) && !RGFW_wasPressedI(win, 58)) { + RGFW_keyBoard[58] = 1; + win->event.type = RGFW_keyPressed; + win->event.keyCode = 58; + break; + } if (!(flags & NSEventModifierFlagOption) && RGFW_wasPressedI(win, 58)) { + RGFW_keyBoard[58] = 0; + win->event.type = RGFW_keyReleased; + win->event.keyCode = 58; + break; + } + + if ((flags & NSEventModifierFlagControl) && !RGFW_wasPressedI(win, 59)) { + RGFW_keyBoard[59] = 1; + win->event.type = RGFW_keyPressed; + win->event.keyCode = 59; + break; + } if (!(flags & NSEventModifierFlagControl) && RGFW_wasPressedI(win, 59)) { + RGFW_keyBoard[59] = 0; + win->event.type = RGFW_keyReleased; + win->event.keyCode = 59; + break; + } + + if ((flags & NSEventModifierFlagCommand) && !RGFW_wasPressedI(win, 55)) { + RGFW_keyBoard[55] = 1; + win->event.type = RGFW_keyPressed; + win->event.keyCode = 55; + break; + } if (!(flags & NSEventModifierFlagCommand) && RGFW_wasPressedI(win, 55)) { + RGFW_keyBoard[55] = 0; + win->event.type = RGFW_keyReleased; + win->event.keyCode = 55; + break; + } - if (win->src.winArgs & RGFW_HOLD_MOUSE) { - RGFW_vector mouse = RGFW_getGlobalMousePoint(); - if ((mouse.x != win->r.x + (win->r.w / 2) || mouse.y != win->r.y + (win->r.h / 2))) { - RGFW_window_moveMouse(win, RGFW_VECTOR(win->r.x + (win->r.w / 2), win->r.y + (win->r.h / 2))); + if ((flags & NSEventModifierFlagShift) && !RGFW_wasPressedI(win, 56)) { + RGFW_keyBoard[56] = 1; + win->event.type = RGFW_keyPressed; + win->event.keyCode = 56; + break; + } if (!(flags & NSEventModifierFlagShift) && RGFW_wasPressedI(win, 56)) { + RGFW_keyBoard[56] = 0; + win->event.type = RGFW_keyReleased; + win->event.keyCode = 56; + break; } + + break; } - break; + case NSEventTypeLeftMouseDragged: + case NSEventTypeOtherMouseDragged: + case NSEventTypeRightMouseDragged: + case NSEventTypeMouseMoved: + win->event.type = RGFW_mousePosChanged; + NSPoint p = ((NSPoint(*)(id, SEL)) objc_msgSend)(e, sel_registerName("locationInWindow")); - case NSEventTypeLeftMouseDown: - win->event.button = RGFW_mouseLeft; - win->event.type = RGFW_mouseButtonPressed; - break; + win->event.point = RGFW_VECTOR((u32) p.x, (u32) (win->r.h - p.y)); - case NSEventTypeOtherMouseDown: - win->event.button = RGFW_mouseMiddle; - win->event.type = RGFW_mouseButtonPressed; - break; + if (win->src.winArgs & RGFW_HOLD_MOUSE) { + RGFW_vector mouse = RGFW_getGlobalMousePoint(); + if ((mouse.x != win->r.x + (win->r.w / 2) || mouse.y != win->r.y + (win->r.h / 2))) { + RGFW_window_moveMouse(win, RGFW_VECTOR(win->r.x + (win->r.w / 2), win->r.y + (win->r.h / 2))); + } + } + break; - case NSEventTypeRightMouseDown: - win->event.button = RGFW_mouseRight; - win->event.type = RGFW_mouseButtonPressed; - break; + case NSEventTypeLeftMouseDown: + win->event.button = RGFW_mouseLeft; + win->event.type = RGFW_mouseButtonPressed; + break; - case NSEventTypeLeftMouseUp: - win->event.button = RGFW_mouseLeft; - win->event.type = RGFW_mouseButtonReleased; - break; + case NSEventTypeOtherMouseDown: + win->event.button = RGFW_mouseMiddle; + win->event.type = RGFW_mouseButtonPressed; + break; - case NSEventTypeOtherMouseUp: - win->event.button = RGFW_mouseMiddle; - win->event.type = RGFW_mouseButtonReleased; - break; + case NSEventTypeRightMouseDown: + win->event.button = RGFW_mouseRight; + win->event.type = RGFW_mouseButtonPressed; + break; - case NSEventTypeScrollWheel: { - double deltaY = ((CGFloat(*)(id, SEL))abi_objc_msgSend_fpret)(e, sel_registerName("deltaY")); + case NSEventTypeLeftMouseUp: + win->event.button = RGFW_mouseLeft; + win->event.type = RGFW_mouseButtonReleased; + break; + + case NSEventTypeOtherMouseUp: + win->event.button = RGFW_mouseMiddle; + win->event.type = RGFW_mouseButtonReleased; + break; - if (deltaY > 0) - win->event.button = RGFW_mouseScrollUp; + case NSEventTypeScrollWheel: { + double deltaY = ((CGFloat(*)(id, SEL))abi_objc_msgSend_fpret)(e, sel_registerName("deltaY")); - else if (deltaY < 0) - win->event.button = RGFW_mouseScrollDown; + if (deltaY > 0) + win->event.button = RGFW_mouseScrollUp; - win->event.scroll = deltaY; + else if (deltaY < 0) + win->event.button = RGFW_mouseScrollDown; - win->event.type = RGFW_mouseButtonReleased; - break; - } - case NSEventTypeRightMouseUp: - win->event.button = RGFW_mouseRight; - win->event.type = RGFW_mouseButtonReleased; - break; + win->event.scroll = deltaY; - default: - break; + win->event.type = RGFW_mouseButtonReleased; + break; + } + case NSEventTypeRightMouseUp: + win->event.button = RGFW_mouseRight; + win->event.type = RGFW_mouseButtonReleased; + break; + + default: + break; } objc_msgSend_void_id(NSApp, sel_registerName("sendEvent:"), e); @@ -5617,6 +5850,8 @@ static HMODULE wglinstance = NULL; } void RGFW_window_showMouse(RGFW_window* win, i8 show) { + RGFW_UNUSED(win); + if (show) { CGDisplayShowCursor(kCGDirectMainDisplay); } @@ -5626,11 +5861,13 @@ static HMODULE wglinstance = NULL; } void RGFW_window_setMouseStandard(RGFW_window* win, void* mouse) { + RGFW_UNUSED(win); CGDisplayShowCursor(kCGDirectMainDisplay); objc_msgSend_void(mouse, sel_registerName("set")); } void RGFW_window_moveMouse(RGFW_window* win, RGFW_vector v) { + RGFW_UNUSED(win); assert(win != NULL); CGWarpMouseCursorPosition(CGPointMake(v.x, v.y)); @@ -5716,6 +5953,7 @@ static HMODULE wglinstance = NULL; } u8 RGFW_isPressedI(RGFW_window* win, u32 key) { + RGFW_UNUSED(win); if (key >= 128) { #ifdef RGFW_PRINT_ERRORS fprintf(stderr, "RGFW_isPressedI : invalid keycode\n"); @@ -5723,7 +5961,19 @@ static HMODULE wglinstance = NULL; RGFW_error = 1; } - return RGFW_keyMap[key]; + return RGFW_keyBoard[key]; + } + + u8 RGFW_wasPressedI(RGFW_window* win, u32 key) { + RGFW_UNUSED(win); + if (key >= 128) { +#ifdef RGFW_PRINT_ERRORS + fprintf(stderr, "RGFW_wasPressedI : invalid keycode\n"); +#endif + RGFW_error = 1; + } + + return RGFW_keyBoard_prev[key]; } #ifdef __cplusplus @@ -5740,6 +5990,8 @@ static HMODULE wglinstance = NULL; } void RGFW_writeClipboard(const char* text, u32 textLen) { + RGFW_UNUSED(textLen); + NSPasteboardType array[] = { NSPasteboardTypeString, NULL }; NSPasteBoard_declareTypes(NSPasteboard_generalPasteboard(), array, 1, NULL); @@ -5747,12 +5999,16 @@ static HMODULE wglinstance = NULL; } u16 RGFW_registerJoystick(RGFW_window* win, i32 jsNumber) { + RGFW_UNUSED(jsNumber); + assert(win != NULL); return RGFW_registerJoystickF(win, (char*) ""); } u16 RGFW_registerJoystickF(RGFW_window* win, char* file) { + RGFW_UNUSED(file); + assert(win != NULL); return win->src.joystickCount - 1; @@ -5820,9 +6076,11 @@ static HMODULE wglinstance = NULL; #ifndef RGFW_NO_THREADS #include - RGFW_thread RGFW_createThread(void* (*function_ptr)(void*), void* args) { + RGFW_thread RGFW_createThread(RGFW_threadFunc_ptr ptr, void* args) { + RGFW_UNUSED(args); + RGFW_thread t; - pthread_create((pthread_t*) &t, NULL, *function_ptr, NULL); + pthread_create((pthread_t*) &t, NULL, *ptr, NULL); return t; } void RGFW_cancelThread(RGFW_thread thread) { pthread_cancel((pthread_t) thread); } @@ -5848,7 +6106,7 @@ static HMODULE wglinstance = NULL; #endif #else #ifdef RGFW_EGL - eglMakeCurrent(win->src.EGL_display, win->src.EGL_surface, win->src.EGL_surface, win->src.rSurf); + eglMakeCurrent(win->src.EGL_display, win->src.EGL_surface, win->src.EGL_surface, win->src.EGL_context); #endif #endif @@ -5927,9 +6185,6 @@ static HMODULE wglinstance = NULL; void RGFW_window_swapBuffers(RGFW_window* win) { assert(win != NULL); - win->event.frames++; - RGFW_window_checkFPS(win); - RGFW_window_makeCurrent(win); /* clear the window*/ @@ -5958,10 +6213,10 @@ static HMODULE wglinstance = NULL; RGFW_area area = RGFW_getScreenSize(); #ifndef RGFW_X11_DONT_CONVERT_BGR - win->src.bitmap->data = (const char*) win->buffer; + win->src.bitmap->data = (char*) win->buffer; u32 x, y; - for (y = 0; y < win->r.h; y++) { - for (x = 0; x < win->r.w; x++) { + for (y = 0; y < (u32)win->r.h; y++) { + for (x = 0; x < (u32)win->r.w; x++) { u32 index = (y * 4 * area.w) + x * 4; u8 red = win->src.bitmap->data[index]; @@ -5992,7 +6247,7 @@ static HMODULE wglinstance = NULL; "NSDeviceRGBColorSpace", 0, area.w * 4, 32 ); - id image = NSAlloc(objc_getClass("NSImage")); + id image = NSAlloc((id)objc_getClass("NSImage")); NSImage_addRepresentation(image, rep); objc_msgSend_void_id(layer, sel_registerName("setContents:"), (id) image); @@ -6009,28 +6264,25 @@ static HMODULE wglinstance = NULL; #endif } - if (win->src.winArgs & RGFW_NO_GPU_RENDER) - return; + if (!(win->src.winArgs & RGFW_NO_GPU_RENDER)) { + #ifdef RGFW_EGL + eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface); + #elif defined(RGFW_OPENGL) + #if defined(RGFW_X11) && defined(RGFW_OPENGL) + glXSwapBuffers((Display*) win->src.display, (Window) win->src.window); + #elif defined(RGFW_WINDOWS) + SwapBuffers(win->src.hdc); + #elif defined(RGFW_MACOS) + NSOpenGLContext_flushBuffer(win->src.rSurf); + #endif + #endif -#ifdef RGFW_OPENGL -#ifdef RGFW_EGL - eglSwapBuffers(win->src.EGL_display, win->src.EGL_surface); -#else -#if defined(RGFW_X11) && defined(RGFW_OPENGL) - glXSwapBuffers((Display*) win->src.display, (Window) win->src.window); -#endif -#ifdef RGFW_WINDOWS - SwapBuffers(win->src.hdc); -#endif -#if defined(RGFW_MACOS) - NSOpenGLContext_flushBuffer(win->src.rSurf); -#endif -#endif -#endif + #if defined(RGFW_WINDOWS) && defined(RGFW_DIRECTX) + win->src.swapchain->lpVtbl->Present(win->src.swapchain, 0, 0); + #endif + } -#if defined(RGFW_WINDOWS) && defined(RGFW_DIRECTX) - win->src.swapchain->lpVtbl->Present(win->src.swapchain, 0, 0); -#endif + RGFW_window_checkFPS(win); } void RGFW_window_maximize(RGFW_window* win) { @@ -6072,11 +6324,11 @@ static HMODULE wglinstance = NULL; #endif } - void RGFW_sleep(u32 ms) { + void RGFW_sleep(u64 ms) { #ifndef RGFW_WINDOWS struct timespec time; time.tv_sec = 0; - time.tv_nsec = ms * 1000; + time.tv_nsec = ms * 1e+6; nanosleep(&time, NULL); #else @@ -6084,32 +6336,31 @@ static HMODULE wglinstance = NULL; #endif } - static float currentFrameTime = 0; - void RGFW_window_checkFPS(RGFW_window* win) { - assert(win != NULL); - - win->event.fps = RGFW_getFPS(); + u64 deltaTime = RGFW_getTimeNS() - win->event.frameTime; - if (win->fpsCap == 0) - return; + u64 fps = round(1e+9 / deltaTime); + win->event.fps = fps; - double targetFrameTime = 1.0 / win->fpsCap; - double elapsedTime = RGFW_getTime() - currentFrameTime; + if (win->fpsCap && fps > win->fpsCap) { + u64 frameTimeNS = 1e+9 / win->fpsCap; + u64 sleepTimeMS = (frameTimeNS - deltaTime) / 1e6; - if (elapsedTime < targetFrameTime) { - u32 sleepTime = (u32) ((targetFrameTime - elapsedTime) * 1e3); - RGFW_sleep(sleepTime); + if (sleepTimeMS > 0) { + RGFW_sleep(sleepTimeMS); + win->event.frameTime = 0; + } } - currentFrameTime = (float) RGFW_getTime(); + win->event.frameTime = RGFW_getTimeNS(); + + if (win->fpsCap) { + u64 deltaTime = RGFW_getTimeNS() - win->event.frameTime2; - if (elapsedTime < targetFrameTime) { - u32 sleepTime = (u32) ((targetFrameTime - elapsedTime) * 1e3); - RGFW_sleep(sleepTime); + win->event.fps = round(1e+9 / deltaTime); + + win->event.frameTime2 = RGFW_getTimeNS(); } - - currentFrameTime = (float) RGFW_getTime(); } #ifdef __APPLE__ @@ -6127,7 +6378,7 @@ static HMODULE wglinstance = NULL; return (u64) (counter.QuadPart * 1e9 / frequency.QuadPart); #elif defined(__unix__) struct timespec ts = { 0 }; - clock_gettime(CLOCK_MONOTONIC, &ts); + clock_gettime(1, &ts); unsigned long long int nanoSeconds = (unsigned long long int)ts.tv_sec*1000000000LLU + (unsigned long long int)ts.tv_nsec; return nanoSeconds; @@ -6151,7 +6402,7 @@ static HMODULE wglinstance = NULL; return (u64) (counter.QuadPart / (double) frequency.QuadPart); #elif defined(__unix__) struct timespec ts = { 0 }; - clock_gettime(CLOCK_MONOTONIC, &ts); + clock_gettime(1, &ts); unsigned long long int nanoSeconds = (unsigned long long int)ts.tv_sec*1000000000LLU + (unsigned long long int)ts.tv_nsec; return (double)(nanoSeconds) * 1e-9; @@ -6165,27 +6416,6 @@ static HMODULE wglinstance = NULL; return 0; } - u32 RGFW_getFPS(void) { - static double previousSeconds = 0.0; - if (previousSeconds == 0.0) - previousSeconds = (double) RGFW_getTime();//glfwGetTime(); - - static i16 frameCount; - double currentSeconds = (double) RGFW_getTime();//glfwGetTime(); - double elapsedSeconds = currentSeconds - previousSeconds; - static double fps = 0; - - if (elapsedSeconds > 0.25) { - previousSeconds = currentSeconds; - fps = (double) frameCount / elapsedSeconds; - frameCount = 0; - } - - frameCount++; - - return (u32) fps; - } - #endif /*RGFW_IMPLEMENTATION*/ #define RGFW_Escape RGFW_OS_BASED_VALUE(0xff1b, 0x1B, 53) diff --git a/src/raylib/external/jar_xm.h b/src/raylib/external/jar_xm.h index a9dcc5c..4a1bfbf 100644 --- a/src/raylib/external/jar_xm.h +++ b/src/raylib/external/jar_xm.h @@ -2373,23 +2373,23 @@ void jar_xm_debug(jar_xm_context_t *ctx) { int x = 0, y = 0; // DEBUG VARIABLES - y += size; rlDrawText(TextFormat("CUR TBL = %i", ctx->current_table_index), x, y, size, WHITE); - y += size; rlDrawText(TextFormat("CUR PAT = %i", ctx->module.pattern_table[ctx->current_table_index]), x, y, size, WHITE); - y += size; rlDrawText(TextFormat("POS JMP = %d", ctx->position_jump), x, y, size, WHITE); - y += size; rlDrawText(TextFormat("JMP DST = %i", ctx->jump_dest), x, y, size, WHITE); - y += size; rlDrawText(TextFormat("PTN BRK = %d", ctx->pattern_break), x, y, size, WHITE); - y += size; rlDrawText(TextFormat("CUR ROW = %i", ctx->current_row), x, y, size, WHITE); - y += size; rlDrawText(TextFormat("JMP ROW = %i", ctx->jump_row), x, y, size, WHITE); - y += size; rlDrawText(TextFormat("ROW LCT = %i", ctx->row_loop_count), x, y, size, WHITE); - y += size; rlDrawText(TextFormat("LCT = %i", ctx->loop_count), x, y, size, WHITE); - y += size; rlDrawText(TextFormat("MAX LCT = %i", ctx->max_loop_count), x, y, size, WHITE); + y += size; DrawText(TextFormat("CUR TBL = %i", ctx->current_table_index), x, y, size, WHITE); + y += size; DrawText(TextFormat("CUR PAT = %i", ctx->module.pattern_table[ctx->current_table_index]), x, y, size, WHITE); + y += size; DrawText(TextFormat("POS JMP = %d", ctx->position_jump), x, y, size, WHITE); + y += size; DrawText(TextFormat("JMP DST = %i", ctx->jump_dest), x, y, size, WHITE); + y += size; DrawText(TextFormat("PTN BRK = %d", ctx->pattern_break), x, y, size, WHITE); + y += size; DrawText(TextFormat("CUR ROW = %i", ctx->current_row), x, y, size, WHITE); + y += size; DrawText(TextFormat("JMP ROW = %i", ctx->jump_row), x, y, size, WHITE); + y += size; DrawText(TextFormat("ROW LCT = %i", ctx->row_loop_count), x, y, size, WHITE); + y += size; DrawText(TextFormat("LCT = %i", ctx->loop_count), x, y, size, WHITE); + y += size; DrawText(TextFormat("MAX LCT = %i", ctx->max_loop_count), x, y, size, WHITE); x = size * 12; y = 0; - y += size; rlDrawText(TextFormat("CUR TCK = %i", ctx->current_tick), x, y, size, WHITE); - y += size; rlDrawText(TextFormat("XTR TCK = %i", ctx->extra_ticks), x, y, size, WHITE); - y += size; rlDrawText(TextFormat("TCK/ROW = %i", ctx->tempo), x, y, size, ORANGE); - y += size; rlDrawText(TextFormat("SPL TCK = %f", ctx->remaining_samples_in_tick), x, y, size, WHITE); - y += size; rlDrawText(TextFormat("GEN SPL = %i", ctx->generated_samples), x, y, size, WHITE); + y += size; DrawText(TextFormat("CUR TCK = %i", ctx->current_tick), x, y, size, WHITE); + y += size; DrawText(TextFormat("XTR TCK = %i", ctx->extra_ticks), x, y, size, WHITE); + y += size; DrawText(TextFormat("TCK/ROW = %i", ctx->tempo), x, y, size, ORANGE); + y += size; DrawText(TextFormat("SPL TCK = %f", ctx->remaining_samples_in_tick), x, y, size, WHITE); + y += size; DrawText(TextFormat("GEN SPL = %i", ctx->generated_samples), x, y, size, WHITE); y += size * 7; x = 0; @@ -2404,13 +2404,13 @@ void jar_xm_debug(jar_xm_context_t *ctx) { }; }; if (i == ctx->current_table_index) { -// rlDrawText(TextFormat("%02X", ctx->current_tick), i * size * 2, y - size, size, WHITE); +// DrawText(TextFormat("%02X", ctx->current_tick), i * size * 2, y - size, size, WHITE); DrawRectangle(i * size * 2, y, size * 2, size, RED); - rlDrawText(TextFormat("%02X", ctx->current_row), i * size * 2, y - size, size, YELLOW); + DrawText(TextFormat("%02X", ctx->current_row), i * size * 2, y - size, size, YELLOW); } else { DrawRectangle(i * size * 2, y, size * 2, size, ORANGE); }; - rlDrawText(TextFormat("%02X", ctx->module.pattern_table[i]), i * size * 2, y, size, WHITE); + DrawText(TextFormat("%02X", ctx->module.pattern_table[i]), i * size * 2, y, size, WHITE); }; y += size; @@ -2421,10 +2421,10 @@ void jar_xm_debug(jar_xm_context_t *ctx) { x += 2 * size; for(uint8_t i = 0; i < ctx->module.num_channels; i++) { DrawRectangle(x, y, 8 * size, size, PURPLE); - rlDrawText("N", x, y, size, YELLOW); - rlDrawText("I", x + size * 2, y, size, YELLOW); - rlDrawText("V", x + size * 4, y, size, YELLOW); - rlDrawText("FX", x + size * 6, y, size, YELLOW); + DrawText("N", x, y, size, YELLOW); + DrawText("I", x + size * 2, y, size, YELLOW); + DrawText("V", x + size * 4, y, size, YELLOW); + DrawText("FX", x + size * 6, y, size, YELLOW); x += 9 * size; }; x += size; @@ -2433,7 +2433,7 @@ void jar_xm_debug(jar_xm_context_t *ctx) { x = 0; if (j >=0 && j < (cur->num_rows)) { DrawRectangle(x, y, size * 2, size, BROWN); - rlDrawText(TextFormat("%02X",j), x, y, size, WHITE); + DrawText(TextFormat("%02X",j), x, y, size, WHITE); x += 2 * size; for(uint8_t i = 0; i < ctx->module.num_channels; i++) { if (j==(ctx->current_row)) { @@ -2443,20 +2443,20 @@ void jar_xm_debug(jar_xm_context_t *ctx) { }; jar_xm_pattern_slot_t *s = cur->slots + j * ctx->module.num_channels + i; // jar_xm_channel_context_t *ch = ctx->channels + i; - if (s->note > 0) {rlDrawText(TextFormat("%s%s", xm_note_chr(s->note), xm_octave_chr(s->note) ), x, y, size, WHITE);} else {rlDrawText("...", x, y, size, GRAY);}; + if (s->note > 0) {DrawText(TextFormat("%s%s", xm_note_chr(s->note), xm_octave_chr(s->note) ), x, y, size, WHITE);} else {DrawText("...", x, y, size, GRAY);}; if (s->instrument > 0) { - rlDrawText(TextFormat("%02X", s->instrument), x + size * 2, y, size, WHITE); + DrawText(TextFormat("%02X", s->instrument), x + size * 2, y, size, WHITE); if (s->volume_column == 0) { - rlDrawText(TextFormat("%02X", 64), x + size * 4, y, size, YELLOW); + DrawText(TextFormat("%02X", 64), x + size * 4, y, size, YELLOW); }; } else { - rlDrawText("..", x + size * 2, y, size, GRAY); + DrawText("..", x + size * 2, y, size, GRAY); if (s->volume_column == 0) { - rlDrawText("..", x + size * 4, y, size, GRAY); + DrawText("..", x + size * 4, y, size, GRAY); }; }; - if (s->volume_column > 0) {rlDrawText(TextFormat("%02X", (s->volume_column - 16)), x + size * 4, y, size, WHITE);}; - if (s->effect_type > 0 || s->effect_param > 0) {rlDrawText(TextFormat("%s%02X", xm_effect_chr(s->effect_type), s->effect_param), x + size * 6, y, size, WHITE);}; + if (s->volume_column > 0) {DrawText(TextFormat("%02X", (s->volume_column - 16)), x + size * 4, y, size, WHITE);}; + if (s->effect_type > 0 || s->effect_param > 0) {DrawText(TextFormat("%s%02X", xm_effect_chr(s->effect_type), s->effect_param), x + size * 6, y, size, WHITE);}; x += 9 * size; }; }; diff --git a/src/raylib/platforms/rcore_android.c b/src/raylib/platforms/rcore_android.c index 5f38019..d8568d9 100644 --- a/src/raylib/platforms/rcore_android.c +++ b/src/raylib/platforms/rcore_android.c @@ -515,7 +515,7 @@ const char *GetClipboardText(void) } // Show mouse cursor -void rlShowCursor(void) +void ShowCursor(void) { CORE.Input.Mouse.cursorHidden = false; } @@ -989,16 +989,16 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd) #if defined(SUPPORT_MODULE_RSHAPES) // Set font white rectangle for shapes drawing, so shapes and text can be batched together // WARNING: rshapes module is required, if not available, default internal white rectangle is used - rlRectangle rec = GetFontDefault().recs[95]; + Rectangle rec = GetFontDefault().recs[95]; if (CORE.Window.flags & FLAG_MSAA_4X_HINT) { // NOTE: We try to maxime rec padding to avoid pixel bleeding on MSAA filtering - SetShapesTexture(GetFontDefault().texture, (rlRectangle){ rec.x + 2, rec.y + 2, 1, 1 }); + SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 2, rec.y + 2, 1, 1 }); } else { // NOTE: We set up a 1px padding on char rectangle to avoid pixel bleeding - SetShapesTexture(GetFontDefault().texture, (rlRectangle){ rec.x + 1, rec.y + 1, rec.width - 2, rec.height - 2 }); + SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 1, rec.y + 1, rec.width - 2, rec.height - 2 }); } #endif #else @@ -1006,7 +1006,7 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd) // Set default texture and rectangle to be used for shapes drawing // NOTE: rlgl default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8 Texture2D texture = { rlGetTextureIdDefault(), 1, 1, 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 }; - SetShapesTexture(texture, (rlRectangle){ 0.0f, 0.0f, 1.0f, 1.0f }); // WARNING: Module required: rshapes + SetShapesTexture(texture, (Rectangle){ 0.0f, 0.0f, 1.0f, 1.0f }); // WARNING: Module required: rshapes #endif #endif diff --git a/src/raylib/platforms/rcore_desktop.c b/src/raylib/platforms/rcore_desktop.c index 6d05f40..6fe054a 100644 --- a/src/raylib/platforms/rcore_desktop.c +++ b/src/raylib/platforms/rcore_desktop.c @@ -951,7 +951,7 @@ const char *GetClipboardText(void) } // Show mouse cursor -void rlShowCursor(void) +void ShowCursor(void) { glfwSetInputMode(platform.handle, GLFW_CURSOR, GLFW_CURSOR_NORMAL); CORE.Input.Mouse.cursorHidden = false; diff --git a/src/raylib/platforms/rcore_desktop_rgfw.c b/src/raylib/platforms/rcore_desktop_rgfw.c index 623dc0e..f4e3174 100644 --- a/src/raylib/platforms/rcore_desktop_rgfw.c +++ b/src/raylib/platforms/rcore_desktop_rgfw.c @@ -431,7 +431,11 @@ void SetWindowFocused(void) // Get native window handle void *GetWindowHandle(void) { - return platform.window->src.window; + #ifndef RGFW_WINDOWS + return (void*)platform.window->src.window; + #else + return platform.window->src.hwnd; + #endif } // Get number of monitors @@ -890,8 +894,6 @@ void PollInputEvents(void) CORE.Input.Mouse.currentPosition.x = (event->point.x - (platform.window->r.w / 2)) * 2; CORE.Input.Mouse.currentPosition.y = (event->point.y - (platform.window->r.h / 2)) * 2; - - RGFW_window_showMouse(platform.window, 1); } else { CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition; diff --git a/src/raylib/platforms/rcore_desktop_sdl.c b/src/raylib/platforms/rcore_desktop_sdl.c index 84462ae..c22150e 100644 --- a/src/raylib/platforms/rcore_desktop_sdl.c +++ b/src/raylib/platforms/rcore_desktop_sdl.c @@ -864,7 +864,7 @@ const char *GetClipboardText(void) } // Show mouse cursor -void rlShowCursor(void) +void ShowCursor(void) { SDL_ShowCursor(SDL_ENABLE); diff --git a/src/raylib/platforms/rcore_drm.c b/src/raylib/platforms/rcore_drm.c index 4c84cc0..ba60714 100644 --- a/src/raylib/platforms/rcore_drm.c +++ b/src/raylib/platforms/rcore_drm.c @@ -119,7 +119,7 @@ typedef struct { char currentButtonStateEvdev[MAX_MOUSE_BUTTONS]; // Holds the new mouse state for the next polling event to grab bool cursorRelative; // Relative cursor mode int mouseFd; // File descriptor for the evdev mouse/touch/gestures - rlRectangle absRange; // Range of values for absolute pointing devices (touchscreens) + Rectangle absRange; // Range of values for absolute pointing devices (touchscreens) int touchSlot; // Hold the touch slot number of the currently being sent multitouch block // Gamepad data @@ -510,7 +510,7 @@ const char *GetClipboardText(void) } // Show mouse cursor -void rlShowCursor(void) +void ShowCursor(void) { CORE.Input.Mouse.cursorHidden = false; } diff --git a/src/raylib/platforms/rcore_template.c b/src/raylib/platforms/rcore_template.c index 65bf34d..7a48c46 100644 --- a/src/raylib/platforms/rcore_template.c +++ b/src/raylib/platforms/rcore_template.c @@ -293,7 +293,7 @@ const char *GetClipboardText(void) } // Show mouse cursor -void rlShowCursor(void) +void ShowCursor(void) { CORE.Input.Mouse.cursorHidden = false; } diff --git a/src/raylib/platforms/rcore_web.c b/src/raylib/platforms/rcore_web.c index 233feb7..afe8adf 100644 --- a/src/raylib/platforms/rcore_web.c +++ b/src/raylib/platforms/rcore_web.c @@ -768,7 +768,7 @@ const char *GetClipboardText(void) } // Show mouse cursor -void rlShowCursor(void) +void ShowCursor(void) { if (CORE.Input.Mouse.cursorHidden) { diff --git a/src/raylib/raudio.c b/src/raylib/raudio.c index c6bd001..623984e 100644 --- a/src/raylib/raudio.c +++ b/src/raylib/raudio.c @@ -1304,8 +1304,8 @@ float *LoadWaveSamples(Wave wave) for (unsigned int i = 0; i < wave.frameCount*wave.channels; i++) { - if (wave.sampleSize == 8) samples[i] = (float)(((unsigned char *)wave.data)[i] - 127)/256.0f; - else if (wave.sampleSize == 16) samples[i] = (float)(((short *)wave.data)[i])/32767.0f; + if (wave.sampleSize == 8) samples[i] = (float)(((unsigned char *)wave.data)[i] - 128)/128.0f; + else if (wave.sampleSize == 16) samples[i] = (float)(((short *)wave.data)[i])/32768.0f; else if (wave.sampleSize == 32) samples[i] = ((float *)wave.data)[i]; } @@ -1428,7 +1428,9 @@ Music LoadMusicStream(const char *fileName) { music.ctxType = MUSIC_AUDIO_FLAC; music.ctxData = ctxFlac; - music.stream = LoadAudioStream(ctxFlac->sampleRate, ctxFlac->bitsPerSample, ctxFlac->channels); + int sampleSize = ctxFlac->bitsPerSample; + if (ctxFlac->bitsPerSample == 24) sampleSize = 16; // Forcing conversion to s16 on UpdateMusicStream() + music.stream = LoadAudioStream(ctxFlac->sampleRate, sampleSize, ctxFlac->channels); music.frameCount = (unsigned int)ctxFlac->totalPCMFrameCount; music.looping = true; // Looping enabled by default musicLoaded = true; diff --git a/src/raylib/raylib.h b/src/raylib/raylib.h index f3cc0f8..9f06462 100644 --- a/src/raylib/raylib.h +++ b/src/raylib/raylib.h @@ -246,12 +246,12 @@ typedef struct Color { } Color; // Rectangle, 4 components -typedef struct rlRectangle { +typedef struct Rectangle { float x; // Rectangle top-left corner position x float y; // Rectangle top-left corner position y float width; // Rectangle width float height; // Rectangle height -} rlRectangle; +} Rectangle; // Image, pixel data stored in CPU memory (RAM) typedef struct Image { @@ -289,7 +289,7 @@ typedef RenderTexture RenderTexture2D; // NPatchInfo, n-patch layout info typedef struct NPatchInfo { - rlRectangle source; // Texture source rectangle + Rectangle source; // Texture source rectangle int left; // Left border offset int top; // Top border offset int right; // Right border offset @@ -312,7 +312,7 @@ typedef struct Font { int glyphCount; // Number of glyph characters int glyphPadding; // Padding around the glyph characters Texture2D texture; // Texture atlas containing the glyphs - rlRectangle *recs; // Rectangles in texture for the glyphs + Rectangle *recs; // Rectangles in texture for the glyphs GlyphInfo *glyphs; // Glyphs info data } Font; @@ -956,7 +956,7 @@ extern "C" { // Prevents name mangling of functions // Window-related functions RLAPI void InitWindow(int width, int height, const char *title); // Initialize window and OpenGL context -RLAPI void rlCloseWindow(void); // Close window and unload OpenGL context +RLAPI void CloseWindow(void); // Close window and unload OpenGL context RLAPI bool WindowShouldClose(void); // Check if application should close (KEY_ESCAPE pressed or windows close icon clicked) RLAPI bool IsWindowReady(void); // Check if window has been initialized successfully RLAPI bool IsWindowFullscreen(void); // Check if window is currently fullscreen @@ -1005,7 +1005,7 @@ RLAPI void EnableEventWaiting(void); // Enable wait RLAPI void DisableEventWaiting(void); // Disable waiting for events on EndDrawing(), automatic events polling // Cursor-related functions -RLAPI void rlShowCursor(void); // Shows cursor +RLAPI void ShowCursor(void); // Shows cursor RLAPI void HideCursor(void); // Hides cursor RLAPI bool IsCursorHidden(void); // Check if cursor is not visible RLAPI void EnableCursor(void); // Enables cursor (unlock cursor) @@ -1141,7 +1141,7 @@ RLAPI unsigned char *DecodeDataBase64(const unsigned char *data, int *outputSize // Automation events functionality RLAPI AutomationEventList LoadAutomationEventList(const char *fileName); // Load automation events list from file, NULL for empty list, capacity = MAX_AUTOMATION_EVENTS -RLAPI void UnloadAutomationEventList(AutomationEventList list); // Unload automation events list from file +RLAPI void UnloadAutomationEventList(AutomationEventList list); // Unload automation events list from file RLAPI bool ExportAutomationEventList(AutomationEventList list, const char *fileName); // Export automation events list as text file RLAPI void SetAutomationEventList(AutomationEventList *list); // Set automation event list to record to RLAPI void SetAutomationEventBaseFrame(int frame); // Set automation event internal base frame to start recording @@ -1223,9 +1223,9 @@ RLAPI void UpdateCameraPro(Camera *camera, Vector3 movement, Vector3 rotation, f // Set texture and rectangle to be used on shapes drawing // NOTE: It can be useful when using basic shapes and one single font, // defining a font char white rectangle would allow drawing everything in a single draw call -RLAPI void SetShapesTexture(Texture2D texture, rlRectangle source); // Set texture and rectangle to be used on shapes drawing +RLAPI void SetShapesTexture(Texture2D texture, Rectangle source); // Set texture and rectangle to be used on shapes drawing RLAPI Texture2D GetShapesTexture(void); // Get texture that is used for shapes drawing -RLAPI rlRectangle GetShapesTextureRectangle(void); // Get texture source rectangle that is used for shapes drawing +RLAPI Rectangle GetShapesTextureRectangle(void); // Get texture source rectangle that is used for shapes drawing // Basic shapes drawing functions RLAPI void DrawPixel(int posX, int posY, Color color); // Draw a pixel @@ -1233,7 +1233,7 @@ RLAPI void DrawPixelV(Vector2 position, Color color); RLAPI void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line RLAPI void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (using gl lines) RLAPI void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw a line (using triangles/quads) -RLAPI void DrawLineStrip(Vector2 *points, int pointCount, Color color); // Draw lines sequence (using gl lines) +RLAPI void DrawLineStrip(const Vector2 *points, int pointCount, Color color); // Draw lines sequence (using gl lines) RLAPI void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw line segment cubic-bezier in-out interpolation RLAPI void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle RLAPI void DrawCircleSector(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color); // Draw a piece of a circle @@ -1248,30 +1248,30 @@ RLAPI void DrawRing(Vector2 center, float innerRadius, float outerRadius, float RLAPI void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color); // Draw ring outline RLAPI void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle RLAPI void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version) -RLAPI void DrawRectangleRec(rlRectangle rec, Color color); // Draw a color-filled rectangle -RLAPI void DrawRectanglePro(rlRectangle rec, Vector2 origin, float rotation, Color color); // Draw a color-filled rectangle with pro parameters +RLAPI void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle +RLAPI void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color); // Draw a color-filled rectangle with pro parameters RLAPI void DrawRectangleGradientV(int posX, int posY, int width, int height, Color color1, Color color2);// Draw a vertical-gradient-filled rectangle RLAPI void DrawRectangleGradientH(int posX, int posY, int width, int height, Color color1, Color color2);// Draw a horizontal-gradient-filled rectangle -RLAPI void DrawRectangleGradientEx(rlRectangle rec, Color col1, Color col2, Color col3, Color col4); // Draw a gradient-filled rectangle with custom vertex colors +RLAPI void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3, Color col4); // Draw a gradient-filled rectangle with custom vertex colors RLAPI void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline -RLAPI void DrawRectangleLinesEx(rlRectangle rec, float lineThick, Color color); // Draw rectangle outline with extended parameters -RLAPI void DrawRectangleRounded(rlRectangle rec, float roundness, int segments, Color color); // Draw rectangle with rounded edges -RLAPI void DrawRectangleRoundedLines(rlRectangle rec, float roundness, int segments, Color color); // Draw rectangle lines with rounded edges -RLAPI void DrawRectangleRoundedLinesEx(rlRectangle rec, float roundness, int segments, float lineThick, Color color); // Draw rectangle with rounded edges outline +RLAPI void DrawRectangleLinesEx(Rectangle rec, float lineThick, Color color); // Draw rectangle outline with extended parameters +RLAPI void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color color); // Draw rectangle with rounded edges +RLAPI void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, Color color); // Draw rectangle lines with rounded edges +RLAPI void DrawRectangleRoundedLinesEx(Rectangle rec, float roundness, int segments, float lineThick, Color color); // Draw rectangle with rounded edges outline RLAPI void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle (vertex in counter-clockwise order!) RLAPI void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline (vertex in counter-clockwise order!) -RLAPI void DrawTriangleFan(Vector2 *points, int pointCount, Color color); // Draw a triangle fan defined by points (first vertex is the center) -RLAPI void DrawTriangleStrip(Vector2 *points, int pointCount, Color color); // Draw a triangle strip defined by points +RLAPI void DrawTriangleFan(const Vector2 *points, int pointCount, Color color); // Draw a triangle fan defined by points (first vertex is the center) +RLAPI void DrawTriangleStrip(const Vector2 *points, int pointCount, Color color); // Draw a triangle strip defined by points RLAPI void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a regular polygon (Vector version) RLAPI void DrawPolyLines(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a polygon outline of n sides RLAPI void DrawPolyLinesEx(Vector2 center, int sides, float radius, float rotation, float lineThick, Color color); // Draw a polygon outline of n sides with extended parameters // Splines drawing functions -RLAPI void DrawSplineLinear(Vector2 *points, int pointCount, float thick, Color color); // Draw spline: Linear, minimum 2 points -RLAPI void DrawSplineBasis(Vector2 *points, int pointCount, float thick, Color color); // Draw spline: B-Spline, minimum 4 points -RLAPI void DrawSplineCatmullRom(Vector2 *points, int pointCount, float thick, Color color); // Draw spline: Catmull-Rom, minimum 4 points -RLAPI void DrawSplineBezierQuadratic(Vector2 *points, int pointCount, float thick, Color color); // Draw spline: Quadratic Bezier, minimum 3 points (1 control point): [p1, c2, p3, c4...] -RLAPI void DrawSplineBezierCubic(Vector2 *points, int pointCount, float thick, Color color); // Draw spline: Cubic Bezier, minimum 4 points (2 control points): [p1, c2, c3, p4, c5, c6...] +RLAPI void DrawSplineLinear(const Vector2 *points, int pointCount, float thick, Color color); // Draw spline: Linear, minimum 2 points +RLAPI void DrawSplineBasis(const Vector2 *points, int pointCount, float thick, Color color); // Draw spline: B-Spline, minimum 4 points +RLAPI void DrawSplineCatmullRom(const Vector2 *points, int pointCount, float thick, Color color); // Draw spline: Catmull-Rom, minimum 4 points +RLAPI void DrawSplineBezierQuadratic(const Vector2 *points, int pointCount, float thick, Color color); // Draw spline: Quadratic Bezier, minimum 3 points (1 control point): [p1, c2, p3, c4...] +RLAPI void DrawSplineBezierCubic(const Vector2 *points, int pointCount, float thick, Color color); // Draw spline: Cubic Bezier, minimum 4 points (2 control points): [p1, c2, c3, p4, c5, c6...] RLAPI void DrawSplineSegmentLinear(Vector2 p1, Vector2 p2, float thick, Color color); // Draw spline segment: Linear, 2 points RLAPI void DrawSplineSegmentBasis(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float thick, Color color); // Draw spline segment: B-Spline, 4 points RLAPI void DrawSplineSegmentCatmullRom(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float thick, Color color); // Draw spline segment: Catmull-Rom, 4 points @@ -1286,17 +1286,17 @@ RLAPI Vector2 GetSplinePointBezierQuad(Vector2 p1, Vector2 c2, Vector2 p3, float RLAPI Vector2 GetSplinePointBezierCubic(Vector2 p1, Vector2 c2, Vector2 c3, Vector2 p4, float t); // Get (evaluate) spline point: Cubic Bezier // Basic shapes collision detection functions -RLAPI bool CheckCollisionRecs(rlRectangle rec1, rlRectangle rec2); // Check collision between two rectangles +RLAPI bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles RLAPI bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles -RLAPI bool CheckCollisionCircleRec(Vector2 center, float radius, rlRectangle rec); // Check collision between circle and rectangle -RLAPI bool CheckCollisionPointRec(Vector2 point, rlRectangle rec); // Check if point is inside rectangle +RLAPI bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle +RLAPI bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle RLAPI bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle RLAPI bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); // Check if point is inside a triangle -RLAPI bool CheckCollisionPointPoly(Vector2 point, Vector2 *points, int pointCount); // Check if point is within a polygon described by array of vertices +RLAPI bool CheckCollisionPointPoly(Vector2 point, const Vector2 *points, int pointCount); // Check if point is within a polygon described by array of vertices RLAPI bool CheckCollisionLines(Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2, Vector2 *collisionPoint); // Check the collision between two lines defined by two points each, returns collision point by reference RLAPI bool CheckCollisionPointLine(Vector2 point, Vector2 p1, Vector2 p2, int threshold); // Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold] RLAPI bool CheckCollisionCircleLine(Vector2 center, float radius, Vector2 p1, Vector2 p2); // Check if circle collides with a line created betweeen two points [p1] and [p2] -RLAPI rlRectangle GetCollisionRec(rlRectangle rec1, rlRectangle rec2); // Get collision rectangle for two rectangles collision +RLAPI Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision //------------------------------------------------------------------------------------ // Texture Loading and Drawing Functions (Module: textures) @@ -1304,7 +1304,7 @@ RLAPI rlRectangle GetCollisionRec(rlRectangle rec1, rlRectangle rec2); // Image loading functions // NOTE: These functions do not require GPU access -RLAPI Image rlLoadImage(const char *fileName); // Load image from file into CPU memory (RAM) +RLAPI Image LoadImage(const char *fileName); // Load image from file into CPU memory (RAM) RLAPI Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image from RAW file data RLAPI Image LoadImageSvg(const char *fileNameOrString, int width, int height); // Load image from SVG file data or string with specified size RLAPI Image LoadImageAnim(const char *fileName, int *frames); // Load image sequence from file (frames appended to image.data) @@ -1331,21 +1331,21 @@ RLAPI Image GenImageText(int width, int height, const char *text); // Image manipulation functions RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) -RLAPI Image ImageFromImage(Image image, rlRectangle rec); // Create an image from another image piece +RLAPI Image ImageFromImage(Image image, Rectangle rec); // Create an image from another image piece RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) RLAPI Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Color tint); // Create an image from text (custom sprite font) RLAPI void ImageFormat(Image *image, int newFormat); // Convert image data to desired format RLAPI void ImageToPOT(Image *image, Color fill); // Convert image to POT (power-of-two) -RLAPI void ImageCrop(Image *image, rlRectangle crop); // Crop an image to a defined rectangle +RLAPI void ImageCrop(Image *image, Rectangle crop); // Crop an image to a defined rectangle RLAPI void ImageAlphaCrop(Image *image, float threshold); // Crop image depending on alpha value RLAPI void ImageAlphaClear(Image *image, Color color, float threshold); // Clear alpha channel to desired color RLAPI void ImageAlphaMask(Image *image, Image alphaMask); // Apply alpha mask to image RLAPI void ImageAlphaPremultiply(Image *image); // Premultiply alpha channel RLAPI void ImageBlurGaussian(Image *image, int blurSize); // Apply Gaussian blur using a box blur approximation -RLAPI void ImageKernelConvolution(Image *image, float* kernel, int kernelSize); // Apply Custom Square image convolution kernel +RLAPI void ImageKernelConvolution(Image *image, float *kernel, int kernelSize); // Apply Custom Square image convolution kernel RLAPI void ImageResize(Image *image, int newWidth, int newHeight); // Resize image (Bicubic scaling algorithm) RLAPI void ImageResizeNN(Image *image, int newWidth,int newHeight); // Resize image (Nearest-Neighbor scaling algorithm) -RLAPI void ImageResizeCanvas(Image *image, int newWidth, int newHeight, int offsetX, int offsetY, Color fill); // Resize canvas and fill with color +RLAPI void ImageResizeCanvas(Image *image, int newWidth, int newHeight, int offsetX, int offsetY, Color fill); // Resize canvas and fill with color RLAPI void ImageMipmaps(Image *image); // Compute all mipmap levels for a provided image RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) RLAPI void ImageFlipVertical(Image *image); // Flip image vertically @@ -1363,7 +1363,7 @@ RLAPI Color *LoadImageColors(Image image); RLAPI Color *LoadImagePalette(Image image, int maxPaletteSize, int *colorCount); // Load colors palette from image as a Color array (RGBA - 32bit) RLAPI void UnloadImageColors(Color *colors); // Unload color data loaded with LoadImageColors() RLAPI void UnloadImagePalette(Color *colors); // Unload colors palette loaded with LoadImagePalette() -RLAPI rlRectangle GetImageAlphaBorder(Image image, float threshold); // Get image alpha border rectangle +RLAPI Rectangle GetImageAlphaBorder(Image image, float threshold); // Get image alpha border rectangle RLAPI Color GetImageColor(Image image, int x, int y); // Get image pixel color at (x, y) position // Image drawing functions @@ -1379,9 +1379,9 @@ RLAPI void ImageDrawCircleLines(Image *dst, int centerX, int centerY, int radius RLAPI void ImageDrawCircleLinesV(Image *dst, Vector2 center, int radius, Color color); // Draw circle outline within an image (Vector version) RLAPI void ImageDrawRectangle(Image *dst, int posX, int posY, int width, int height, Color color); // Draw rectangle within an image RLAPI void ImageDrawRectangleV(Image *dst, Vector2 position, Vector2 size, Color color); // Draw rectangle within an image (Vector version) -RLAPI void ImageDrawRectangleRec(Image *dst, rlRectangle rec, Color color); // Draw rectangle within an image -RLAPI void ImageDrawRectangleLines(Image *dst, rlRectangle rec, int thick, Color color); // Draw rectangle lines within an image -RLAPI void ImageDraw(Image *dst, Image src, rlRectangle srcRec, rlRectangle dstRec, Color tint); // Draw a source image within a destination image (tint applied to source) +RLAPI void ImageDrawRectangleRec(Image *dst, Rectangle rec, Color color); // Draw rectangle within an image +RLAPI void ImageDrawRectangleLines(Image *dst, Rectangle rec, int thick, Color color); // Draw rectangle lines within an image +RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint); // Draw a source image within a destination image (tint applied to source) RLAPI void ImageDrawText(Image *dst, const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) within an image (destination) RLAPI void ImageDrawTextEx(Image *dst, Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text (custom sprite font) within an image (destination) @@ -1396,7 +1396,7 @@ RLAPI void UnloadTexture(Texture2D texture); RLAPI bool IsRenderTextureReady(RenderTexture2D target); // Check if a render texture is ready RLAPI void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory (VRAM) RLAPI void UpdateTexture(Texture2D texture, const void *pixels); // Update GPU texture with new data -RLAPI void UpdateTextureRec(Texture2D texture, rlRectangle rec, const void *pixels); // Update GPU texture rectangle with new data +RLAPI void UpdateTextureRec(Texture2D texture, Rectangle rec, const void *pixels); // Update GPU texture rectangle with new data // Texture configuration functions RLAPI void GenTextureMipmaps(Texture2D *texture); // Generate GPU mipmaps for a texture @@ -1407,9 +1407,9 @@ RLAPI void SetTextureWrap(Texture2D texture, int wrap); RLAPI void DrawTexture(Texture2D texture, int posX, int posY, Color tint); // Draw a Texture2D RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 RLAPI void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters -RLAPI void DrawTextureRec(Texture2D texture, rlRectangle source, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle -RLAPI void DrawTexturePro(Texture2D texture, rlRectangle source, rlRectangle dest, Vector2 origin, float rotation, Color tint); // Draw a part of a texture defined by a rectangle with 'pro' parameters -RLAPI void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, rlRectangle dest, Vector2 origin, float rotation, Color tint); // Draws a texture (or part of it) that stretches or shrinks nicely +RLAPI void DrawTextureRec(Texture2D texture, Rectangle source, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle +RLAPI void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint); // Draw a part of a texture defined by a rectangle with 'pro' parameters +RLAPI void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint); // Draws a texture (or part of it) that stretches or shrinks nicely // Color/pixel related functions RLAPI bool ColorIsEqual(Color col1, Color col2); // Check if two colors are equal @@ -1436,20 +1436,20 @@ RLAPI int GetPixelDataSize(int width, int height, int format); // G // Font loading/unloading functions RLAPI Font GetFontDefault(void); // Get the default Font RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM) -RLAPI Font LoadFontEx(const char *fileName, int fontSize, int *codepoints, int codepointCount); // Load font from file with extended parameters, use NULL for codepoints and 0 for codepointCount to load the default character set +RLAPI Font LoadFontEx(const char *fileName, int fontSize, int *codepoints, int codepointCount); // Load font from file with extended parameters, use NULL for codepoints and 0 for codepointCount to load the default character set RLAPI Font LoadFontFromImage(Image image, Color key, int firstChar); // Load font from Image (XNA style) RLAPI Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, int fontSize, int *codepoints, int codepointCount); // Load font from memory buffer, fileType refers to extension: i.e. '.ttf' RLAPI bool IsFontReady(Font font); // Check if a font is ready RLAPI GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSize, int *codepoints, int codepointCount, int type); // Load font data for further use -RLAPI Image GenImageFontAtlas(const GlyphInfo *glyphs, rlRectangle **glyphRecs, int glyphCount, int fontSize, int padding, int packMethod); // Generate image font atlas using chars info +RLAPI Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyphCount, int fontSize, int padding, int packMethod); // Generate image font atlas using chars info RLAPI void UnloadFontData(GlyphInfo *glyphs, int glyphCount); // Unload font chars info data (RAM) RLAPI void UnloadFont(Font font); // Unload font from GPU memory (VRAM) RLAPI bool ExportFontAsCode(Font font, const char *fileName); // Export font as code file, returns true on success // Text drawing functions RLAPI void DrawFPS(int posX, int posY); // Draw current FPS -RLAPI void rlDrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) -RLAPI void rlDrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using font and additional parameters +RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) +RLAPI void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using font and additional parameters RLAPI void DrawTextPro(Font font, const char *text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint); // Draw text using Font and pro parameters (rotation) RLAPI void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float fontSize, Color tint); // Draw one character (codepoint) RLAPI void DrawTextCodepoints(Font font, const int *codepoints, int codepointCount, Vector2 position, float fontSize, float spacing, Color tint); // Draw multiple character (codepoint) @@ -1460,7 +1460,7 @@ RLAPI int MeasureText(const char *text, int fontSize); RLAPI Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing); // Measure string size for Font RLAPI int GetGlyphIndex(Font font, int codepoint); // Get glyph index position in font for a codepoint (unicode character), fallback to '?' if not found RLAPI GlyphInfo GetGlyphInfo(Font font, int codepoint); // Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found -RLAPI rlRectangle GetGlyphAtlasRec(Font font, int codepoint); // Get glyph rectangle in font atlas for a codepoint (unicode character), fallback to '?' if not found +RLAPI Rectangle GetGlyphAtlasRec(Font font, int codepoint); // Get glyph rectangle in font atlas for a codepoint (unicode character), fallback to '?' if not found // Text codepoints management functions (unicode characters) RLAPI char *LoadUTF8(const int *codepoints, int length); // Load UTF-8 text encoded from codepoints array @@ -1504,7 +1504,7 @@ RLAPI void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color); RLAPI void DrawPoint3D(Vector3 position, Color color); // Draw a point in 3D space, actually a small line RLAPI void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color); // Draw a circle in 3D world space RLAPI void DrawTriangle3D(Vector3 v1, Vector3 v2, Vector3 v3, Color color); // Draw a color-filled triangle (vertex in counter-clockwise order!) -RLAPI void DrawTriangleStrip3D(Vector3 *points, int pointCount, Color color); // Draw a triangle strip defined by points +RLAPI void DrawTriangleStrip3D(const Vector3 *points, int pointCount, Color color); // Draw a triangle strip defined by points RLAPI void DrawCube(Vector3 position, float width, float height, float length, Color color); // Draw cube RLAPI void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) RLAPI void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires @@ -1540,8 +1540,8 @@ RLAPI void DrawModelWires(Model model, Vector3 position, float scale, Color tint RLAPI void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters RLAPI void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires) RLAPI void DrawBillboard(Camera camera, Texture2D texture, Vector3 position, float size, Color tint); // Draw a billboard texture -RLAPI void DrawBillboardRec(Camera camera, Texture2D texture, rlRectangle source, Vector3 position, Vector2 size, Color tint); // Draw a billboard texture defined by source -RLAPI void DrawBillboardPro(Camera camera, Texture2D texture, rlRectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint); // Draw a billboard texture defined by source and rotation +RLAPI void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint); // Draw a billboard texture defined by source +RLAPI void DrawBillboardPro(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint); // Draw a billboard texture defined by source and rotation // Mesh management functions RLAPI void UploadMesh(Mesh *mesh, bool dynamic); // Upload mesh vertex data in GPU and provide VAO/VBO ids diff --git a/src/raylib/rcore.c b/src/raylib/rcore.c index 53fe4d3..a4fc4d6 100644 --- a/src/raylib/rcore.c +++ b/src/raylib/rcore.c @@ -642,16 +642,16 @@ void InitWindow(int width, int height, const char *title) #if defined(SUPPORT_MODULE_RSHAPES) // Set font white rectangle for shapes drawing, so shapes and text can be batched together // WARNING: rshapes module is required, if not available, default internal white rectangle is used - rlRectangle rec = GetFontDefault().recs[95]; + Rectangle rec = GetFontDefault().recs[95]; if (CORE.Window.flags & FLAG_MSAA_4X_HINT) { // NOTE: We try to maxime rec padding to avoid pixel bleeding on MSAA filtering - SetShapesTexture(GetFontDefault().texture, (rlRectangle){ rec.x + 2, rec.y + 2, 1, 1 }); + SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 2, rec.y + 2, 1, 1 }); } else { // NOTE: We set up a 1px padding on char rectangle to avoid pixel bleeding - SetShapesTexture(GetFontDefault().texture, (rlRectangle){ rec.x + 1, rec.y + 1, rec.width - 2, rec.height - 2 }); + SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 1, rec.y + 1, rec.width - 2, rec.height - 2 }); } #endif #else @@ -659,7 +659,7 @@ void InitWindow(int width, int height, const char *title) // Set default texture and rectangle to be used for shapes drawing // NOTE: rlgl default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8 Texture2D texture = { rlGetTextureIdDefault(), 1, 1, 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 }; - SetShapesTexture(texture, (rlRectangle){ 0.0f, 0.0f, 1.0f, 1.0f }); // WARNING: Module required: rshapes + SetShapesTexture(texture, (Rectangle){ 0.0f, 0.0f, 1.0f, 1.0f }); // WARNING: Module required: rshapes #endif #endif #if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT) @@ -680,7 +680,7 @@ void InitWindow(int width, int height, const char *title) } // Close window and unload OpenGL context -void rlCloseWindow(void) +void CloseWindow(void) { #if defined(SUPPORT_GIF_RECORDING) if (gifRecording) @@ -882,7 +882,7 @@ void EndDrawing(void) if ((int)(GetTime()/0.5)%2 == 1) { DrawCircle(30, CORE.Window.screen.height - 20, 10, MAROON); // WARNING: Module required: rshapes - rlDrawText("GIF RECORDING", 50, CORE.Window.screen.height - 25, 10, RED); // WARNING: Module required: rtext + DrawText("GIF RECORDING", 50, CORE.Window.screen.height - 25, 10, RED); // WARNING: Module required: rtext } #endif @@ -2251,7 +2251,7 @@ bool IsFileNameValid(const char *fileName) if ((fileName != NULL) && (fileName[0] != '\0')) { - int length = strlen(fileName); + int length = (int)strlen(fileName); bool allPeriods = true; for (int i = 0; i < length; i++) diff --git a/src/raylib/rlgl.h b/src/raylib/rlgl.h index 2f6a03b..530e44e 100644 --- a/src/raylib/rlgl.h +++ b/src/raylib/rlgl.h @@ -4518,7 +4518,7 @@ Matrix rlGetMatrixTransform(void) } // Get internal projection matrix for stereo render (selected eye) -RLAPI Matrix rlGetMatrixProjectionStereo(int eye) +Matrix rlGetMatrixProjectionStereo(int eye) { Matrix mat = rlMatrixIdentity(); #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) @@ -4528,7 +4528,7 @@ RLAPI Matrix rlGetMatrixProjectionStereo(int eye) } // Get internal view offset matrix for stereo render (selected eye) -RLAPI Matrix rlGetMatrixViewOffsetStereo(int eye) +Matrix rlGetMatrixViewOffsetStereo(int eye) { Matrix mat = rlMatrixIdentity(); #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) diff --git a/src/raylib/rmodels.c b/src/raylib/rmodels.c index 07dc5cb..308fb0a 100644 --- a/src/raylib/rmodels.c +++ b/src/raylib/rmodels.c @@ -226,7 +226,7 @@ void DrawTriangle3D(Vector3 v1, Vector3 v2, Vector3 v3, Color color) } // Draw a triangle strip defined by points -void DrawTriangleStrip3D(Vector3 *points, int pointCount, Color color) +void DrawTriangleStrip3D(const Vector3 *points, int pointCount, Color color) { if (pointCount < 3) return; // Security check @@ -3436,7 +3436,12 @@ void GenMeshTangents(Mesh *mesh) Vector3 *tan1 = (Vector3 *)RL_MALLOC(mesh->vertexCount*sizeof(Vector3)); Vector3 *tan2 = (Vector3 *)RL_MALLOC(mesh->vertexCount*sizeof(Vector3)); - for (int i = 0; i < mesh->vertexCount - 3; i += 3) + if (mesh->vertexCount % 3 != 0) + { + TRACELOG(LOG_WARNING, "MESH: vertexCount expected to be a multiple of 3. Expect uninitialized values."); + } + + for (int i = 0; i <= mesh->vertexCount - 3; i += 3) { // Get triangle vertices Vector3 v1 = { mesh->vertices[(i + 0)*3 + 0], mesh->vertices[(i + 0)*3 + 1], mesh->vertices[(i + 0)*3 + 2] }; @@ -3585,13 +3590,13 @@ void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float // Draw a billboard void DrawBillboard(Camera camera, Texture2D texture, Vector3 position, float size, Color tint) { - rlRectangle source = { 0.0f, 0.0f, (float)texture.width, (float)texture.height }; + Rectangle source = { 0.0f, 0.0f, (float)texture.width, (float)texture.height }; DrawBillboardRec(camera, texture, source, position, (Vector2){ size, size }, tint); } // Draw a billboard (part of a texture defined by a rectangle) -void DrawBillboardRec(Camera camera, Texture2D texture, rlRectangle source, Vector3 position, Vector2 size, Color tint) +void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint) { // NOTE: Billboard locked on axis-Y Vector3 up = { 0.0f, 1.0f, 0.0f }; @@ -3601,7 +3606,7 @@ void DrawBillboardRec(Camera camera, Texture2D texture, rlRectangle source, Vect // Draw a billboard with additional parameters // NOTE: Size defines the destination rectangle size, stretching the source texture as required -void DrawBillboardPro(Camera camera, Texture2D texture, rlRectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint) +void DrawBillboardPro(Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint) { // NOTE: Billboard size will maintain source rectangle aspect ratio, size will represent billboard width Vector2 sizeRatio = { size.x*fabsf((float)source.width/source.height), size.y }; @@ -4825,7 +4830,7 @@ static Image LoadImageFromCgltfImage(cgltf_image *cgltfImage, const char *texPat } else // Check if image is provided as image path { - image = rlLoadImage(TextFormat("%s/%s", texPath, cgltfImage->uri)); + image = LoadImage(TextFormat("%s/%s", texPath, cgltfImage->uri)); } } else if (cgltfImage->buffer_view->buffer->data != NULL) // Check if image is provided as data buffer @@ -4864,7 +4869,7 @@ static BoneInfo *LoadBoneInfoGLTF(cgltf_skin skin, int *boneCount) for (unsigned int i = 0; i < skin.joints_count; i++) { cgltf_node node = *skin.joints[i]; - strncpy(bones[i].name, node.name, sizeof(bones[i].name)); + if (node.name != NULL) strncpy(bones[i].name, node.name, sizeof(bones[i].name)); // Find parent bone index unsigned int parentIndex = -1; @@ -5772,8 +5777,11 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, int *animCo animDuration = (t > animDuration)? t : animDuration; } - strncpy(animations[i].name, animData.name, sizeof(animations[i].name)); - animations[i].name[sizeof(animations[i].name) - 1] = '\0'; + if (animData.name != NULL) + { + strncpy(animations[i].name, animData.name, sizeof(animations[i].name)); + animations[i].name[sizeof(animations[i].name) - 1] = '\0'; + } animations[i].frameCount = (int)(animDuration*1000.0f/GLTF_ANIMDELAY) + 1; animations[i].framePoses = RL_MALLOC(animations[i].frameCount*sizeof(Transform *)); @@ -5823,7 +5831,7 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, int *animCo BuildPoseFromParentJoints(animations[i].bones, animations[i].boneCount, animations[i].framePoses[j]); } - TRACELOG(LOG_INFO, "MODEL: [%s] Loaded animation: %s (%d frames, %fs)", fileName, animData.name, animations[i].frameCount, animDuration); + TRACELOG(LOG_INFO, "MODEL: [%s] Loaded animation: %s (%d frames, %fs)", fileName, (animData.name != NULL)? animData.name : "NULL", animations[i].frameCount, animDuration); RL_FREE(boneChannels); } } diff --git a/src/raylib/rshapes.c b/src/raylib/rshapes.c index 5f442c7..95c5477 100644 --- a/src/raylib/rshapes.c +++ b/src/raylib/rshapes.c @@ -80,7 +80,7 @@ // Global Variables Definition //---------------------------------------------------------------------------------- Texture2D texShapes = { 1, 1, 1, 1, 7 }; // Texture used on shapes drawing (white pixel loaded by rlgl) -rlRectangle texShapesRec = { 0.0f, 0.0f, 1.0f, 1.0f }; // Texture source rectangle used on shapes drawing +Rectangle texShapesRec = { 0.0f, 0.0f, 1.0f, 1.0f }; // Texture source rectangle used on shapes drawing //---------------------------------------------------------------------------------- // Module specific Functions Declaration @@ -94,7 +94,7 @@ static float EaseCubicInOut(float t, float b, float c, float d); // Cubic eas // Set texture and rectangle to be used on shapes drawing // NOTE: It can be useful when using basic shapes and one single font, // defining a font char white rectangle would allow drawing everything in a single draw call -void SetShapesTexture(Texture2D texture, rlRectangle source) +void SetShapesTexture(Texture2D texture, Rectangle source) { // Reset texture to default pixel if required // WARNING: Shapes texture should be probably better validated, @@ -102,7 +102,7 @@ void SetShapesTexture(Texture2D texture, rlRectangle source) if ((texture.id == 0) || (source.width == 0) || (source.height == 0)) { texShapes = (Texture2D){ 1, 1, 1, 1, 7 }; - texShapesRec = (rlRectangle){ 0.0f, 0.0f, 1.0f, 1.0f }; + texShapesRec = (Rectangle){ 0.0f, 0.0f, 1.0f, 1.0f }; } else { @@ -118,7 +118,7 @@ Texture2D GetShapesTexture(void) } // Get texture source rectangle that is used for shapes drawing -rlRectangle GetShapesTextureRectangle(void) +Rectangle GetShapesTextureRectangle(void) { return texShapesRec; } @@ -134,7 +134,7 @@ void DrawPixelV(Vector2 position, Color color) { #if defined(SUPPORT_QUADS_DRAW_MODE) rlSetTexture(GetShapesTexture().id); - rlRectangle shapeRect = GetShapesTextureRectangle(); + Rectangle shapeRect = GetShapesTextureRectangle(); rlBegin(RL_QUADS); @@ -196,7 +196,7 @@ void DrawLineV(Vector2 startPos, Vector2 endPos, Color color) } // Draw lines sequuence (using gl lines) -void DrawLineStrip(Vector2 *points, int pointCount, Color color) +void DrawLineStrip(const Vector2 *points, int pointCount, Color color) { if (pointCount < 2) return; // Security check @@ -314,7 +314,7 @@ void DrawCircleSector(Vector2 center, float radius, float startAngle, float endA #if defined(SUPPORT_QUADS_DRAW_MODE) rlSetTexture(GetShapesTexture().id); - rlRectangle shapeRect = GetShapesTextureRectangle(); + Rectangle shapeRect = GetShapesTextureRectangle(); rlBegin(RL_QUADS); @@ -543,7 +543,7 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, float startA #if defined(SUPPORT_QUADS_DRAW_MODE) rlSetTexture(GetShapesTexture().id); - rlRectangle shapeRect = GetShapesTextureRectangle(); + Rectangle shapeRect = GetShapesTextureRectangle(); rlBegin(RL_QUADS); for (int i = 0; i < segments; i++) @@ -672,17 +672,17 @@ void DrawRectangle(int posX, int posY, int width, int height, Color color) // NOTE: On OpenGL 3.3 and ES2 we use QUADS to avoid drawing order issues void DrawRectangleV(Vector2 position, Vector2 size, Color color) { - DrawRectanglePro((rlRectangle){ position.x, position.y, size.x, size.y }, (Vector2){ 0.0f, 0.0f }, 0.0f, color); + DrawRectanglePro((Rectangle){ position.x, position.y, size.x, size.y }, (Vector2){ 0.0f, 0.0f }, 0.0f, color); } // Draw a color-filled rectangle -void DrawRectangleRec(rlRectangle rec, Color color) +void DrawRectangleRec(Rectangle rec, Color color) { DrawRectanglePro(rec, (Vector2){ 0.0f, 0.0f }, 0.0f, color); } // Draw a color-filled rectangle with pro parameters -void DrawRectanglePro(rlRectangle rec, Vector2 origin, float rotation, Color color) +void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color) { Vector2 topLeft = { 0 }; Vector2 topRight = { 0 }; @@ -723,7 +723,7 @@ void DrawRectanglePro(rlRectangle rec, Vector2 origin, float rotation, Color col #if defined(SUPPORT_QUADS_DRAW_MODE) rlSetTexture(GetShapesTexture().id); - rlRectangle shapeRect = GetShapesTextureRectangle(); + Rectangle shapeRect = GetShapesTextureRectangle(); rlBegin(RL_QUADS); @@ -766,22 +766,22 @@ void DrawRectanglePro(rlRectangle rec, Vector2 origin, float rotation, Color col // NOTE: Gradient goes from bottom (color1) to top (color2) void DrawRectangleGradientV(int posX, int posY, int width, int height, Color color1, Color color2) { - DrawRectangleGradientEx((rlRectangle){ (float)posX, (float)posY, (float)width, (float)height }, color1, color2, color2, color1); + DrawRectangleGradientEx((Rectangle){ (float)posX, (float)posY, (float)width, (float)height }, color1, color2, color2, color1); } // Draw a horizontal-gradient-filled rectangle // NOTE: Gradient goes from bottom (color1) to top (color2) void DrawRectangleGradientH(int posX, int posY, int width, int height, Color color1, Color color2) { - DrawRectangleGradientEx((rlRectangle){ (float)posX, (float)posY, (float)width, (float)height }, color1, color1, color2, color2); + DrawRectangleGradientEx((Rectangle){ (float)posX, (float)posY, (float)width, (float)height }, color1, color1, color2, color2); } // Draw a gradient-filled rectangle // NOTE: Colors refer to corners, starting at top-lef corner and counter-clockwise -void DrawRectangleGradientEx(rlRectangle rec, Color col1, Color col2, Color col3, Color col4) +void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3, Color col4) { rlSetTexture(GetShapesTexture().id); - rlRectangle shapeRect = GetShapesTextureRectangle(); + Rectangle shapeRect = GetShapesTextureRectangle(); rlBegin(RL_QUADS); rlNormal3f(0.0f, 0.0f, 1.0f); @@ -830,7 +830,7 @@ void DrawRectangleLines(int posX, int posY, int width, int height, Color color) } // Draw rectangle outline with extended parameters -void DrawRectangleLinesEx(rlRectangle rec, float lineThick, Color color) +void DrawRectangleLinesEx(Rectangle rec, float lineThick, Color color) { if ((lineThick > rec.width) || (lineThick > rec.height)) { @@ -849,10 +849,10 @@ void DrawRectangleLinesEx(rlRectangle rec, float lineThick, Color color) // BBBBBBBB // - rlRectangle top = { rec.x, rec.y, rec.width, lineThick }; - rlRectangle bottom = { rec.x, rec.y - lineThick + rec.height, rec.width, lineThick }; - rlRectangle left = { rec.x, rec.y + lineThick, lineThick, rec.height - lineThick*2.0f }; - rlRectangle right = { rec.x - lineThick + rec.width, rec.y + lineThick, lineThick, rec.height - lineThick*2.0f }; + Rectangle top = { rec.x, rec.y, rec.width, lineThick }; + Rectangle bottom = { rec.x, rec.y - lineThick + rec.height, rec.width, lineThick }; + Rectangle left = { rec.x, rec.y + lineThick, lineThick, rec.height - lineThick*2.0f }; + Rectangle right = { rec.x - lineThick + rec.width, rec.y + lineThick, lineThick, rec.height - lineThick*2.0f }; DrawRectangleRec(top, color); DrawRectangleRec(bottom, color); @@ -861,7 +861,7 @@ void DrawRectangleLinesEx(rlRectangle rec, float lineThick, Color color) } // Draw rectangle with rounded edges -void DrawRectangleRounded(rlRectangle rec, float roundness, int segments, Color color) +void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color color) { // Not a rounded rectangle if ((roundness <= 0.0f) || (rec.width < 1) || (rec.height < 1 )) @@ -917,7 +917,7 @@ void DrawRectangleRounded(rlRectangle rec, float roundness, int segments, Color #if defined(SUPPORT_QUADS_DRAW_MODE) rlSetTexture(GetShapesTexture().id); - rlRectangle shapeRect = GetShapesTextureRectangle(); + Rectangle shapeRect = GetShapesTextureRectangle(); rlBegin(RL_QUADS); // Draw all the 4 corners: [1] Upper Left Corner, [3] Upper Right Corner, [5] Lower Right Corner, [7] Lower Left Corner @@ -1088,20 +1088,20 @@ void DrawRectangleRounded(rlRectangle rec, float roundness, int segments, Color // Draw rectangle with rounded edges // TODO: This function should be refactored to use RL_LINES, for consistency with other Draw*Lines() -void DrawRectangleRoundedLines(rlRectangle rec, float roundness, int segments, Color color) +void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, Color color) { DrawRectangleRoundedLinesEx(rec, roundness, segments, 1.0f, color); } // Draw rectangle with rounded edges outline -void DrawRectangleRoundedLinesEx(rlRectangle rec, float roundness, int segments, float lineThick, Color color) +void DrawRectangleRoundedLinesEx(Rectangle rec, float roundness, int segments, float lineThick, Color color) { if (lineThick < 0) lineThick = 0; // Not a rounded rectangle if (roundness <= 0.0f) { - DrawRectangleLinesEx((rlRectangle){rec.x-lineThick, rec.y-lineThick, rec.width+2*lineThick, rec.height+2*lineThick}, lineThick, color); + DrawRectangleLinesEx((Rectangle){rec.x-lineThick, rec.y-lineThick, rec.width+2*lineThick, rec.height+2*lineThick}, lineThick, color); return; } @@ -1160,7 +1160,7 @@ void DrawRectangleRoundedLinesEx(rlRectangle rec, float roundness, int segments, { #if defined(SUPPORT_QUADS_DRAW_MODE) rlSetTexture(GetShapesTexture().id); - rlRectangle shapeRect = GetShapesTextureRectangle(); + Rectangle shapeRect = GetShapesTextureRectangle(); rlBegin(RL_QUADS); @@ -1336,7 +1336,7 @@ void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color) { #if defined(SUPPORT_QUADS_DRAW_MODE) rlSetTexture(GetShapesTexture().id); - rlRectangle shapeRect = GetShapesTextureRectangle(); + Rectangle shapeRect = GetShapesTextureRectangle(); rlBegin(RL_QUADS); rlColor4ub(color.r, color.g, color.b, color.a); @@ -1385,12 +1385,12 @@ void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color) // Draw a triangle fan defined by points // NOTE: First vertex provided is the center, shared by all triangles // By default, following vertex should be provided in counter-clockwise order -void DrawTriangleFan(Vector2 *points, int pointCount, Color color) +void DrawTriangleFan(const Vector2 *points, int pointCount, Color color) { if (pointCount >= 3) { rlSetTexture(GetShapesTexture().id); - rlRectangle shapeRect = GetShapesTextureRectangle(); + Rectangle shapeRect = GetShapesTextureRectangle(); rlBegin(RL_QUADS); rlColor4ub(color.r, color.g, color.b, color.a); @@ -1416,7 +1416,7 @@ void DrawTriangleFan(Vector2 *points, int pointCount, Color color) // Draw a triangle strip defined by points // NOTE: Every new vertex connects with previous two -void DrawTriangleStrip(Vector2 *points, int pointCount, Color color) +void DrawTriangleStrip(const Vector2 *points, int pointCount, Color color) { if (pointCount >= 3) { @@ -1451,7 +1451,7 @@ void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color col #if defined(SUPPORT_QUADS_DRAW_MODE) rlSetTexture(GetShapesTexture().id); - rlRectangle shapeRect = GetShapesTextureRectangle(); + Rectangle shapeRect = GetShapesTextureRectangle(); rlBegin(RL_QUADS); for (int i = 0; i < sides; i++) @@ -1520,7 +1520,7 @@ void DrawPolyLinesEx(Vector2 center, int sides, float radius, float rotation, fl #if defined(SUPPORT_QUADS_DRAW_MODE) rlSetTexture(GetShapesTexture().id); - rlRectangle shapeRect = GetShapesTextureRectangle(); + Rectangle shapeRect = GetShapesTextureRectangle(); rlBegin(RL_QUADS); for (int i = 0; i < sides; i++) @@ -1570,7 +1570,7 @@ void DrawPolyLinesEx(Vector2 center, int sides, float radius, float rotation, fl //---------------------------------------------------------------------------------- // Draw spline: linear, minimum 2 points -void DrawSplineLinear(Vector2 *points, int pointCount, float thick, Color color) +void DrawSplineLinear(const Vector2 *points, int pointCount, float thick, Color color) { if (pointCount < 2) return; @@ -1687,7 +1687,7 @@ void DrawSplineLinear(Vector2 *points, int pointCount, float thick, Color color) } // Draw spline: B-Spline, minimum 4 points -void DrawSplineBasis(Vector2 *points, int pointCount, float thick, Color color) +void DrawSplineBasis(const Vector2 *points, int pointCount, float thick, Color color) { if (pointCount < 4) return; @@ -1759,11 +1759,12 @@ void DrawSplineBasis(Vector2 *points, int pointCount, float thick, Color color) DrawTriangleStrip(vertices, 2*SPLINE_SEGMENT_DIVISIONS + 2, color); } - DrawCircleV(currentPoint, thick/2.0f, color); // Draw end line circle-cap + // Cap circle drawing at the end of every segment + DrawCircleV(currentPoint, thick/2.0f, color); } // Draw spline: Catmull-Rom, minimum 4 points -void DrawSplineCatmullRom(Vector2 *points, int pointCount, float thick, Color color) +void DrawSplineCatmullRom(const Vector2 *points, int pointCount, float thick, Color color) { if (pointCount < 4) return; @@ -1825,28 +1826,31 @@ void DrawSplineCatmullRom(Vector2 *points, int pointCount, float thick, Color co DrawTriangleStrip(vertices, 2*SPLINE_SEGMENT_DIVISIONS + 2, color); } - DrawCircleV(currentPoint, thick/2.0f, color); // Draw end line circle-cap + // Cap circle drawing at the end of every segment + DrawCircleV(currentPoint, thick/2.0f, color); } // Draw spline: Quadratic Bezier, minimum 3 points (1 control point): [p1, c2, p3, c4...] -void DrawSplineBezierQuadratic(Vector2 *points, int pointCount, float thick, Color color) +void DrawSplineBezierQuadratic(const Vector2 *points, int pointCount, float thick, Color color) { - if (pointCount < 3) return; - - for (int i = 0; i < pointCount - 2; i++) + if (pointCount >= 3) { - DrawSplineSegmentBezierQuadratic(points[i], points[i + 1], points[i + 2], thick, color); + for (int i = 0; i < pointCount - 2; i += 2) DrawSplineSegmentBezierQuadratic(points[i], points[i + 1], points[i + 2], thick, color); + + // Cap circle drawing at the end of every segment + //for (int i = 2; i < pointCount - 2; i += 2) DrawCircleV(points[i], thick/2.0f, color); } } // Draw spline: Cubic Bezier, minimum 4 points (2 control points): [p1, c2, c3, p4, c5, c6...] -void DrawSplineBezierCubic(Vector2 *points, int pointCount, float thick, Color color) +void DrawSplineBezierCubic(const Vector2 *points, int pointCount, float thick, Color color) { - if (pointCount < 4) return; - - for (int i = 0; i < pointCount - 3; i++) + if (pointCount >= 4) { - DrawSplineSegmentBezierCubic(points[i], points[i + 1], points[i + 2], points[i + 3], thick, color); + for (int i = 0; i < pointCount - 3; i += 3) DrawSplineSegmentBezierCubic(points[i], points[i + 1], points[i + 2], points[i + 3], thick, color); + + // Cap circle drawing at the end of every segment + //for (int i = 3; i < pointCount - 3; i += 3) DrawCircleV(points[i], thick/2.0f, color); } } @@ -2156,7 +2160,7 @@ Vector2 GetSplinePointBezierCubic(Vector2 startPos, Vector2 startControlPos, Vec //---------------------------------------------------------------------------------- // Check if point is inside rectangle -bool CheckCollisionPointRec(Vector2 point, rlRectangle rec) +bool CheckCollisionPointRec(Vector2 point, Rectangle rec) { bool collision = false; @@ -2195,7 +2199,7 @@ bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 // Check if point is within a polygon described by array of vertices // NOTE: Based on http://jeffreythompson.org/collision-detection/poly-point.php -bool CheckCollisionPointPoly(Vector2 point, Vector2 *points, int pointCount) +bool CheckCollisionPointPoly(Vector2 point, const Vector2 *points, int pointCount) { bool inside = false; @@ -2215,7 +2219,7 @@ bool CheckCollisionPointPoly(Vector2 point, Vector2 *points, int pointCount) } // Check collision between two rectangles -bool CheckCollisionRecs(rlRectangle rec1, rlRectangle rec2) +bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2) { bool collision = false; @@ -2233,16 +2237,17 @@ bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, floa float dx = center2.x - center1.x; // X distance between centers float dy = center2.y - center1.y; // Y distance between centers - float distance = sqrtf(dx*dx + dy*dy); // Distance between centers + float distanceSquared = dx * dx + dy * dy; // Distance between centers squared + float radiusSum = radius1 + radius2; - if (distance <= (radius1 + radius2)) collision = true; + collision = (distanceSquared <= (radiusSum * radiusSum)); return collision; } // Check collision between circle and rectangle // NOTE: Reviewed version to take into account corner limit case -bool CheckCollisionCircleRec(Vector2 center, float radius, rlRectangle rec) +bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec) { bool collision = false; @@ -2340,9 +2345,9 @@ RLAPI bool CheckCollisionCircleLine(Vector2 center, float radius, Vector2 p1, Ve } // Get collision rectangle for two rectangles collision -rlRectangle GetCollisionRec(rlRectangle rec1, rlRectangle rec2) +Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2) { - rlRectangle overlap = { 0 }; + Rectangle overlap = { 0 }; float left = (rec1.x > rec2.x)? rec1.x : rec2.x; float right1 = rec1.x + rec1.width; diff --git a/src/raylib/rtext.c b/src/raylib/rtext.c index 709a6b8..6ad0f90 100644 --- a/src/raylib/rtext.c +++ b/src/raylib/rtext.c @@ -7,8 +7,8 @@ * rtext module is included in the build * * #define SUPPORT_DEFAULT_FONT -* Load default raylib font on initialization to be used by rlDrawText() and MeasureText(). -* If no default font loaded, rlDrawTextEx() and MeasureTextEx() are required. +* Load default raylib font on initialization to be used by DrawText() and MeasureText(). +* If no default font loaded, DrawTextEx() and MeasureTextEx() are required. * * #define SUPPORT_FILEFORMAT_FNT * #define SUPPORT_FILEFORMAT_TTF @@ -260,7 +260,7 @@ extern void LoadFontDefault(void) // Allocate space for our characters info data // NOTE: This memory must be freed at end! --> Done by CloseWindow() defaultFont.glyphs = (GlyphInfo *)RL_MALLOC(defaultFont.glyphCount*sizeof(GlyphInfo)); - defaultFont.recs = (rlRectangle *)RL_MALLOC(defaultFont.glyphCount*sizeof(rlRectangle)); + defaultFont.recs = (Rectangle *)RL_MALLOC(defaultFont.glyphCount*sizeof(Rectangle)); int currentLine = 0; int currentPosX = charsDivisor; @@ -357,7 +357,7 @@ Font LoadFont(const char *fileName) else #endif { - Image image = rlLoadImage(fileName); + Image image = LoadImage(fileName); if (image.data != NULL) font = LoadFontFromImage(image, MAGENTA, FONT_TTF_DEFAULT_FIRST_CHAR); UnloadImage(image); } @@ -419,7 +419,7 @@ Font LoadFontFromImage(Image image, Color key, int firstChar) // We allocate a temporal arrays for chars data measures, // once we get the actual number of chars, we copy data to a sized arrays int tempCharValues[MAX_GLYPHS_FROM_IMAGE] = { 0 }; - rlRectangle tempCharRecs[MAX_GLYPHS_FROM_IMAGE] = { 0 }; + Rectangle tempCharRecs[MAX_GLYPHS_FROM_IMAGE] = { 0 }; Color *pixels = LoadImageColors(image); @@ -499,7 +499,7 @@ Font LoadFontFromImage(Image image, Color key, int firstChar) // We got tempCharValues and tempCharsRecs populated with chars data // Now we move temp data to sized charValues and charRecs arrays font.glyphs = (GlyphInfo *)RL_MALLOC(font.glyphCount*sizeof(GlyphInfo)); - font.recs = (rlRectangle *)RL_MALLOC(font.glyphCount*sizeof(rlRectangle)); + font.recs = (Rectangle *)RL_MALLOC(font.glyphCount*sizeof(Rectangle)); for (int i = 0; i < font.glyphCount; i++) { @@ -735,7 +735,7 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz // Generate image font atlas using chars info // NOTE: Packing method: 0-Default, 1-Skyline #if defined(SUPPORT_FILEFORMAT_TTF) || defined(SUPPORT_FILEFORMAT_BDF) -Image GenImageFontAtlas(const GlyphInfo *glyphs, rlRectangle **glyphRecs, int glyphCount, int fontSize, int padding, int packMethod) +Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyphCount, int fontSize, int padding, int packMethod) { Image atlas = { 0 }; @@ -751,7 +751,7 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, rlRectangle **glyphRecs, int gl glyphCount = (glyphCount > 0)? glyphCount : 95; // NOTE: Rectangles memory is loaded here! - rlRectangle *recs = (rlRectangle *)RL_MALLOC(glyphCount*sizeof(rlRectangle)); + Rectangle *recs = (Rectangle *)RL_MALLOC(glyphCount*sizeof(Rectangle)); // Calculate image size based on total glyph width and glyph row count int totalWidth = 0; @@ -1035,7 +1035,7 @@ bool ExportFontAsCode(Font font, const char *fileName) // Save font recs data byteCount += sprintf(txtData + byteCount, "// Font characters rectangles data\n"); - byteCount += sprintf(txtData + byteCount, "static rlRectangle fontRecs_%s[%i] = {\n", fileNamePascal, font.glyphCount); + byteCount += sprintf(txtData + byteCount, "static Rectangle fontRecs_%s[%i] = {\n", fileNamePascal, font.glyphCount); for (int i = 0; i < font.glyphCount; i++) { byteCount += sprintf(txtData + byteCount, " { %1.0f, %1.0f, %1.0f , %1.0f },\n", font.recs[i].x, font.recs[i].y, font.recs[i].width, font.recs[i].height); @@ -1083,8 +1083,8 @@ bool ExportFontAsCode(Font font, const char *fileName) #if defined(SUPPORT_FONT_DATA_COPY) byteCount += sprintf(txtData + byteCount, " // Copy glyph recs data from global fontRecs\n"); byteCount += sprintf(txtData + byteCount, " // NOTE: Required to avoid issues if trying to free font\n"); - byteCount += sprintf(txtData + byteCount, " font.recs = (rlRectangle *)malloc(font.glyphCount*sizeof(rlRectangle));\n"); - byteCount += sprintf(txtData + byteCount, " memcpy(font.recs, fontRecs_%s, font.glyphCount*sizeof(rlRectangle));\n\n", fileNamePascal); + byteCount += sprintf(txtData + byteCount, " font.recs = (Rectangle *)malloc(font.glyphCount*sizeof(Rectangle));\n"); + byteCount += sprintf(txtData + byteCount, " memcpy(font.recs, fontRecs_%s, font.glyphCount*sizeof(Rectangle));\n\n", fileNamePascal); byteCount += sprintf(txtData + byteCount, " // Copy font glyph info data from global fontChars\n"); byteCount += sprintf(txtData + byteCount, " // NOTE: Required to avoid issues if trying to free font\n"); @@ -1122,13 +1122,13 @@ void DrawFPS(int posX, int posY) if ((fps < 30) && (fps >= 15)) color = ORANGE; // Warning FPS else if (fps < 15) color = RED; // Low FPS - rlDrawText(TextFormat("%2i FPS", fps), posX, posY, 20, color); + DrawText(TextFormat("%2i FPS", fps), posX, posY, 20, color); } // Draw text (using default font) // NOTE: fontSize work like in any drawing program but if fontSize is lower than font-base-size, then font-base-size is used // NOTE: chars spacing is proportional to fontSize -void rlDrawText(const char *text, int posX, int posY, int fontSize, Color color) +void DrawText(const char *text, int posX, int posY, int fontSize, Color color) { // Check if default font has been loaded if (GetFontDefault().texture.id != 0) @@ -1139,13 +1139,13 @@ void rlDrawText(const char *text, int posX, int posY, int fontSize, Color color) if (fontSize < defaultFontSize) fontSize = defaultFontSize; int spacing = fontSize/defaultFontSize; - rlDrawTextEx(GetFontDefault(), text, position, (float)fontSize, (float)spacing, color); + DrawTextEx(GetFontDefault(), text, position, (float)fontSize, (float)spacing, color); } } // Draw text using Font // NOTE: chars spacing is NOT proportional to fontSize -void rlDrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint) +void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint) { if (font.texture.id == 0) font = GetFontDefault(); // Security check in case of not valid font @@ -1193,7 +1193,7 @@ void DrawTextPro(Font font, const char *text, Vector2 position, Vector2 origin, rlRotatef(rotation, 0.0f, 0.0f, 1.0f); rlTranslatef(-origin.x, -origin.y, 0.0f); - rlDrawTextEx(font, text, (Vector2){ 0.0f, 0.0f }, fontSize, spacing, tint); + DrawTextEx(font, text, (Vector2){ 0.0f, 0.0f }, fontSize, spacing, tint); rlPopMatrix(); } @@ -1208,14 +1208,14 @@ void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float fontSiz // Character destination rectangle on screen // NOTE: We consider glyphPadding on drawing - rlRectangle dstRec = { position.x + font.glyphs[index].offsetX*scaleFactor - (float)font.glyphPadding*scaleFactor, + Rectangle dstRec = { position.x + font.glyphs[index].offsetX*scaleFactor - (float)font.glyphPadding*scaleFactor, position.y + font.glyphs[index].offsetY*scaleFactor - (float)font.glyphPadding*scaleFactor, (font.recs[index].width + 2.0f*font.glyphPadding)*scaleFactor, (font.recs[index].height + 2.0f*font.glyphPadding)*scaleFactor }; // Character source rectangle from font texture atlas // NOTE: We consider chars padding when drawing, it could be required for outline/glow shader effects - rlRectangle srcRec = { font.recs[index].x - (float)font.glyphPadding, font.recs[index].y - (float)font.glyphPadding, + Rectangle srcRec = { font.recs[index].x - (float)font.glyphPadding, font.recs[index].y - (float)font.glyphPadding, font.recs[index].width + 2.0f*font.glyphPadding, font.recs[index].height + 2.0f*font.glyphPadding }; // Draw the character texture on the screen @@ -1376,9 +1376,9 @@ GlyphInfo GetGlyphInfo(Font font, int codepoint) // Get glyph rectangle in font atlas for a codepoint (unicode character) // NOTE: If codepoint is not found in the font it fallbacks to '?' -rlRectangle GetGlyphAtlasRec(Font font, int codepoint) +Rectangle GetGlyphAtlasRec(Font font, int codepoint) { - rlRectangle rec = { 0 }; + Rectangle rec = { 0 }; rec = font.recs[GetGlyphIndex(font, codepoint)]; @@ -1807,10 +1807,7 @@ const char *TextToSnake(const char *text) } buffer[i] = text[j] + 32; } - else - { - buffer[i] = text[j]; - } + else buffer[i] = text[j]; } } @@ -1827,23 +1824,17 @@ const char *TextToCamel(const char *text) if (text != NULL) { // Lower case first character - if ((text[0] >= 'A') && (text[0] <= 'Z')) - buffer[0] = text[0] + 32; - else - buffer[0] = text[0]; + 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++) { - if (text[j] != '_') - buffer[i] = text[j]; + if (text[j] != '_') buffer[i] = text[j]; else { j++; - if ((text[j] >= 'a') && (text[j] <= 'z')) - { - buffer[i] = text[j] - 32; - } + if ((text[j] >= 'a') && (text[j] <= 'z')) buffer[i] = text[j] - 32; } } } @@ -2229,7 +2220,7 @@ static Font LoadBMFont(const char *fileName) for (int i = 0; i < pageCount; i++) { - imFonts[i] = rlLoadImage(TextFormat("%s/%s", GetDirectoryPath(fileName), imFileName[i])); + imFonts[i] = LoadImage(TextFormat("%s/%s", GetDirectoryPath(fileName), imFileName[i])); if (imFonts[i].format == PIXELFORMAT_UNCOMPRESSED_GRAYSCALE) { @@ -2265,8 +2256,8 @@ static Font LoadBMFont(const char *fileName) for (int i = 1; i < pageCount; i++) { - rlRectangle srcRec = { 0.0f, 0.0f, (float)imWidth, (float)imHeight }; - rlRectangle destRec = { 0.0f, (float)imHeight*(float)i, (float)imWidth, (float)imHeight }; + Rectangle srcRec = { 0.0f, 0.0f, (float)imWidth, (float)imHeight }; + Rectangle destRec = { 0.0f, (float)imHeight*(float)i, (float)imWidth, (float)imHeight }; ImageDraw(&fullFont, imFonts[i], srcRec, destRec, WHITE); } } @@ -2280,7 +2271,7 @@ static Font LoadBMFont(const char *fileName) font.glyphCount = glyphCount; font.glyphPadding = 0; font.glyphs = (GlyphInfo *)RL_MALLOC(glyphCount*sizeof(GlyphInfo)); - font.recs = (rlRectangle *)RL_MALLOC(glyphCount*sizeof(rlRectangle)); + font.recs = (Rectangle *)RL_MALLOC(glyphCount*sizeof(Rectangle)); int charId, charX, charY, charWidth, charHeight, charOffsetX, charOffsetY, charAdvanceX, pageID; @@ -2294,7 +2285,7 @@ static Font LoadBMFont(const char *fileName) if (readVars == 9) // Make sure all char data has been properly read { // Get character rectangle in the font atlas texture - font.recs[i] = (rlRectangle){ (float)charX, (float)charY + (float)imHeight*pageID, (float)charWidth, (float)charHeight }; + font.recs[i] = (Rectangle){ (float)charX, (float)charY + (float)imHeight*pageID, (float)charWidth, (float)charHeight }; // Save data properly in sprite font font.glyphs[i].value = charId; diff --git a/src/raylib/rtextures.c b/src/raylib/rtextures.c index ac125fa..2f02afe 100644 --- a/src/raylib/rtextures.c +++ b/src/raylib/rtextures.c @@ -271,7 +271,7 @@ static Vector4 *LoadImageDataNormalized(Image image); // Load pixel data f //---------------------------------------------------------------------------------- // Load image from file into CPU memory (RAM) -Image rlLoadImage(const char *fileName) +Image LoadImage(const char *fileName) { Image image = { 0 }; @@ -447,7 +447,7 @@ Image LoadImageAnim(const char *fileName, int *frames) #endif else { - image = rlLoadImage(fileName); + image = LoadImage(fileName); frameCount = 1; } @@ -1269,7 +1269,7 @@ Image ImageCopy(Image image) } // Create an image from another image piece -Image ImageFromImage(Image image, rlRectangle rec) +Image ImageFromImage(Image image, Rectangle rec) { Image result = { 0 }; @@ -1291,7 +1291,7 @@ Image ImageFromImage(Image image, rlRectangle rec) // Crop an image to area defined by a rectangle // NOTE: Security checks are performed in case rectangle goes out of bounds -void ImageCrop(Image *image, rlRectangle crop) +void ImageCrop(Image *image, Rectangle crop) { // Security check to avoid program crash if ((image->data == NULL) || (image->width == 0) || (image->height == 0)) return; @@ -1601,8 +1601,8 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co { if ((codepoint != ' ') && (codepoint != '\t')) { - rlRectangle rec = { (float)(textOffsetX + font.glyphs[index].offsetX), (float)(textOffsetY + font.glyphs[index].offsetY), (float)font.recs[index].width, (float)font.recs[index].height }; - ImageDraw(&imText, font.glyphs[index].image, (rlRectangle){ 0, 0, (float)font.glyphs[index].image.width, (float)font.glyphs[index].image.height }, rec, tint); + Rectangle rec = { (float)(textOffsetX + font.glyphs[index].offsetX), (float)(textOffsetY + font.glyphs[index].offsetY), (float)font.recs[index].width, (float)font.recs[index].height }; + ImageDraw(&imText, font.glyphs[index].image, (Rectangle){ 0, 0, (float)font.glyphs[index].image.width, (float)font.glyphs[index].image.height }, rec, tint); } if (font.glyphs[index].advanceX == 0) textOffsetX += (int)(font.recs[index].width + spacing); @@ -1736,7 +1736,7 @@ void ImageResizeCanvas(Image *image, int newWidth, int newHeight, int offsetX, i if (image->format >= PIXELFORMAT_COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Image manipulation not supported for compressed formats"); else if ((newWidth != image->width) || (newHeight != image->height)) { - rlRectangle srcRec = { 0, 0, (float)image->width, (float)image->height }; + Rectangle srcRec = { 0, 0, (float)image->width, (float)image->height }; Vector2 dstPos = { (float)offsetX, (float)offsetY }; if (offsetX < 0) @@ -1816,7 +1816,7 @@ void ImageAlphaCrop(Image *image, float threshold) // Security check to avoid program crash if ((image->data == NULL) || (image->width == 0) || (image->height == 0)) return; - rlRectangle crop = GetImageAlphaBorder(*image, threshold); + Rectangle crop = GetImageAlphaBorder(*image, threshold); // Crop if rectangle is valid if (((int)crop.width != 0) && ((int)crop.height != 0)) ImageCrop(image, crop); @@ -3065,9 +3065,9 @@ void UnloadImagePalette(Color *colors) // Get image alpha border rectangle // NOTE: Threshold is defined as a percentage: 0.0f -> 1.0f -rlRectangle GetImageAlphaBorder(Image image, float threshold) +Rectangle GetImageAlphaBorder(Image image, float threshold) { - rlRectangle crop = { 0 }; + Rectangle crop = { 0 }; Color *pixels = LoadImageColors(image); @@ -3095,7 +3095,7 @@ rlRectangle GetImageAlphaBorder(Image image, float threshold) // Check for empty blank image if ((xMin != 65536) && (xMax != 65536)) { - crop = (rlRectangle){ (float)xMin, (float)yMin, (float)((xMax + 1) - xMin), (float)((yMax + 1) - yMin) }; + crop = (Rectangle){ (float)xMin, (float)yMin, (float)((xMax + 1) - xMin), (float)((yMax + 1) - yMin) }; } UnloadImageColors(pixels); @@ -3564,7 +3564,7 @@ void ImageDrawCircleLinesV(Image *dst, Vector2 center, int radius, Color color) // Draw rectangle within an image void ImageDrawRectangle(Image *dst, int posX, int posY, int width, int height, Color color) { - ImageDrawRectangleRec(dst, (rlRectangle){ (float)posX, (float)posY, (float)width, (float)height }, color); + ImageDrawRectangleRec(dst, (Rectangle){ (float)posX, (float)posY, (float)width, (float)height }, color); } // Draw rectangle within an image (Vector version) @@ -3574,7 +3574,7 @@ void ImageDrawRectangleV(Image *dst, Vector2 position, Vector2 size, Color color } // Draw rectangle within an image -void ImageDrawRectangleRec(Image *dst, rlRectangle rec, Color color) +void ImageDrawRectangleRec(Image *dst, Rectangle rec, Color color) { // Security check to avoid program crash if ((dst->data == NULL) || (dst->width == 0) || (dst->height == 0)) return; @@ -3619,7 +3619,7 @@ void ImageDrawRectangleRec(Image *dst, rlRectangle rec, Color color) } // Draw rectangle lines within an image -void ImageDrawRectangleLines(Image *dst, rlRectangle rec, int thick, Color color) +void ImageDrawRectangleLines(Image *dst, Rectangle rec, int thick, Color color) { ImageDrawRectangle(dst, (int)rec.x, (int)rec.y, (int)rec.width, thick, color); ImageDrawRectangle(dst, (int)rec.x, (int)(rec.y + thick), thick, (int)(rec.height - thick*2), color); @@ -3629,7 +3629,7 @@ void ImageDrawRectangleLines(Image *dst, rlRectangle rec, int thick, Color color // Draw an image (source) within an image (destination) // NOTE: Color tint is applied to source image -void ImageDraw(Image *dst, Image src, rlRectangle srcRec, rlRectangle dstRec, Color tint) +void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint) { // Security check to avoid program crash if ((dst->data == NULL) || (dst->width == 0) || (dst->height == 0) || @@ -3655,7 +3655,7 @@ void ImageDraw(Image *dst, Image src, rlRectangle srcRec, rlRectangle dstRec, Co { srcMod = ImageFromImage(src, srcRec); // Create image from another image ImageResize(&srcMod, (int)dstRec.width, (int)dstRec.height); // Resize to destination rectangle - srcRec = (rlRectangle){ 0, 0, (float)srcMod.width, (float)srcMod.height }; + srcRec = (Rectangle){ 0, 0, (float)srcMod.width, (float)srcMod.height }; srcPtr = &srcMod; useSrcMod = true; @@ -3762,8 +3762,8 @@ void ImageDrawTextEx(Image *dst, Font font, const char *text, Vector2 position, { Image imText = ImageTextEx(font, text, fontSize, spacing, tint); - rlRectangle srcRec = { 0.0f, 0.0f, (float)imText.width, (float)imText.height }; - rlRectangle dstRec = { position.x, position.y, (float)imText.width, (float)imText.height }; + Rectangle srcRec = { 0.0f, 0.0f, (float)imText.width, (float)imText.height }; + Rectangle dstRec = { position.x, position.y, (float)imText.width, (float)imText.height }; ImageDraw(dst, imText, srcRec, dstRec, WHITE); @@ -3778,7 +3778,7 @@ Texture2D LoadTexture(const char *fileName) { Texture2D texture = { 0 }; - Image image = rlLoadImage(fileName); + Image image = LoadImage(fileName); if (image.data != NULL) { @@ -3846,9 +3846,9 @@ TextureCubemap LoadTextureCubemap(Image image, int layout) int size = cubemap.width; Image faces = { 0 }; // Vertical column image - rlRectangle faceRecs[6] = { 0 }; // Face source rectangles + Rectangle faceRecs[6] = { 0 }; // Face source rectangles - for (int i = 0; i < 6; i++) faceRecs[i] = (rlRectangle){ 0, 0, (float)size, (float)size }; + for (int i = 0; i < 6; i++) faceRecs[i] = (Rectangle){ 0, 0, (float)size, (float)size }; if (layout == CUBEMAP_LAYOUT_LINE_VERTICAL) { @@ -3887,7 +3887,7 @@ TextureCubemap LoadTextureCubemap(Image image, int layout) // NOTE: Image formatting does not work with compressed textures - for (int i = 0; i < 6; i++) ImageDraw(&faces, image, faceRecs[i], (rlRectangle){ 0, (float)size*i, (float)size, (float)size }, WHITE); + for (int i = 0; i < 6; i++) ImageDraw(&faces, image, faceRecs[i], (Rectangle){ 0, (float)size*i, (float)size, (float)size }, WHITE); } // NOTE: Cubemap data is expected to be provided as 6 images in a single data array, @@ -4013,7 +4013,7 @@ void UpdateTexture(Texture2D texture, const void *pixels) // Update GPU texture rectangle with new data // NOTE: pixels data must match texture.format -void UpdateTextureRec(Texture2D texture, rlRectangle rec, const void *pixels) +void UpdateTextureRec(Texture2D texture, Rectangle rec, const void *pixels) { rlUpdateTexture(texture.id, (int)rec.x, (int)rec.y, (int)rec.width, (int)rec.height, texture.format, pixels); } @@ -4143,17 +4143,17 @@ void DrawTextureV(Texture2D texture, Vector2 position, Color tint) // Draw a texture with extended parameters void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint) { - rlRectangle source = { 0.0f, 0.0f, (float)texture.width, (float)texture.height }; - rlRectangle dest = { position.x, position.y, (float)texture.width*scale, (float)texture.height*scale }; + Rectangle source = { 0.0f, 0.0f, (float)texture.width, (float)texture.height }; + Rectangle dest = { position.x, position.y, (float)texture.width*scale, (float)texture.height*scale }; Vector2 origin = { 0.0f, 0.0f }; DrawTexturePro(texture, source, dest, origin, rotation, tint); } // Draw a part of a texture (defined by a rectangle) -void DrawTextureRec(Texture2D texture, rlRectangle source, Vector2 position, Color tint) +void DrawTextureRec(Texture2D texture, Rectangle source, Vector2 position, Color tint) { - rlRectangle dest = { position.x, position.y, fabsf(source.width), fabsf(source.height) }; + Rectangle dest = { position.x, position.y, fabsf(source.width), fabsf(source.height) }; Vector2 origin = { 0.0f, 0.0f }; DrawTexturePro(texture, source, dest, origin, 0.0f, tint); @@ -4161,7 +4161,7 @@ void DrawTextureRec(Texture2D texture, rlRectangle source, Vector2 position, Col // Draw a part of a texture (defined by a rectangle) with 'pro' parameters // NOTE: origin is relative to destination rectangle size -void DrawTexturePro(Texture2D texture, rlRectangle source, rlRectangle dest, Vector2 origin, float rotation, Color tint) +void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint) { // Check if texture is valid if (texture.id > 0) @@ -4283,7 +4283,7 @@ void DrawTexturePro(Texture2D texture, rlRectangle source, rlRectangle dest, Vec } // Draws a texture (or part of it) that stretches or shrinks nicely using n-patch info -void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, rlRectangle dest, Vector2 origin, float rotation, Color tint) +void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint) { if (texture.id > 0) { diff --git a/update_bindings.nims b/update_bindings.nims index f7980fc..7254ff4 100644 --- a/update_bindings.nims +++ b/update_bindings.nims @@ -5,7 +5,7 @@ const PkgDir = thisDir().quoteShell RaylibDir = PkgDir / "raylib" RaylibGit = "https://github.com/raysan5/raylib.git" - RayLatestCommit = "7b92b5bde77f857dbf25a2e0aaacb79f592c18b2" + RayLatestCommit = "dcf2f6a8e97911c90efce5722bd7f0c7cdc8601e" ApiDir = PkgDir / "api" DocsDir = PkgDir / "docs"