examples: use engine.core.setKeyCallback() instead of accessing glfw directly

This commit is contained in:
iddev5 2022-05-09 12:55:45 +05:30 committed by Stephen Gutekanst
parent 5396769227
commit 1f95bd48df
6 changed files with 18 additions and 32 deletions

View file

@ -38,7 +38,7 @@ const FrameParams = struct {
};
pub fn init(app: *App, engine: *mach.Engine) !void {
engine.core.internal.window.setKeyCallback(keyCallback);
engine.core.setKeyCallback(keyCallback);
// todo
// engine.core.internal.window.setKeyCallback(struct {
// fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void {
@ -879,14 +879,10 @@ const Instance = struct {
}
};
fn keyCallback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void {
_ = window;
_ = scancode;
_ = mods;
fn keyCallback(_: *App, engine: *mach.Engine, key: mach.Key, action: mach.Action) void {
if (action == .press) {
switch (key) {
.q, .escape, .space => window.setShouldClose(true),
.q, .escape, .space => engine.core.internal.window.setShouldClose(true),
.w, .up => {
global_params.keys |= FrameParams.up;
},

View file

@ -40,13 +40,11 @@ bgl: gpu.BindGroupLayout,
pub fn init(app: *App, engine: *mach.Engine) !void {
timer = try std.time.Timer.start();
engine.core.internal.window.setKeyCallback(struct {
fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void {
_ = scancode;
_ = mods;
engine.core.setKeyCallback(struct {
fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void {
if (action == .press) {
switch (key) {
.space => window.setShouldClose(true),
.space => eng.core.internal.window.setShouldClose(true),
else => {},
}
}

View file

@ -23,13 +23,11 @@ const App = @This();
pub fn init(app: *App, engine: *mach.Engine) !void {
timer = try std.time.Timer.start();
engine.core.internal.window.setKeyCallback(struct {
fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void {
_ = scancode;
_ = mods;
engine.core.setKeyCallback(struct {
fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void {
if (action == .press) {
switch (key) {
.space => window.setShouldClose(true),
.space => eng.core.internal.window.setShouldClose(true),
else => {},
}
}

View file

@ -24,13 +24,11 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
timer = try std.time.Timer.start();
// TODO: higher level input handlers
engine.core.internal.window.setKeyCallback(struct {
fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void {
_ = scancode;
_ = mods;
engine.core.setKeyCallback(struct {
fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void {
if (action == .press) {
switch (key) {
.space => window.setShouldClose(true),
.space => eng.core.internal.window.setShouldClose(true),
else => {},
}
}

View file

@ -26,13 +26,11 @@ const App = @This();
pub fn init(app: *App, engine: *mach.Engine) !void {
timer = try std.time.Timer.start();
engine.core.internal.window.setKeyCallback(struct {
fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void {
_ = scancode;
_ = mods;
engine.core.setKeyCallback(struct {
fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void {
if (action == .press) {
switch (key) {
.space => window.setShouldClose(true),
.space => eng.core.internal.window.setShouldClose(true),
else => {},
}
}

View file

@ -24,13 +24,11 @@ const App = @This();
pub fn init(app: *App, engine: *mach.Engine) !void {
timer = try std.time.Timer.start();
engine.core.internal.window.setKeyCallback(struct {
fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void {
_ = scancode;
_ = mods;
engine.core.setKeyCallback(struct {
fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void {
if (action == .press) {
switch (key) {
.space => window.setShouldClose(true),
.space => eng.core.internal.window.setShouldClose(true),
else => {},
}
}