mach: Create binding methods for all glfw methods in use and update

examples
This commit is contained in:
iddev5 2022-05-12 12:54:01 +05:30 committed by Stephen Gutekanst
parent 9106a9839d
commit 8b46f46cf8
11 changed files with 62 additions and 24 deletions

View file

@ -3,6 +3,7 @@ const Allocator = std.mem.Allocator;
const glfw = @import("glfw");
const gpu = @import("gpu");
const App = @import("app");
const structs = @import("structs.zig");
const enums = @import("enums.zig");
pub const VSyncMode = enum {
@ -71,6 +72,18 @@ timer: std.time.Timer,
pub const Core = struct {
internal: GetCoreInternalType(),
pub fn setShouldClose(core: *Core, value: bool) void {
core.internal.setShouldClose(value);
}
pub fn getFramebufferSize(core: *Core) !structs.Size {
return core.internal.getFramebufferSize();
}
pub fn setSizeLimits(core: *Core, min: structs.SizeOptional, max: structs.SizeOptional) !void {
return core.internal.setSizeLimits(min, max);
}
pub fn setKeyCallback(core: *Core, comptime cb: fn (app: *App, engine: *Engine, key: enums.Key, action: enums.Action) void) void {
core.internal.setKeyCallback(cb);
}

View file

@ -1,2 +1,3 @@
pub usingnamespace @import("structs.zig");
pub usingnamespace @import("enums.zig");
pub const Engine = @import("Engine.zig");

View file

@ -3,6 +3,7 @@ const glfw = @import("glfw");
const gpu = @import("gpu");
const App = @import("app");
const Engine = @import("Engine.zig");
const structs = @import("structs.zig");
const enums = @import("enums.zig");
const util = @import("util.zig");
const c = @import("c.zig").c;
@ -50,6 +51,22 @@ pub const CoreGlfw = struct {
self.window.setUserPointer(&self.user_ptr);
}
pub fn setShouldClose(self: *CoreGlfw, value: bool) void {
self.window.setShouldClose(value);
}
pub fn getFramebufferSize(self: *CoreGlfw) !structs.Size {
const size = try self.window.getFramebufferSize();
return @bitCast(structs.Size, size);
}
pub fn setSizeLimits(self: *CoreGlfw, min: structs.SizeOptional, max: structs.SizeOptional) !void {
try self.window.setSizeLimits(
@bitCast(glfw.Window.SizeOptional, min),
@bitCast(glfw.Window.SizeOptional, max),
);
}
pub fn setKeyCallback(self: *CoreGlfw, comptime cb: fn (app: *App, engine: *Engine, key: enums.Key, action: enums.Action) void) void {
const callback = struct {
fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void {

9
src/structs.zig Normal file
View file

@ -0,0 +1,9 @@
pub const Size = struct {
width: u32,
height: u32,
};
pub const SizeOptional = struct {
width: ?u32,
height: ?u32,
};