-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.zig
63 lines (51 loc) · 1.7 KB
/
window.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const glfw = @import("glfw_wrapper.zig");
usingnamespace @import("vulkan_general.zig");
pub const Window = struct {
handle: *glfw.GLFWwindow,
pub fn init(width: u31, height: u31, title: [*:0]const u8) !Window {
var window: Window = undefined;
window.handle = try glfw.createWindow(width, height, title);
return window;
}
pub fn deinit(self: Window) void {
glfw.destroyWindow(self.handle);
}
pub fn getSize(self: Window) !Vk.c.VkExtent2D {
var width: i32 = undefined;
var height: i32 = undefined;
try glfw.getWindowSize(self.handle, &width, &height);
return Vk.c.VkExtent2D{ .width = @intCast(u32, width), .height = @intCast(u32, height) };
}
pub fn show(self: Window) !void {
try glfw.showWindow(self.handle);
}
pub fn hide(self: Window) !void {
try glfw.hideWindow(self.handle);
}
};
const testing = @import("std").testing;
test "initializing a window should succeed" {
try glfw.init();
defer glfw.deinit();
const window = try Window.init(10, 10, "test_title");
window.deinit();
}
test "getting the size of the window should work" {
try glfw.init();
defer glfw.deinit();
const width = 200;
const height = 300;
const window = try Window.init(width, height, "");
defer window.deinit();
testing.expectEqual(Vk.c.VkExtent2D{ .width = width, .height = height }, try window.getSize());
}
test "showing and hiding the windows should not fail" {
try glfw.init();
defer glfw.deinit();
const width = 200;
const height = 300;
const window = try Window.init(width, height, "");
defer window.deinit();
try window.show();
try window.hide();
}