Custom logger and console, setup IO callbacks
This commit is contained in:
110
src/game.zig
Normal file
110
src/game.zig
Normal file
@@ -0,0 +1,110 @@
|
||||
const std = @import("std");
|
||||
|
||||
const zglfw = @import("zglfw");
|
||||
const zgui = @import("zgui");
|
||||
|
||||
const main = @import("main.zig");
|
||||
|
||||
var show_console: bool = false;
|
||||
var show_demo_window: bool = false;
|
||||
|
||||
pub fn init() void {}
|
||||
|
||||
pub fn update(dt: f32) void {
|
||||
_ = dt;
|
||||
|
||||
if (show_console) {
|
||||
showConsole();
|
||||
}
|
||||
|
||||
if (show_demo_window) {
|
||||
zgui.showDemoWindow(&show_demo_window);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn charCallback(
|
||||
_: *zglfw.Window,
|
||||
codepoint: u32,
|
||||
) callconv(.C) void {
|
||||
_ = codepoint;
|
||||
}
|
||||
|
||||
pub fn cursorPosCallback(
|
||||
_: *zglfw.Window,
|
||||
xpos: f64,
|
||||
ypos: f64,
|
||||
) callconv(.C) void {
|
||||
_ = xpos;
|
||||
_ = ypos;
|
||||
}
|
||||
|
||||
pub fn keyCallback(
|
||||
_: *zglfw.Window,
|
||||
key: zglfw.Key,
|
||||
scancode: c_int,
|
||||
action: zglfw.Action,
|
||||
mods: zglfw.Mods,
|
||||
) callconv(.C) void {
|
||||
_ = scancode;
|
||||
|
||||
const no_mods = @as(c_int, @bitCast(mods)) == 0;
|
||||
|
||||
if (key == .grave_accent and action == .press and no_mods) {
|
||||
show_console = !show_console;
|
||||
}
|
||||
|
||||
if (key == .F1 and action == .press and no_mods) {
|
||||
show_demo_window = true;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mouseButtonCallback(
|
||||
_: *zglfw.Window,
|
||||
button: zglfw.MouseButton,
|
||||
action: zglfw.Action,
|
||||
mods: zglfw.Mods,
|
||||
) callconv(.C) void {
|
||||
_ = button;
|
||||
_ = action;
|
||||
_ = mods;
|
||||
}
|
||||
|
||||
pub fn scrollCallback(
|
||||
_: *zglfw.Window,
|
||||
xoffset: f64,
|
||||
yoffset: f64,
|
||||
) callconv(.C) void {
|
||||
_ = xoffset;
|
||||
_ = yoffset;
|
||||
}
|
||||
|
||||
pub fn deinit() void {}
|
||||
|
||||
fn showConsole() void {
|
||||
const display_size = zgui.io.getDisplaySize();
|
||||
zgui.setNextWindowPos(.{
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
});
|
||||
zgui.setNextWindowSize(.{
|
||||
.w = display_size[0],
|
||||
.h = main.min_window_height,
|
||||
.cond = .once,
|
||||
});
|
||||
if (zgui.begin("Console", .{ .flags = .{
|
||||
.no_title_bar = true,
|
||||
.no_resize = true,
|
||||
.no_move = true,
|
||||
.no_collapse = true,
|
||||
} })) {
|
||||
for (main.logs.items) |log| {
|
||||
zgui.textUnformattedColored(switch (log.level) {
|
||||
.err => .{ 1, 0, 0, 1 },
|
||||
.warn => .{ 1, 1, 0, 1 },
|
||||
.info => .{ 1, 1, 1, 1 },
|
||||
.debug => .{ 0.5, 0.5, 0.5, 1 },
|
||||
}, log.message);
|
||||
}
|
||||
}
|
||||
zgui.end();
|
||||
}
|
||||
Reference in New Issue
Block a user