From 1dab3352b3b7ecbf7c534fd4ee84292c28f54ee7 Mon Sep 17 00:00:00 2001 From: Not-Nik Date: Tue, 25 Jun 2024 20:01:25 +0200 Subject: [PATCH] Allow not specifiying codepoints in loadFontEx (#110) --- lib/preludes/raylib-prelude.zig | 14 ++++++++++---- lib/raylib.zig | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/preludes/raylib-prelude.zig b/lib/preludes/raylib-prelude.zig index 85f2d7a..2cd1de2 100755 --- a/lib/preludes/raylib-prelude.zig +++ b/lib/preludes/raylib-prelude.zig @@ -1815,6 +1815,16 @@ pub fn loadImagePalette(image: Image, maxPaletteSize: i32) RaylibError![]Color { return res; } +pub fn loadFontEx(fileName: [:0]const u8, fontSize: i32, fontChars: ?[]i32) Font { + var fontCharsFinal = @as([*c]c_int, 0); + var fontCharsLen: c_int = @as(c_int, 0); + if (fontChars) |fontCharsSure| { + fontCharsFinal = @as([*c]c_int, @ptrCast(fontCharsSure)); + fontCharsLen = @as(i32, @intCast(fontCharsSure.len)); + } + return cdef.LoadFontEx(@as([*c]const u8, @ptrCast(fileName)), @as(c_int, fontSize), fontCharsFinal, fontCharsLen); +} + pub fn loadFontFromMemory(fileType: [:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font { var fileDataFinal = @as([*c]const u8, 0); var fileDataLen: i32 = 0; @@ -1939,10 +1949,6 @@ pub fn checkCollisionPointPoly(point: Vector2, points: []Vector2) bool { return cdef.CheckCollisionPointPoly(point, @as([*c]Vector2, @ptrCast(points)), @as(c_int, @intCast(points.len))); } -pub fn loadFontEx(fileName: [:0]const u8, fontSize: i32, fontChars: []i32) Font { - return cdef.LoadFontEx(@as([*c]const u8, @ptrCast(fileName)), @as(c_int, fontSize), @as([*c]c_int, @ptrCast(fontChars)), @as(c_int, @intCast(fontChars.len))); -} - pub fn genImageFontAtlas(chars: []const GlyphInfo, recs: [][]Rectangle, fontSize: i32, padding: i32, packMethod: i32) Image { return cdef.GenImageFontAtlas(@as([*c]const GlyphInfo, @ptrCast(chars)), @as([*c][*c]Rectangle, @ptrCast(recs)), @as(c_int, @intCast(recs.len)), @as(c_int, fontSize), @as(c_int, padding), @as(c_int, packMethod)); } diff --git a/lib/raylib.zig b/lib/raylib.zig index ce9ac17..ca99fb2 100644 --- a/lib/raylib.zig +++ b/lib/raylib.zig @@ -1815,6 +1815,16 @@ pub fn loadImagePalette(image: Image, maxPaletteSize: i32) RaylibError![]Color { return res; } +pub fn loadFontEx(fileName: [:0]const u8, fontSize: i32, fontChars: ?[]i32) Font { + var fontCharsFinal = @as([*c]c_int, 0); + var fontCharsLen: c_int = @as(c_int, 0); + if (fontChars) |fontCharsSure| { + fontCharsFinal = @as([*c]c_int, @ptrCast(fontCharsSure)); + fontCharsLen = @as(i32, @intCast(fontCharsSure.len)); + } + return cdef.LoadFontEx(@as([*c]const u8, @ptrCast(fileName)), @as(c_int, fontSize), fontCharsFinal, fontCharsLen); +} + pub fn loadFontFromMemory(fileType: [:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font { var fileDataFinal = @as([*c]const u8, 0); var fileDataLen: i32 = 0; @@ -1939,10 +1949,6 @@ pub fn checkCollisionPointPoly(point: Vector2, points: []Vector2) bool { return cdef.CheckCollisionPointPoly(point, @as([*c]Vector2, @ptrCast(points)), @as(c_int, @intCast(points.len))); } -pub fn loadFontEx(fileName: [:0]const u8, fontSize: i32, fontChars: []i32) Font { - return cdef.LoadFontEx(@as([*c]const u8, @ptrCast(fileName)), @as(c_int, fontSize), @as([*c]c_int, @ptrCast(fontChars)), @as(c_int, @intCast(fontChars.len))); -} - pub fn genImageFontAtlas(chars: []const GlyphInfo, recs: [][]Rectangle, fontSize: i32, padding: i32, packMethod: i32) Image { return cdef.GenImageFontAtlas(@as([*c]const GlyphInfo, @ptrCast(chars)), @as([*c][*c]Rectangle, @ptrCast(recs)), @as(c_int, @intCast(recs.len)), @as(c_int, fontSize), @as(c_int, padding), @as(c_int, packMethod)); }