summaryrefslogtreecommitdiff
path: root/src/host
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 12:10:40 -0300
committerGabriel Schneider <[email protected]>2026-11-12 13:22:02 -0300
commitfaf40df6f31e98eb752fd5e96330221c8f7dbcc7 (patch)
treeab9356732afbbbb18e85f973945249a738863ae7 /src/host
parent71e534631bf68f33f802d64794340870374b9f69 (diff)
downloadsketchbook-faf40df6f31e98eb752fd5e96330221c8f7dbcc7.tar.gz
sketchbook-faf40df6f31e98eb752fd5e96330221c8f7dbcc7.zip
sketchbook: text in six faces of the Go family, all bundled (f.textIn, host.textSizeIn, sk.Face)
Diffstat (limited to 'src/host')
-rw-r--r--src/host/Host.zig4
-rw-r--r--src/host/gfx.zig12
2 files changed, 8 insertions, 8 deletions
diff --git a/src/host/Host.zig b/src/host/Host.zig
index 4b5f2a4..86e1873 100644
--- a/src/host/Host.zig
+++ b/src/host/Host.zig
@@ -834,8 +834,8 @@ fn apiSamples(ctx: *anyopaque, audio: abi.Audio) []const f32 {
fn apiImageSize(ctx: *anyopaque, image: abi.Image) [2]u32 {
return hostOf(ctx).images.size(image);
}
-fn apiTextSize(ctx: *anyopaque, scale: f32, bytes: []const u8) [2]f32 {
- return gfx.textSize(hostOf(ctx).renderer, scale, bytes);
+fn apiTextSize(ctx: *anyopaque, scale: f32, bytes: []const u8, face: abi.Face) [2]f32 {
+ return gfx.textSize(hostOf(ctx).renderer, scale, bytes, face);
}
fn apiLoadSound(ctx: *anyopaque, path: []const u8) abi.Audio {
return hostOf(ctx).audio.load(path);
diff --git a/src/host/gfx.zig b/src/host/gfx.zig
index 0466f27..2aac380 100644
--- a/src/host/gfx.zig
+++ b/src/host/gfx.zig
@@ -239,7 +239,7 @@ pub const Painter = struct {
.image => |img| p.drawImage(img.image, img.dst, img.src, img.tint, img.corners),
.text => |text| {
_ = c.SDL_SetRenderDrawBlendMode(renderer, c.SDL_BLENDMODE_BLEND);
- drawText(renderer, text.x, text.y, text.scale, text.bytes, text.color);
+ drawText(renderer, text.x, text.y, text.scale, text.bytes, text.color, text.face);
},
.clip => |clip| {
if (clip) |r| {
@@ -527,8 +527,8 @@ fn fcolor(color: abi.Color) c.SDL_FColor {
/// Native shaped text on Linux, using a 13px monospace face at scale 1.
/// Other targets retain SDL's built-in 8x8 fallback. Coordinates are line-box tops.
-pub fn drawText(renderer: *c.SDL_Renderer, x: f32, y: f32, scale: f32, bytes: []const u8, color: abi.Color) void {
- if (@import("builtin").os.tag == .linux and c.sk_text_draw(renderer, x, y, scale, bytes.ptr, bytes.len, color.r, color.g, color.b, color.a)) return;
+pub fn drawText(renderer: *c.SDL_Renderer, x: f32, y: f32, scale: f32, bytes: []const u8, color: abi.Color, face: abi.Face) void {
+ if (@import("builtin").os.tag == .linux and c.sk_text_draw_face(renderer, @intFromEnum(face), x, y, scale, bytes.ptr, bytes.len, color.r, color.g, color.b, color.a)) return;
var buf: [1024]u8 = undefined;
const len = @min(std.mem.indexOfScalar(u8, bytes, 0) orelse bytes.len, buf.len - 1);
@memcpy(buf[0..len], bytes[0..len]);
@@ -558,9 +558,9 @@ pub fn drawText(renderer: *c.SDL_Renderer, x: f32, y: f32, scale: f32, bytes: []
/// 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 {
+pub fn textSize(renderer: *c.SDL_Renderer, scale: f32, bytes: []const u8, face: abi.Face) [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;
+ if (@import("builtin").os.tag == .linux and c.sk_text_measure_face(renderer, @intFromEnum(face), 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 };
@@ -575,7 +575,7 @@ fn missing(renderer: *c.SDL_Renderer, dst: abi.Rect) void {
_ = c.SDL_SetRenderDrawBlendMode(renderer, c.SDL_BLENDMODE_BLEND);
setColor(renderer, .{ .r = 110, .g = 30, .b = 70 });
_ = c.SDL_RenderFillRect(renderer, &frect(dst));
- drawText(renderer, dst.x + 4, dst.y + 4, 1, "missing image", .{ .r = 255, .g = 210, .b = 240 });
+ drawText(renderer, dst.x + 4, dst.y + 4, 1, "missing image", .{ .r = 255, .g = 210, .b = 240 }, .mono);
}
fn setColor(renderer: *c.SDL_Renderer, color: abi.Color) void {