diff options
Diffstat (limited to 'src/host/gfx.zig')
| -rw-r--r-- | src/host/gfx.zig | 10 |
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 }; |
