summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/gui.zig86
1 files changed, 34 insertions, 52 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index bfec8352..2533fbef 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -6845,28 +6845,19 @@ fn emitTagLayer(g: *Gui, instances: [*]CellInstance, next: *u32, layer: *const p
// A theme's plaque is drawn under the band: the band's own ground
// lets it show (tagPlaques).
if (cell_decor.nplaques != 0 and cell_decor.inPlaque(left + 0.5, top + 0.5)) plaqueThrough(instances, next.*);
- if (slide != 0) clipInstanceTop(&instances[next.*], top, win_h);
+ if (slide != 0) clipInstance(&instances[next.*], .{ -1e9, top, 1e9, 1e9 }, win_w, win_h);
next.* += 1;
const cells = layer.cells[index * layer.cols ..][0..layer.cols];
const line_cursor: ?usize = if (layer.cursor) |cu| (if (cu.y == index) cu.x else null) else null;
for (0..tagLayerCellCount(g, layer)) |col| {
const cursor = if (layer.cursor) |cu| show_cursor and !cu.bar and cu.x == col and cu.y == index else false;
emitInstance(g, instances, next.*, @intCast(col), y, .{ .w = tw, .h = bh, .x_off = left, .y_off = slide }, win_w, win_h, track, .tagline, cells, col, line_cursor, old_layer, cursor, page);
- clipInstanceRight(&instances[next.*], right, win_w);
- if (slide != 0) clipInstanceTop(&instances[next.*], top, win_h);
+ clipInstance(&instances[next.*], .{ -1e9, if (slide != 0) top else -1e9, right, 1e9 }, win_w, win_h);
next.* += 1;
}
}
}
-fn clipInstanceTop(instance: *CellInstance, top: f32, win_h: f32) void {
- const limit = 1 - top / win_h * 2;
- if (instance.y0 <= limit) return;
- const fraction = std.math.clamp((limit - instance.y1) / (instance.y0 - instance.y1), 0, 1);
- instance.v0 = instance.v1 + (instance.v0 - instance.v1) * fraction;
- instance.y0 = @max(instance.y1, limit);
-}
-
fn bodyLayerIn(layers: []const pardes.Layer, col: u16, row: u16) ?*const pardes.Layer {
for (layers) |*layer| {
const r = layer.viewport;
@@ -6875,22 +6866,6 @@ fn bodyLayerIn(layers: []const pardes.Layer, col: u16, row: u16) ?*const pardes.
return null;
}
-fn clipInstanceRight(instance: *CellInstance, right: f32, win_w: f32) void {
- const edge = right / win_w * 2 - 1;
- if (instance.x1 <= edge) return;
- const fraction = std.math.clamp((edge - instance.x0) / (instance.x1 - instance.x0), 0, 1);
- instance.u1 = instance.u0 + (instance.u1 - instance.u0) * fraction;
- instance.x1 = @max(instance.x0, edge);
-}
-
-fn clipBodyInstance(instance: *CellInstance, bottom: f32, win_h: f32) void {
- const limit = 1 - bottom / win_h * 2;
- if (instance.y1 >= limit) return;
- const fraction = (instance.y0 - limit) / (instance.y0 - instance.y1);
- instance.v1 = instance.v0 + (instance.v1 - instance.v0) * fraction;
- instance.y1 = limit;
-}
-
fn emitBodyLayer(g: *Gui, instances: [*]CellInstance, next: *u32, layer: *const pardes.Layer, win_w: f32, win_h: f32, track: ?pardes.animation.Track, page: [3]u8, show_cursor: bool, old_layer: bool, border_rgb: [3]u8) void {
const bw: f32 = @floatFromInt(g.cell_w);
const bh: f32 = @floatFromInt(g.cell_h);
@@ -6911,8 +6886,7 @@ fn emitBodyLayer(g: *Gui, instances: [*]CellInstance, next: *u32, layer: *const
var background: pardes.Cell = .{ .default = false, .style = layer.cells[index * layer.cols].style };
background.style.font_role = .body;
emitInstance(g, instances, next.*, 0, 0, .{ .w = @as(f32, @floatFromInt(layer.viewport.w)) * bw, .h = height, .x_off = left, .y_off = top }, win_w, win_h, track, .body, (&background)[0..1], 0, null, old_layer, false, page);
- clipBodyInstance(&instances[next.*], bottom, win_h);
- clipInstanceRight(&instances[next.*], right, win_w);
+ clipInstance(&instances[next.*], .{ -1e9, -1e9, right, bottom }, win_w, win_h);
next.* += 1;
}
const line = layer.cells[index * layer.cols ..][0..layer.cols];
@@ -6922,8 +6896,7 @@ fn emitBodyLayer(g: *Gui, instances: [*]CellInstance, next: *u32, layer: *const
const cursor = if (layer.cursor) |cu| show_cursor and !cu.bar and cu.x == col and cu.y == row else false;
const glyph_top = top - (if (header) @as(f32, @floatFromInt(taglineBandOffset(0, win_h, g.cell_h, g.tagline_height))) else 0);
emitInstance(g, instances, next.*, 0, 0, .{ .w = width, .h = height, .x_off = left + @as(f32, @floatFromInt(col)) * width, .y_off = glyph_top }, win_w, win_h, track, role, line, col, line_cursor, old_layer, cursor, page);
- clipBodyInstance(&instances[next.*], bottom, win_h);
- clipInstanceRight(&instances[next.*], right, win_w);
+ clipInstance(&instances[next.*], .{ -1e9, -1e9, right, bottom }, win_w, win_h);
next.* += 1;
}
if (layer.hasContextBorderAfter(row)) {
@@ -6934,8 +6907,7 @@ fn emitBodyLayer(g: *Gui, instances: [*]CellInstance, next: *u32, layer: *const
.x_off = left,
.y_off = top + height - 1,
}, win_w, win_h, track, .body, (&border)[0..1], 0, null, old_layer, false, page);
- clipBodyInstance(&instances[next.*], bottom, win_h);
- clipInstanceRight(&instances[next.*], right, win_w);
+ clipInstance(&instances[next.*], .{ -1e9, -1e9, right, bottom }, win_w, win_h);
next.* += 1;
}
}
@@ -6985,30 +6957,40 @@ fn inkOn(bg: [3]u8) [3]u8 {
return if (lum > 140) .{ 0x00, 0x00, 0x00 } else .{ 0xff, 0xff, 0xff };
}
-/// Cuts an instance's quad to a pixel rectangle, its atlas window with it so
-/// the glyph neither moves nor stretches; nothing left, an empty quad.
+/// Cuts an instance's quad to a pixel rectangle (left, top, right, bottom),
+/// its atlas window in proportion, so the glyph neither moves nor stretches
+/// (a band is a stretched quad); nothing left, an empty quad.
fn clipInstance(instance: *CellInstance, r: [4]f32, win_w: f32, win_h: f32) void {
- const x0 = (instance.x0 + 1) / 2 * win_w;
- const x1 = (instance.x1 + 1) / 2 * win_w;
- const y0 = (1 - instance.y0) / 2 * win_h;
- const y1 = (1 - instance.y1) / 2 * win_h;
- const left = @max(0, r[0] - x0);
- const right = @max(0, x1 - r[2]);
- const top = @max(0, r[1] - y0);
- const bottom = @max(0, y1 - r[3]);
- if (x1 - right <= x0 + left or y1 - bottom <= y0 + top) {
+ // In clip space, where y grows up: a quad's y0 is its top.
+ const left = r[0] / win_w * 2 - 1;
+ const right = r[2] / win_w * 2 - 1;
+ const top = 1 - r[1] / win_h * 2;
+ const bottom = 1 - r[3] / win_h * 2;
+ if (instance.x1 <= left or instance.x0 >= right or instance.y0 <= bottom or instance.y1 >= top) {
instance.x1 = instance.x0;
instance.y1 = instance.y0;
return;
}
- instance.x0 += left / win_w * 2;
- instance.u0 += left / atlas_w;
- instance.x1 -= right / win_w * 2;
- instance.u1 -= right / atlas_w;
- instance.y0 -= top / win_h * 2;
- instance.v0 += top / atlas_h;
- instance.y1 += bottom / win_h * 2;
- instance.v1 -= bottom / atlas_h;
+ if (instance.x0 < left) {
+ const fraction = (instance.x1 - left) / (instance.x1 - instance.x0);
+ instance.u0 = instance.u1 + (instance.u0 - instance.u1) * fraction;
+ instance.x0 = left;
+ }
+ if (instance.x1 > right) {
+ const fraction = (right - instance.x0) / (instance.x1 - instance.x0);
+ instance.u1 = instance.u0 + (instance.u1 - instance.u0) * fraction;
+ instance.x1 = right;
+ }
+ if (instance.y0 > top) {
+ const fraction = (top - instance.y1) / (instance.y0 - instance.y1);
+ instance.v0 = instance.v1 + (instance.v0 - instance.v1) * fraction;
+ instance.y0 = top;
+ }
+ if (instance.y1 < bottom) {
+ const fraction = (instance.y0 - bottom) / (instance.y0 - instance.y1);
+ instance.v1 = instance.v0 + (instance.v1 - instance.v0) * fraction;
+ instance.y1 = bottom;
+ }
}
fn emitSurfaceCell(