zsdl: Progress.

This commit is contained in:
Michal Ziulek committed 2023-02-21 13:10:53 +01:00
1 parent b4a7b786d6
commit 4a12e45295
4 files changed
+78 -6

No files matched your search

+2
View File
@@ -1,4 +1,6 @@
*.exe
*.a
*.so
*.dll
*.pdb
*.bin
+2 -2
View File
@@ -17,6 +17,8 @@ pub const Package = struct {
}
pub fn link(_: Package, exe: *std.Build.CompileStep) void {
exe.linkLibC();
const target = (std.zig.system.NativeTargetInfo.detect(exe.target) catch unreachable).target;
switch (target.os.tag) {
@@ -64,8 +66,6 @@ pub const Package = struct {
},
else => unreachable,
}
exe.linkLibC();
}
};
+63 -3
View File
@@ -24,7 +24,7 @@ pub const InitFlags = packed struct(u32) {
no_parachute: bool = false,
__unused: u11 = 0,
pub const everything = InitFlags{
pub const everything: InitFlags = .{
.timer = true,
.audio = true,
.video = true,
@@ -38,8 +38,7 @@ pub const InitFlags = packed struct(u32) {
extern fn SDL_Init(flags: InitFlags) i32;
pub fn init(flags: InitFlags) Error!void {
if (SDL_Init(flags) < 0)
return makeError();
if (SDL_Init(flags) < 0) return makeError();
}
extern fn SDL_Quit() void;
@@ -58,3 +57,64 @@ pub fn makeError() error{SdlError} {
}
return error.SdlError;
}
pub const Window = opaque {
pub const Flags = packed struct(u32) {
fullscreen: bool = false,
opengl: bool = false,
shown: bool = false,
hidden: bool = false,
borderless: bool = false,
resizable: bool = false,
minimized: bool = false,
maximized: bool = false,
mouse_grabbed: bool = false,
input_focus: bool = false,
mouse_focus: bool = false,
foreign: bool = false,
_desktop: bool = false,
allow_highdpi: bool = false,
mouse_capture: bool = false,
always_on_top: bool = false,
skip_taskbar: bool = false,
utility: bool = false,
tooltip: bool = false,
popup_menu: bool = false,
keyboard_grabbed: bool = false,
__unused21: bool = false,
__unused22: bool = false,
__unused23: bool = false,
__unused24: bool = false,
vulkan: bool = false,
metal: bool = false,
__unused: u5 = 0,
pub const fullscreen_desktop: Flags = .{ .fullscreen = true, ._desktop = true };
pub const input_grabbed: Flags = .{ .mouse_grabbed = true };
};
pub const pos_undefined = posUndefinedDisplay(0);
pub const pos_centered = posCenteredDisplay(0);
pub fn posUndefinedDisplay(x: i32) i32 {
return pos_undefined_mask | x;
}
pub fn posCenteredDisplay(x: i32) i32 {
return pos_centered_mask | x;
}
const pos_undefined_mask: i32 = 0x1fff_0000;
const pos_centered_mask: i32 = 0x2fff_0000;
extern fn SDL_CreateWindow(title: ?[*:0]const u8, x: i32, y: i32, w: i32, h: i32, flags: Flags) ?*Window;
pub fn create(title: [:0]const u8, x: i32, y: i32, w: i32, h: i32, flags: Flags) Error!*Window {
return SDL_CreateWindow(title, x, y, w, h, flags) orelse return makeError();
}
extern fn SDL_DestroyWindow(window: *Window) void;
/// `pub fn destroy(window: *Window) void`
pub const destroy = SDL_DestroyWindow;
};
+11 -1
View File
@@ -5,5 +5,15 @@ pub fn main() !void {
try sdl.init(.{ .audio = true, .video = true });
defer sdl.quit();
std.debug.print("sdl.init() call was successful\n", .{});
const window = try sdl.Window.create(
"zig-gamedev-window",
sdl.Window.pos_undefined,
200,
400,
400,
.{ .shown = true },
);
defer window.destroy();
std.debug.print("All OK\n", .{});
}