Minor updates to member functions

This commit is contained in:
Not-Nik 2023-07-20 17:10:06 +02:00
parent 286324cf03
commit d80ffdf645
No known key found for this signature in database
GPG Key ID: 08BB71E672DB3BFD
3 changed files with 48 additions and 16 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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);
}