simplify the code for separated block quadrants

This commit is contained in:
Jeffrey C. Ollie
2024-12-15 17:59:04 -06:00
parent d0677928af
commit 3588d81dcb

View File

@ -2921,61 +2921,46 @@ fn draw_separated_block_quadrant(self: Box, canvas: *font.sprite.Canvas, comptim
}, },
}; };
const left: f64 = 0.5; const gap: f64 = @max(1.0, @as(f64, @floatFromInt(self.metrics.cell_width)) * 0.10) / 2.0;
const right = @as(f64, @floatFromInt(self.metrics.cell_width)) - 0.5; const left: f64 = gap;
const top: f64 = 0.5; const right = @as(f64, @floatFromInt(self.metrics.cell_width)) - gap;
const bottom = @as(f64, @floatFromInt(self.metrics.cell_height)) - 0.5; const top: f64 = gap;
const bottom = @as(f64, @floatFromInt(self.metrics.cell_height)) - gap;
const center_x = @as(f64, @floatFromInt(self.metrics.cell_width)) / 2.0; const center_x = @as(f64, @floatFromInt(self.metrics.cell_width)) / 2.0;
const center_left = center_x - 0.5; const center_left = center_x - gap;
const center_right = center_x + 0.5; const center_right = center_x + gap;
const center_y = @as(f64, @floatFromInt(self.metrics.cell_height)) / 2.0; const center_y = @as(f64, @floatFromInt(self.metrics.cell_height)) / 2.0;
const center_top = center_y - 0.5; const center_top = center_y - gap;
const center_bottom = center_y + 0.5; const center_bottom = center_y + gap;
inline for (fmt) |c| { inline for (fmt) |c| {
switch (c) { const x1, const y1, const x2, const y2 = switch (c) {
'1' => { '1' => .{
var path = z2d.Path.init(canvas.alloc); left, top,
defer path.deinit(); center_left, center_top,
try path.moveTo(left, top);
try path.lineTo(center_left, top);
try path.lineTo(center_left, center_top);
try path.lineTo(left, center_top);
try path.close();
try ctx.fill(canvas.alloc, path);
}, },
'2' => { '2' => .{
var path = z2d.Path.init(canvas.alloc); center_right, top,
defer path.deinit(); right, center_top,
try path.moveTo(center_right, top);
try path.lineTo(right, top);
try path.lineTo(right, center_top);
try path.lineTo(center_right, center_top);
try path.close();
try ctx.fill(canvas.alloc, path);
}, },
'3' => { '3' => .{
var path = z2d.Path.init(canvas.alloc); left, center_bottom,
defer path.deinit(); center_left, bottom,
try path.moveTo(left, center_bottom);
try path.lineTo(center_left, center_bottom);
try path.lineTo(center_left, bottom);
try path.lineTo(left, bottom);
try path.close();
try ctx.fill(canvas.alloc, path);
}, },
'4' => { '4' => .{
var path = z2d.Path.init(canvas.alloc); center_right, center_bottom,
defer path.deinit(); right, bottom,
try path.moveTo(center_right, center_bottom);
try path.lineTo(right, center_bottom);
try path.lineTo(right, bottom);
try path.lineTo(center_right, bottom);
try path.close();
try ctx.fill(canvas.alloc, path);
}, },
else => unreachable, else => unreachable,
} };
var path = z2d.Path.init(canvas.alloc);
defer path.deinit();
try path.moveTo(x1, y1);
try path.lineTo(x2, y1);
try path.lineTo(x2, y2);
try path.lineTo(x1, y2);
try path.close();
try ctx.fill(canvas.alloc, path);
} }
} }