summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.zig322
1 files changed, 2 insertions, 320 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index ee565aeb..ca3c7724 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -1166,10 +1166,6 @@ const Gui = struct {
/// whether this loop's wait read an input (drawn at once, not paced).
pace_ns: u64 = 0,
input_seen: bool = false,
- /// G9 and G11: the selection's and the hovered word's glow blocks as
- /// last drawn, for their fade-in.
- sel_glow: SelGlow = .{},
- hover_glow: SelGlow = .{},
/// G14: the cells last drawn and when each last changed.
/// The cursor's blink (blinkNow): when the frame drawn last arrived,
/// a redraw owed for an edge, and this frame's cursor mode and alpha.
@@ -1235,7 +1231,7 @@ const window_fields = [_][:0]const u8{
"window_w", "window_h", "scroll_pane", "scroll_rect", "scroll_body_y",
"scroll_body_h", "scroll_held_px", "scroll_col", "scroll_row", "scroll_delta",
"scroll_lag", "scroll_edge", "scroll_edge_len", "scroll_notch", "program_wheel",
- "glide", "pace_ns", "sel_glow", "hover_glow", "frame_arrival_ns",
+ "glide", "pace_ns", "frame_arrival_ns",
"blink_due", "cursor_quad_alpha", "pointer_present", "pointer_shape",
"pointer_cell", "presented_images", "prepared_images", "touch",
"live_ctrl", "live_alt", "applied_window_opacity", "capture_tex", "capture_tex_w",
@@ -4817,7 +4813,7 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void {
const glide = &g.glide;
// The glide runs on the core's continuous path: frames every loop, and
// a virtual clock carried on.
- defer core.shell_continuous = glide.moving() or g.sel_glow.fading or g.hover_glow.fading;
+ defer core.shell_continuous = glide.moving();
const notch = g.scroll_notch;
g.scroll_notch = 0;
var wheeled: ?usize = null;
@@ -5812,11 +5808,6 @@ fn renderFrame(
// G6: what the scroll just done moved the pane's rows by, measured on
// this frame against the last (the glide follows it from there).
if (g.glide.pending) g.glide.measure(gpa, surface);
- g.sel_glow.now_ns = core.now_ns;
- // Off, or while panes move, no glow and nothing fading.
- if (surface.chrome.fx & 1 == 0 or surface.panelTracks().len != 0) g.sel_glow = .{ .now_ns = g.sel_glow.now_ns };
- g.hover_glow.now_ns = g.sel_glow.now_ns;
- if (surface.chrome.fx & 2 == 0 or surface.panelTracks().len != 0) g.hover_glow = .{ .now_ns = g.sel_glow.now_ns };
if (g.glide.moving()) g.glide.advance(g.glide.now_ns, g.glide.motion);
cell_decor = CellDecor.of(chrome);
plaque_through_len = 0;
@@ -8645,13 +8636,6 @@ fn buildDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, g
const bodies = body_buf[0..nbodies];
const ticks: []const pardes.RailTick = if (closing) &.{} else surface.rail_ticks[0..surface.nrail_ticks];
try paneDecor(g, gpa, placed, ticks, groups, index, chrome, layout, surface.cols, surface.rows, win_w, win_h, track);
- // G9, while nothing moves: a halo round the body's selection.
- if (index == 0 and groups.tracks == 0 and chrome.fx & 1 != 0) try glowBlocks(g, gpa, surface, .selection, layout, win_w, win_h);
- // G11: a glow under the word a look-hover would open.
- if (index == 0 and groups.tracks == 0 and chrome.fx & 2 != 0) try glowBlocks(g, gpa, surface, .hover, layout, win_w, win_h);
- // G14: what changed glows, while nothing moves.
- // G12: the bodies' edges shaded, a pane's in its own group.
- if (chrome.fx & 4 != 0) try occlusion(g, gpa, placed, groups, index, surface, ceilings, layout, win_w, win_h, track);
// A single spine runs down each column, through every tag and body.
if (index == 0) for (regions) |column| {
if (column.kind != .column) continue;
@@ -8935,187 +8919,6 @@ fn dp(logical: f32) f32 {
return @max(1, @round(logical * display_scale));
}
-/// G9's state: the selection's blocks last drawn and when each appeared.
-const SelGlow = struct {
- const Block = struct { box: [4]u16, start_ns: u64 };
- blocks: [32]Block = undefined,
- len: usize = 0,
- now_ns: u64 = 0,
- /// A block is still fading in: the core keeps frames coming.
- fading: bool = false,
-};
-
-/// How long a glow takes to come up (§8.1's micro-feedback: 80 to 120 ms).
-const sel_glow_ns: u64 = 100 * std.time.ns_per_ms;
-
-/// A glow's kind: G9's halo round the selection, G11's under a hovered word.
-const GlowKind = enum { selection, hover };
-
-/// G9: a soft halo of the selection's own colour round each block of it in
-/// a pane body (rows of selected cells that touch), fading in over 100 ms
-/// with an ease-out. The selection itself is the halo's caster, never
-/// touched; so is a cursor beside it; the halo stays on bodies (never a
-/// tag or a grip) and at most 22%, less where the text round it would drop
-/// below min(its contrast, 4.5).
-/// G11: under the word a look-hover would open (its cells in the
-/// affordance's tint), a soft line of the theme's accent along its foot,
-/// fading in over 80 ms, as strong at most, never under a cursor.
-fn glowBlocks(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, kind: GlowKind, layout: CellLayout, win_w: f32, win_h: f32) !void {
- const chrome = &surface.chrome;
- const page = chrome.page orelse bg_default;
- const fg = chrome.fg orelse fg_default;
- // The selection's halo is its own colour; a hovered word's underline is
- // the theme's accent (its focused grip), like a link's.
- const glow = if (kind == .selection) chrome.sel_bg else chrome.accent;
- // The cells a block is made of: the selection's, or the hover
- // affordance's tint (draw.zig: halfway to a quarter of the selection).
- const sel = if (kind == .selection) chrome.sel_bg else mixRgb(page, mixRgb(page, chrome.sel_bg));
- const tracker = if (kind == .selection) &g.sel_glow else &g.hover_glow;
- const rise_ns: u64 = if (kind == .selection) sel_glow_ns else 80 * std.time.ns_per_ms;
- const cap = @min(0.22, lightenCeiling(fg, page, glow));
- var blocks: [32][4]u16 = undefined;
- var nblocks: usize = 0;
- var bodies: [pardes.MAX_PANES][4]f32 = undefined;
- var nbodies: usize = 0;
- for (surface.regionList()) |body| {
- if (body.kind != .body or body.rect.w == 0) continue;
- if (nbodies < bodies.len) {
- bodies[nbodies] = bodyPixels(body, layout);
- nbodies += 1;
- }
- var open: ?[4]u16 = null; // x0, y0, x1, y1 of the block being grown
- var row = body.rect.y;
- while (row < body.rect.y + body.rect.h and row < surface.rows) : (row += 1) {
- var x0: ?u16 = null;
- var x1: u16 = 0;
- var col = body.rect.x;
- while (col < body.rect.x + body.rect.w and col < surface.cols) : (col += 1) {
- const cell = &surface.cells[@as(usize, row) * surface.cols + col];
- const selected = !cell.default and switch (cell.style.bg) {
- .rgb => |rgb| std.mem.eql(u8, &rgb, &sel),
- else => false,
- };
- if (!selected) continue;
- if (x0 == null) x0 = col;
- x1 = col + 1;
- }
- if (x0) |start| {
- if (open) |*block| {
- block.* = .{ @min(block[0], start), block[1], @max(block[2], x1), row + 1 };
- } else open = .{ start, row, x1, row + 1 };
- } else if (open) |block| {
- if (nblocks < blocks.len) blocks[nblocks] = block;
- nblocks += 1;
- open = null;
- }
- }
- if (open) |block| if (nblocks < blocks.len) {
- blocks[nblocks] = block;
- nblocks += 1;
- };
- }
- nblocks = @min(nblocks, blocks.len);
- // Each block keeps the start of the one it overlaps from the last frame.
- var next: SelGlow = .{ .now_ns = tracker.now_ns };
- for (blocks[0..nblocks]) |block| {
- const start = for (tracker.blocks[0..tracker.len]) |old| {
- if (old.box[0] < block[2] and block[0] < old.box[2] and old.box[1] < block[3] and block[1] < old.box[3]) break old.start_ns;
- } else tracker.now_ns;
- next.blocks[next.len] = .{ .box = block, .start_ns = start };
- next.len += 1;
- const t = @as(f32, @floatFromInt(tracker.now_ns -| start)) / @as(f32, @floatFromInt(rise_ns));
- if (t < 1) next.fading = true;
- const u = std.math.clamp(t, 0, 1);
- const fade = 1 - (1 - u) * (1 - u) * (1 - u);
- var caster: [4]f32 = .{ @as(f32, @floatFromInt(block[0])) * layout.w, @as(f32, @floatFromInt(block[1])) * layout.h, @as(f32, @floatFromInt(block[2])) * layout.w, @as(f32, @floatFromInt(block[3])) * layout.h };
- const cursor_box: ?[4]f32 = if (surface.cursor) |cu| .{ @as(f32, @floatFromInt(cu.x)) * layout.w, @as(f32, @floatFromInt(cu.y)) * layout.h, @as(f32, @floatFromInt(cu.x + 1)) * layout.w, @as(f32, @floatFromInt(cu.y + 1)) * layout.h } else null;
- const first = g.decor.items.len;
- switch (kind) {
- .selection => {
- // A cursor beside the selection is not glowed over: it
- // joins the caster.
- if (surface.cursor) |cu| if (cu.x + 1 >= block[0] and cu.x <= block[2] and cu.y + 1 >= block[1] and cu.y <= block[3]) {
- const cb = cursor_box.?;
- caster = .{ @min(caster[0], cb[0]), @min(caster[1], cb[1]), @max(caster[2], cb[2]), @max(caster[3], cb[3]) };
- };
- try addSoft(g, gpa, caster, 0.3 * layout.h, 0, 0, cap * fade, glow, null, win_w, win_h);
- try clipToBodies(g, gpa, first, bodies[0..nbodies]);
- },
- .hover => {
- // A strip three logical pixels tall along the word's foot,
- // its edges blurred by one: an underline of light. It is
- // cast from a row away (addSoft leaves its caster's own
- // rectangle out), so all of it shows.
- const foot = caster[3] - dp(1);
- const away = layout.h;
- try addSoft(g, gpa, .{ caster[0] + dp(1), foot - dp(3) - away, caster[2] - dp(1), foot - away }, dp(1), 0, away, cap * fade, glow, null, win_w, win_h);
- // Kept to the bodies, and off a cursor: the parts either
- // side of it.
- var parts: [4 * pardes.MAX_PANES][4]f32 = undefined;
- var nparts: usize = 0;
- for (bodies[0..nbodies]) |b| {
- const cb = cursor_box orelse {
- parts[nparts] = b;
- nparts += 1;
- continue;
- };
- if (cb[0] >= b[2] or cb[2] <= b[0] or cb[1] >= b[3] or cb[3] <= b[1]) {
- parts[nparts] = b;
- nparts += 1;
- continue;
- }
- // Left and right of it, and above and below it.
- parts[nparts] = .{ b[0], b[1], cb[0], b[3] };
- parts[nparts + 1] = .{ cb[2], b[1], b[2], b[3] };
- parts[nparts + 2] = .{ cb[0], b[1], cb[2], cb[1] };
- parts[nparts + 3] = .{ cb[0], cb[3], cb[2], b[3] };
- nparts += 4;
- }
- try clipToBodies(g, gpa, first, parts[0..nparts]);
- },
- }
- }
- tracker.* = next;
-}
-
-/// G12: ambient occlusion, a pane body darkening faintly toward its edges
-/// (§9.1: an inner shadow of 1 to 2%): four soft strips cast from just
-/// outside the body inward, clipped to it and round a cursor, black in
-/// linear light, under the same contrast ceiling as a lift.
-fn occlusion(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, groups: *const Groups, index: usize, surface: *const pardes.Surface, ceilings: LiftCeilings, layout: CellLayout, win_w: f32, win_h: f32, track: ?pardes.animation.Track) !void {
- const strength = @min(0.02, ceilings.shadow);
- if (strength <= 0.002) return;
- const reach = 0.5 * layout.h;
- for (regions) |body| {
- if (body.kind != .body or body.rect.w == 0 or body.rect.h == 0 or groupOf(groups, body.serial) != index) continue;
- const b = bodyPixels(body, layout);
- // The body, less a cursor's cell in it: left, right, above, below.
- var parts: [4][4]f32 = undefined;
- var nparts: usize = 0;
- const cursor: ?[4]f32 = if (surface.cursor) |cu| .{ @as(f32, @floatFromInt(cu.x)) * layout.w, @as(f32, @floatFromInt(cu.y)) * layout.h, @as(f32, @floatFromInt(cu.x + 1)) * layout.w, @as(f32, @floatFromInt(cu.y + 1)) * layout.h } else null;
- if (cursor) |cb| if (!(cb[0] >= b[2] or cb[2] <= b[0] or cb[1] >= b[3] or cb[3] <= b[1])) {
- parts = .{ .{ b[0], b[1], cb[0], b[3] }, .{ cb[2], b[1], b[2], b[3] }, .{ cb[0], b[1], cb[2], cb[1] }, .{ cb[0], cb[3], cb[2], b[3] } };
- nparts = 4;
- };
- if (nparts == 0) {
- parts[0] = b;
- nparts = 1;
- }
- const t = reach / 3;
- const strips = [_][4]f32{
- .{ b[0], b[1] - t, b[2], b[1] },
- .{ b[0], b[3], b[2], b[3] + t },
- .{ b[0] - t, b[1], b[0], b[3] },
- .{ b[2], b[1], b[2] + t, b[3] },
- };
- for (strips) |strip| {
- const first = g.decor.items.len;
- try addSoft(g, gpa, strip, reach / 3, 0, 0, strength, .{ 0, 0, 0 }, track, win_w, win_h);
- try clipToBodies(g, gpa, first, parts[0..nparts]);
- }
- }
-}
-
/// A theme's tag plaques (Chrome.decor_box_*), drawn under the cells of
/// group `index`: each pane tag, and with the still panes the column and
/// workspace tags, becomes a framed box inside its own band with a hard
@@ -9651,127 +9454,6 @@ test "a pane on the move casts a shadow on the other panes' bodies alone, most a
try std.testing.expectEqual(@as(f32, 0), strengths[2]);
}
-test "the selection glows round its block, on the body only, fading in over 100 ms" {
- const gpa = std.testing.allocator;
- const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 });
- defer core.deinit();
- _ = try core.setTestFile(std.mem.asBytes(&@as([30][20]u8, @splat("some text on a line\n".*))));
- core.settings.selection_glow = true;
- core.sync();
- const s = try core.render(core.scratch.allocator());
- try std.testing.expectEqual(@as(u8, 1), s.chrome.fx);
- // Two rows of a selection in the body, as the core paints one.
- const body = for (s.regionList()) |region| {
- if (region.kind == .body) break region;
- } else return error.NoBody;
- for (0..2) |dy| for (5..12) |x| {
- const cell = &s.cells[(@as(usize, body.rect.y) + 3 + dy) * s.cols + body.rect.x + x];
- cell.default = false;
- cell.style.bg = .{ .rgb = s.chrome.sel_bg };
- };
- s.cursor = null;
- var g = testGui(10, 20, 6, 12);
- defer g.decor.deinit(gpa);
- g.sel_glow = .{ .now_ns = std.time.ns_per_s };
- var strengths: [2]f32 = .{ 0, 0 };
- for ([_]u64{ 0, 150 * std.time.ns_per_ms }, 0..) |later, i| {
- g.decor.clearRetainingCapacity();
- g.sel_glow.now_ns = std.time.ns_per_s + later;
- var groups = makeGroups(&.{}, false);
- try buildDecor(&g, gpa, s, &groups, fixedCellLayout(&g), 800, 480, true);
- for (g.decor.items) |item| {
- if (item.effect & soft_shadow_bit == 0) continue;
- const rgb: [3]u8 = .{ @intFromFloat(@round(item.br * 255)), @intFromFloat(@round(item.bg * 255)), @intFromFloat(@round(item.bb * 255)) };
- if (!std.mem.eql(u8, &rgb, &s.chrome.sel_bg)) continue;
- strengths[i] = @max(strengths[i], item.fr);
- // On the body alone.
- const r = bodyPixels(body, fixedCellLayout(&g));
- try std.testing.expect(item.clip_x0 >= r[0] - 0.01 and item.clip_x1 <= r[2] + 0.01 and item.clip_y0 >= r[1] - 0.01 and item.clip_y1 <= r[3] + 0.01);
- }
- try std.testing.expectEqual(@as(usize, 1), g.sel_glow.len);
- }
- // Just appeared: nothing yet, and still fading; later, up to its cap.
- try std.testing.expectEqual(@as(f32, 0), strengths[0]);
- try std.testing.expect(strengths[1] > 0.05 and strengths[1] <= 0.22 + 1e-4);
- try std.testing.expect(!g.sel_glow.fading);
-}
-
-test "a hovered word glows along its foot, never over the cursor, fading in over 80 ms" {
- const gpa = std.testing.allocator;
- const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 });
- defer core.deinit();
- _ = try core.setTestFile(std.mem.asBytes(&@as([30][20]u8, @splat("some text on a line\n".*))));
- core.settings.hover_glow = true;
- core.sync();
- const s = try core.render(core.scratch.allocator());
- try std.testing.expectEqual(@as(u8, 2), s.chrome.fx);
- const body = for (s.regionList()) |region| {
- if (region.kind == .body) break region;
- } else return error.NoBody;
- const page = s.chrome.page orelse bg_default;
- const tint = mixRgb(page, mixRgb(page, s.chrome.sel_bg));
- const row = body.rect.y + 4;
- for (5..12) |x| {
- const cell = &s.cells[@as(usize, row) * s.cols + body.rect.x + x];
- cell.default = false;
- cell.style.bg = .{ .rgb = tint };
- }
- s.cursor = .{ .x = body.rect.x + 8, .y = row };
- var g = testGui(10, 20, 6, 12);
- defer g.decor.deinit(gpa);
- g.hover_glow = .{ .now_ns = std.time.ns_per_s };
- var strongest: f32 = 0;
- for ([_]u64{ 0, 90 * std.time.ns_per_ms }) |later| {
- g.decor.clearRetainingCapacity();
- g.hover_glow.now_ns = std.time.ns_per_s + later;
- var groups = makeGroups(&.{}, false);
- try buildDecor(&g, gpa, s, &groups, fixedCellLayout(&g), 800, 480, true);
- for (g.decor.items) |item| {
- if (item.effect & soft_shadow_bit == 0) continue;
- if (later == 0) try std.testing.expect(false);
- strongest = @max(strongest, item.fr);
- // Never over the cursor's cell.
- const cx0: f32 = @floatFromInt(@as(u32, s.cursor.?.x) * 10);
- const cy0: f32 = @floatFromInt(@as(u32, s.cursor.?.y) * 20);
- try std.testing.expect(item.clip_x1 <= cx0 + 0.01 or item.clip_x0 >= cx0 + 10 - 0.01 or item.clip_y1 <= cy0 + 0.01 or item.clip_y0 >= cy0 + 20 - 0.01);
- }
- }
- try std.testing.expect(strongest > 0.05);
- try std.testing.expect(!g.hover_glow.fading);
-}
-
-test "occlusion shades each body's edges, inside it, never a tag, a grip or the cursor" {
- const gpa = std.testing.allocator;
- const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 });
- defer core.deinit();
- _ = try core.setTestFile(std.mem.asBytes(&@as([30][20]u8, @splat("some text on a line\n".*))));
- core.settings.occlusion = true;
- core.sync();
- const s = try core.render(core.scratch.allocator());
- try std.testing.expectEqual(@as(u8, 4), s.chrome.fx);
- const body = for (s.regionList()) |region| {
- if (region.kind == .body) break region;
- } else return error.NoBody;
- // The cursor on the body's top-left cell, where the shade is.
- s.cursor = .{ .x = body.rect.x, .y = body.rect.y };
- var g = testGui(10, 20, 6, 12);
- defer g.decor.deinit(gpa);
- var groups = makeGroups(&.{}, false);
- try buildDecor(&g, gpa, s, &groups, fixedCellLayout(&g), 800, 480, true);
- const r = bodyPixels(body, fixedCellLayout(&g));
- var shades: usize = 0;
- for (g.decor.items) |item| {
- if (item.effect & soft_shadow_bit == 0) continue;
- shades += 1;
- try std.testing.expect(item.fr <= 0.02 + 1e-6);
- try std.testing.expect(item.clip_x0 >= r[0] - 0.01 and item.clip_x1 <= r[2] + 0.01 and item.clip_y0 >= r[1] - 0.01 and item.clip_y1 <= r[3] + 0.01);
- const cx: f32 = @floatFromInt(@as(u32, s.cursor.?.x) * 10);
- const cy: f32 = @floatFromInt(@as(u32, s.cursor.?.y) * 20);
- try std.testing.expect(item.clip_x1 <= cx + 0.01 or item.clip_x0 >= cx + 10 - 0.01 or item.clip_y1 <= cy + 0.01 or item.clip_y0 >= cy + 20 - 0.01);
- }
- try std.testing.expect(shades >= 4);
-}
-
test "a body tells its first line, and lapis's dots under it move a quarter as far" {
const gpa = std.testing.allocator;
const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 });