diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/draw.zig | 444 | ||||
| -rw-r--r-- | src/gui/gui.zig | 335 | ||||
| -rw-r--r-- | src/pardes.zig | 16 | ||||
| -rw-r--r-- | src/surface.zig | 10 | ||||
| -rw-r--r-- | src/views.zig | 7 |
5 files changed, 310 insertions, 502 deletions
diff --git a/src/draw.zig b/src/draw.zig index 9db5d0ff..fe4921ff 100644 --- a/src/draw.zig +++ b/src/draw.zig @@ -160,166 +160,6 @@ fn inkOn(bg: [3]u8) [3]u8 { return if (lum > 140) .{ 0x00, 0x00, 0x00 } else .{ 0xff, 0xff, 0xff }; } -/// The focused cursor's box in grid cells, at the pitch it is drawn at: a -/// tag's at the tagline's (Layer.Metrics), else a grid cell. -fn focusedCursorBox(p: *const Pardes, s: *const Surface) ?animation.Box { - const cursor = s.cursor orelse return null; - const m = p.row_metrics; - const bw: f32 = @floatFromInt(@max(1, m.body_w)); - const bh: f32 = @floatFromInt(@max(1, m.body_h)); - const tw: f32 = @floatFromInt(@max(1, m.tagline_w)); - const th: f32 = @floatFromInt(@max(1, @min(m.tagline_h, m.body_h))); - for (s.tagLayers()) |*layer| { - const caret = layer.cursor orelse continue; - if (layer.rows == 0 or layer.viewport.y + caret.y != cursor.y) continue; - if (cursor.x < layer.viewport.x or cursor.x >= layer.viewport.x + layer.viewport.w) continue; - const w = if (caret.bar) tw / bw / 8 else tw / bw; - const x = layer.caretSpan(caret.x, 1, tw / bw, w)[0]; - return .{ .x = x, .y = @as(f32, @floatFromInt(cursor.y)) + (bh - th) / 2 / bh, .w = w, .h = th / bh }; - } - return .{ .x = @floatFromInt(cursor.x), .y = @floatFromInt(cursor.y), .w = if (cursor.bar) 1.0 / 8.0 else 1, .h = 1 }; -} - -/// G3 (docs/render-pipeline.md §5.4): the focused cursor on its springs, -/// at the Motion flavour's pace, a jump gliding and a step easing over a -/// few frames (CursorGlide.aim), the thin insert-mode caret as the block; -/// blinking unless typing. A pixel shell's: a grid's cursor is the -/// terminal's own. -/// -/// The springs hold the cursor where the pane's final layout puts it, and -/// the quad is drawn through the pane's frame (paneFrame): while the pane -/// slides, zooms or is dragged, the cursor rides with its text. A pane that -/// moved in the layout carries the springs with it (they keep their place -/// in the pane), so with no transition the cursor lands with the text. A -/// focus change glides from where the cursor is drawn to the new pane's -/// cursor, wherever that pane is drawn now. -fn glideCursor(p: *Pardes, s: *Surface) void { - s.chrome.cursor_glide = 0; - s.chrome.cursor_alpha = 1; - s.chrome.cursor_idle_ms = std.math.maxInt(u32); - if (!builtins.frontend.lift) return; - const box = focusedCursorBox(p, s) orelse { - // No cursor drawn (a PDF or picture took focus, a program hid its - // own): a glide under way has nowhere to land, and its springs, - // never stepped again, held continuous() and the frames on for - // ever. It stops; the next cursor lands where it is. - p.cursor_glide = .{}; - p.cursor_crossing = false; - return; - }; - const motion = animation.Motion.of(p.settings.motion); - // The thin insert-mode caret glides as the block does (a jump smears - // and bows, a step eases); a scroll lands it, below. - var how: animation.CursorGlide.How = .ease; - var frame: PaneFrame = .{}; - // In a column's or the workspace's tag the cursor is not the pane's, - // and does not move with it. - var inside = false; - if (p.panes[p.active]) |pane| { - const rect = p.rects[p.active]; - const cx = box.x + box.w / 2; - const cy = box.y + box.h / 2; - inside = cx >= @as(f32, @floatFromInt(rect.x)) and cx <= @as(f32, @floatFromInt(rect.x + rect.w)) and - cy >= @as(f32, @floatFromInt(rect.y)) and cy <= @as(f32, @floatFromInt(rect.y + rect.h)); - if (inside) frame = paneFrame(s, pane.serial, rect); - const origin: [2]f32 = .{ @floatFromInt(rect.x), @floatFromInt(rect.y) }; - const view = p.cursor_view; - const line: i64 = if (pane.file) |f| @intCast(f.scroll) else if (pane.isTerminal()) panes.terminal.gridOffset(pane) else 0; - if (view.serial == pane.serial and view.inside == inside) { - // The pane moved in the layout: the springs move with it (its - // own cursor's; one in a column's tag stays). - if (inside) p.cursor_glide.shift(origin[0] - view.origin[0], origin[1] - view.origin[1]); - // Scrolled (a file's view, a terminal's output): the caret did not - // move, the text did. Its springs land on its cell (the core's - // view is the settled one), so a page that keeps its row leaves - // it still, and a scroll that carries its line has the shell draw - // it with the text's own glide (Glide.caret_rides), one picture, - // never a second spring chasing the first. - if (inside and line != view.line) how = .land; - } else if (view.serial != 0 and p.cursor_glide.placed) { - // Focus moved (to another pane, or between a pane and a - // column's or the workspace's tag): the glide starts where the - // cursor is drawn, in the old place's frame, and heads for the - // new cursor through the new one's. - const old: PaneFrame = if (!view.inside) .{} else for (p.panes, 0..) |slot, id| { - const other = slot orelse continue; - if (other.serial != view.serial) continue; - const r = p.rects[id]; - p.cursor_glide.shift(@as(f32, @floatFromInt(r.x)) - view.origin[0], @as(f32, @floatFromInt(r.y)) - view.origin[1]); - break paneFrame(s, view.serial, r); - } else .{}; - const at = p.cursor_glide.centreAt(p.now_ns); - const seen = frame.unplace(old.place(at)); - p.cursor_glide.shift(seen[0] - at[0], seen[1] - at[1]); - p.cursor_crossing = true; - p.cursor_held = p.drag == .select; - } - p.cursor_view = .{ .serial = pane.serial, .line = line, .origin = origin, .inside = inside }; - } - // A click that took focus places the cursor on its release; aimed at - // the pane's old cursor meanwhile, it would glide there first. - if (p.drag != .select) p.cursor_held = false; - if (!p.cursor_held) p.cursor_glide.aim(box, p.now_ns, motion, how); - _ = p.cursor_glide.step(p.now_ns); - const moving = p.cursor_glide.moving(); - if (!moving and !p.cursor_held) p.cursor_crossing = false; - // Drawn as the quad while it glides, while its pane moves and while it - // waits for a click's release. - s.chrome.cursor_glide = 2 | @as(u8, @intFromBool(moving or frame.moving() or p.cursor_held)); - // The shell blinks it, from how long ago the last key or click was. - if (p.settings.cursor_blink) - s.chrome.cursor_idle_ms = @intCast(@min(std.math.maxInt(u32) - 1, (p.now_ns -| p.input_ns) / std.time.ns_per_ms)); - // A little less than solid while it glides, so the glyphs it passes - // stay legible (less on the long flavours), solid again as it lands. - const remaining = p.cursor_glide.remaining(p.now_ns); - const see_through: f32 = if (motion.zeta < 1) 0.7 else 0.85; - s.chrome.cursor_alpha = if (moving) see_through + (1 - see_through) * std.math.clamp(1 - remaining / 0.5, 0, 1) else 1; - const quad = p.cursor_glide.sample(p.now_ns, motion); - // Never outside the focused pane as drawn, however far a flavour - // overshoots or a scroll carried it: it squashes against the pane's - // edges. Crossing to another pane, it may pass over any of the grid. - const bounds: animation.Box = if (p.cursor_crossing or !inside) - .{ .w = @floatFromInt(s.cols), .h = @floatFromInt(s.rows) } - else - frame.at; - for (quad, 0..) |corner, i| { - const point = frame.place(corner); - s.chrome.cursor_quad[i * 2] = std.math.clamp(point[0], bounds.x, bounds.x + bounds.w); - s.chrome.cursor_quad[i * 2 + 1] = std.math.clamp(point[1], bounds.y, bounds.y + bounds.h); - } -} - -/// Where a pane is drawn against where the layout puts it: its transition -/// track's presented box against the track's target, or the layout's box -/// both ways when it is still. Maps grid points between the two. -const PaneFrame = struct { - to: animation.Box = .{ .w = 1, .h = 1 }, - at: animation.Box = .{ .w = 1, .h = 1 }, - - fn moving(f: PaneFrame) bool { - return !std.meta.eql(f.to, f.at); - } - - fn place(f: PaneFrame, point: [2]f32) [2]f32 { - return .{ f.at.x + (point[0] - f.to.x) * scale(f.at.w, f.to.w), f.at.y + (point[1] - f.to.y) * scale(f.at.h, f.to.h) }; - } - - fn unplace(f: PaneFrame, point: [2]f32) [2]f32 { - return .{ f.to.x + (point[0] - f.at.x) * scale(f.to.w, f.at.w), f.to.y + (point[1] - f.at.y) * scale(f.to.h, f.at.h) }; - } - - fn scale(num: f32, den: f32) f32 { - return if (den > 0.001) num / den else 1; - } -}; - -fn paneFrame(s: *const Surface, serial: u32, rect: Rect) PaneFrame { - _ = s; - _ = serial; - const still = layout.panelBox(rect); - return .{ .to = still, .at = still }; -} - pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { const taped = pardes.tape.enter(p, .render); defer pardes.tape.leave(p, taped); @@ -526,7 +366,6 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { } } }; - glideCursor(p, s); return s; } @@ -1357,174 +1196,6 @@ test "a notice wider than its band, as a shader's compile error is, draws its en } } -test "with no motion a focus switch asks for no frames" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 }); - defer p.deinit(); - _ = try p.setTestFile("text\n"); - p.newScratchBelow(0); - // With motion the cursor glides to the other pane (glideCursor). - p.settings.motion = .off; - var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); - defer arena.deinit(); - p.advance(std.time.ns_per_s); - _ = try p.render(arena.allocator()); - p.active = 0; - _ = arena.reset(.retain_capacity); - _ = try p.render(arena.allocator()); - try std.testing.expect(!p.continuous()); -} - -test "the caret is its own body: a page leaves it still under the moving text, a wheel scroll lands its springs on its line's new row" { - if (!builtins.frontend.lift) return error.SkipZigTest; - const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 30 }); - defer p.deinit(); - var text: std.ArrayList(u8) = .empty; - defer text.deinit(std.testing.allocator); - for (0..400) |i| try text.print(std.testing.allocator, "line {d}\n", .{i}); - const pane = try p.setTestFile(text.items); - p.settings.cursor_blink = false; - var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); - defer arena.deinit(); - var now: u64 = std.time.ns_per_s; - p.advance(now); - // Mid-file, where a half page keeps the caret's row. - for ("200G") |ch| p.update(.{ .key = .{ .cp = ch, .text = &.{ch} } }); - _ = try p.render(arena.allocator()); - now += std.time.ns_per_s; - p.advance(now); - _ = arena.reset(.retain_capacity); - _ = try p.render(arena.allocator()); - // Ctrl-d: the caret moves with the view and keeps its screen row: it - // does not ride the glide, and it does not move. - const row_before = (try p.render(arena.allocator())).cursor.?.y; - p.update(.{ .key = .{ .cp = 'd', .ctrl = true } }); - now += 16 * std.time.ns_per_ms; - p.advance(now); - _ = arena.reset(.retain_capacity); - var s = try p.render(arena.allocator()); - try std.testing.expect(pane.file.?.scroll > 0); - try std.testing.expectEqual(row_before, s.cursor.?.y); - try std.testing.expectEqual(@as(u8, 0), s.chrome.cursor_glide & 1); - try std.testing.expectEqual(@as(f32, @floatFromInt(row_before)), s.chrome.cursor_quad[1]); - // The view scrolled with the caret on its line: its springs land on - // the line's new row at once, no second glide; the shell carries it - // there with the text's own (Glide.caret_rides). - pane.scrollBy(-3); - now += 16 * std.time.ns_per_ms; - p.advance(now); - _ = arena.reset(.retain_capacity); - s = try p.render(arena.allocator()); - try std.testing.expectEqual(@as(u8, 0), s.chrome.cursor_glide & 1); - try std.testing.expectEqual(@as(f32, @floatFromInt(s.cursor.?.y)), s.chrome.cursor_quad[1]); -} - -test "the focused cursor glides a jump, eases a step, the thin caret too, and is exact at rest" { - if (!builtins.frontend.lift) return error.SkipZigTest; - const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 30 }); - defer p.deinit(); - _ = try p.setTestFile(std.mem.asBytes(&@as([20][20]u8, @splat("some text on a line\n".*)))); - p.settings.cursor_blink = false; - var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); - defer arena.deinit(); - const ms = std.time.ns_per_ms; - var now: u64 = std.time.ns_per_s; - p.advance(now); - _ = try p.render(arena.allocator()); - // A step down: eases there in a few frames. - p.update(.{ .key = .{ .cp = 'j' } }); - now += 16 * ms; - p.advance(now); - _ = arena.reset(.retain_capacity); - var s = try p.render(arena.allocator()); - try std.testing.expectEqual(@as(u8, 3), s.chrome.cursor_glide); - now += 100 * ms; - p.advance(now); - _ = arena.reset(.retain_capacity); - s = try p.render(arena.allocator()); - try std.testing.expectEqual(@as(u8, 2), s.chrome.cursor_glide); - const before = s.cursor.?; - // To the last line: it glides, a quad partway, and asks for frames. - p.update(.{ .key = .{ .cp = 'g' } }); - p.update(.{ .key = .{ .cp = 'e' } }); - now += 16 * ms; - p.advance(now); - _ = arena.reset(.retain_capacity); - s = try p.render(arena.allocator()); - const target = s.cursor.?; - try std.testing.expect(target.y > before.y + 5); - try std.testing.expectEqual(@as(u8, 3), s.chrome.cursor_glide); - try std.testing.expect(s.chrome.cursor_quad[1] < @as(f32, @floatFromInt(target.y)) - 1); - try std.testing.expect(p.continuous()); - // Frame by frame to rest: gliding exactly while it moves (the shell then - // draws the quad, never the cells' cursor too), at under full alpha - // until it lands, solid as it does. - var frames: usize = 0; - while (p.continuous()) : (frames += 1) { - now += 7 * ms; - p.advance(now); - _ = arena.reset(.retain_capacity); - s = try p.render(arena.allocator()); - try std.testing.expect(s.chrome.cursor_glide & 2 != 0); - try std.testing.expectEqual(p.cursor_glide.moving(), s.chrome.cursor_glide & 1 != 0); - if (s.chrome.cursor_glide & 1 != 0) try std.testing.expect(s.chrome.cursor_alpha <= 1 and s.chrome.cursor_alpha >= 0.7); - for (s.chrome.cursor_quad) |value| try std.testing.expect(std.math.isFinite(value)); - } - try std.testing.expect(frames > 3); - try std.testing.expectEqual(@as(u8, 2), s.chrome.cursor_glide); - try std.testing.expectEqual(@as(f32, 1), s.chrome.cursor_alpha); - // At rest the quad is the cursor's own cell. - try std.testing.expectEqual(@as(f32, @floatFromInt(target.x)), s.chrome.cursor_quad[0]); - try std.testing.expectEqual(@as(f32, @floatFromInt(target.y)), s.chrome.cursor_quad[1]); - // A mode change mid-glide: the thin caret glides on to the mark. - p.update(.{ .key = .{ .cp = 'g' } }); - p.update(.{ .key = .{ .cp = 'g' } }); - now += 7 * ms; - p.advance(now); - _ = arena.reset(.retain_capacity); - s = try p.render(arena.allocator()); - try std.testing.expectEqual(@as(u8, 3), s.chrome.cursor_glide); - p.update(.{ .key = .{ .cp = 'i' } }); - now += 7 * ms; - p.advance(now); - _ = arena.reset(.retain_capacity); - s = try p.render(arena.allocator()); - try std.testing.expectEqual(@as(u8, 3), s.chrome.cursor_glide); - try std.testing.expect(s.cursor.?.bar); - while (p.continuous()) { - now += 7 * ms; - p.advance(now); - _ = arena.reset(.retain_capacity); - s = try p.render(arena.allocator()); - } - // At rest, a bar's width at the caret's cell. - try std.testing.expectEqual(@as(f32, @floatFromInt(s.cursor.?.x)), s.chrome.cursor_quad[0]); - try std.testing.expectApproxEqAbs(@as(f32, 1.0 / 8.0), s.chrome.cursor_quad[2] - s.chrome.cursor_quad[0], 1e-4); -} - -test "a terminal's cursor lands with scrolling output, never gliding against it" { - if (!builtins.frontend.lift) return error.SkipZigTest; - const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 12 }); - defer p.deinit(); - while (p.nextEffect()) |_| {} - const term = p.active; - try std.testing.expect(p.panes[term].?.isTerminal()); - p.settings.cursor_blink = false; - var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); - defer arena.deinit(); - const ms = std.time.ns_per_ms; - var now: u64 = std.time.ns_per_s; - p.update(.{ .output = .{ .pane = @intCast(term), .bytes = std.mem.asBytes(&@as([20][6]u8, @splat("line\r\n".*))) ++ "$ some command typed" } }); - p.advance(now); - _ = try p.render(arena.allocator()); - // Enter: three lines of output scroll up, the cursor to a new prompt. - p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\r\nout\r\nout\r\nout\r\n$ " } }); - now += 16 * ms; - p.advance(now); - _ = arena.reset(.retain_capacity); - const s = try p.render(arena.allocator()); - try std.testing.expectEqual(@as(u8, 2), s.chrome.cursor_glide); -} - test "a monkey over notices, prompts, tags and tiny panes at a gui's metrics never panics" { // The snapshot harness runs the tty, whose tagline pitch is the body's, // so it never reaches what a narrower tagline does to a notice's band: @@ -1679,118 +1350,3 @@ test "a body with context rows is painted once, and the grid's rows are what a p } } -/// Two columns, the file in the left one and a shell in the right, the -/// right one focused with its cursor settled. -fn twoColumns(p: *Pardes, arena: *std.heap.ArenaAllocator) !void { - _ = try p.setTestFile(std.mem.asBytes(&@as([6][20]u8, @splat("some text on a line\n".*)))); - _ = try p.newShell(1, ""); - try std.testing.expect(layout.splitColumn(p, 0, 1, false)); - p.sync(); - p.advance(std.time.ns_per_s); - _ = try p.render(arena.allocator()); - p.presented(); - p.advance(2 * std.time.ns_per_s); - _ = arena.reset(.retain_capacity); - _ = try p.render(arena.allocator()); - p.presented(); - try std.testing.expect(!p.cursor_glide.moving()); -} - -test "focus moved to another column glides from where the cursor was drawn" { - 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 = .smooth; - try twoColumns(p, &arena); - p.active = 0; - p.advance(3 * std.time.ns_per_s); - _ = arena.reset(.retain_capacity); - const before = try p.render(arena.allocator()); - try std.testing.expect(!p.cursor_glide.moving()); - const was: [2]f32 = .{ before.chrome.cursor_quad[0], before.chrome.cursor_quad[1] }; - - p.active = 1; - _ = arena.reset(.retain_capacity); - const start = try p.render(arena.allocator()); - // It sets off from where it was drawn, in the left column... - try std.testing.expectApproxEqAbs(was[0], start.chrome.cursor_quad[0], 0.01); - try std.testing.expectApproxEqAbs(was[1], start.chrome.cursor_quad[1], 0.01); - try std.testing.expect(p.cursor_glide.moving() and start.chrome.cursor_glide & 1 != 0); - // ...crosses the grid, not squashed against the right one's edge... - p.advance(3 * std.time.ns_per_s + 40 * std.time.ns_per_ms); - _ = arena.reset(.retain_capacity); - const mid = try p.render(arena.allocator()); - try std.testing.expect(mid.chrome.cursor_quad[0] > was[0] and mid.chrome.cursor_quad[0] < @as(f32, @floatFromInt(p.rects[1].x)) + 1); - // ...and lands on the right one's cursor. - p.advance(5 * std.time.ns_per_s); - _ = 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 std.testing.expect(!p.cursor_glide.moving() and !p.cursor_crossing); -} - -test "a click that takes focus glides the cursor once, to where it lands on release" { - 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 = .smooth; - try twoColumns(p, &arena); - p.active = 0; - p.advance(3 * std.time.ns_per_s); - _ = arena.reset(.retain_capacity); - const before = try p.render(arena.allocator()); - const was: [2]f32 = .{ before.chrome.cursor_quad[0], before.chrome.cursor_quad[1] }; - // Pressed in the other column: focus moves, the cursor waits. - p.active = 1; - p.drag = .{ .select = .{ .id = 1, .button = config.select_button } }; - for (0..3) |_| { - p.advance(p.now_ns + 100 * std.time.ns_per_ms); - _ = arena.reset(.retain_capacity); - const held = try p.render(arena.allocator()); - try std.testing.expectApproxEqAbs(was[0], held.chrome.cursor_quad[0], 0.01); - try std.testing.expectApproxEqAbs(was[1], held.chrome.cursor_quad[1], 0.01); - } - // Released: one glide, from there to the placed cursor. - p.drag = .none; - _ = arena.reset(.retain_capacity); - _ = try p.render(arena.allocator()); - try std.testing.expect(p.cursor_glide.moving()); - p.advance(p.now_ns + 5 * std.time.ns_per_s); - _ = arena.reset(.retain_capacity); - const landed = try p.render(arena.allocator()); - try std.testing.expectApproxEqAbs(focusedCursorBox(p, landed).?.x, landed.chrome.cursor_quad[0], 0.01); -} - -test "focus moving to a pane with no cursor while the cursor glides lets the session go idle" { - 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 = .smooth; - try twoColumns(p, &arena); - p.active = 0; - p.advance(3 * std.time.ns_per_s); - _ = arena.reset(.retain_capacity); - _ = try p.render(arena.allocator()); - p.active = 1; - _ = arena.reset(.retain_capacity); - _ = try p.render(arena.allocator()); - try std.testing.expect(p.cursor_glide.moving()); - // Mid-glide, the pane focused draws no cursor (as a PDF pane does). - p.panes[1].?.body.mode = .tty; - p.update(.{ .output = .{ .pane = 1, .bytes = "\x1b[?25l" } }); - p.advance(3 * std.time.ns_per_s + 20 * std.time.ns_per_ms); - _ = arena.reset(.retain_capacity); - const hidden = try p.render(arena.allocator()); - try std.testing.expect(hidden.cursor == null); - p.advance(5 * std.time.ns_per_s); - _ = arena.reset(.retain_capacity); - _ = try p.render(arena.allocator()); - try std.testing.expect(!p.cursor_glide.moving() and !p.continuous()); -} diff --git a/src/gui/gui.zig b/src/gui/gui.zig index f5b486c1..343ad991 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -997,6 +997,10 @@ const Gui = struct { pet_state: pet.State = .{}, /// The cursor's jump trail (JumpTrail), on the window's own clock. trail: JumpTrail = .{}, + /// The caret's ease, on the window's own clock (Caret). + caret: Caret = .{}, + /// The last key, click or wheel, which the blink holds for. + input_ns: u64 = 0, live_ctrl: bool = false, live_alt: bool = false, @@ -1093,7 +1097,7 @@ const window_fields = [_][:0]const u8{ "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", "frame_arrival_ns", - "blink_due", "cursor_quad_alpha", "pointer_present", "pointer_shape", + "blink_due", "cursor_quad_alpha", "caret", "input_ns", "pointer_present", "pointer_shape", "pointer_cell", "prepared_images", "touch", "live_ctrl", "live_alt", "applied_window_opacity", "capture_tex", "capture_tex_w", "capture_tex_h", "capture_xfer", "capture_xfer_size", "captured", "capture_dir", @@ -2577,6 +2581,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void { switch (sev.type) { c.SDL_EVENT_KEY_DOWN, c.SDL_EVENT_TEXT_INPUT, c.SDL_EVENT_MOUSE_BUTTON_DOWN, c.SDL_EVENT_MOUSE_WHEEL => { g.input_seen = true; + g.input_ns = monoNs(); if (frame_probe) |probe| probe.input(monoNs() -| (c.SDL_GetTicksNS() -| sev.common.timestamp)); }, else => {}, @@ -3647,11 +3652,11 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void { // waiting here too would make every tick cost two frames. const poll_ms: c_int = 16; const waited: c_int = if (latency_fd >= 0) 0 else if (minimized) -1 else if (timeout_ms != 0) @min(@as(c_int, @intCast(@min(timeout_ms, std.math.maxInt(c_int)))), if (polls) poll_ms else std.math.maxInt(c_int)) else if (polls) poll_ms else -1; - // The cursor's blink is the shell's to time (Chrome.cursor_idle_ms): + // The cursor's blink is the window's to time (Gui.input_ns): // a frame a loop through an edge, else a wake at the next one; none // while the window is minimized or unfocused. A virtual clock never // blinks, so goldens hold still. - const blink = if (s.test_clock != null or minimized) null else blinkNow(g, if (s.surface) |frame| &frame.chrome else null); + const blink = if (s.test_clock != null or minimized or s.surface == null) null else blinkNow(g, s.core.settings.cursor_blink); const blink_ms: ?c_int = if (blink) |b| (if (b.edge) 1 else if (b.next_ns) |next| @as(c_int, @intCast(@min(std.math.maxInt(c_int), next / std.time.ns_per_ms + 1))) else null) else null; const blinked: c_int = if (blink_ms) |b| (if (waited < 0) b else @min(waited, b)) else waited; // The timedemo's next step is a wake too. @@ -3970,11 +3975,10 @@ fn runDemo(g: *Gui, in: *Input, core: *pardes.Pardes) void { /// The blink now, from the frame's time since input and how long ago it /// arrived; null where nothing blinks (off, idle, an unfocused window). -fn blinkNow(g: *const Gui, chrome: ?*const pardes.Chrome) ?pardes.animation.Blink { - const frame = chrome orelse return null; - if (g.no_blink or frame.cursor_glide & 2 == 0 or frame.cursor_idle_ms == std.math.maxInt(u32)) return null; +fn blinkNow(g: *const Gui, on: bool) ?pardes.animation.Blink { + if (g.no_blink or !on or !g.caret.placed) return null; if (c.SDL_GetWindowFlags(g.window) & c.SDL_WINDOW_INPUT_FOCUS == 0) return null; - const since = @as(u64, frame.cursor_idle_ms) * std.time.ns_per_ms + (monoNs() -| g.frame_arrival_ns); + const since = monoNs() -| g.input_ns; // Relative to now: `next_ns` is how long until the next edge. const b = pardes.animation.Blink.at(since, 0); return .{ .alpha = b.alpha, .edge = b.edge, .next_ns = if (b.next_ns) |next| next -| since else null }; @@ -4561,7 +4565,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.trail.active; + defer core.shell_continuous = glide.moving() or g.trail.active or g.caret.moving(); const notch = g.scroll_notch; g.scroll_notch = 0; var wheeled: ?usize = null; @@ -4697,18 +4701,19 @@ test "a wheel's caret rides with its line, the text's own glide, never a spring _ = arena.reset(.retain_capacity); s = try core.render(arena.allocator()); if (g.glide.pending) g.glide.measure(gpa, s); + seeCaret(&g, s, fixedCellLayout(&g), 480, now); if (frames == 0) { try std.testing.expect(g.glide.caret_rides); // Where its line is drawn: on the row it was on, the cell a row up. - try std.testing.expectApproxEqAbs(before, caretRow(&g, s).?, 1e-3); + try std.testing.expectApproxEqAbs(before, caretRow(&g, s, now).?, 1e-3); } // Always exactly with its line, the cell less the text's offset. - try std.testing.expectApproxEqAbs(@as(f32, @floatFromInt(s.cursor.?.y)) - g.glide.follow.offset, caretRow(&g, s).?, 1e-3); + try std.testing.expectApproxEqAbs(@as(f32, @floatFromInt(s.cursor.?.y)) - g.glide.follow.offset, caretRow(&g, s, now).?, 1e-3); if (!g.glide.moving()) break; stepGlide(&g, core, gpa); if (frames > 200) return error.NeverSettled; } - try std.testing.expectEqual(@as(f32, @floatFromInt(s.cursor.?.y)), caretRow(&g, s).?); + try std.testing.expectEqual(@as(f32, @floatFromInt(s.cursor.?.y)), caretRow(&g, s, now).?); } /// The scripted scroll sequence of the glide tests: a frame a 60 Hz @@ -4735,9 +4740,10 @@ const GlideRun = struct { const s = try core.render(arena.allocator()); if (g.glide.pending) g.glide.measure(gpa, s); if (g.glide.moving()) g.glide.advance(g.glide.now_ns, g.glide.motion); + seeCaret(g, s, fixedCellLayout(g), @floatFromInt(@as(u32, s.rows) * g.cell_h), now); seq.offsets[frame] = g.glide.follow.offset; seq.lines[frame] = @intCast(core.panes[core.active].?.file.?.scroll); - seq.carets[frame] = caretRow(g, s) orelse -1; + seq.carets[frame] = caretRow(g, s, now) orelse -1; seq.cells[frame] = if (s.cursor) |cu| @floatFromInt(cu.y) else -1; } seq.frames = frames; @@ -5415,21 +5421,29 @@ fn renderFrame( if (g.glide.pending) g.glide.measure(gpa, surface); if (g.glide.moving()) g.glide.advance(g.glide.now_ns, g.glide.motion); var groups: Groups = .{}; + const now = monoNs(); + seeCaret(g, surface, layout, win_h, now); // While the cursor glides or blinks the cells' cursors are not drawn; // the focused one is the overlay's quad. One or the other every frame // (none only at a blink's off half). - const blink_alpha: f32 = if (blinkNow(g, chrome)) |b| b.alpha else 1; + const blink_alpha: f32 = if (blinkNow(g, core.settings.cursor_blink)) |b| b.alpha else 1; // While a glide moves the text, the caret is its quad, drawn from its // own springs, not a cell of the moving rows. - const quad_mode = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or blink_alpha < 1 or g.glide.follow.offset != 0); - g.cursor_quad_alpha = if (quad_mode) chrome.cursor_alpha * blink_alpha else 0; + const gliding = g.caret.moving(); + const quad_mode = g.caret.placed and (gliding or blink_alpha < 1 or g.glide.follow.offset != 0); + // A little less than solid while it glides, so the glyphs it passes + // stay legible; solid again as it lands. + const caret_alpha: f32 = if (gliding) 0.85 + 0.15 * std.math.clamp(1 - g.caret.remaining(now) / 0.5, 0, 1) else 1; + g.cursor_quad_alpha = if (quad_mode) caret_alpha * blink_alpha else 0; + // A gliding caret asks for the frames it glides through. + if (gliding) core.shell_continuous = true; // The probe's view of this frame's motion (FrameStats.Frame). // A focused PDF's strip is the core's (pdf_view.draw). const pdf_focus = if (core.panes[core.active]) |pane| pane.hasPdf() else false; if (!pdf_focus) core.frames.scroll = g.glide.follow.offset; - core.frames.caret = caretRow(g, surface) orelse 0; + core.frames.caret = caretRow(g, surface, now) orelse 0; const cursors_shown = !quad_mode; - var overlay_count = buildOverlay(g, core.settings.pet, core.settings.jump_trail and core.settings.motion != .off, surface, sw, sh); + var overlay_count = buildOverlay(g, core.settings.pet, core.settings.jump_trail and core.settings.motion != .off, surface, now, sw, sh); // A trail fading asks for the frames it fades through. if (g.trail.active) core.shell_continuous = true; if (overlay_count != 0 and !uploadOverlayGpu(g, cmd, overlay_count)) @@ -8098,16 +8112,273 @@ const max_cursors = 1 + pardes.MAX_PANES + pardes.MAX_TAG_LAYERS; /// own springs (the quad's, while it moves or while a glide moves the text) /// or its cell; carried by the text's glide when its line rode it. The probe /// records it and the glide tests hold its invariants. -fn caretRow(g: *const Gui, surface: *const pardes.Surface) ?f32 { - const chrome = &surface.chrome; +fn caretRow(g: *const Gui, surface: *const pardes.Surface, now_ns: u64) ?f32 { const cursor = surface.cursor orelse return null; - const quad = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or g.glide.follow.offset != 0); - return if (quad) chrome.cursor_quad[1] - caretRide(g, surface) else @floatFromInt(cursor.y); + const quad = g.caret.placed and (g.caret.moving() or g.glide.follow.offset != 0); + return if (quad) g.caret.sample(now_ns)[0][1] - caretRide(g, surface) else @floatFromInt(cursor.y); +} + +/// What the caret's ease sees in the frame about to be drawn (Caret.see): +/// the focused cursor's box in cells (its own cell's, or the layer's that +/// draws it), and the focused body's pane, first line and place. +fn seeCaret(g: *Gui, surface: *const pardes.Surface, layout: CellLayout, win_h: f32, now_ns: u64) void { + const box: ?Caret.Box = if (surface.cursor) |cursor| box: { + var boxes: [max_cursors]CursorBox = undefined; + const all = boxes[0..cursorBoxes(g, surface, layout, win_h, &boxes)]; + if (all.len == 0) break :box null; + const cx = (@as(f32, @floatFromInt(cursor.x)) + 0.5) * layout.w; + const cy = (@as(f32, @floatFromInt(cursor.y)) + 0.5) * layout.h; + var best = all[0]; + var nearest = std.math.inf(f32); + for (all) |b| { + const dx = (b.x0 + b.x1) / 2 - cx; + const dy = (b.y0 + b.y1) / 2 - cy; + if (dx * dx + dy * dy < nearest) { + nearest = dx * dx + dy * dy; + best = b; + } + } + break :box .{ .x = best.x0 / layout.w, .y = best.y0 / layout.h, .w = (best.x1 - best.x0) / layout.w, .h = (best.y1 - best.y0) / layout.h }; + } else null; + for (surface.regionList()) |region| if (region.kind == .body and region.active) + return g.caret.see(box, region.owner, region.line, region.rect.x, region.rect.y, now_ns); + g.caret.see(box, pardes.Region.none, 0, 0, 0, now_ns); } +/// The caret's ease (G3), the window's own: the focused cursor's quad on +/// critically damped springs at its box's corners, in grid cells, on the +/// window's clock, from the cursor the Surface shows. A jump glides, its +/// leading corners first, bowing a little on a long one; a step eases, and +/// a stream of them (typing, a held key) keeps up; a scroll or a pane's move +/// carries it with its text; a focus change glides from where it was drawn. +/// The quad is drawn only while it moves: at rest the cells draw the cursor. +const Caret = struct { + /// Top left, top right, bottom right, bottom left; x then y. + corners: [4][2]Spring = @splat(@splat(.{})), + target: Box = .{}, + from_centre: [2]f32 = .{ 0, 0 }, + placed: bool = false, + /// When the last step (a move of a cell or less) came. + step_ns: u64 = 0, + /// The focused body as the last frame showed it: its pane, its first + /// line and its top left, to tell a scroll and a pane's move from the + /// caret's own. + seen: struct { owner: u8 = pardes.Region.none, line: i32 = 0, x: u16 = 0, y: u16 = 0 } = .{}, + + /// The default flavour's spring, as fast again as the caret follows + /// input (§8.1: it settles in 90-150 ms). + const omega: f32 = 34 * 2.4; + /// The trailing corners of a jump, a little behind the leading ones. + const follow: f32 = 0.85; + /// A step's spring, stiffer than a jump's. + const step_pace: f32 = 1.5; + /// A jump longer than this, in cells, bows, by this much of its length. + const arc_from: f32 = 8; + const arc: f32 = 0.04; + /// Steps this close are a stream: each lands. + const stream_ns: u64 = 150 * std.time.ns_per_ms; + + const Box = struct { x: f32 = 0, y: f32 = 0, w: f32 = 0, h: f32 = 0 }; + + /// One axis on a critically damped spring, closed form: a new target + /// keeps the value and its speed; settled, it is its target. + const Spring = struct { + omega: f32 = omega, + target: f32 = 0, + from: f32 = 0, + velocity: f32 = 0, + from_ns: u64 = 0, + settled: bool = true, + + fn at(s: *const Spring, now_ns: u64) [2]f32 { + if (s.settled) return .{ s.target, 0 }; + const t: f32 = @floatCast(@as(f64, @floatFromInt(now_ns -| s.from_ns)) / std.time.ns_per_s); + const x0 = s.from - s.target; + const k = s.velocity + s.omega * x0; + const decay = @exp(-s.omega * t); + return .{ s.target + (x0 + k * t) * decay, (s.velocity - s.omega * t * k) * decay }; + } + + fn value(s: *const Spring, now_ns: u64) f32 { + return s.at(now_ns)[0]; + } + + fn retarget(s: *Spring, target: f32, now_ns: u64, w: f32) void { + if (target == s.target) return; + const state = s.at(now_ns); + s.* = .{ .omega = w, .target = target, .from = state[0], .velocity = state[1], .from_ns = now_ns, .settled = false }; + } + + /// Settles within half a percent of a cell, barely moving; true + /// while it still moves. + fn step(s: *Spring, now_ns: u64) bool { + if (s.settled) return false; + const state = s.at(now_ns); + if (@abs(state[0] - s.target) < 5e-3 and @abs(state[1]) < 5e-2) s.settled = true; + return !s.settled; + } + }; + + fn cornersOf(box: Box) [4][2]f32 { + return .{ .{ box.x, box.y }, .{ box.x + box.w, box.y }, .{ box.x + box.w, box.y + box.h }, .{ box.x, box.y + box.h } }; + } + + fn centre(box: Box) [2]f32 { + return .{ box.x + box.w / 2, box.y + box.h / 2 }; + } + + /// Heads for `box`: eased, or landed at once (`land`: a scroll moved + /// the text under it, not the caret). + fn aim(caret: *Caret, box: Box, now_ns: u64, land_it: bool) void { + if (caret.placed and std.meta.eql(box, caret.target) and !(land_it and caret.moving())) return; + const to = cornersOf(box); + const from_c = if (caret.placed) caret.centreAt(now_ns) else centre(box); + const to_c = centre(box); + const dx = to_c[0] - from_c[0]; + const dy = to_c[1] - from_c[1]; + const jump = @abs(dx) > 1.01 or @abs(dy) > 1.01; + // A step is measured mark to mark, not from where an ease under way + // has got to (a held key's steps would read as jumps from there). + const last = centre(caret.target); + const one_step = caret.placed and @abs(to_c[0] - last[0]) <= 1.01 and @abs(to_c[1] - last[1]) <= 1.01; + const streaming = one_step and caret.step_ns != 0 and now_ns -| caret.step_ns < stream_ns; + if (one_step) caret.step_ns = now_ns; + const land = !caret.placed or land_it or streaming; + caret.from_centre = from_c; + caret.target = box; + caret.placed = true; + for (&caret.corners, to) |*corner, point| { + // Leading: the corner ahead of the move, on the side it goes. + const ahead = (point[0] - to_c[0]) * dx + (point[1] - to_c[1]) * dy; + const w = if (jump) omega * (if (ahead > 0) 1 else follow) else omega * step_pace; + for (corner, point) |*axis, v| { + if (land) axis.* = .{ .omega = w, .target = v, .from = v } else axis.retarget(v, now_ns, w); + } + } + } + + fn centreAt(caret: *const Caret, now_ns: u64) [2]f32 { + var sum: [2]f32 = .{ 0, 0 }; + for (caret.corners) |corner| for (&sum, corner) |*s, axis| { + s.* += axis.value(now_ns) / 4; + }; + return sum; + } + + /// The text under it moved by (dx, dy) cells: so does the quad. + fn shift(caret: *Caret, dx: f32, dy: f32) void { + for (&caret.corners) |*corner| for (corner, [2]f32{ dx, dy }) |*axis, d| { + axis.from += d; + axis.target += d; + }; + caret.from_centre = .{ caret.from_centre[0] + dx, caret.from_centre[1] + dy }; + caret.target.x += dx; + caret.target.y += dy; + } + + /// The quad at `now_ns`, bowed on a long jump. + fn sample(caret: *const Caret, now_ns: u64) [4][2]f32 { + var out: [4][2]f32 = undefined; + for (&out, caret.corners) |*point, corner| for (point, corner) |*v, axis| { + v.* = axis.value(now_ns); + }; + const to_c = centre(caret.target); + const dx = to_c[0] - caret.from_centre[0]; + const dy = to_c[1] - caret.from_centre[1]; + const length = @sqrt(dx * dx + dy * dy); + if (length < arc_from) return out; + const now_c = caret.centreAt(now_ns); + const left = @sqrt((to_c[0] - now_c[0]) * (to_c[0] - now_c[0]) + (to_c[1] - now_c[1]) * (to_c[1] - now_c[1])); + const travelled = std.math.clamp(1 - left / length, 0, 1); + const bow = arc * length * 4 * travelled * (1 - travelled); + for (&out) |*point| { + point[0] += -dy / length * bow; + point[1] += dx / length * bow; + } + return out; + } + + /// Steps the springs to `now_ns`; true while the quad still moves. + fn step(caret: *Caret, now_ns: u64) bool { + var any = false; + for (&caret.corners) |*corner| for (corner) |*axis| { + if (axis.step(now_ns)) any = true; + }; + return any; + } + + /// How far, in cells, the furthest corner still is from its mark. + fn remaining(caret: *const Caret, now_ns: u64) f32 { + var most: f32 = 0; + for (caret.corners) |corner| for (corner) |axis| { + most = @max(most, @abs(axis.value(now_ns) - axis.target)); + }; + return most; + } + + fn moving(caret: *const Caret) bool { + for (caret.corners) |corner| for (corner) |axis| { + if (!axis.settled) return true; + }; + return false; + } + + /// The frame about to be drawn shows the focused cursor at `box` (grid + /// cells; null: none) in pane `owner`'s body, whose first line is + /// `line` and top left (x, y): carried with that body when it moved or + /// scrolled, eased to its box otherwise. + fn see(caret: *Caret, box: ?Box, owner: u8, line: i32, x: u16, y: u16, now_ns: u64) void { + const b = box orelse { + // Nowhere to land: a glide under way stops; the next cursor + // lands where it is. + caret.* = .{}; + return; + }; + var land = false; + const was = caret.seen; + if (was.owner == owner and owner != pardes.Region.none) { + // The pane moved in the layout: its caret moves with it. + caret.shift(@as(f32, @floatFromInt(x)) - @as(f32, @floatFromInt(was.x)), @as(f32, @floatFromInt(y)) - @as(f32, @floatFromInt(was.y))); + // Scrolled: the text moved, not the caret; it lands on its + // cell (the glide draws it with the text, caretRide). + land = line != was.line; + } + caret.seen = .{ .owner = owner, .line = line, .x = x, .y = y }; + caret.aim(b, now_ns, land); + _ = caret.step(now_ns); + } +}; + +test "a caret eases a cell at a time, keeps up with typing, and glides a jump, landing exactly" { + const ms = std.time.ns_per_ms; + var caret: Caret = .{}; + caret.aim(.{ .x = 3, .y = 4, .w = 1, .h = 1 }, 0, false); + // The first mark lands at once. + try std.testing.expect(!caret.moving()); + // A step eases, a stream of them keeps up. + caret.aim(.{ .x = 4, .y = 4, .w = 1, .h = 1 }, 1000 * ms, false); + try std.testing.expect(caret.moving()); + caret.aim(.{ .x = 5, .y = 4, .w = 1, .h = 1 }, 1050 * ms, false); + try std.testing.expect(!caret.moving()); + // A jump glides, the leading corner ahead, and lands exactly. + caret.aim(.{ .x = 30, .y = 10, .w = 1, .h = 1 }, 2000 * ms, false); + try std.testing.expect(caret.moving()); + const mid = caret.sample(2040 * ms); + try std.testing.expect(mid[1][0] > mid[0][0] - 1 and mid[0][0] > 5 and mid[0][0] < 30); + var t: u64 = 2040 * ms; + while (caret.step(t)) t += 16 * ms; + try std.testing.expect(t < 2400 * ms); + try std.testing.expectEqual([2]f32{ 30, 10 }, caret.sample(t)[0]); + // A scroll lands it with its text. + caret.see(.{ .x = 30, .y = 8, .w = 1, .h = 1 }, 0, 10, 2, 1, t); + caret.see(.{ .x = 30, .y = 6, .w = 1, .h = 1 }, 0, 12, 2, 1, t + 16 * ms); + try std.testing.expect(!caret.moving()); +} + + /// The rows a caret whose line rode the wheel's glide is drawn above its /// cell: the text's own offset, so it moves with its line as a glyph does -/// (its springs landed on the cell, draw.glideCursor). +/// (its springs landed on the cell, Caret.see). fn caretRide(g: *const Gui, surface: *const pardes.Surface) f32 { const glide = &g.glide; if (!glide.caret_rides or glide.follow.offset == 0) return 0; @@ -8178,14 +8449,15 @@ fn buildOverlay( which: pardes.config.Runtime.Pet, trail_on: bool, surface: *const pardes.Surface, + now_ns: u64, sw: u32, sh: u32, ) u32 { if (g.overlay_vertices.len == 0 or sw == 0 or sh == 0) return 0; var builder = OverlayBuilder{ .vertices = g.overlay_vertices, .win_w = @floatFromInt(sw), .win_h = @floatFromInt(sh) }; appendWorkspacePet(g, which, surface, &builder); - appendJumpTrail(g, trail_on, surface, monoNs(), &builder); - appendCursorGlide(g, surface, &builder); + appendJumpTrail(g, trail_on, surface, now_ns, &builder); + appendCursorGlide(g, surface, now_ns, &builder); return @intCast(builder.len); } @@ -8327,24 +8599,27 @@ fn overlayRgb(rgb: [3]u8) OverlayColor { }; } -/// G3: the focused cursor while it glides or blinks, its quad from the core -/// (Chrome.cursor_quad, grid cells) in its cursor colour; a little less than -/// solid, so the glyphs it passes over stay legible. -fn appendCursorGlide(g: *Gui, surface: *const pardes.Surface, builder: *OverlayBuilder) void { +/// G3: the focused cursor while it glides or blinks, its quad from the +/// window's caret (Caret, grid cells) in its cursor colour; a little less +/// than solid, so the glyphs it passes over stay legible. +fn appendCursorGlide(g: *Gui, surface: *const pardes.Surface, now_ns: u64, builder: *OverlayBuilder) void { const chrome = &surface.chrome; if (g.cursor_quad_alpha <= 0.001) return; const layout = fixedCellLayout(g); const ride = caretRide(g, surface); + // Never off the grid, however a long jump bows. + var quad = g.caret.sample(now_ns); + for (&quad) |*point| point.* = .{ std.math.clamp(point[0], 0, @as(f32, @floatFromInt(surface.cols))), std.math.clamp(point[1], 0, @as(f32, @floatFromInt(surface.rows))) }; if (ride != 0) { // Carried past the body's edge with its line: clipped as the text is. - const mid = chrome.cursor_quad[1] - ride + 0.5; + const mid = quad[0][1] - ride + 0.5; const top: f32 = @floatFromInt(g.glide.body_y); if (mid < top or mid > top + @as(f32, @floatFromInt(g.glide.body_h))) return; } var px: [4][2]f32 = undefined; var centre: [2]f32 = .{ 0, 0 }; for (&px, 0..) |*point, i| { - point.* = .{ chrome.cursor_quad[i * 2] * layout.w, (chrome.cursor_quad[i * 2 + 1] - ride) * layout.h }; + point.* = .{ quad[i][0] * layout.w, (quad[i][1] - ride) * layout.h }; centre[0] += point[0] / 4; centre[1] += point[1] / 4; } diff --git a/src/pardes.zig b/src/pardes.zig index 8204915d..fb5b7f43 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -3367,23 +3367,12 @@ pub const Pardes = struct { theme_file_generation: u32 = 0, theme_file_pane: u8 = 0, chrome: colors.ChromeTheme = colors.initial_chrome, - /// The focused cursor's quad on its springs (animation.CursorGlide), - /// the pane and view origin it was last aimed in, and the last key or - /// click, which a blink holds for. - cursor_glide: animation.CursorGlide = .{}, /// Every drawn frame's timings (FrameStats: the Debug box, PARDES_FRAMES). frames: FrameStats = .{}, /// A pixel shell's own render-time motion is under way (its smooth /// scroll, G6): the core then keeps the continuous path running, so the /// shell draws every loop and a virtual clock moves on, as for a lift. shell_continuous: bool = false, - cursor_view: struct { serial: u32 = 0, line: i64 = 0, origin: [2]f32 = .{ 0, 0 }, inside: bool = true } = .{}, - /// The cursor glides from one pane to another: it may cross the grid. - cursor_crossing: bool = false, - /// A click took focus to another pane and its button is still down: the - /// cursor waits where it was drawn for the release that places it. - cursor_held: bool = false, - input_ns: u64 = 0, native_images: bool = false, /// The shell can take a changed image a few rows at a time (a texture row /// upload, a shared-memory hand-off), so a PDF selection is repainted as @@ -3601,7 +3590,7 @@ pub const Pardes = struct { .local = .{ // A frame, and the animations and timings that make it. "surface", "frames", "chrome", - "cursor_glide", "cursor_view", "cursor_crossing", "cursor_held", "frame_arena", "scratch", + "frame_arena", "scratch", "needs_frame", "present_skipped", "shell_continuous", "native_image_patches", "echo", // Drained by every pump before its digest; a replica's queues @@ -5180,7 +5169,6 @@ pub const Pardes = struct { } switch (ev) { .key, .mouse => { - if (ev == .key or ev.mouse.kind != .motion) p.input_ns = p.now_ns; for (p.panes) |slot| { if (slot) |pane| Messages.dismissMessage(p, pane); } @@ -6878,7 +6866,7 @@ pub const Pardes = struct { /// and its present (vsync) paces it, at the display's rate. `nextWake` /// is for the stepped animations, which count frames of `frame_ns`. pub fn continuous(p: *const Pardes) bool { - return p.cursor_glide.moving() or p.shell_continuous or panes.Pdf.moving(p); + return p.shell_continuous or panes.Pdf.moving(p); } /// For shells that only need a yes or no: macOS, which keeps its own diff --git a/src/surface.zig b/src/surface.zig index 998e3230..ec4d73b1 100644 --- a/src/surface.zig +++ b/src/surface.zig @@ -290,16 +290,6 @@ pub const Chrome = struct { grip_focus_ring: [3]u8 = .{ 0, 0, 0 }, /// A dirty pane's button fill. grip_dirty: [3]u8 = .{ 0, 0, 0 }, - /// The focused cursor's quad (four corners, x then y, in grid cells, top - /// left clockwise): `cursor_glide` bit 1 says there is one, bit 0 that - /// it glides, when a pixel shell draws it at `cursor_alpha` in place of - /// its cursors (as it does while it blinks, from `cursor_idle_ms`, the - /// time since the last key or click when the frame was made; maxInt, - /// no blink). - cursor_glide: u8 = 0, - cursor_alpha: f32 = 1, - cursor_quad: [8]f32 = @splat(0), - cursor_idle_ms: u32 = std.math.maxInt(u32), /// The rule between a pane's tag and its body; null is halfway between /// the tag's ground and the page the shell actually draws. tag_rule: ?[3]u8 = null, diff --git a/src/views.zig b/src/views.zig index c796bd85..59910f5b 100644 --- a/src/views.zig +++ b/src/views.zig @@ -37,9 +37,8 @@ pub const fields = [_][:0]const u8{ "col_tags", "col_serial", "finder", "rects", "col_x", "col_w", "active", "jumps", "njumps", "jcur", "jump_force", - "active_column", "cursor_glide", - "cursor_view", "cursor_crossing", "cursor_held", "shell_continuous", - "input_ns", "native_images", "native_image_patches", "windowed", + "active_column", "shell_continuous", + "native_images", "native_image_patches", "windowed", "drag", "mouse_grab", "window_focused", "focus_told", "hover_col", "hover_row", "pointer_raw_col", "pointer_raw_row", "pointer_body_hit", "pointer_tag_hit", "raw_hover_intent", "pointer_inside", @@ -537,7 +536,7 @@ pub fn deinit(p: *Pardes) void { /// What drawing a view keeps of its own (its animations, its panels as /// presented), kept from a frame drawn while it was out. -const drawn_fields = [_][:0]const u8{ "cursor_glide", "cursor_view", "cursor_crossing", "cursor_held", "shell_continuous" }; +const drawn_fields = [_][:0]const u8{"shell_continuous"}; /// Each view but the live one drawn and presented, the live one put back /// after exactly as it was: no digested field moves, so a replica that |
