70 lines
1.8 KiB
Zig
70 lines
1.8 KiB
Zig
const std = @import("std");
|
|
const core = @import("core");
|
|
const test_vert = @import("test.vert");
|
|
|
|
// controls glfw and general windowing
|
|
// graphics depends on this one
|
|
|
|
pub const windowing = @import("windowing.zig");
|
|
|
|
pub const Module: core.ModuleDescription = .{
|
|
.name = "platform",
|
|
.enabledByDefault = true,
|
|
};
|
|
|
|
var gPlatformInstance: *windowing.PlatformInstance = undefined;
|
|
var gStartupParams: windowing.PlatformParams = .{};
|
|
|
|
pub fn context() *windowing.PlatformInstance {
|
|
return gPlatformInstance;
|
|
}
|
|
|
|
pub fn setWindowSettings(params: windowing.PlatformParams) void {
|
|
gStartupParams = params;
|
|
}
|
|
|
|
pub fn getCursorPosition() core.Vector2f {
|
|
return gPlatformInstance.getCursorPosition();
|
|
}
|
|
|
|
pub fn setCursorVisible(visible: bool) void {
|
|
return gPlatformInstance.setCursorVisible(visible);
|
|
}
|
|
|
|
pub fn setMousePosition(pos: core.Vector2f) void {
|
|
gPlatformInstance.setMousePosition(pos);
|
|
}
|
|
|
|
pub fn setMouseRelativeMode(relativeMode: bool) void {
|
|
gPlatformInstance.setMouseRelativeMode(relativeMode);
|
|
}
|
|
|
|
pub fn start_module(comptime programSpec: anytype, args: anytype, allocator: std.mem.Allocator) !void {
|
|
_ = args;
|
|
_ = programSpec;
|
|
if (core.isUtility()) {
|
|
return;
|
|
}
|
|
|
|
gPlatformInstance = try allocator.create(windowing.PlatformInstance);
|
|
gPlatformInstance.* = try windowing.PlatformInstance.init(allocator, gStartupParams);
|
|
|
|
try gPlatformInstance.setupWindow();
|
|
|
|
try gPlatformInstance.registerFuncs();
|
|
}
|
|
|
|
pub fn getInstance() *windowing.PlatformInstance {
|
|
return gPlatformInstance;
|
|
}
|
|
|
|
pub fn shutdown_module(allocator: std.mem.Allocator) void {
|
|
if (core.isUtility()) {
|
|
return;
|
|
}
|
|
|
|
gPlatformInstance.deinit();
|
|
|
|
allocator.destroy(gPlatformInstance);
|
|
}
|