From 05a5cfddb5cc1888c134ad3d6307d24f8d5478a6 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 13 Dec 2022 22:22:00 -0800 Subject: [PATCH] font: web canvas sprite trapezoid --- src/font/sprite/canvas.zig | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/font/sprite/canvas.zig b/src/font/sprite/canvas.zig index 68c08e709..28f17337a 100644 --- a/src/font/sprite/canvas.zig +++ b/src/font/sprite/canvas.zig @@ -152,8 +152,15 @@ const WebCanvasImpl = struct { } pub fn trapezoid(self: *WebCanvasImpl, t: Trapezoid) void { - _ = self; - _ = t; + const ctx = self.context(.on) catch return; + defer ctx.deinit(); + + ctx.call(void, "beginPath", .{}) catch return; + ctx.call(void, "moveTo", .{ t.left.p1.x, t.left.p1.y }) catch return; + ctx.call(void, "lineTo", .{ t.right.p1.x, t.right.p1.y }) catch return; + ctx.call(void, "lineTo", .{ t.right.p2.x, t.right.p2.y }) catch return; + ctx.call(void, "lineTo", .{ t.left.p2.x, t.left.p2.y }) catch return; + ctx.call(void, "fill", .{}) catch return; } pub fn triangle(self: *WebCanvasImpl, t: Triangle, color: Color) void {