summaryrefslogtreecommitdiff
path: root/src/host/gfx.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 11:13:20 -0300
committerGabriel Schneider <[email protected]>2026-11-12 13:22:02 -0300
commit86ffca0024326110962f0880727f4eb84e6a48d1 (patch)
tree055f489341053c1db258606bb63b282bc7345a89 /src/host/gfx.zig
parenta62a6aa896adda901d335ef38814a13b8839545c (diff)
downloadsketchbook-86ffca0024326110962f0880727f4eb84e6a48d1.tar.gz
sketchbook-86ffca0024326110962f0880727f4eb84e6a48d1.zip
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 <[email protected]>
Diffstat (limited to 'src/host/gfx.zig')
-rw-r--r--src/host/gfx.zig10
1 files changed, 10 insertions, 0 deletions
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 };