summaryrefslogtreecommitdiff
path: root/src/gui/gui.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/gui.zig')
-rw-r--r--src/gui/gui.zig335
1 files changed, 305 insertions, 30 deletions
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;
}