summaryrefslogtreecommitdiff
path: root/src/host/gfx.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/host/gfx.zig')
-rw-r--r--src/host/gfx.zig12
1 files changed, 6 insertions, 6 deletions
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 {