summaryrefslogtreecommitdiff
path: root/anim/src/source.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/src/source.zig')
-rw-r--r--anim/src/source.zig56
1 files changed, 38 insertions, 18 deletions
diff --git a/anim/src/source.zig b/anim/src/source.zig
index 3843825..0705f5b 100644
--- a/anim/src/source.zig
+++ b/anim/src/source.zig
@@ -32,21 +32,29 @@ pub const Source = struct {
/// In a `descent`: while the pc is in code without source, the line it
/// called from waits, ringed, and the tag says where the pc is.
descent: bool = false,
+ /// Which box of its stage it is in: on the map the source may go on in `source_more`.
+ part: @import("stage.zig").Part = .source,
pub fn draw(p: *const Source, f: *sk.Frame, placed: anim.Placed) void {
- const box = p.stage.box(placed, .source);
+ const box = p.stage.box(placed, p.part);
+ if (box.h < m.tag + m.row) return;
const u = context.at(f, placed, box);
const rec = p.cursor.rec;
const now = p.cursor.now(placed);
const text = prepared(rec.source, rec.file) orelse return;
+ // Its window, and on the map the lines of both its boxes (`continued`): this one from `skip` lines in.
+ const head = theme.layout.rowsIn(p.stage.box(placed, .source).h);
+ const tail = theme.layout.rowsIn(p.stage.box(placed, .source_more).h);
const fit: u32 = @intCast(theme.layout.rowsIn(box.h));
+ const span_fit: u32 = @intCast(head + tail);
+ const skip: f32 = if (p.part == .source_more) @floatFromInt(head) else 0;
// The mark: leaving the line of one moment for that of the next.
const was = rec.own[now.marks[0]];
const here = rec.own[now.marks[1]];
// The window: where the line it is on has it, and (as the mark
// moves on) gliding to where the next one does. It never cuts.
const going = now.advancing();
- const windows = [2]f32{ @floatFromInt(rec.viewFirst(fit, was)), @floatFromInt(rec.viewFirst(fit, here)) };
+ const windows = [2]f32{ @as(f32, @floatFromInt(rec.viewFirst(span_fit, was))) + skip, @as(f32, @floatFromInt(rec.viewFirst(span_fit, here))) + skip };
// Farther than its own height (another function far off): what
// leaves has left before what replaces it arrives; a scroll of more
// lines than the window shows would be a blur, and say nothing.
@@ -64,9 +72,9 @@ pub const Source = struct {
var notes: [2][]const u8 = undefined;
for (now.marks, &notes) |mk, *note| note.* = if (p.descent and !rec.sourced(mk) and rec.own[mk] != 0) u.print("{s} waits at line {d} \u{00b7} the pc is in {s}", .{ context.frameName(u, rec, rec.register(firstOwn(rec, mk), "rip")), rec.own[mk], whereIs(u, rec, mk) }) else lines_note;
const swap = !std.mem.eql(u8, notes[0], notes[1]) and (notes[0].ptr != lines_note.ptr or notes[1].ptr != lines_note.ptr) and now.walking();
- const body = u.panel(box.w, box.h, rec.file, .{ .focus = p.focus, .note = if (swap) "" else if (waits) notes[if (going >= 0.5) 1 else 0] else lines_note });
+ const body = u.panel(box.w, box.h, if (p.part == .source_more) u.print("{s}, continued", .{rec.file}) else rec.file, .{ .focus = p.focus, .note = if (swap) "" else if (waits) notes[if (going >= 0.5) 1 else 0] else lines_note });
if (swap) {
- const c = std.math.clamp((now.time - now.plan.advance + 12.0 / 60.0) / (12.0 / 60.0), 0, 1);
+ const c = now.renaming();
u.faded(1 - c).tagNote(box.w, notes[0]);
u.faded(c).tagNote(box.w, notes[1]);
}
@@ -109,28 +117,40 @@ pub const Source = struct {
} else if (shows > 0) u.faded(shows).current(.{ .x = theme.stroke.rule, .y = mark_y, .w = box.w - 2 * theme.stroke.rule, .h = m.row }, theme.metric.plaque.line + widen, now.fires(.source));
if (shows >= 1 and mark_y >= body.y and mark_y + m.row <= box.h) ties.anchor(u, .source, .{ .x = 0, .y = mark_y, .w = box.w, .h = m.row });
- // The trail: the last three other lines it was on. It shifts without animation.
- const on_line = rec.own[now.marked()];
- var trail: [3]u32 = @splat(0);
- var found: usize = 0;
- var back = now.marked();
- while (back > 0 and found < trail.len) {
- back -= 1;
- const l = rec.own[back];
- if (l == 0 or l == on_line or std.mem.indexOfScalar(u32, trail[0..found], l) != null) continue;
- trail[found] = l;
- found += 1;
+ // The trail: the last three other lines it was on, as the mark left
+ // them and as it finds them: a bar that moves crossfades with the advance.
+ var trails: [2][3]u32 = @splat(@splat(0));
+ var founds = [2]usize{ 0, 0 };
+ for (now.marks, &trails, &founds) |mk, *trail, *found| {
+ const on_line = rec.own[mk];
+ var back = mk;
+ while (back > 0 and found.* < trail.len) {
+ back -= 1;
+ const l = rec.own[back];
+ if (l == 0 or l == on_line or std.mem.indexOfScalar(u32, trail[0..found.*], l) != null) continue;
+ trail[found.*] = l;
+ found.* += 1;
+ }
}
- map.window(.source, shown_first, @min(shown_first + fit - 1, rec.line_count));
+ const lines_of = struct {
+ fn of(at: f32, n: u32, lines: u32) [2]u64 {
+ const a: u32 = @intFromFloat(at);
+ return .{ a, @min(a + n - 1, lines) };
+ }
+ }.of;
+ map.window(.source, lines_of(windows[1], fit, rec.line_count), lines_of(windows[0], fit, rec.line_count), cursors.glide(going));
var line = @max(from, 1);
while (line <= last) : (line += 1) {
const y = top + (@as(f32, @floatFromInt(line)) - first) * m.row;
map.row(.source, line, u, .{ .x = 0, .y = y, .w = box.w, .h = m.row });
const span = text.lines[line - 1];
- const k = std.mem.indexOfScalar(u32, trail[0..found], line);
+ const ks = [2]?usize{ std.mem.indexOfScalar(u32, trails[0][0..founds[0]], line), std.mem.indexOfScalar(u32, trails[1][0..founds[1]], line) };
+ const k = if (going >= 0.5) ks[1] else ks[0];
const on = shows >= 0.5 and line == mark_line;
- rows.line(lit, y, box.w, line, widen, text.bytes[span[0]..span[1]], text.styles[span[0]..span[1]], if (on and !waits) .marked else if (k) |n| .{ .trail = n } else .plain);
+ const fading = !std.meta.eql(ks[0], ks[1]) and going > 0 and going < 1;
+ rows.line(lit, y, box.w, line, widen, text.bytes[span[0]..span[1]], text.styles[span[0]..span[1]], if (on and !waits) .marked else if (fading) .plain else if (k) |n| .{ .trail = n } else .plain);
+ if (fading and !(on and !waits)) for (ks, [2]f32{ 1 - going, going }) |kk, amount| if (kk) |n| lit.faded(amount).trail(theme.stroke.rule, y, n);
}
// The source is read at a run; at a sprint it is veiled too.
context.veiled(u, box, now.sprint_veil);