From a7e7dc800db6910d306b6802dd699c8a1fb58263 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sun, 22 May 2022 08:53:38 -0700 Subject: [PATCH] mach: expose window size (pixel units, vs. framebuffer subpixel units) Signed-off-by: Stephen Gutekanst --- src/Engine.zig | 10 ++++++++++ src/native.zig | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/src/Engine.zig b/src/Engine.zig index 29382109..11de2bde 100644 --- a/src/Engine.zig +++ b/src/Engine.zig @@ -34,10 +34,20 @@ pub const Core = struct { core.internal.setShouldClose(value); } + // Returns the framebuffer size, in subpixel units. + // + // e.g. returns 1280x960 on macOS for a window that is 640x480 pub fn getFramebufferSize(core: *Core) !structs.Size { return core.internal.getFramebufferSize(); } + // Returns the widow size, in pixel units. + // + // e.g. returns 1280x960 on macOS for a window that is 640x480 + pub fn getWindowSize(core: *Core) !structs.Size { + return core.internal.getWindowSize(); + } + pub fn setSizeLimits(core: *Core, min: structs.SizeOptional, max: structs.SizeOptional) !void { return core.internal.setSizeLimits(min, max); } diff --git a/src/native.zig b/src/native.zig index 42120e32..5ac5c8e1 100644 --- a/src/native.zig +++ b/src/native.zig @@ -93,6 +93,11 @@ pub const CoreGlfw = struct { return @bitCast(structs.Size, size); } + pub fn getWindowSize(self: *CoreGlfw) !structs.Size { + const size = try self.window.getSize(); + return @bitCast(structs.Size, size); + } + pub fn setSizeLimits(self: *CoreGlfw, min: structs.SizeOptional, max: structs.SizeOptional) !void { try self.window.setSizeLimits( @bitCast(glfw.Window.SizeOptional, min),