diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 11:50:43 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 15:17:05 -0300 |
| commit | ecdb0996147f319a4427273bf276e1fc5bf89156 (patch) | |
| tree | 0b1be457ce4b8ce99db4acd713ff2620cde2d015 /src/draw.zig | |
| parent | 2bd4066a932ec8fc401e4b85e9f8441b17df3cfb (diff) | |
| download | pardes-ecdb0996147f319a4427273bf276e1fc5bf89156.tar.gz pardes-ecdb0996147f319a4427273bf276e1fc5bf89156.zip | |
effects out, the panel transitions: the eleven Panel words in both tracks go, with the core's Presentation (tracks, the frozen previous grid, cell diffs, the acknowledged-geometry pending guard, and the pointer's mapping through a moving pane, so a pointer's cell is the cell it is over), draw.zig's core-composed character effects, animation.zig's transition half, the Surface's tracks and previous grid, the tty's compositor (src/tui/panel_compositor.zig: the glide's rows move into tui.zig) and the window's track groups, frozen old layers, last-frame image snapshot, transition instance fields and shader paths (ui.vert, ui.frag's crossfade, image.vert and image.frag, the transition-<n>.ppm capture); acknowledgePanelPresentation becomes `presented`, which a frontend calls after drawing a frame (a drag's moving end and a look-hover follow what is under the pointer now), and its tape site with it; the pointer tape site goes; GUI golden 18-mid-transition goes, ttyhelp's golden loses the `SPC a` rows (its wait is on `SPC Y` now), the window monkey loses PanelSlide, and the settings behaviour test's floor of on/off words is ten
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/draw.zig')
| -rw-r--r-- | src/draw.zig | 195 |
1 files changed, 10 insertions, 185 deletions
diff --git a/src/draw.zig b/src/draw.zig index 2ddb8faf..015d2def 100644 --- a/src/draw.zig +++ b/src/draw.zig @@ -2,7 +2,7 @@ //! `render` is the whole order, top to bottom: the page, each pane (its //! grip, tag and body, and the body layer of its compact rows), the notice //! chips, the workspace and column tags, the tag layers, drag overlays, the -//! debug box, then the presentation's tracks and the character effects. +//! debug box, then the cursor. const std = @import("std"); const vaxis = @import("vaxis"); const pardes = @import("pardes.zig"); @@ -314,11 +314,9 @@ const PaneFrame = struct { }; fn paneFrame(s: *const Surface, serial: u32, rect: Rect) PaneFrame { + _ = s; + _ = serial; const still = layout.panelBox(rect); - for (s.panelTracks()) |track| { - if (track.serial != serial or track.phase == .closing or !track.active()) continue; - return .{ .to = track.to, .at = track.visualBox() }; - } return .{ .to = still, .at = still }; } @@ -356,12 +354,6 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { for (&s.body_layers) |*layer| layer.rows = 0; for (&s.tag_layers) |*layer| layer.rows = 0; s.images.clearRetainingCapacity(); - s.npanel_tracks = 0; - s.previous_cells = &.{}; - s.previous_body_layers = &.{}; - s.previous_tag_layers = &.{}; - s.previous_regions = &.{}; - s.cell_diffs = &.{}; const chrome = p.chromeTheme(); s.chrome = .{ .page = p.theme().bg, @@ -552,122 +544,8 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { } } }; - // After the tracks are submitted: the cursor is drawn through its - // pane's. - try p.presentation.submit(p, s); glideCursor(p, s); - return composeAsciiTransitions(p, arena, s); -} - -pub fn composeAsciiTransitions(p: *Pardes, arena: std.mem.Allocator, canonical: *Surface) !*Surface { - _ = p; - if (!canonical.hasPanelDiff()) return canonical; - var presented: ?*Surface = null; - for (canonical.panelTracks()) |track| { - if (!track.effect.composedByCore() or track.phase == .closing) continue; - const area = animation.CellArea.of(track.to); - const col_end = @min(canonical.cols, area.x0 +| area.cols); - const row_end = @min(canonical.rows, area.y0 +| area.rows); - var row: u16 = area.y0; - while (row < row_end) : (row += 1) { - var col: u16 = area.x0; - while (col < col_end) : (col += 1) { - const index = @as(usize, row) * canonical.cols + col; - const composed = composedCell(canonical, track, area, col, row, index) orelse - continue; - if (composed.visuallyEqual(&canonical.cells[index])) continue; - if (presented == null) { - const next = try arena.create(Surface); - next.* = canonical.*; - next.cells = try arena.dupe(Cell, canonical.cells); - presented = next; - } - presented.?.cells[index] = composed; - } - } - } - return presented orelse canonical; -} - -fn composedCell( - canonical: *const Surface, - track: animation.Track, - area: animation.CellArea, - col: u16, - row: u16, - index: usize, -) ?Cell { - if (track.effect == .ascii) { - const diff = switch (canonical.cell_diffs[index]) { - .ascii => |diff| diff, - .unchanged, .visual => return null, - }; - const byte = diff.byteAt(track.frame); - if (byte == diff.to) return null; - if (track.frame == 0) return canonical.previous_cells[index]; - return withByte(canonical.cells[index], byte); - } - return switch (animation.charSource(track, col - area.x0, row - area.y0, area)) { - .old => canonical.previous_cells[index], - .byte => |byte| withByte(canonical.cells[index], byte), - .edge => |weight| towardGround(canonical.cells[index], canonical.previous_cells[index].style.bg, weight), - // Churn belongs on the glyph, not on the pane's empty space, and it - // borrows whichever side of the diff actually has one. - .churn => |byte| blk: { - const new_cell = &canonical.cells[index]; - if (hasGlyph(new_cell)) break :blk withByte(new_cell.*, byte); - const old_cell = &canonical.previous_cells[index]; - if (hasGlyph(old_cell)) break :blk withByte(old_cell.*, byte); - break :blk old_cell.*; - }, - .at => |offset| blk: { - const source_col = @as(i32, col) + offset.cols; - const source_row = @as(i32, row) + offset.rows; - // A glyph whose source lies outside the pane has not arrived - // yet: the frozen old cell is the only truthful thing under it. - if (source_col < area.x0 or source_row < area.y0 or - source_col >= @as(i32, area.x0) + area.cols or - source_row >= @as(i32, area.y0) + area.rows or - source_col >= canonical.cols or source_row >= canonical.rows) - break :blk canonical.previous_cells[index]; - const source = @as(usize, @intCast(source_row)) * canonical.cols + - @as(usize, @intCast(source_col)); - break :blk canonical.cells[source]; - }, - }; -} - -/// A cell with its ink and ground drawn `weight` of the way toward another -/// ground, in OKLab. A palette or default colour cannot be mixed, so the -/// ground steps over at the halfway point instead. -fn towardGround(cell: Cell, ground: Color, weight: f32) Cell { - var out = cell; - const to = switch (ground) { - .rgb => |rgb| rgb, - .default, .index => return if (weight >= 0.5) blk: { - out.style.bg = ground; - break :blk out; - } else out, - }; - inline for (.{ &out.style.fg, &out.style.bg }) |color| switch (color.*) { - .rgb => |rgb| color.* = .{ .rgb = colors.mixOklab(rgb, to, weight) }, - .default, .index => {}, - }; - return out; -} - -fn withByte(cell: Cell, byte: u8) Cell { - var out = cell; - out.text[0] = byte; - out.len = 1; - out.default = false; - return out; -} - -/// Whether a cell shows a glyph a character effect can work on. An unpainted -/// cell and a space are both blank space, whatever style they carry. -fn hasGlyph(cell: *const Cell) bool { - return !cell.default and !(cell.len == 1 and cell.text[0] == ' '); + return s; } fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool) !void { @@ -1750,8 +1628,8 @@ test "a monkey over notices, prompts, tags and tiny panes at a gui's metrics nev } p.sync(); _ = arena.reset(.retain_capacity); - const s = try p.render(arena.allocator()); - p.acknowledgePanelPresentation(s.panelTracks()); + _ = try p.render(arena.allocator()); + p.presented(); } } @@ -1842,65 +1720,12 @@ fn twoColumns(p: *Pardes, arena: *std.heap.ArenaAllocator) !void { try std.testing.expect(layout.splitColumn(p, 0, 1, false)); p.sync(); p.advance(std.time.ns_per_s); - const boot = try p.render(arena.allocator()); - p.acknowledgePanelPresentation(boot.panelTracks()); + _ = try p.render(arena.allocator()); + p.presented(); p.advance(2 * std.time.ns_per_s); _ = arena.reset(.retain_capacity); - const settled = try p.render(arena.allocator()); - p.acknowledgePanelPresentation(settled.panelTracks()); - try std.testing.expect(!p.cursor_glide.moving()); -} - -test "while its pane slides the cursor rides with it, at the same cell of the pane every frame" { - if (!builtins.frontend.lift) return error.SkipZigTest; - const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20 }); - defer p.deinit(); - var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); - defer arena.deinit(); - p.settings.motion = .bouncy; - try twoColumns(p, &arena); - p.active = 1; - p.advance(3 * std.time.ns_per_s); - _ = arena.reset(.retain_capacity); - p.acknowledgePanelPresentation((try p.render(arena.allocator())).panelTracks()); - p.advance(4 * std.time.ns_per_s); - p.settings.panel_transition = .slide; - // The right column's pane moves right. - p.col_weight[0] = layout.column_weight_unit * 2; - p.col_weight[1] = layout.column_weight_unit; - p.sync(); - var now: u64 = 4 * std.time.ns_per_s; - var riding: usize = 0; - for (0..40) |_| { - now += 16 * std.time.ns_per_ms; - p.advance(now); - _ = arena.reset(.retain_capacity); - const s = try p.render(arena.allocator()); - p.acknowledgePanelPresentation(s.panelTracks()); - const frame = paneFrame(s, p.panes[1].?.serial, p.rects[1]); - const box = focusedCursorBox(p, s).?; - const want = frame.place(.{ box.x, box.y }); - try std.testing.expectApproxEqAbs(want[0], s.chrome.cursor_quad[0], 0.01); - try std.testing.expectApproxEqAbs(want[1], s.chrome.cursor_quad[1], 0.01); - if (frame.moving()) { - riding += 1; - // Drawn as the quad while the pane moves. - try std.testing.expect(s.chrome.cursor_glide & 1 != 0); - } - } - try std.testing.expect(riding >= 3); - - // With no transition, the cursor lands with the text at once. - p.settings.panel_transition = .off; - p.col_weight[0] = layout.column_weight_unit; - p.col_weight[1] = layout.column_weight_unit * 2; - p.sync(); - now += 16 * std.time.ns_per_ms; - p.advance(now); - _ = arena.reset(.retain_capacity); - const landed = try p.render(arena.allocator()); - const box = focusedCursorBox(p, landed).?; - try std.testing.expectApproxEqAbs(box.x, landed.chrome.cursor_quad[0], 0.01); + _ = try p.render(arena.allocator()); + p.presented(); try std.testing.expect(!p.cursor_glide.moving()); } |
