From 86ffca0024326110962f0880727f4eb84e6a48d1 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 11:13:20 -0300 Subject: sketchbook: frames for ffmpeg (--export, on a clock of its own), text sizes, a font from the environment Co-Authored-By: Claude Fable 5.2 --- src/host/gfx.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/host/gfx.zig') diff --git a/src/host/gfx.zig b/src/host/gfx.zig index 20b4dcc..3affa6e 100644 --- a/src/host/gfx.zig +++ b/src/host/gfx.zig @@ -555,6 +555,16 @@ pub fn drawText(renderer: *c.SDL_Renderer, x: f32, y: f32, scale: f32, bytes: [] if (clipped and s != 1) _ = c.SDL_SetRenderClipRect(renderer, &clip); } +/// What `drawText` gives `bytes` at `scale`: its width and the height of +/// its line, in canvas units (`Host.textSize`). +pub fn textSize(renderer: *c.SDL_Renderer, scale: f32, bytes: []const u8) [2]f32 { + var size: [2]f32 = .{ 0, 0 }; + if (@import("builtin").os.tag == .linux and c.sk_text_measure(renderer, scale, bytes.ptr, bytes.len, &size[0], &size[1])) return size; + // The debug font's 8 px cells. + const s = @max(scale, 1); + return .{ @as(f32, @floatFromInt(bytes.len)) * 8 * s, 8 * s }; +} + fn premultiply(color: abi.Color) abi.Color { const a: u32 = color.a; return .{ .r = @intCast((color.r * a + 127) / 255), .g = @intCast((color.g * a + 127) / 255), .b = @intCast((color.b * a + 127) / 255), .a = color.a }; -- cgit v1.3