Bump raylib to master

This commit is contained in:
Nikolas 2025-09-21 18:27:37 +02:00
parent d64fc43f38
commit 0248dc6e98
No known key found for this signature in database
GPG Key ID: E95F679E3CDD9784
8 changed files with 176 additions and 106 deletions

View File

@ -4,12 +4,12 @@
.fingerprint = 0xc4cfa8c610114f28,
.dependencies = .{
.raylib = .{
.url = "git+https://github.com/raysan5/raylib#82d65e110a2caba862b31a3f1c11ca7a8ba60e3b",
.hash = "raylib-5.6.0-dev-whq8uHRjyARJNFHTJ8fBtYU71IrnB-rTHJwuasjUnRWt",
.url = "git+https://github.com/raysan5/raylib#8ada37d9671682f420a2be1f1afd4b06173b81ad",
.hash = "raylib-5.6.0-dev-whq8uCg2ywTzCiX3VEP9RuCMXR6_VnDBmkj8GjL_p5QN",
},
.raygui = .{
.url = "git+https://github.com/raysan5/raygui#6530ee136b3c5af86c5640151f07837a604308ec",
.hash = "N-V-__8AAOQabwCjOjMI2uUTw4Njc0tAUOO6Lw2kCydLbvVG",
.url = "git+https://github.com/raysan5/raygui#9cdfec460b43a17264af3c181c46f62bf107ac17",
.hash = "N-V-__8AALUbbwDKkSH4nbf3Ml_dTWo9qbELvle5i9eQZMuo",
},
.emsdk = .{
.url = "git+https://github.com/emscripten-core/emsdk#4.0.9",

View File

@ -90,6 +90,7 @@ MANUAL = [
"DrawTextCodepoints",
"LoadUTF8",
"LoadTextLines",
"UnloadTextLines",
"TextJoin",
"DrawLineStrip",
"DrawTriangleFan",
@ -142,7 +143,7 @@ def ziggify_type(name: str, t: str, func_name: str) -> str:
"AutomationEventList", "list", "batch", "glInternalFormat", "glFormat",
"glType", "mipmaps", "active", "scroll", "view", "checked", "mouseCell",
"scrollIndex", "focus", "secretViewActive", "color", "alpha", "colorHsv",
"translation", "rotation", "scale", "mat"
"translation", "rotation", "scale", "mat", "glyphCount"
]
multi = [
"data", "compData", "points", "fileData", "colors", "pixels",
@ -365,6 +366,8 @@ def parse_header(header_name: str, output_file: str, ext_file: str, prefix: str,
if not arguments:
arguments = "void"
zig_name = convert_name(func_name)
for arg in arguments.split(", "):
if arg == "void":
break
@ -383,6 +386,9 @@ def parse_header(header_name: str, output_file: str, ext_file: str, prefix: str,
arg_type = c_to_zig_type(arg_type)
arg_name, arg_type = fix_pointer(arg_name, arg_type)
if arg_name == zig_name:
arg_name += "_"
single_opt = [
("rlDrawVertexArrayElements", "buffer"),
("rlDrawVertexArrayElementsInstanced", "buffer"),
@ -418,8 +424,6 @@ def parse_header(header_name: str, output_file: str, ext_file: str, prefix: str,
ext_ret = add_namespace_to_type(return_type)
ext_heads.append(f"pub extern \"c\" fn {func_name}({zig_c_arguments}) {ext_ret};")
zig_name = convert_name(func_name)
func_prelude = ""
if func_name in TRIVIAL_SIZE:

View File

@ -2287,19 +2287,19 @@ pub fn loadFontFromImage(image: Image, key: Color, firstChar: i32) RaylibError!F
}
/// Load font data for further use
pub fn loadFontData(fileData: []const u8, fontSize: i32, codePoints: ?[]i32, ty: FontType) RaylibError![]GlyphInfo {
pub fn loadFontData(fileData: []const u8, fontSize: i32, codePoints: ?[]const i32, ty: FontType) RaylibError![]GlyphInfo {
var res: []GlyphInfo = undefined;
var codePointsFinal = @as([*c]i32, 0);
var codePointsFinal = @as([*c]const i32, 0);
var codePointsLen: i32 = 0;
if (codePoints) |codePointsSure| {
codePointsFinal = @as([*c]i32, @ptrCast(codePointsSure));
codePointsFinal = @as([*c]const i32, @ptrCast(codePointsSure));
codePointsLen = @as(i32, @intCast(codePointsSure.len));
} else {
codePointsLen = 95;
}
const ptr = cdef.LoadFontData(@as([*c]const u8, @ptrCast(fileData)), @as(c_int, @intCast(fileData.len)), @as(c_int, fontSize), codePointsFinal, @as(c_int, @intCast(codePointsLen)), ty);
const ptr = cdef.LoadFontData(@as([*c]const u8, @ptrCast(fileData)), @as(c_int, @intCast(fileData.len)), @as(c_int, fontSize), codePointsFinal, @as(c_int, @intCast(codePointsLen)), ty, @as([*c]i32, &codePointsLen));
if (ptr == 0) return RaylibError.LoadFontData;
res.ptr = @as([*]GlyphInfo, @ptrCast(ptr));
@ -2536,6 +2536,10 @@ pub fn loadTextLines(text: [:0]const u8) RaylibError![][:0]u8 {
return res;
}
pub fn unloadTextLines(lines: [][:0]u8) void {
cdef.UnloadTextLines(@as([*c][*c]u8, @ptrCast(lines)), @as(c_int, @intCast(lines.len)));
}
/// Join text strings with delimiter
pub fn textJoin(textList: [][:0]u8, delimiter: [:0]const u8) [:0]const u8 {
return std.mem.span(cdef.TextJoin(@as([*c][*c]u8, @ptrCast(textList)), @as(c_int, @intCast(textList.len)), @as([*c]const u8, @ptrCast(delimiter))));

27
lib/raygui.h vendored
View File

@ -1381,7 +1381,7 @@ static unsigned int *guiIconsPtr = guiIcons;
#define RAYGUI_MAX_PROPS_EXTENDED 8 // Maximum number of extended properties
//----------------------------------------------------------------------------------
// Types and Structures Definition
// Module Types and Structures Definition
//----------------------------------------------------------------------------------
// Gui control property style color element
typedef enum { BORDER = 0, BASE, TEXT, OTHER } GuiPropertyElement;
@ -1497,7 +1497,7 @@ static void DrawRectangleGradientV(int posX, int posY, int width, int height, Co
#endif // RAYGUI_STANDALONE
//----------------------------------------------------------------------------------
// Module specific Functions Declaration
// Module Internal Functions Declaration
//----------------------------------------------------------------------------------
static void GuiLoadStyleFromMemory(const unsigned char *fileData, int dataSize); // Load style from memory (binary only)
@ -4408,7 +4408,7 @@ void GuiLoadStyle(const char *fileName)
if (fileDataSize > 0)
{
unsigned char *fileData = (unsigned char *)RAYGUI_MALLOC(fileDataSize*sizeof(unsigned char));
unsigned char *fileData = (unsigned char *)RAYGUI_CALLOC(fileDataSize, sizeof(unsigned char));
fread(fileData, sizeof(unsigned char), fileDataSize, rgsFile);
GuiLoadStyleFromMemory(fileData, fileDataSize);
@ -4616,10 +4616,10 @@ char **GuiLoadIcons(const char *fileName, bool loadIconsName)
{
if (loadIconsName)
{
guiIconsName = (char **)RAYGUI_MALLOC(iconCount*sizeof(char **));
guiIconsName = (char **)RAYGUI_CALLOC(iconCount, sizeof(char *));
for (int i = 0; i < iconCount; i++)
{
guiIconsName[i] = (char *)RAYGUI_MALLOC(RAYGUI_ICON_MAX_NAME_LENGTH);
guiIconsName[i] = (char *)RAYGUI_CALLOC(RAYGUI_ICON_MAX_NAME_LENGTH, sizeof(char));
fread(guiIconsName[i], 1, RAYGUI_ICON_MAX_NAME_LENGTH, rgiFile);
}
}
@ -4662,10 +4662,10 @@ char **GuiLoadIconsFromMemory(const unsigned char *fileData, int dataSize, bool
{
if (loadIconsName)
{
guiIconsName = (char **)RAYGUI_MALLOC(iconCount*sizeof(char *));
guiIconsName = (char **)RAYGUI_CALLOC(iconCount, sizeof(char *));
for (int i = 0; i < iconCount; i++)
{
guiIconsName[i] = (char *)RAYGUI_MALLOC(RAYGUI_ICON_MAX_NAME_LENGTH);
guiIconsName[i] = (char *)RAYGUI_CALLOC(RAYGUI_ICON_MAX_NAME_LENGTH, sizeof(char));
memcpy(guiIconsName[i], fileDataPtr, RAYGUI_ICON_MAX_NAME_LENGTH);
fileDataPtr += RAYGUI_ICON_MAX_NAME_LENGTH;
}
@ -4677,7 +4677,7 @@ char **GuiLoadIconsFromMemory(const unsigned char *fileData, int dataSize, bool
}
int iconDataSize = iconCount*((int)iconSize*(int)iconSize/32)*(int)sizeof(unsigned int);
guiIconsPtr = (unsigned int *)RAYGUI_MALLOC(iconDataSize);
guiIconsPtr = (unsigned int *)RAYGUI_CALLOC(iconDataSize, 1);
memcpy(guiIconsPtr, fileDataPtr, iconDataSize);
}
@ -4777,9 +4777,8 @@ int GuiGetTextWidth(const char *text)
#endif // !RAYGUI_NO_ICONS
//----------------------------------------------------------------------------------
// Module specific Functions Definition
// Module Internal Functions Definition
//----------------------------------------------------------------------------------
// Load style from memory
// WARNING: Binary files only
static void GuiLoadStyleFromMemory(const unsigned char *fileData, int dataSize)
@ -4865,7 +4864,7 @@ static void GuiLoadStyleFromMemory(const unsigned char *fileData, int dataSize)
{
// Compressed font atlas image data (DEFLATE), it requires DecompressData()
int dataUncompSize = 0;
unsigned char *compData = (unsigned char *)RAYGUI_MALLOC(fontImageCompSize);
unsigned char *compData = (unsigned char *)RAYGUI_CALLOC(fontImageCompSize, sizeof(unsigned char));
memcpy(compData, fileDataPtr, fontImageCompSize);
fileDataPtr += fontImageCompSize;
@ -4879,7 +4878,7 @@ static void GuiLoadStyleFromMemory(const unsigned char *fileData, int dataSize)
else
{
// Font atlas image data is not compressed
imFont.data = (unsigned char *)RAYGUI_MALLOC(fontImageUncompSize);
imFont.data = (unsigned char *)RAYGUI_CALLOC(fontImageUncompSize, sizeof(unsigned char));
memcpy(imFont.data, fileDataPtr, fontImageUncompSize);
fileDataPtr += fontImageUncompSize;
}
@ -4907,7 +4906,7 @@ static void GuiLoadStyleFromMemory(const unsigned char *fileData, int dataSize)
if ((recsDataCompressedSize > 0) && (recsDataCompressedSize != recsDataSize))
{
// Recs data is compressed, uncompress it
unsigned char *recsDataCompressed = (unsigned char *)RAYGUI_MALLOC(recsDataCompressedSize);
unsigned char *recsDataCompressed = (unsigned char *)RAYGUI_CALLOC(recsDataCompressedSize, sizeof(unsigned char));
memcpy(recsDataCompressed, fileDataPtr, recsDataCompressedSize);
fileDataPtr += recsDataCompressedSize;
@ -4949,7 +4948,7 @@ static void GuiLoadStyleFromMemory(const unsigned char *fileData, int dataSize)
if ((glyphsDataCompressedSize > 0) && (glyphsDataCompressedSize != glyphsDataSize))
{
// Glyphs data is compressed, uncompress it
unsigned char *glypsDataCompressed = (unsigned char *)RAYGUI_MALLOC(glyphsDataCompressedSize);
unsigned char *glypsDataCompressed = (unsigned char *)RAYGUI_CALLOC(glyphsDataCompressedSize, sizeof(unsigned char));
memcpy(glypsDataCompressed, fileDataPtr, glyphsDataCompressedSize);
fileDataPtr += glyphsDataCompressedSize;

View File

@ -124,10 +124,17 @@ pub extern "c" fn ExportDataAsCode(data: [*c]const u8, dataSize: c_int, fileName
pub extern "c" fn LoadFileText(fileName: [*c]const u8) [*c]u8;
pub extern "c" fn UnloadFileText(text: [*c]u8) void;
pub extern "c" fn SaveFileText(fileName: [*c]const u8, text: [*c]const u8) bool;
pub extern "c" fn FileRename(fileName: [*c]const u8, fileRename_: [*c]const u8) c_int;
pub extern "c" fn FileRemove(fileName: [*c]const u8) c_int;
pub extern "c" fn FileCopy(srcPath: [*c]const u8, dstPath: [*c]const u8) c_int;
pub extern "c" fn FileMove(srcPath: [*c]const u8, dstPath: [*c]const u8) c_int;
pub extern "c" fn FileTextReplace(fileName: [*c]const u8, search: [*c]const u8, replacement: [*c]const u8) c_int;
pub extern "c" fn FileTextFindIndex(fileName: [*c]const u8, search: [*c]const u8) c_int;
pub extern "c" fn FileExists(fileName: [*c]const u8) bool;
pub extern "c" fn DirectoryExists(dirPath: [*c]const u8) bool;
pub extern "c" fn IsFileExtension(fileName: [*c]const u8, ext: [*c]const u8) bool;
pub extern "c" fn GetFileLength(fileName: [*c]const u8) c_int;
pub extern "c" fn GetFileModTime(fileName: [*c]const u8) c_long;
pub extern "c" fn GetFileExtension(fileName: [*c]const u8) [*c]const u8;
pub extern "c" fn GetFileName(filePath: [*c]const u8) [*c]const u8;
pub extern "c" fn GetFileNameWithoutExt(filePath: [*c]const u8) [*c]const u8;
@ -145,7 +152,6 @@ pub extern "c" fn UnloadDirectoryFiles(files: rl.FilePathList) void;
pub extern "c" fn IsFileDropped() bool;
pub extern "c" fn LoadDroppedFiles() rl.FilePathList;
pub extern "c" fn UnloadDroppedFiles(files: rl.FilePathList) void;
pub extern "c" fn GetFileModTime(fileName: [*c]const u8) c_long;
pub extern "c" fn CompressData(data: [*c]const u8, dataSize: c_int, compDataSize: [*c]c_int) [*c]u8;
pub extern "c" fn DecompressData(compData: [*c]const u8, compDataSize: c_int, dataSize: [*c]c_int) [*c]u8;
pub extern "c" fn EncodeDataBase64(data: [*c]const u8, dataSize: c_int, outputSize: [*c]c_int) [*c]u8;
@ -399,7 +405,7 @@ pub extern "c" fn LoadFontEx(fileName: [*c]const u8, fontSize: c_int, codepoints
pub extern "c" fn LoadFontFromImage(image: rl.Image, key: rl.Color, firstChar: c_int) rl.Font;
pub extern "c" fn LoadFontFromMemory(fileType: [*c]const u8, fileData: [*c]const u8, dataSize: c_int, fontSize: c_int, codepoints: [*c]const c_int, codepointCount: c_int) rl.Font;
pub extern "c" fn IsFontValid(font: rl.Font) bool;
pub extern "c" fn LoadFontData(fileData: [*c]const u8, dataSize: c_int, fontSize: c_int, codepoints: [*c]c_int, codepointCount: c_int, ty: rl.FontType) [*c]rl.GlyphInfo;
pub extern "c" fn LoadFontData(fileData: [*c]const u8, dataSize: c_int, fontSize: c_int, codepoints: [*c]const c_int, codepointCount: c_int, ty: rl.FontType, glyphCount: [*c]c_int) [*c]rl.GlyphInfo;
pub extern "c" fn GenImageFontAtlas(glyphs: [*c]const rl.GlyphInfo, glyphRecs: [*c][*c]rl.Rectangle, glyphCount: c_int, fontSize: c_int, padding: c_int, packMethod: c_int) rl.Image;
pub extern "c" fn UnloadFontData(glyphs: [*c]rl.GlyphInfo, glyphCount: c_int) void;
pub extern "c" fn UnloadFont(font: rl.Font) void;
@ -426,18 +432,21 @@ pub extern "c" fn GetCodepointNext(text: [*c]const u8, codepointSize: [*c]c_int)
pub extern "c" fn GetCodepointPrevious(text: [*c]const u8, codepointSize: [*c]c_int) c_int;
pub extern "c" fn CodepointToUTF8(codepoint: c_int, utf8Size: [*c]c_int) [*c]const u8;
pub extern "c" fn LoadTextLines(text: [*c]const u8, count: [*c]c_int) [*c][*c]u8;
pub extern "c" fn UnloadTextLines(text: [*c][*c]u8) void;
pub extern "c" fn UnloadTextLines(text: [*c][*c]u8, lineCount: c_int) void;
pub extern "c" fn TextCopy(dst: [*c]u8, src: [*c]const u8) c_int;
pub extern "c" fn TextIsEqual(text1: [*c]const u8, text2: [*c]const u8) bool;
pub extern "c" fn TextLength(text: [*c]const u8) c_uint;
pub extern "c" fn TextFormat(text: [*c]const u8, ...) [*c]const u8;
pub extern "c" fn TextSubtext(text: [*c]const u8, position: c_int, length: c_int) [*c]const u8;
pub extern "c" fn TextReplace(text: [*c]const u8, replace: [*c]const u8, by: [*c]const u8) [*c]u8;
pub extern "c" fn TextRemoveSpaces(text: [*c]const u8) [*c]const u8;
pub extern "c" fn GetTextBetween(text: [*c]const u8, begin: [*c]const u8, end: [*c]const u8) [*c]u8;
pub extern "c" fn TextReplace(text: [*c]const u8, search: [*c]const u8, replacement: [*c]const u8) [*c]u8;
pub extern "c" fn TextReplaceBetween(text: [*c]const u8, begin: [*c]const u8, end: [*c]const u8, replacement: [*c]const u8) [*c]u8;
pub extern "c" fn TextInsert(text: [*c]const u8, insert: [*c]const u8, position: c_int) [*c]u8;
pub extern "c" fn TextJoin(textList: [*c][*c]u8, count: c_int, delimiter: [*c]const u8) [*c]u8;
pub extern "c" fn TextSplit(text: [*c]const u8, delimiter: u8, count: [*c]c_int) [*c][*c]u8;
pub extern "c" fn TextAppend(text: [*c]u8, append: [*c]const u8, position: [*c]c_int) void;
pub extern "c" fn TextFindIndex(text: [*c]const u8, find: [*c]const u8) c_int;
pub extern "c" fn TextFindIndex(text: [*c]const u8, search: [*c]const u8) c_int;
pub extern "c" fn TextToUpper(text: [*c]const u8) [*c]u8;
pub extern "c" fn TextToLower(text: [*c]const u8) [*c]u8;
pub extern "c" fn TextToPascal(text: [*c]const u8) [*c]u8;

29
lib/raylib.h vendored
View File

@ -115,7 +115,7 @@
#endif
//----------------------------------------------------------------------------------
// Some basic Defines
// Defines and Macros
//----------------------------------------------------------------------------------
#ifndef PI
#define PI 3.14159265358979323846f
@ -201,7 +201,7 @@
#define RAYWHITE CLITERAL(Color){ 245, 245, 245, 255 } // My own White (raylib logo)
//----------------------------------------------------------------------------------
// Structures Definition
// Types and Structures Definition
//----------------------------------------------------------------------------------
// Boolean type
#if (defined(__STDC__) && __STDC_VERSION__ >= 199901L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
@ -327,7 +327,7 @@ typedef struct Camera3D {
Vector3 position; // Camera position
Vector3 target; // Camera target it looks-at
Vector3 up; // Camera up vector (rotation over its axis)
float fovy; // Camera field-of-view aperture in Y (degrees) in perspective, used as near plane width in orthographic
float fovy; // Camera field-of-view aperture in Y (degrees) in perspective, used as near plane height in world units in orthographic
int projection; // Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
} Camera3D;
@ -1127,10 +1127,17 @@ RLAPI bool SaveFileText(const char *fileName, const char *text); // Save text d
//------------------------------------------------------------------
// File system functions
RLAPI int FileRename(const char *fileName, const char *fileRename); // Rename file (if exists)
RLAPI int FileRemove(const char *fileName); // Remove file (if exists)
RLAPI int FileCopy(const char *srcPath, const char *dstPath); // Copy file from one path to another, dstPath created if it doesn't exist
RLAPI int FileMove(const char *srcPath, const char *dstPath); // Move file from one directory to another, dstPath created if it doesn't exist
RLAPI int FileTextReplace(const char *fileName, const char *search, const char *replacement); // Replace text in an existing file
RLAPI int FileTextFindIndex(const char *fileName, const char *search); // Find text in existing file
RLAPI bool FileExists(const char *fileName); // Check if file exists
RLAPI bool DirectoryExists(const char *dirPath); // Check if a directory path exists
RLAPI bool IsFileExtension(const char *fileName, const char *ext); // Check file extension (recommended include point: .png, .wav)
RLAPI int GetFileLength(const char *fileName); // Get file length in bytes (NOTE: GetFileSize() conflicts with windows.h)
RLAPI long GetFileModTime(const char *fileName); // Get file modification time (last write time)
RLAPI const char *GetFileExtension(const char *fileName); // Get pointer to extension for a filename string (includes dot: '.png')
RLAPI const char *GetFileName(const char *filePath); // Get pointer to filename for a path string
RLAPI const char *GetFileNameWithoutExt(const char *filePath); // Get filename string without extension (uses static string)
@ -1148,7 +1155,6 @@ RLAPI void UnloadDirectoryFiles(FilePathList files); // Unload file
RLAPI bool IsFileDropped(void); // Check if a file has been dropped into window
RLAPI FilePathList LoadDroppedFiles(void); // Load dropped filepaths
RLAPI void UnloadDroppedFiles(FilePathList files); // Unload dropped filepaths
RLAPI long GetFileModTime(const char *fileName); // Get file modification time (last write time)
// Compression/Encoding functionality
RLAPI unsigned char *CompressData(const unsigned char *data, int dataSize, int *compDataSize); // Compress data (DEFLATE algorithm), memory must be MemFree()
@ -1470,7 +1476,7 @@ RLAPI Font LoadFontEx(const char *fileName, int fontSize, const int *codepoints,
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, const int *codepoints, int codepointCount); // Load font from memory buffer, fileType refers to extension: i.e. '.ttf'
RLAPI bool IsFontValid(Font font); // Check if a font is valid (font data loaded, WARNING: GPU texture not checked)
RLAPI GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSize, int *codepoints, int codepointCount, int type); // Load font data for further use
RLAPI GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSize, const int *codepoints, int codepointCount, int type, int *glyphCount); // Load font data for further use
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)
@ -1504,21 +1510,24 @@ RLAPI int GetCodepointPrevious(const char *text, int *codepointSize);
RLAPI const char *CodepointToUTF8(int codepoint, int *utf8Size); // Encode one codepoint into UTF-8 byte array (array length returned as parameter)
// Text strings management functions (no UTF-8 strings, only byte chars)
// WARNING 1: Most of these functions use internal static buffers, it's recommended to store returned data on user-side for re-use
// WARNING 1: Most of these functions use internal static buffers[], it's recommended to store returned data on user-side for re-use
// WARNING 2: Some strings allocate memory internally for the returned strings, those strings must be free by user using MemFree()
RLAPI char **LoadTextLines(const char *text, int *count); // Load text as separate lines ('\n')
RLAPI void UnloadTextLines(char **text); // Unload text lines
RLAPI void UnloadTextLines(char **text, int lineCount); // Unload text lines
RLAPI int TextCopy(char *dst, const char *src); // Copy one string to another, returns bytes copied
RLAPI bool TextIsEqual(const char *text1, const char *text2); // Check if two text string are equal
RLAPI unsigned int TextLength(const char *text); // Get text length, checks for '\0' ending
RLAPI const char *TextFormat(const char *text, ...); // Text formatting with variables (sprintf() style)
RLAPI const char *TextSubtext(const char *text, int position, int length); // Get a piece of a text string
RLAPI char *TextReplace(const char *text, const char *replace, const char *by); // Replace text string (WARNING: memory must be freed!)
RLAPI const char *TextRemoveSpaces(const char *text); // Remove text spaces, concat words
RLAPI char *GetTextBetween(const char *text, const char *begin, const char *end); // Get text between two strings
RLAPI char *TextReplace(const char *text, const char *search, const char *replacement); // Replace text string (WARNING: memory must be freed!)
RLAPI char *TextReplaceBetween(const char *text, const char *begin, const char *end, const char *replacement); // Replace text between two specific strings (WARNING: memory must be freed!)
RLAPI char *TextInsert(const char *text, const char *insert, int position); // Insert text in a position (WARNING: memory must be freed!)
RLAPI char *TextJoin(char **textList, int count, const char *delimiter); // Join text strings with delimiter
RLAPI char **TextSplit(const char *text, char delimiter, int *count); // Split text into multiple strings, using MAX_TEXTSPLIT_COUNT static strings
RLAPI void TextAppend(char *text, const char *append, int *position); // Append text at specific position and move cursor!
RLAPI int TextFindIndex(const char *text, const char *find); // Find first text occurrence within a string, -1 if not found
RLAPI void TextAppend(char *text, const char *append, int *position); // Append text at specific position and move cursor
RLAPI int TextFindIndex(const char *text, const char *search); // Find first text occurrence within a string, -1 if not found
RLAPI char *TextToUpper(const char *text); // Get upper case version of provided string
RLAPI char *TextToLower(const char *text); // Get lower case version of provided string
RLAPI char *TextToPascal(const char *text); // Get Pascal case notation version of provided string

View File

@ -2287,19 +2287,19 @@ pub fn loadFontFromImage(image: Image, key: Color, firstChar: i32) RaylibError!F
}
/// Load font data for further use
pub fn loadFontData(fileData: []const u8, fontSize: i32, codePoints: ?[]i32, ty: FontType) RaylibError![]GlyphInfo {
pub fn loadFontData(fileData: []const u8, fontSize: i32, codePoints: ?[]const i32, ty: FontType) RaylibError![]GlyphInfo {
var res: []GlyphInfo = undefined;
var codePointsFinal = @as([*c]i32, 0);
var codePointsFinal = @as([*c]const i32, 0);
var codePointsLen: i32 = 0;
if (codePoints) |codePointsSure| {
codePointsFinal = @as([*c]i32, @ptrCast(codePointsSure));
codePointsFinal = @as([*c]const i32, @ptrCast(codePointsSure));
codePointsLen = @as(i32, @intCast(codePointsSure.len));
} else {
codePointsLen = 95;
}
const ptr = cdef.LoadFontData(@as([*c]const u8, @ptrCast(fileData)), @as(c_int, @intCast(fileData.len)), @as(c_int, fontSize), codePointsFinal, @as(c_int, @intCast(codePointsLen)), ty);
const ptr = cdef.LoadFontData(@as([*c]const u8, @ptrCast(fileData)), @as(c_int, @intCast(fileData.len)), @as(c_int, fontSize), codePointsFinal, @as(c_int, @intCast(codePointsLen)), ty, @as([*c]i32, &codePointsLen));
if (ptr == 0) return RaylibError.LoadFontData;
res.ptr = @as([*]GlyphInfo, @ptrCast(ptr));
@ -2536,6 +2536,10 @@ pub fn loadTextLines(text: [:0]const u8) RaylibError![][:0]u8 {
return res;
}
pub fn unloadTextLines(lines: [][:0]u8) void {
cdef.UnloadTextLines(@as([*c][*c]u8, @ptrCast(lines)), @as(c_int, @intCast(lines.len)));
}
/// Join text strings with delimiter
pub fn textJoin(textList: [][:0]u8, delimiter: [:0]const u8) [:0]const u8 {
return std.mem.span(cdef.TextJoin(@as([*c][*c]u8, @ptrCast(textList)), @as(c_int, @intCast(textList.len)), @as([*c]const u8, @ptrCast(delimiter))));
@ -3159,6 +3163,36 @@ pub fn saveFileText(fileName: [:0]const u8, text: [:0]const u8) bool {
return cdef.SaveFileText(@as([*c]const u8, @ptrCast(fileName)), @as([*c]const u8, @ptrCast(text)));
}
/// Rename file (if exists)
pub fn fileRename(fileName: [:0]const u8, fileRename_: [:0]const u8) i32 {
return @as(i32, cdef.FileRename(@as([*c]const u8, @ptrCast(fileName)), @as([*c]const u8, @ptrCast(fileRename_))));
}
/// Remove file (if exists)
pub fn fileRemove(fileName: [:0]const u8) i32 {
return @as(i32, cdef.FileRemove(@as([*c]const u8, @ptrCast(fileName))));
}
/// Copy file from one path to another, dstPath created if it doesn't exist
pub fn fileCopy(srcPath: [:0]const u8, dstPath: [:0]const u8) i32 {
return @as(i32, cdef.FileCopy(@as([*c]const u8, @ptrCast(srcPath)), @as([*c]const u8, @ptrCast(dstPath))));
}
/// Move file from one directory to another, dstPath created if it doesn't exist
pub fn fileMove(srcPath: [:0]const u8, dstPath: [:0]const u8) i32 {
return @as(i32, cdef.FileMove(@as([*c]const u8, @ptrCast(srcPath)), @as([*c]const u8, @ptrCast(dstPath))));
}
/// Replace text in an existing file
pub fn fileTextReplace(fileName: [:0]const u8, search: [:0]const u8, replacement: [:0]const u8) i32 {
return @as(i32, cdef.FileTextReplace(@as([*c]const u8, @ptrCast(fileName)), @as([*c]const u8, @ptrCast(search)), @as([*c]const u8, @ptrCast(replacement))));
}
/// Find text in existing file
pub fn fileTextFindIndex(fileName: [:0]const u8, search: [:0]const u8) i32 {
return @as(i32, cdef.FileTextFindIndex(@as([*c]const u8, @ptrCast(fileName)), @as([*c]const u8, @ptrCast(search))));
}
/// Check if file exists
pub fn fileExists(fileName: [:0]const u8) bool {
return cdef.FileExists(@as([*c]const u8, @ptrCast(fileName)));
@ -3179,6 +3213,11 @@ pub fn getFileLength(fileName: [:0]const u8) i32 {
return @as(i32, cdef.GetFileLength(@as([*c]const u8, @ptrCast(fileName))));
}
/// Get file modification time (last write time)
pub fn getFileModTime(fileName: [:0]const u8) i64 {
return @as(i64, cdef.GetFileModTime(@as([*c]const u8, @ptrCast(fileName))));
}
/// Get pointer to extension for a filename string (includes dot: '.png')
pub fn getFileExtension(fileName: [:0]const u8) [:0]const u8 {
return std.mem.span(cdef.GetFileExtension(@as([*c]const u8, @ptrCast(fileName))));
@ -3264,11 +3303,6 @@ pub fn unloadDroppedFiles(files: FilePathList) void {
cdef.UnloadDroppedFiles(files);
}
/// Get file modification time (last write time)
pub fn getFileModTime(fileName: [:0]const u8) i64 {
return @as(i64, cdef.GetFileModTime(@as([*c]const u8, @ptrCast(fileName))));
}
/// Compress data (DEFLATE algorithm), memory must be MemFree()
pub fn compressData(data: []const u8, dataSize: i32) RaylibError![]u8 {
var _len: i32 = 0;
@ -4495,11 +4529,6 @@ pub fn codepointToUTF8(codepoint: i32, utf8Size: *i32) [:0]const u8 {
return std.mem.span(cdef.CodepointToUTF8(@as(c_int, codepoint), @as([*c]c_int, @ptrCast(utf8Size))));
}
/// Unload text lines
pub fn unloadTextLines(text: [][:0]const u8) void {
cdef.UnloadTextLines(@as([*c][*c]u8, @ptrCast(text)));
}
/// Copy one string to another, returns bytes copied
pub fn textCopy(dst: *u8, src: [:0]const u8) i32 {
return @as(i32, cdef.TextCopy(@as([*c]u8, @ptrCast(dst)), @as([*c]const u8, @ptrCast(src))));
@ -4520,9 +4549,24 @@ pub fn textSubtext(text: [:0]const u8, position: i32, length: i32) [:0]const u8
return std.mem.span(cdef.TextSubtext(@as([*c]const u8, @ptrCast(text)), @as(c_int, position), @as(c_int, length)));
}
/// Remove text spaces, concat words
pub fn textRemoveSpaces(text: [:0]const u8) [:0]const u8 {
return std.mem.span(cdef.TextRemoveSpaces(@as([*c]const u8, @ptrCast(text))));
}
/// Get text between two strings
pub fn getTextBetween(text: [:0]const u8, begin: [:0]const u8, end: [:0]const u8) [:0]u8 {
return std.mem.span(cdef.GetTextBetween(@as([*c]const u8, @ptrCast(text)), @as([*c]const u8, @ptrCast(begin)), @as([*c]const u8, @ptrCast(end))));
}
/// Replace text string (WARNING: memory must be freed!)
pub fn textReplace(text: [:0]const u8, replace: [:0]const u8, by: [:0]const u8) [:0]u8 {
return std.mem.span(cdef.TextReplace(@as([*c]const u8, @ptrCast(text)), @as([*c]const u8, @ptrCast(replace)), @as([*c]const u8, @ptrCast(by))));
pub fn textReplace(text: [:0]const u8, search: [:0]const u8, replacement: [:0]const u8) [:0]u8 {
return std.mem.span(cdef.TextReplace(@as([*c]const u8, @ptrCast(text)), @as([*c]const u8, @ptrCast(search)), @as([*c]const u8, @ptrCast(replacement))));
}
/// Replace text between two specific strings (WARNING: memory must be freed!)
pub fn textReplaceBetween(text: [:0]const u8, begin: [:0]const u8, end: [:0]const u8, replacement: [:0]const u8) [:0]u8 {
return std.mem.span(cdef.TextReplaceBetween(@as([*c]const u8, @ptrCast(text)), @as([*c]const u8, @ptrCast(begin)), @as([*c]const u8, @ptrCast(end)), @as([*c]const u8, @ptrCast(replacement))));
}
/// Insert text in a position (WARNING: memory must be freed!)
@ -4538,14 +4582,14 @@ pub fn textSplit(text: []const u8, delimiter: u8) RaylibError![][:0]u8 {
return @as([*][:0]u8, @ptrCast(_ptr))[0..@as(usize, @intCast(_len))];
}
/// Append text at specific position and move cursor!
/// Append text at specific position and move cursor
pub fn textAppend(text: [:0]u8, append: [:0]const u8, position: *i32) void {
cdef.TextAppend(@as([*c]u8, @ptrCast(text)), @as([*c]const u8, @ptrCast(append)), @as([*c]c_int, @ptrCast(position)));
}
/// Find first text occurrence within a string, -1 if not found
pub fn textFindIndex(text: [:0]const u8, find: [:0]const u8) i32 {
return @as(i32, cdef.TextFindIndex(@as([*c]const u8, @ptrCast(text)), @as([*c]const u8, @ptrCast(find))));
pub fn textFindIndex(text: [:0]const u8, search: [:0]const u8) i32 {
return @as(i32, cdef.TextFindIndex(@as([*c]const u8, @ptrCast(text)), @as([*c]const u8, @ptrCast(search))));
}
/// Get upper case version of provided string

31
lib/rlgl.h vendored
View File

@ -870,6 +870,7 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
#elif defined(GRAPHICS_API_OPENGL_ES2)
// NOTE: OpenGL ES 2.0 can be enabled on Desktop platforms,
// in that case, functions are loaded from a custom glad for OpenGL ES 2.0
// TODO: OpenGL ES 2.0 support shouldn't be platform-dependant, neither require GLAD
#if defined(PLATFORM_DESKTOP_GLFW) || defined(PLATFORM_DESKTOP_SDL)
#define GLAD_GLES2_IMPLEMENTATION
#include "external/glad_gles2.h"
@ -889,7 +890,7 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
#endif
#endif
#include <stdlib.h> // Required for: malloc(), free()
#include <stdlib.h> // Required for: calloc(), free()
#include <string.h> // Required for: strcmp(), strlen() [Used in rlglInit(), on extensions loading]
#include <math.h> // Required for: sqrtf(), sinf(), cosf(), floor(), log()
@ -1039,7 +1040,7 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
#endif
//----------------------------------------------------------------------------------
// Types and Structures Definition
// Module Types and Structures Definition
//----------------------------------------------------------------------------------
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
@ -1145,7 +1146,7 @@ static PFNGLVERTEXATTRIBDIVISOREXTPROC glVertexAttribDivisor = NULL;
#endif
//----------------------------------------------------------------------------------
// Module specific Functions Declaration
// Module Functions Declaration
//----------------------------------------------------------------------------------
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
static void rlLoadShaderDefault(void); // Load default shader
@ -2429,7 +2430,7 @@ void rlLoadExtensions(void *loader)
// Get supported extensions list
GLint numExt = 0;
const char **extList = (const char **)RL_MALLOC(512*sizeof(const char *)); // Allocate 512 strings pointers (2 KB)
const char **extList = (const char **)RL_CALLOC(512, sizeof(const char *)); // Allocate 512 strings pointers (2 KB)
const char *extensions = (const char *)glGetString(GL_EXTENSIONS); // One big const string
// NOTE: We have to duplicate string because glGetString() returns a const string
@ -2741,21 +2742,21 @@ rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements)
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// Initialize CPU (RAM) vertex buffers (position, texcoord, color data and indexes)
//--------------------------------------------------------------------------------------------
batch.vertexBuffer = (rlVertexBuffer *)RL_MALLOC(numBuffers*sizeof(rlVertexBuffer));
batch.vertexBuffer = (rlVertexBuffer *)RL_CALLOC(numBuffers, sizeof(rlVertexBuffer));
for (int i = 0; i < numBuffers; i++)
{
batch.vertexBuffer[i].elementCount = bufferElements;
batch.vertexBuffer[i].vertices = (float *)RL_MALLOC(bufferElements*3*4*sizeof(float)); // 3 float by vertex, 4 vertex by quad
batch.vertexBuffer[i].texcoords = (float *)RL_MALLOC(bufferElements*2*4*sizeof(float)); // 2 float by texcoord, 4 texcoord by quad
batch.vertexBuffer[i].normals = (float *)RL_MALLOC(bufferElements*3*4*sizeof(float)); // 3 float by vertex, 4 vertex by quad
batch.vertexBuffer[i].colors = (unsigned char *)RL_MALLOC(bufferElements*4*4*sizeof(unsigned char)); // 4 float by color, 4 colors by quad
batch.vertexBuffer[i].vertices = (float *)RL_CALLOC(bufferElements*3*4, sizeof(float)); // 3 float by vertex, 4 vertex by quad
batch.vertexBuffer[i].texcoords = (float *)RL_CALLOC(bufferElements*2*4, sizeof(float)); // 2 float by texcoord, 4 texcoord by quad
batch.vertexBuffer[i].normals = (float *)RL_CALLOC(bufferElements*3*4, sizeof(float)); // 3 float by vertex, 4 vertex by quad
batch.vertexBuffer[i].colors = (unsigned char *)RL_CALLOC(bufferElements*4*4, sizeof(unsigned char)); // 4 float by color, 4 colors by quad
#if defined(GRAPHICS_API_OPENGL_33)
batch.vertexBuffer[i].indices = (unsigned int *)RL_MALLOC(bufferElements*6*sizeof(unsigned int)); // 6 int by quad (indices)
batch.vertexBuffer[i].indices = (unsigned int *)RL_CALLOC(bufferElements*6, sizeof(unsigned int)); // 6 int by quad (indices)
#endif
#if defined(GRAPHICS_API_OPENGL_ES2)
batch.vertexBuffer[i].indices = (unsigned short *)RL_MALLOC(bufferElements*6*sizeof(unsigned short)); // 6 int by quad (indices)
batch.vertexBuffer[i].indices = (unsigned short *)RL_CALLOC(bufferElements*6, sizeof(unsigned short)); // 6 int by quad (indices)
#endif
for (int j = 0; j < (3*4*bufferElements); j++) batch.vertexBuffer[i].vertices[j] = 0.0f;
@ -2843,7 +2844,7 @@ rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements)
// Init draw calls tracking system
//--------------------------------------------------------------------------------------------
batch.draws = (rlDrawCall *)RL_MALLOC(RL_DEFAULT_BATCH_DRAWCALLS*sizeof(rlDrawCall));
batch.draws = (rlDrawCall *)RL_CALLOC(RL_DEFAULT_BATCH_DRAWCALLS, sizeof(rlDrawCall));
for (int i = 0; i < RL_DEFAULT_BATCH_DRAWCALLS; i++)
{
@ -3649,7 +3650,7 @@ void *rlReadTexturePixels(unsigned int id, int width, int height, int format)
if ((glInternalFormat != 0) && (format < RL_PIXELFORMAT_COMPRESSED_DXT1_RGB))
{
pixels = RL_MALLOC(size);
pixels = RL_CALLOC(size, 1);
glGetTexImage(GL_TEXTURE_2D, 0, glFormat, glType, pixels);
}
else TRACELOG(RL_LOG_WARNING, "TEXTURE: [ID %i] Data retrieval not suported for pixel format (%i)", id, format);
@ -3674,7 +3675,7 @@ void *rlReadTexturePixels(unsigned int id, int width, int height, int format)
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, id, 0);
// We read data as RGBA because FBO texture is configured as RGBA, despite binding another texture format
pixels = (unsigned char *)RL_MALLOC(rlGetPixelDataSize(width, height, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8));
pixels = RL_CALLOC(rlGetPixelDataSize(width, height, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8), 1);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
@ -4864,7 +4865,7 @@ const char *rlGetPixelFormatName(unsigned int format)
}
//----------------------------------------------------------------------------------
// Module specific Functions Definition
// Module Functions Definition
//----------------------------------------------------------------------------------
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// Load default shader (just vertex positioning and texture coloring)