From 183cc437acc3a1f75620f0174c3e6d7db9025198 Mon Sep 17 00:00:00 2001 From: Not-Nik Date: Thu, 20 Jul 2023 16:13:59 +0200 Subject: [PATCH] Font & unloading member functions --- lib/preludes/raylib-zig-prelude.zig | 44 +++++++++++++++++++++++++++++ lib/raylib-zig.zig | 44 +++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/lib/preludes/raylib-zig-prelude.zig b/lib/preludes/raylib-zig-prelude.zig index 9fec964..45c927f 100755 --- a/lib/preludes/raylib-zig-prelude.zig +++ b/lib/preludes/raylib-zig-prelude.zig @@ -206,6 +206,10 @@ pub const Image = extern struct { return rl.genImageCellular(width, height, tileSize); } + pub fn unload(self: Image) void { + rl.unloadImage(self); + } + pub fn useAsWindowIcon(self: Image) void { rl.setWindowIcon(self); } @@ -230,6 +234,10 @@ pub const Texture = extern struct { return rl.loadTextureCubemap(image, layout); } + pub fn unload(self: Texture) void { + rl.unloadTexture(self); + } + pub fn draw(self: Texture, posX: i32, posY: i32, tint: Color) void { rl.drawTexture(self, posX, posY, tint); } @@ -266,6 +274,10 @@ pub const RenderTexture = extern struct { return rl.loadRenderTexture(width, height); } + pub fn unload(self: RenderTexture) void { + rl.unloadRenderTexture(self); + } + pub fn begin(self: RenderTexture2D) void { rl.beginTextureMode(self); } @@ -300,6 +312,34 @@ pub const Font = extern struct { texture: Texture2D, recs: [*c]Rectangle, glyphs: [*c]GlyphInfo, + + pub fn init(fileName: [:0]const u8) Font { + return rl.loadFont(fileName); + } + + pub fn initEx(fileName: [:0]const u8, fontSize: i32, fontChars: []i32, glyphCount: i32) Font { + return rl.loadFontEx(fileName, fontSize, fontChars, glyphCount); + } + + pub fn initFromImage(image: Image, key: Color, firstChar: i32) Font { + return rl.loadFontFromImage(image, key, firstChar); + } + + pub fn initFromMemory(fileType: [:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font { + return rl.loadFontFromMemory(fileType, fileData, fontSize, fontChars); + } + + pub fn unload(self: Font) void { + rl.unloadFont(self); + } + + pub fn isReady(self: Font) bool { + return rl.isFontReady(self); + } + + pub fn exportAsCode(self: Font, fileName: [:0]const u8) bool { + return rl.exportFontAsCode(self, fileName); + } }; pub const Camera3D = extern struct { @@ -431,6 +471,10 @@ pub const Model = extern struct { return rl.loadModelFromMesh(mesh); } + pub fn unload(self: Model) void { + rl.unloadModel(self); + } + pub fn draw(self: Mesh, position: Vector3, scale: f32, tint: Color) void { return rl.drawMesh(self, position, scale, tint); } diff --git a/lib/raylib-zig.zig b/lib/raylib-zig.zig index caee825..1239589 100644 --- a/lib/raylib-zig.zig +++ b/lib/raylib-zig.zig @@ -206,6 +206,10 @@ pub const Image = extern struct { return rl.genImageCellular(width, height, tileSize); } + pub fn unload(self: Image) void { + rl.unloadImage(self); + } + pub fn useAsWindowIcon(self: Image) void { rl.setWindowIcon(self); } @@ -230,6 +234,10 @@ pub const Texture = extern struct { return rl.loadTextureCubemap(image, layout); } + pub fn unload(self: Texture) void { + rl.unloadTexture(self); + } + pub fn draw(self: Texture, posX: i32, posY: i32, tint: Color) void { rl.drawTexture(self, posX, posY, tint); } @@ -266,6 +274,10 @@ pub const RenderTexture = extern struct { return rl.loadRenderTexture(width, height); } + pub fn unload(self: RenderTexture) void { + rl.unloadRenderTexture(self); + } + pub fn begin(self: RenderTexture2D) void { rl.beginTextureMode(self); } @@ -300,6 +312,34 @@ pub const Font = extern struct { texture: Texture2D, recs: [*c]Rectangle, glyphs: [*c]GlyphInfo, + + pub fn init(fileName: [:0]const u8) Font { + return rl.loadFont(fileName); + } + + pub fn initEx(fileName: [:0]const u8, fontSize: i32, fontChars: []i32, glyphCount: i32) Font { + return rl.loadFontEx(fileName, fontSize, fontChars, glyphCount); + } + + pub fn initFromImage(image: Image, key: Color, firstChar: i32) Font { + return rl.loadFontFromImage(image, key, firstChar); + } + + pub fn initFromMemory(fileType: [:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font { + return rl.loadFontFromMemory(fileType, fileData, fontSize, fontChars); + } + + pub fn unload(self: Font) void { + rl.unloadFont(self); + } + + pub fn isReady(self: Font) bool { + return rl.isFontReady(self); + } + + pub fn exportAsCode(self: Font, fileName: [:0]const u8) bool { + return rl.exportFontAsCode(self, fileName); + } }; pub const Camera3D = extern struct { @@ -431,6 +471,10 @@ pub const Model = extern struct { return rl.loadModelFromMesh(mesh); } + pub fn unload(self: Model) void { + rl.unloadModel(self); + } + pub fn draw(self: Mesh, position: Vector3, scale: f32, tint: Color) void { return rl.drawMesh(self, position, scale, tint); }