diff options
Diffstat (limited to 'anim/src/source.zig')
| -rw-r--r-- | anim/src/source.zig | 72 |
1 files changed, 64 insertions, 8 deletions
diff --git a/anim/src/source.zig b/anim/src/source.zig index 5a5f1cd..ab49bc0 100644 --- a/anim/src/source.zig +++ b/anim/src/source.zig @@ -64,12 +64,24 @@ pub const Source = struct { // arrives; a scroll of more lines than the window shows would be a // blur, and say nothing. const turn = at[0].src != at[1].src and going < 1; - const far = !turn and @abs(windows[1] - windows[0]) > @as(f32, @floatFromInt(fit)) and going < 1; - const side: usize = if (turn) @intFromBool(going >= 0.5) else if (far) @intFromBool(going >= 0.75) else @intFromBool(going >= 0.5); + // At a walk, a window going farther than its height to lines its + // column on the map has too: the pane `unroll`s to the column, its + // window travels there along it, and it `roll`s back in at its new + // place (`unrolling`, 96 f); the pane goes into the column as it + // grows and comes out of it as it rolls back, never a fade. + const jump = unrolling(rec, now, at, p.cursor.levels.source_rows); + // (On the map, for the strips, half its height: a column scrolling most of its rows would be a smear on a strip.) + const far = !turn and jump == null and @abs(windows[1] - windows[0]) > @as(f32, @floatFromInt(if (ui.mapping) fit / 2 else fit)) and going < 1; + if (jump) |j| if (!ui.mapping and p.part == .source) { + map.jumping = .{ .panel = .source, .grow = j.grow, .veil = j.veil }; + }; + // On the map, for the strip, a far window's column goes over as the advance starts: + // the strip (6 to 11 f behind) shows where the pane goes before the pane fades. + const side: usize = if (jump) |j| @intFromBool(j.travel >= 0.5) else if (turn) @intFromBool(going >= 0.5) else if (far) @intFromBool(if (ui.mapping) going > 0 else going >= 0.75) else @intFromBool(going >= 0.5); const file = rec.sources[at[side].src]; const text = prepared(file.text, file.path) orelse return; - const first = if (turn or far) windows[side] else std.math.lerp(windows[0], windows[1], cursors.glide(going)); - const fade: f32 = if (turn) @abs(2 * going - 1) else if (far) (if (going < 0.5) 1 else @abs(4 * going - 3)) else 1; + const first = if (jump) |j| (if (ui.mapping) std.math.lerp(windows[0], windows[1], cursors.glide(j.travel)) else windows[side]) else if (turn or far) windows[side] else std.math.lerp(windows[0], windows[1], cursors.glide(going)); + const fade: f32 = if (jump) |j| (if (ui.mapping) 1 else 1 - theme.ease(.glide, j.grow)) else if (turn) @abs(2 * going - 1) else if (far and !ui.mapping) (if (going < 0.5) 1 else @abs(4 * going - 3)) else 1; const lit = u.faded(fade); const from: u32 = @intFromFloat(@floor(first)); const last: u32 = @min(from + @as(u32, @intCast(context.rowsOf(box))), file.lines); @@ -92,8 +104,12 @@ pub const Source = struct { // Its tag's file and note change with the fade through it; a note otherwise over the 12 f before the advance. if (turn) for (titles, [2]f32{ 1 - 2 * going, 2 * going - 1 }) |t, shows| u.faded(shows).tagTitle(t, p.focus); if (swap) { - const c = if (turn) std.math.clamp(2 * going - 1, 0, 1) else now.renaming(); - u.faded(if (turn) 1 - 2 * going else 1 - c).tagNote(box.w, notes[0]); + // Through another file, or to lines far off, it changes with the pane's fade: the lines it names are the lines shown. + // A window scrolling: its range changes with the scroll, the lines it names the lines shown (never before them). + const scrolls = std.mem.eql(u8, notes[0], lines_notes[0]) and std.mem.eql(u8, notes[1], lines_notes[1]); + const c = if (jump) |j| std.math.clamp(2 * j.travel - 0.5, 0, 1) else if (turn) std.math.clamp(2 * going - 1, 0, 1) else if (far) std.math.clamp(4 * going - 3, 0, 1) else if (scrolls) cursors.glide(going) else now.renaming(); + const old = if (jump != null) 1 - c else if (turn) 1 - 2 * going else if (far) std.math.clamp(3 - 4 * going, 0, 1) else 1 - c; + u.faded(old).tagNote(box.w, notes[0]); u.faded(c).tagNote(box.w, notes[1]); } const top = body.y + m.pad; @@ -104,7 +120,12 @@ pub const Source = struct { var mark_line = here; var mark_at: f32 = @floatFromInt(here); var shows: f32 = 1; - if (turn or far) { + if (jump) |j| { + // In the column it lights at its new line as the window gets there; in the pane it goes with the pane. + mark_line = if (j.travel >= 0.5) here else was; + mark_at = @floatFromInt(mark_line); + shows = fade; + } else if (turn or far) { // It goes with the fade: out with the old window, in with the new. mark_line = at[side].line; mark_at = @floatFromInt(mark_line); @@ -173,7 +194,7 @@ pub const Source = struct { } }.of; // On the strip the window glides there; a window fading through goes before the fade, so the strip shows where it went first. - map.window(.source, lines_of(windows[1], fit, rec.sources[at[1].src].lines), lines_of(windows[0], fit, rec.sources[at[0].src].lines), if (turn) @floatFromInt(side) else cursors.glide(if (far) @min(2 * going, 1) else going)); + map.window(.source, lines_of(windows[1], fit, rec.sources[at[1].src].lines), lines_of(windows[0], fit, rec.sources[at[0].src].lines), if (jump) |j| cursors.glide(j.travel) else if (turn) @floatFromInt(side) else cursors.glide(if (far) @min(2 * going, 1) else going)); var line = @max(from, 1); while (line <= last) : (line += 1) { const y = top + (@as(f32, @floatFromInt(line)) - first) * m.row; @@ -194,6 +215,41 @@ pub const Source = struct { } }; +/// A walked step whose source window (`fit` lines) goes farther than its +/// own height to lines the map's column holds as well (69 round the line, +/// or the whole file): the far jump in the same column, told by `unroll`, +/// the window's travel and `roll` (design/motion.md, "The map and the +/// working frame"). Where it is in them, 0 to 1 each: how far the column +/// has grown (before its `glide`), the window's travel along it, the veil. +pub fn unrolling(rec: *const Recording, now: cursors.Now, at: [2]Recording.Shown, fit: u32) ?struct { grow: f32, travel: f32, veil: f32 } { + const going = now.advancing(); + // A step said faster in a hurry is no beat for it: it fades through as at a run. + if (!now.walking() or now.hurried > 0 or going <= 0 or going >= 1 or at[0].src != at[1].src) return null; + const w = [2]u32{ rec.shownFirst(fit, at[0]), rec.shownFirst(fit, at[1]) }; + if (!inColumn(rec, at[0].src, w, fit)) return null; + const t = theme.time.unroll; + // Its phases in proportion to the advance's travel (96 f as `Cursor.travel` gives it). + const g = going * (t.grow + t.travel + t.roll); + const back = g - t.grow - t.travel; + return .{ + .grow = if (back <= 0) std.math.clamp(g / t.grow, 0, 1) else 1 - std.math.clamp(back / t.roll, 0, 1), + .travel = std.math.clamp((g - t.grow) / t.travel, 0, 1), + .veil = @min(std.math.clamp(g / t.veil, 0, 1), std.math.clamp((t.grow + t.travel + t.roll - g) / t.veil, 0, 1)), + }; +} + +/// Whether windows of `fit` lines at `w` in source `src` are farther apart +/// than their height and both in the map's column of it (the lines its +/// source panels hold round the line, or the file whole): a far jump the +/// unrolled column can show. +pub fn inColumn(rec: *const Recording, src: u16, w: [2]u32, fit: u32) bool { + const lo = @min(w[0], w[1]); + const hi = @max(w[0], w[1]); + // The map's column as the scene's map packs it (69 lines where there is none). + const column: u32 = if (map.current) |mp| @intCast(theme.layout.rowsIn(mp.stage.first.source.h) + theme.layout.rowsIn(mp.stage.first.source_more.h)) else theme.map.disasm_rows; + return hi - lo > fit and (rec.sources[src].lines <= column or hi + fit - lo <= column); +} + /// The last moment at or before `i` whose pc was on a line the panel can show. fn lastShown(rec: *const Recording, i: u64) u64 { var at = i; |
