summaryrefslogtreecommitdiff
path: root/src/renderer/Window.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer/Window.zig')
-rw-r--r--src/renderer/Window.zig20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/renderer/Window.zig b/src/renderer/Window.zig
index a80f277..9ef389d 100644
--- a/src/renderer/Window.zig
+++ b/src/renderer/Window.zig
@@ -1,4 +1,5 @@
const c = @import("c.zig");
+const ecs = @import("ecs");
const std = @import("std");
const Window = @This();
@@ -36,6 +37,7 @@ pub fn create(width: usize, height: usize, title: []const u8) !Window {
c.glfwWindowHint(c.GLFW_CLIENT_API, c.GLFW_NO_API);
const raw = c.glfwCreateWindow(@intCast(width), @intCast(height), title.ptr, null, null);
c.glfwShowWindow(raw);
+ _ = c.glfwSetKeyCallback(raw, keyCallback);
return Window{
.title = title,
@@ -45,6 +47,10 @@ pub fn create(width: usize, height: usize, title: []const u8) !Window {
};
}
+pub fn setResources(self: *Window, resources: *ecs.Resources) void {
+ c.glfwSetWindowUserPointer(self.raw, resources);
+}
+
pub fn pollEvents() void {
c.glfwPollEvents();
}
@@ -66,3 +72,17 @@ pub fn destroy(self: Window) void {
c.glfwDestroyWindow(self.raw);
c.glfwTerminate();
}
+
+pub fn keyCallback(window: ?*c.GLFWwindow, key: c_int, scancode: c_int, action: c_int, mods: c_int) callconv(.c) void {
+ _ = scancode;
+ _ = mods;
+ std.debug.print("test {d}\n", .{key});
+ if (c.glfwGetWindowUserPointer(window)) |r| {
+ const resources: *ecs.Resources = @alignCast(@ptrCast(r));
+ if (action == c.GLFW_PRESS) {
+ resources.input.key_pressed[@intCast(key)] = true;
+ } else if (action == c.GLFW_RELEASE) {
+ resources.input.key_pressed[@intCast(key)] = false;
+ }
+ }
+}