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

View File

@ -90,6 +90,7 @@ MANUAL = [
"DrawTextCodepoints", "DrawTextCodepoints",
"LoadUTF8", "LoadUTF8",
"LoadTextLines", "LoadTextLines",
"UnloadTextLines",
"TextJoin", "TextJoin",
"DrawLineStrip", "DrawLineStrip",
"DrawTriangleFan", "DrawTriangleFan",
@ -142,7 +143,7 @@ def ziggify_type(name: str, t: str, func_name: str) -> str:
"AutomationEventList", "list", "batch", "glInternalFormat", "glFormat", "AutomationEventList", "list", "batch", "glInternalFormat", "glFormat",
"glType", "mipmaps", "active", "scroll", "view", "checked", "mouseCell", "glType", "mipmaps", "active", "scroll", "view", "checked", "mouseCell",
"scrollIndex", "focus", "secretViewActive", "color", "alpha", "colorHsv", "scrollIndex", "focus", "secretViewActive", "color", "alpha", "colorHsv",
"translation", "rotation", "scale", "mat" "translation", "rotation", "scale", "mat", "glyphCount"
] ]
multi = [ multi = [
"data", "compData", "points", "fileData", "colors", "pixels", "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: if not arguments:
arguments = "void" arguments = "void"
zig_name = convert_name(func_name)
for arg in arguments.split(", "): for arg in arguments.split(", "):
if arg == "void": if arg == "void":
break 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_type = c_to_zig_type(arg_type)
arg_name, arg_type = fix_pointer(arg_name, arg_type) arg_name, arg_type = fix_pointer(arg_name, arg_type)
if arg_name == zig_name:
arg_name += "_"
single_opt = [ single_opt = [
("rlDrawVertexArrayElements", "buffer"), ("rlDrawVertexArrayElements", "buffer"),
("rlDrawVertexArrayElementsInstanced", "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_ret = add_namespace_to_type(return_type)
ext_heads.append(f"pub extern \"c\" fn {func_name}({zig_c_arguments}) {ext_ret};") ext_heads.append(f"pub extern \"c\" fn {func_name}({zig_c_arguments}) {ext_ret};")
zig_name = convert_name(func_name)
func_prelude = "" func_prelude = ""
if func_name in TRIVIAL_SIZE: 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 /// 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 res: []GlyphInfo = undefined;
var codePointsFinal = @as([*c]i32, 0); var codePointsFinal = @as([*c]const i32, 0);
var codePointsLen: i32 = 0; var codePointsLen: i32 = 0;
if (codePoints) |codePointsSure| { if (codePoints) |codePointsSure| {
codePointsFinal = @as([*c]i32, @ptrCast(codePointsSure)); codePointsFinal = @as([*c]const i32, @ptrCast(codePointsSure));
codePointsLen = @as(i32, @intCast(codePointsSure.len)); codePointsLen = @as(i32, @intCast(codePointsSure.len));
} else { } else {
codePointsLen = 95; 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; if (ptr == 0) return RaylibError.LoadFontData;
res.ptr = @as([*]GlyphInfo, @ptrCast(ptr)); res.ptr = @as([*]GlyphInfo, @ptrCast(ptr));
@ -2536,6 +2536,10 @@ pub fn loadTextLines(text: [:0]const u8) RaylibError![][:0]u8 {
return res; 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 /// Join text strings with delimiter
pub fn textJoin(textList: [][:0]u8, delimiter: [:0]const u8) [:0]const u8 { 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)))); return std.mem.span(cdef.TextJoin(@as([*c][*c]u8, @ptrCast(textList)), @as(c_int, @intCast(textList.len)), @as([*c]const u8, @ptrCast(delimiter))));

29
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 #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 // Gui control property style color element
typedef enum { BORDER = 0, BASE, TEXT, OTHER } GuiPropertyElement; 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 #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) static void GuiLoadStyleFromMemory(const unsigned char *fileData, int dataSize); // Load style from memory (binary only)
@ -3175,7 +3175,7 @@ int GuiValueBoxFloat(Rectangle bounds, const char *text, char *textValue, float
//char textValue[RAYGUI_VALUEBOX_MAX_CHARS + 1] = "\0"; //char textValue[RAYGUI_VALUEBOX_MAX_CHARS + 1] = "\0";
//snprintf(textValue, sizeof(textValue), "%2.2f", *value); //snprintf(textValue, sizeof(textValue), "%2.2f", *value);
Rectangle textBounds = {0}; Rectangle textBounds = { 0 };
if (text != NULL) if (text != NULL)
{ {
textBounds.width = (float)GuiGetTextWidth(text) + 2; textBounds.width = (float)GuiGetTextWidth(text) + 2;
@ -4408,7 +4408,7 @@ void GuiLoadStyle(const char *fileName)
if (fileDataSize > 0) 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); fread(fileData, sizeof(unsigned char), fileDataSize, rgsFile);
GuiLoadStyleFromMemory(fileData, fileDataSize); GuiLoadStyleFromMemory(fileData, fileDataSize);
@ -4616,10 +4616,10 @@ char **GuiLoadIcons(const char *fileName, bool loadIconsName)
{ {
if (loadIconsName) if (loadIconsName)
{ {
guiIconsName = (char **)RAYGUI_MALLOC(iconCount*sizeof(char **)); guiIconsName = (char **)RAYGUI_CALLOC(iconCount, sizeof(char *));
for (int i = 0; i < iconCount; i++) 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); 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) if (loadIconsName)
{ {
guiIconsName = (char **)RAYGUI_MALLOC(iconCount*sizeof(char *)); guiIconsName = (char **)RAYGUI_CALLOC(iconCount, sizeof(char *));
for (int i = 0; i < iconCount; i++) 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); memcpy(guiIconsName[i], fileDataPtr, RAYGUI_ICON_MAX_NAME_LENGTH);
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); 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); memcpy(guiIconsPtr, fileDataPtr, iconDataSize);
} }
@ -4777,9 +4777,8 @@ int GuiGetTextWidth(const char *text)
#endif // !RAYGUI_NO_ICONS #endif // !RAYGUI_NO_ICONS
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module specific Functions Definition // Module Internal Functions Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Load style from memory // Load style from memory
// WARNING: Binary files only // WARNING: Binary files only
static void GuiLoadStyleFromMemory(const unsigned char *fileData, int dataSize) 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() // Compressed font atlas image data (DEFLATE), it requires DecompressData()
int dataUncompSize = 0; 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); memcpy(compData, fileDataPtr, fontImageCompSize);
fileDataPtr += fontImageCompSize; fileDataPtr += fontImageCompSize;
@ -4879,7 +4878,7 @@ static void GuiLoadStyleFromMemory(const unsigned char *fileData, int dataSize)
else else
{ {
// Font atlas image data is not compressed // 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); memcpy(imFont.data, fileDataPtr, fontImageUncompSize);
fileDataPtr += fontImageUncompSize; fileDataPtr += fontImageUncompSize;
} }
@ -4907,7 +4906,7 @@ static void GuiLoadStyleFromMemory(const unsigned char *fileData, int dataSize)
if ((recsDataCompressedSize > 0) && (recsDataCompressedSize != recsDataSize)) if ((recsDataCompressedSize > 0) && (recsDataCompressedSize != recsDataSize))
{ {
// Recs data is compressed, uncompress it // 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); memcpy(recsDataCompressed, fileDataPtr, recsDataCompressedSize);
fileDataPtr += recsDataCompressedSize; fileDataPtr += recsDataCompressedSize;
@ -4949,7 +4948,7 @@ static void GuiLoadStyleFromMemory(const unsigned char *fileData, int dataSize)
if ((glyphsDataCompressedSize > 0) && (glyphsDataCompressedSize != glyphsDataSize)) if ((glyphsDataCompressedSize > 0) && (glyphsDataCompressedSize != glyphsDataSize))
{ {
// Glyphs data is compressed, uncompress it // 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); memcpy(glypsDataCompressed, fileDataPtr, glyphsDataCompressedSize);
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 LoadFileText(fileName: [*c]const u8) [*c]u8;
pub extern "c" fn UnloadFileText(text: [*c]u8) void; 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 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 FileExists(fileName: [*c]const u8) bool;
pub extern "c" fn DirectoryExists(dirPath: [*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 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 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 GetFileExtension(fileName: [*c]const u8) [*c]const u8;
pub extern "c" fn GetFileName(filePath: [*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; 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 IsFileDropped() bool;
pub extern "c" fn LoadDroppedFiles() rl.FilePathList; pub extern "c" fn LoadDroppedFiles() rl.FilePathList;
pub extern "c" fn UnloadDroppedFiles(files: rl.FilePathList) void; 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 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 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; 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 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 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 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 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 UnloadFontData(glyphs: [*c]rl.GlyphInfo, glyphCount: c_int) void;
pub extern "c" fn UnloadFont(font: rl.Font) 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 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 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 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 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 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 TextLength(text: [*c]const u8) c_uint;
pub extern "c" fn TextFormat(text: [*c]const u8, ...) [*c]const u8; 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 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 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 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 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 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 TextToUpper(text: [*c]const u8) [*c]u8;
pub extern "c" fn TextToLower(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; pub extern "c" fn TextToPascal(text: [*c]const u8) [*c]u8;

87
lib/raylib.h vendored
View File

@ -115,7 +115,7 @@
#endif #endif
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Some basic Defines // Defines and Macros
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
#ifndef PI #ifndef PI
#define PI 3.14159265358979323846f #define PI 3.14159265358979323846f
@ -201,7 +201,7 @@
#define RAYWHITE CLITERAL(Color){ 245, 245, 245, 255 } // My own White (raylib logo) #define RAYWHITE CLITERAL(Color){ 245, 245, 245, 255 } // My own White (raylib logo)
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Structures Definition // Types and Structures Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Boolean type // Boolean type
#if (defined(__STDC__) && __STDC_VERSION__ >= 199901L) || (defined(_MSC_VER) && _MSC_VER >= 1800) #if (defined(__STDC__) && __STDC_VERSION__ >= 199901L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
@ -327,7 +327,7 @@ typedef struct Camera3D {
Vector3 position; // Camera position Vector3 position; // Camera position
Vector3 target; // Camera target it looks-at Vector3 target; // Camera target it looks-at
Vector3 up; // Camera up vector (rotation over its axis) 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 int projection; // Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
} Camera3D; } Camera3D;
@ -1110,45 +1110,51 @@ RLAPI void MemFree(void *ptr); // Internal me
// Set custom callbacks // Set custom callbacks
// WARNING: Callbacks setup is intended for advanced users // WARNING: Callbacks setup is intended for advanced users
RLAPI void SetTraceLogCallback(TraceLogCallback callback); // Set custom trace log RLAPI void SetTraceLogCallback(TraceLogCallback callback); // Set custom trace log
RLAPI void SetLoadFileDataCallback(LoadFileDataCallback callback); // Set custom file binary data loader RLAPI void SetLoadFileDataCallback(LoadFileDataCallback callback); // Set custom file binary data loader
RLAPI void SetSaveFileDataCallback(SaveFileDataCallback callback); // Set custom file binary data saver RLAPI void SetSaveFileDataCallback(SaveFileDataCallback callback); // Set custom file binary data saver
RLAPI void SetLoadFileTextCallback(LoadFileTextCallback callback); // Set custom file text data loader RLAPI void SetLoadFileTextCallback(LoadFileTextCallback callback); // Set custom file text data loader
RLAPI void SetSaveFileTextCallback(SaveFileTextCallback callback); // Set custom file text data saver RLAPI void SetSaveFileTextCallback(SaveFileTextCallback callback); // Set custom file text data saver
// Files management functions // Files management functions
RLAPI unsigned char *LoadFileData(const char *fileName, int *dataSize); // Load file data as byte array (read) RLAPI unsigned char *LoadFileData(const char *fileName, int *dataSize); // Load file data as byte array (read)
RLAPI void UnloadFileData(unsigned char *data); // Unload file data allocated by LoadFileData() RLAPI void UnloadFileData(unsigned char *data); // Unload file data allocated by LoadFileData()
RLAPI bool SaveFileData(const char *fileName, void *data, int dataSize); // Save data to file from byte array (write), returns true on success RLAPI bool SaveFileData(const char *fileName, void *data, int dataSize); // Save data to file from byte array (write), returns true on success
RLAPI bool ExportDataAsCode(const unsigned char *data, int dataSize, const char *fileName); // Export data to code (.h), returns true on success RLAPI bool ExportDataAsCode(const unsigned char *data, int dataSize, const char *fileName); // Export data to code (.h), returns true on success
RLAPI char *LoadFileText(const char *fileName); // Load text data from file (read), returns a '\0' terminated string RLAPI char *LoadFileText(const char *fileName); // Load text data from file (read), returns a '\0' terminated string
RLAPI void UnloadFileText(char *text); // Unload file text data allocated by LoadFileText() RLAPI void UnloadFileText(char *text); // Unload file text data allocated by LoadFileText()
RLAPI bool SaveFileText(const char *fileName, const char *text); // Save text data to file (write), string must be '\0' terminated, returns true on success RLAPI bool SaveFileText(const char *fileName, const char *text); // Save text data to file (write), string must be '\0' terminated, returns true on success
//------------------------------------------------------------------ //------------------------------------------------------------------
// File system functions // File system functions
RLAPI bool FileExists(const char *fileName); // Check if file exists RLAPI int FileRename(const char *fileName, const char *fileRename); // Rename file (if exists)
RLAPI bool DirectoryExists(const char *dirPath); // Check if a directory path exists RLAPI int FileRemove(const char *fileName); // Remove file (if exists)
RLAPI bool IsFileExtension(const char *fileName, const char *ext); // Check file extension (recommended include point: .png, .wav) 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 GetFileLength(const char *fileName); // Get file length in bytes (NOTE: GetFileSize() conflicts with windows.h) RLAPI int FileMove(const char *srcPath, const char *dstPath); // Move file from one directory to another, dstPath created if it doesn't exist
RLAPI const char *GetFileExtension(const char *fileName); // Get pointer to extension for a filename string (includes dot: '.png') RLAPI int FileTextReplace(const char *fileName, const char *search, const char *replacement); // Replace text in an existing file
RLAPI const char *GetFileName(const char *filePath); // Get pointer to filename for a path string RLAPI int FileTextFindIndex(const char *fileName, const char *search); // Find text in existing file
RLAPI const char *GetFileNameWithoutExt(const char *filePath); // Get filename string without extension (uses static string) RLAPI bool FileExists(const char *fileName); // Check if file exists
RLAPI const char *GetDirectoryPath(const char *filePath); // Get full path for a given fileName with path (uses static string) RLAPI bool DirectoryExists(const char *dirPath); // Check if a directory path exists
RLAPI const char *GetPrevDirectoryPath(const char *dirPath); // Get previous directory path for a given path (uses static string) RLAPI bool IsFileExtension(const char *fileName, const char *ext); // Check file extension (recommended include point: .png, .wav)
RLAPI const char *GetWorkingDirectory(void); // Get current working directory (uses static string) RLAPI int GetFileLength(const char *fileName); // Get file length in bytes (NOTE: GetFileSize() conflicts with windows.h)
RLAPI const char *GetApplicationDirectory(void); // Get the directory of the running application (uses static string) RLAPI long GetFileModTime(const char *fileName); // Get file modification time (last write time)
RLAPI int MakeDirectory(const char *dirPath); // Create directories (including full path requested), returns 0 on success RLAPI const char *GetFileExtension(const char *fileName); // Get pointer to extension for a filename string (includes dot: '.png')
RLAPI bool ChangeDirectory(const char *dir); // Change working directory, return true on success RLAPI const char *GetFileName(const char *filePath); // Get pointer to filename for a path string
RLAPI bool IsPathFile(const char *path); // Check if a given path is a file or a directory RLAPI const char *GetFileNameWithoutExt(const char *filePath); // Get filename string without extension (uses static string)
RLAPI bool IsFileNameValid(const char *fileName); // Check if fileName is valid for the platform/OS RLAPI const char *GetDirectoryPath(const char *filePath); // Get full path for a given fileName with path (uses static string)
RLAPI FilePathList LoadDirectoryFiles(const char *dirPath); // Load directory filepaths RLAPI const char *GetPrevDirectoryPath(const char *dirPath); // Get previous directory path for a given path (uses static string)
RLAPI const char *GetWorkingDirectory(void); // Get current working directory (uses static string)
RLAPI const char *GetApplicationDirectory(void); // Get the directory of the running application (uses static string)
RLAPI int MakeDirectory(const char *dirPath); // Create directories (including full path requested), returns 0 on success
RLAPI bool ChangeDirectory(const char *dir); // Change working directory, return true on success
RLAPI bool IsPathFile(const char *path); // Check if a given path is a file or a directory
RLAPI bool IsFileNameValid(const char *fileName); // Check if fileName is valid for the platform/OS
RLAPI FilePathList LoadDirectoryFiles(const char *dirPath); // Load directory filepaths
RLAPI FilePathList LoadDirectoryFilesEx(const char *basePath, const char *filter, bool scanSubdirs); // Load directory filepaths with extension filtering and recursive directory scan. Use 'DIR' in the filter string to include directories in the result RLAPI FilePathList LoadDirectoryFilesEx(const char *basePath, const char *filter, bool scanSubdirs); // Load directory filepaths with extension filtering and recursive directory scan. Use 'DIR' in the filter string to include directories in the result
RLAPI void UnloadDirectoryFiles(FilePathList files); // Unload filepaths RLAPI void UnloadDirectoryFiles(FilePathList files); // Unload filepaths
RLAPI bool IsFileDropped(void); // Check if a file has been dropped into window RLAPI bool IsFileDropped(void); // Check if a file has been dropped into window
RLAPI FilePathList LoadDroppedFiles(void); // Load dropped filepaths RLAPI FilePathList LoadDroppedFiles(void); // Load dropped filepaths
RLAPI void UnloadDroppedFiles(FilePathList files); // Unload 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 // Compression/Encoding functionality
RLAPI unsigned char *CompressData(const unsigned char *data, int dataSize, int *compDataSize); // Compress data (DEFLATE algorithm), memory must be MemFree() 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 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 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 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 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 UnloadFontData(GlyphInfo *glyphs, int glyphCount); // Unload font chars info data (RAM)
RLAPI void UnloadFont(Font font); // Unload font from GPU memory (VRAM) 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) 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) // 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() // 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 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 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 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 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 *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 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 *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 *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 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 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 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 *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 *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 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 /// 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 res: []GlyphInfo = undefined;
var codePointsFinal = @as([*c]i32, 0); var codePointsFinal = @as([*c]const i32, 0);
var codePointsLen: i32 = 0; var codePointsLen: i32 = 0;
if (codePoints) |codePointsSure| { if (codePoints) |codePointsSure| {
codePointsFinal = @as([*c]i32, @ptrCast(codePointsSure)); codePointsFinal = @as([*c]const i32, @ptrCast(codePointsSure));
codePointsLen = @as(i32, @intCast(codePointsSure.len)); codePointsLen = @as(i32, @intCast(codePointsSure.len));
} else { } else {
codePointsLen = 95; 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; if (ptr == 0) return RaylibError.LoadFontData;
res.ptr = @as([*]GlyphInfo, @ptrCast(ptr)); res.ptr = @as([*]GlyphInfo, @ptrCast(ptr));
@ -2536,6 +2536,10 @@ pub fn loadTextLines(text: [:0]const u8) RaylibError![][:0]u8 {
return res; 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 /// Join text strings with delimiter
pub fn textJoin(textList: [][:0]u8, delimiter: [:0]const u8) [:0]const u8 { 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)))); 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))); 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 /// Check if file exists
pub fn fileExists(fileName: [:0]const u8) bool { pub fn fileExists(fileName: [:0]const u8) bool {
return cdef.FileExists(@as([*c]const u8, @ptrCast(fileName))); 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)))); 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') /// Get pointer to extension for a filename string (includes dot: '.png')
pub fn getFileExtension(fileName: [:0]const u8) [:0]const u8 { pub fn getFileExtension(fileName: [:0]const u8) [:0]const u8 {
return std.mem.span(cdef.GetFileExtension(@as([*c]const u8, @ptrCast(fileName)))); 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); 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() /// Compress data (DEFLATE algorithm), memory must be MemFree()
pub fn compressData(data: []const u8, dataSize: i32) RaylibError![]u8 { pub fn compressData(data: []const u8, dataSize: i32) RaylibError![]u8 {
var _len: i32 = 0; 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)))); 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 /// Copy one string to another, returns bytes copied
pub fn textCopy(dst: *u8, src: [:0]const u8) i32 { 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)))); 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))); 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!) /// 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 { 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(replace)), @as([*c]const u8, @ptrCast(by)))); 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!) /// 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))]; 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 { 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))); 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 /// Find first text occurrence within a string, -1 if not found
pub fn textFindIndex(text: [:0]const u8, find: [:0]const u8) i32 { 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(find)))); return @as(i32, cdef.TextFindIndex(@as([*c]const u8, @ptrCast(text)), @as([*c]const u8, @ptrCast(search))));
} }
/// Get upper case version of provided string /// Get upper case version of provided string

35
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) #elif defined(GRAPHICS_API_OPENGL_ES2)
// NOTE: OpenGL ES 2.0 can be enabled on Desktop platforms, // 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 // 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) #if defined(PLATFORM_DESKTOP_GLFW) || defined(PLATFORM_DESKTOP_SDL)
#define GLAD_GLES2_IMPLEMENTATION #define GLAD_GLES2_IMPLEMENTATION
#include "external/glad_gles2.h" #include "external/glad_gles2.h"
@ -889,7 +890,7 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
#endif #endif
#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 <string.h> // Required for: strcmp(), strlen() [Used in rlglInit(), on extensions loading]
#include <math.h> // Required for: sqrtf(), sinf(), cosf(), floor(), log() #include <math.h> // Required for: sqrtf(), sinf(), cosf(), floor(), log()
@ -1039,7 +1040,7 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
#endif #endif
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Types and Structures Definition // Module Types and Structures Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
@ -1145,7 +1146,7 @@ static PFNGLVERTEXATTRIBDIVISOREXTPROC glVertexAttribDivisor = NULL;
#endif #endif
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module specific Functions Declaration // Module Functions Declaration
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
static void rlLoadShaderDefault(void); // Load default shader static void rlLoadShaderDefault(void); // Load default shader
@ -2429,7 +2430,7 @@ void rlLoadExtensions(void *loader)
// Get supported extensions list // Get supported extensions list
GLint numExt = 0; 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 const char *extensions = (const char *)glGetString(GL_EXTENSIONS); // One big const string
// NOTE: We have to duplicate string because glGetString() returns a const string // NOTE: We have to duplicate string because glGetString() returns a const string
@ -2473,7 +2474,7 @@ void rlLoadExtensions(void *loader)
} }
// Check instanced rendering support // Check instanced rendering support
if (strstr(extList[i], (const char*)"instanced_arrays") != NULL) // Broad check for instanced_arrays if (strstr(extList[i], (const char *)"instanced_arrays") != NULL) // Broad check for instanced_arrays
{ {
// Specific check // Specific check
if (strcmp(extList[i], (const char *)"GL_ANGLE_instanced_arrays") == 0) // ANGLE if (strcmp(extList[i], (const char *)"GL_ANGLE_instanced_arrays") == 0) // ANGLE
@ -2506,7 +2507,7 @@ void rlLoadExtensions(void *loader)
glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDEXTPROC)((rlglLoadProc)loader)("glDrawArraysInstancedEXT"); glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDEXTPROC)((rlglLoadProc)loader)("glDrawArraysInstancedEXT");
glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDEXTPROC)((rlglLoadProc)loader)("glDrawElementsInstancedEXT"); glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDEXTPROC)((rlglLoadProc)loader)("glDrawElementsInstancedEXT");
} }
else if (strcmp(extList[i], (const char*)"GL_NV_draw_instanced") == 0) else if (strcmp(extList[i], (const char *)"GL_NV_draw_instanced") == 0)
{ {
glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDEXTPROC)((rlglLoadProc)loader)("glDrawArraysInstancedNV"); glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDEXTPROC)((rlglLoadProc)loader)("glDrawArraysInstancedNV");
glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDEXTPROC)((rlglLoadProc)loader)("glDrawElementsInstancedNV"); glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDEXTPROC)((rlglLoadProc)loader)("glDrawElementsInstancedNV");
@ -2741,21 +2742,21 @@ rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements)
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// Initialize CPU (RAM) vertex buffers (position, texcoord, color data and indexes) // 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++) for (int i = 0; i < numBuffers; i++)
{ {
batch.vertexBuffer[i].elementCount = bufferElements; 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].vertices = (float *)RL_CALLOC(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].texcoords = (float *)RL_CALLOC(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].normals = (float *)RL_CALLOC(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].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) #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 #endif
#if defined(GRAPHICS_API_OPENGL_ES2) #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 #endif
for (int j = 0; j < (3*4*bufferElements); j++) batch.vertexBuffer[i].vertices[j] = 0.0f; 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 // 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++) 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)) 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); 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); 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); 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 // 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); glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
glBindFramebuffer(GL_FRAMEBUFFER, 0); 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) #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// Load default shader (just vertex positioning and texture coloring) // Load default shader (just vertex positioning and texture coloring)