examples: use engine.core.setKeyCallback() instead of accessing glfw directly
This commit is contained in:
parent
5396769227
commit
1f95bd48df
6 changed files with 18 additions and 32 deletions
|
|
@ -38,7 +38,7 @@ const FrameParams = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn init(app: *App, engine: *mach.Engine) !void {
|
pub fn init(app: *App, engine: *mach.Engine) !void {
|
||||||
engine.core.internal.window.setKeyCallback(keyCallback);
|
engine.core.setKeyCallback(keyCallback);
|
||||||
// todo
|
// todo
|
||||||
// engine.core.internal.window.setKeyCallback(struct {
|
// engine.core.internal.window.setKeyCallback(struct {
|
||||||
// fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void {
|
// 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 {
|
fn keyCallback(_: *App, engine: *mach.Engine, key: mach.Key, action: mach.Action) void {
|
||||||
_ = window;
|
|
||||||
_ = scancode;
|
|
||||||
_ = mods;
|
|
||||||
|
|
||||||
if (action == .press) {
|
if (action == .press) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
.q, .escape, .space => window.setShouldClose(true),
|
.q, .escape, .space => engine.core.internal.window.setShouldClose(true),
|
||||||
.w, .up => {
|
.w, .up => {
|
||||||
global_params.keys |= FrameParams.up;
|
global_params.keys |= FrameParams.up;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,11 @@ bgl: gpu.BindGroupLayout,
|
||||||
pub fn init(app: *App, engine: *mach.Engine) !void {
|
pub fn init(app: *App, engine: *mach.Engine) !void {
|
||||||
timer = try std.time.Timer.start();
|
timer = try std.time.Timer.start();
|
||||||
|
|
||||||
engine.core.internal.window.setKeyCallback(struct {
|
engine.core.setKeyCallback(struct {
|
||||||
fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void {
|
fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void {
|
||||||
_ = scancode;
|
|
||||||
_ = mods;
|
|
||||||
if (action == .press) {
|
if (action == .press) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
.space => window.setShouldClose(true),
|
.space => eng.core.internal.window.setShouldClose(true),
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,11 @@ const App = @This();
|
||||||
pub fn init(app: *App, engine: *mach.Engine) !void {
|
pub fn init(app: *App, engine: *mach.Engine) !void {
|
||||||
timer = try std.time.Timer.start();
|
timer = try std.time.Timer.start();
|
||||||
|
|
||||||
engine.core.internal.window.setKeyCallback(struct {
|
engine.core.setKeyCallback(struct {
|
||||||
fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void {
|
fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void {
|
||||||
_ = scancode;
|
|
||||||
_ = mods;
|
|
||||||
if (action == .press) {
|
if (action == .press) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
.space => window.setShouldClose(true),
|
.space => eng.core.internal.window.setShouldClose(true),
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,11 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
|
||||||
timer = try std.time.Timer.start();
|
timer = try std.time.Timer.start();
|
||||||
|
|
||||||
// TODO: higher level input handlers
|
// TODO: higher level input handlers
|
||||||
engine.core.internal.window.setKeyCallback(struct {
|
engine.core.setKeyCallback(struct {
|
||||||
fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void {
|
fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void {
|
||||||
_ = scancode;
|
|
||||||
_ = mods;
|
|
||||||
if (action == .press) {
|
if (action == .press) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
.space => window.setShouldClose(true),
|
.space => eng.core.internal.window.setShouldClose(true),
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,11 @@ const App = @This();
|
||||||
pub fn init(app: *App, engine: *mach.Engine) !void {
|
pub fn init(app: *App, engine: *mach.Engine) !void {
|
||||||
timer = try std.time.Timer.start();
|
timer = try std.time.Timer.start();
|
||||||
|
|
||||||
engine.core.internal.window.setKeyCallback(struct {
|
engine.core.setKeyCallback(struct {
|
||||||
fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void {
|
fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void {
|
||||||
_ = scancode;
|
|
||||||
_ = mods;
|
|
||||||
if (action == .press) {
|
if (action == .press) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
.space => window.setShouldClose(true),
|
.space => eng.core.internal.window.setShouldClose(true),
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,11 @@ const App = @This();
|
||||||
pub fn init(app: *App, engine: *mach.Engine) !void {
|
pub fn init(app: *App, engine: *mach.Engine) !void {
|
||||||
timer = try std.time.Timer.start();
|
timer = try std.time.Timer.start();
|
||||||
|
|
||||||
engine.core.internal.window.setKeyCallback(struct {
|
engine.core.setKeyCallback(struct {
|
||||||
fn callback(window: glfw.Window, key: glfw.Key, scancode: i32, action: glfw.Action, mods: glfw.Mods) void {
|
fn callback(_: *App, eng: *mach.Engine, key: mach.Key, action: mach.Action) void {
|
||||||
_ = scancode;
|
|
||||||
_ = mods;
|
|
||||||
if (action == .press) {
|
if (action == .press) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
.space => window.setShouldClose(true),
|
.space => eng.core.internal.window.setShouldClose(true),
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue