From d80ffdf645171e7eaa5d0f4dadb234f7cf86fb9a Mon Sep 17 00:00:00 2001 From: Not-Nik Date: Thu, 20 Jul 2023 17:10:06 +0200 Subject: [PATCH] Minor updates to member functions --- README.md | 4 ++-- lib/preludes/raylib-zig-prelude.zig | 30 ++++++++++++++++++++++------- lib/raylib-zig.zig | 30 ++++++++++++++++++++++------- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index ab713ce..3839149 100755 --- a/README.md +++ b/README.md @@ -66,8 +66,8 @@ To build all available examples simply `zig build examples`. To list available e I plan on updating it every mayor release (2.5, 3.0, etc.). Keep in mind these are technically header files, so any implementation stuff should be updatable with some hacks on your side. -### What's to be done? +### What needs to be done? + _(Done)_ Set up a proper package build and a build script for the examples + Port all the examples -+ Object orientation ++ Member functions/initialisers diff --git a/lib/preludes/raylib-zig-prelude.zig b/lib/preludes/raylib-zig-prelude.zig index a0d32c0..bfeb79c 100755 --- a/lib/preludes/raylib-zig-prelude.zig +++ b/lib/preludes/raylib-zig-prelude.zig @@ -145,6 +145,14 @@ pub const Rectangle = extern struct { pub fn init(x: f32, y: f32, width: f32, height: f32) Rectangle { return Rectangle{ .x = x, .y = y, .width = width, .height = height }; } + + pub fn checkCollision(self: Rectangle, rec2: Rectangle) bool { + return rl.CheckCollisionRecs(self, rec2); + } + + pub fn getCollision(self: Rectangle, rec2: Rectangle) Rectangle { + return rl.GetCollisionRec(self, rec2); + } }; pub const Image = extern struct { @@ -170,12 +178,12 @@ pub const Image = extern struct { return rl.imageTextEx(font, text, fontSize, spacing, tint); } - pub fn copy(image: Image) Image { - return rl.imageCopy(image); + pub fn copy(self: Image) Image { + return rl.imageCopy(self); } - pub fn copyRec(image: Image, rec: Rectangle) Image { - return rl.imageFromImage(image, rec); + pub fn copyRec(self: Image, rec: Rectangle) Image { + return rl.imageFromImage(self, rec); } pub fn genColor(width: i32, height: i32, color: Color) Image { @@ -213,6 +221,14 @@ pub const Image = extern struct { pub fn useAsWindowIcon(self: Image) void { rl.setWindowIcon(self); } + + pub fn toTexture(self: Image) Texture { + return Texture.fromImage(self); + } + + pub fn asCubemap(self: Image, layout: i32) Texture { + return Texture.fromCubemap(self, layout); + } }; pub const Texture = extern struct { @@ -321,11 +337,11 @@ pub const Font = extern struct { return rl.loadFontEx(fileName, fontSize, fontChars, glyphCount); } - pub fn initFromImage(image: Image, key: Color, firstChar: i32) Font { + pub fn fromImage(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 { + pub fn fromMemory(fileType: [:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font { return rl.loadFontFromMemory(fileType, fileData, fontSize, fontChars); } @@ -467,7 +483,7 @@ pub const Model = extern struct { return rl.loadModel(fileName); } - pub fn initFromMesh(mesh: Mesh) Model { + pub fn fromMesh(mesh: Mesh) Model { return rl.loadModelFromMesh(mesh); } diff --git a/lib/raylib-zig.zig b/lib/raylib-zig.zig index b7e3749..40a16f1 100644 --- a/lib/raylib-zig.zig +++ b/lib/raylib-zig.zig @@ -145,6 +145,14 @@ pub const Rectangle = extern struct { pub fn init(x: f32, y: f32, width: f32, height: f32) Rectangle { return Rectangle{ .x = x, .y = y, .width = width, .height = height }; } + + pub fn checkCollision(self: Rectangle, rec2: Rectangle) bool { + return rl.CheckCollisionRecs(self, rec2); + } + + pub fn getCollision(self: Rectangle, rec2: Rectangle) Rectangle { + return rl.GetCollisionRec(self, rec2); + } }; pub const Image = extern struct { @@ -170,12 +178,12 @@ pub const Image = extern struct { return rl.imageTextEx(font, text, fontSize, spacing, tint); } - pub fn copy(image: Image) Image { - return rl.imageCopy(image); + pub fn copy(self: Image) Image { + return rl.imageCopy(self); } - pub fn copyRec(image: Image, rec: Rectangle) Image { - return rl.imageFromImage(image, rec); + pub fn copyRec(self: Image, rec: Rectangle) Image { + return rl.imageFromImage(self, rec); } pub fn genColor(width: i32, height: i32, color: Color) Image { @@ -213,6 +221,14 @@ pub const Image = extern struct { pub fn useAsWindowIcon(self: Image) void { rl.setWindowIcon(self); } + + pub fn toTexture(self: Image) Texture { + return Texture.fromImage(self); + } + + pub fn asCubemap(self: Image, layout: i32) Texture { + return Texture.fromCubemap(self, layout); + } }; pub const Texture = extern struct { @@ -321,11 +337,11 @@ pub const Font = extern struct { return rl.loadFontEx(fileName, fontSize, fontChars, glyphCount); } - pub fn initFromImage(image: Image, key: Color, firstChar: i32) Font { + pub fn fromImage(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 { + pub fn fromMemory(fileType: [:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font { return rl.loadFontFromMemory(fileType, fileData, fontSize, fontChars); } @@ -467,7 +483,7 @@ pub const Model = extern struct { return rl.loadModel(fileName); } - pub fn initFromMesh(mesh: Mesh) Model { + pub fn fromMesh(mesh: Mesh) Model { return rl.loadModelFromMesh(mesh); }