diff options
Diffstat (limited to 'anim/src/column.zig')
| -rw-r--r-- | anim/src/column.zig | 119 |
1 files changed, 77 insertions, 42 deletions
diff --git a/anim/src/column.zig b/anim/src/column.zig index 32b3d4d..1484796 100644 --- a/anim/src/column.zig +++ b/anim/src/column.zig @@ -19,9 +19,11 @@ //! }); //! //! Between beats, in a rest (design/README.md, "Panes between beats"): the -//! last bubble dims; the panes that leave fade (12 f) and fold to the shelf -//! (24 f, `glide`); those that stay glide (24 f); those that come unfold -//! (24 f) and fade in (12 f); an older bubble in the way glides out of it +//! last bubble dims; the panes that leave fade (6 f) and fold where they +//! stand, their tags travelling to the shelf (18 f, `glide`); those that +//! stay glide (24 f; a pane crossing to the other column 24 f each way), +//! one that changes its height keeping its rows; those that come unfold +//! (18 f) and fade in (6 f); an older bubble in the way glides out of it //! (24 f); the next arrives (18 f, rising 8), its stem drawing (12 f); the //! lead; the stem draws back as the step fires. A bubble never travels //! between placements: the last leaves (12 f), the frame changes (48 f), the @@ -78,6 +80,9 @@ pub const Beat = struct { notes: []const Note = &.{}, /// `on`: the bubble's top left in the frame (design units), in the drawing's free space. where: ?[2]f32 = null, + /// The rest after this beat's steps is meant (a poster's picture): its + /// bubble may still be read there longer than a hold (design/README.md, `bubble`). + held: bool = false, }; pub const Options = struct { @@ -92,10 +97,9 @@ pub const Options = struct { /// Frames, at 60 a second (design/README.md, "Panes between beats"). const f = struct { const dim = 18.0 / 60.0; - const rows = 12.0 / 60.0; - const fold = 24.0 / 60.0; + const rows = 6.0 / 60.0; + const fold = 18.0 / 60.0; const glide = 24.0 / 60.0; - const relayout = theme.time.relayout; const push = 24.0 / 60.0; const arrive = 18.0 / 60.0; const stem_after = 6.0 / 60.0; @@ -164,6 +168,8 @@ pub const Column = struct { zoom: f32 = 1, read_by: f32 = 0, said: bool = false, + /// The last beat's rest is meant: not flagged. + held: bool = false, /// One beat: the panes change (in a rest, never under a step), the text /// arrives where the beat places it, the lead, then the scene's step. @@ -197,8 +203,12 @@ pub const Column = struct { split.band = room; }, } - // Not before the text up has been read. - s.wait(@max(col.read_by - s.cursor, 0)); + // Not before the text up has been read; and its beat should have covered that + // (its lead, its steps and a hold of at most 84 f), unless its rest is meant. + const still = col.read_by - s.cursor; + if (col.said and !col.held and still > 84.0 / 60.0) flag(col.n, still); + s.wait(@max(still, 0)); + col.held = b.held; const kind = frameOf(at) != frameOf(col.placement); const moves = !std.meta.eql(to, col.standing) or !sameBoxes(col.split, split, to) or zoom != col.zoom or kind; const newest = col.newestStanding(); @@ -295,31 +305,25 @@ pub const Column = struct { fn change(col: *Column, s: *anim.Frame, to: [parts.len]bool, split: Split, at: Placement, zoom: f32, kind: bool) void { var leaving: [parts.len]bool = undefined; var coming: [parts.len]bool = undefined; - // A pane that stays but changes its rows: its rows fade out and in round the - // glide (they are laid out for its height), its frame gliding as the column's. - var resized: [parts.len]bool = undefined; + // A pane that stays and changes its height keeps its rows the whole way: + // it glides with the column, gaining or giving up rows at its moving edge. var any_leaving = false; var any_coming = false; - inline for (.{ "band", "view", "source", "disasm", "registers", "stack", "backtrace" }, 0..) |name, i| { + for (parts, 0..) |_, i| { leaving[i] = col.standing[i] and !to[i]; coming[i] = !col.standing[i] and to[i]; - resized[i] = col.standing[i] and to[i] and i > 1 and @field(col.split, name).h != @field(split, name).h; - any_leaving = any_leaving or leaving[i] or resized[i]; - any_coming = any_coming or coming[i] or resized[i]; + any_leaving = any_leaving or leaving[i]; + any_coming = any_coming or coming[i]; } const band = @intFromEnum(Part.band); const view = @intFromEnum(Part.view); if (any_leaving) { var anims: [3 * parts.len]anim.Animation = undefined; var n: usize = 0; - for (parts, 0..) |_, i| if (leaving[i] or resized[i]) { + for (parts, 0..) |_, i| if (leaving[i]) { anims[n] = col.ghost[i].to(1); n += 1; }; - for (parts, 0..) |_, i| if (resized[i]) if (col.objs[i]) |o| { - anims[n] = o.fadeOut(); - n += 1; - }; for (parts, 0..) |_, i| if (leaving[i]) if (col.objs[i]) |o| { // The lens is one object: it goes when neither of its panes stands (once). const lens = i == band or i == view; @@ -356,8 +360,6 @@ pub const Column = struct { if (i == band) next.band.h = 0; }; const glides = !sameBoxes(col.split, next, col.standing) or zoom != col.zoom or kind; - const seconds: f32 = if (!glides) 0 else if (kind) f.relayout else f.glide; - const start = s.cursor; // A pane going over to the other column goes down (or up) its own // first, as the others make room, then across: never over another's rows. var mid = next; @@ -366,6 +368,9 @@ pub const Column = struct { @field(mid, name).x = @field(col.split, name).x; crosses = true; }; + // 24 f; a pane crossing over, 24 f each way. + const seconds: f32 = if (!glides) 0 else if (crosses) 2 * f.glide else f.glide; + const start = s.cursor; if (crosses) col.stage.glide(s, mid, seconds / 2); col.stage.glide(s, next, if (crosses) seconds / 2 else seconds); const end = s.cursor; @@ -392,14 +397,10 @@ pub const Column = struct { }; if (n > 0) together(s, anims[0..n], f.fold, anim.ease.linear); n = 0; - for (parts, 0..) |_, i| if (coming[i] or resized[i]) { + for (parts, 0..) |_, i| if (coming[i]) { anims[n] = col.ghost[i].to(0); n += 1; }; - for (parts, 0..) |_, i| if (resized[i]) if (col.objs[i]) |o| { - anims[n] = o.fadeIn(); - n += 1; - }; for (parts, 0..) |_, i| if (coming[i]) if (col.objs[i]) |o| { const lens = i == band or i == view; if (!lens or !(col.standing[band] or col.standing[view]) and !(i == view and coming[band])) { @@ -492,10 +493,12 @@ pub const Column = struct { /// between its box and its place there. fn drawShelf(col: *const Column, u: ui.Ui, placed: anim.Placed) void { const before, const after, const p = col.notesNow(placed); + shelf_tags = @splat(null); var x: f32 = theme.layout.program.x; for (parts, 0..) |part, i| { if (col.objs[i] == null) continue; - const on = theme.ease(.glide, placed.value(col.shelf[i])); + const raw = placed.value(col.shelf[i]); + const on = theme.ease(.glide, raw); // Its frame drawn in the pane's stead: crossfading with the pane at its box, alone on its way. const ghost = placed.value(col.ghost[i]); if (on <= 0 and ghost <= 0) continue; @@ -504,7 +507,11 @@ pub const Column = struct { const slot: Rect = .{ .x = x, .y = shelf_y, .w = w, .h = m.tag }; const name = col.title(placed, part); const b = col.box(placed, part); - const r: Rect = if (ghost > 0) .{ .x = std.math.lerp(b.x, slot.x, on), .y = std.math.lerp(b.y, slot.y, on), .w = std.math.lerp(b.w, slot.w, on), .h = std.math.lerp(b.h, slot.h, on) } else slot; + // It closes to its tag where it stands, then the tag travels (unfolding, the + // reverse): only a tag ever crosses another pane, never a panel. + const shut = theme.ease(.glide, std.math.clamp(raw / 0.6, 0, 1)); + const go = theme.ease(.glide, std.math.clamp((raw - 0.4) / 0.6, 0, 1)); + const r: Rect = if (ghost > 0) .{ .x = std.math.lerp(b.x, slot.x, go), .y = std.math.lerp(b.y, slot.y, go), .w = std.math.lerp(b.w, slot.w, shut), .h = std.math.lerp(b.h, slot.h, shut) } else slot; const v = u.moved(r.x, r.y).faded(if (on > 0) 1 else ghost); _ = v.panel(r.w, r.h, name, .{}); // Its note comes as it lands on the shelf, and goes as it leaves. @@ -514,6 +521,7 @@ pub const Column = struct { if (p < 1) _ = col.tagNote(v.faded(shows * (1 - p)), placed, part, nx, notes[0]); _ = col.tagNote(v.faded(shows * p), placed, part, nx, notes[1]); } + if (on >= 1) shelf_tags[i] = slot; x += (w + theme.canvas.row_gap) * on; } } @@ -605,8 +613,12 @@ pub const Column = struct { const digits = if (v < 0x10000) u.print("{d}", .{v}) else u.print("{x}", .{v}); const dw = u.width(.mono, size, digits); const heat = if (age == 0) now.register(i, ties.strikeDelay(now, i)) else now.heat(1, null, 0); - const ink = u.written(.{ .x = at, .y = 0, .w = dw, .h = m.tag }, heat) orelse ui.Ink{}; - u.text(ink.face, size, at, base, digits, ink.ink); + _ = u.written(.{ .x = at, .y = 0, .w = dw, .h = m.tag }, heat); + // Struck, bold and bright: crossfading with the fill (a face changing in a frame on a tag this small is a pop). + const solid = if (heat.level >= 1) heat.solid * heat.in else 0; + const ink = ui.mix(t.primary, t.bright, solid); + if (solid < 1) u.faded(1 - solid).text(.mono, size, at, base, digits, ink); + if (solid > 0) u.faded(solid).text(.mono_bold, size, at, base, digits, ink); at += dw; } shown += 1; @@ -631,8 +643,8 @@ pub const Column = struct { }; var with: [48]f32 = undefined; var without: [48]f32 = undefined; - col.layout(placed, inv, newest, true, &with); - col.layout(placed, inv, newest, false, &without); + col.layout(u.f, placed, inv, newest, true, &with); + col.layout(u.f, placed, inv, newest, false, &without); const push = if (newest) |k| theme.ease(.glide, placed.value(col.texts[k].push)) else 1; for (col.texts[0..col.n], 0..) |x, k| { const in = placed.value(x.in); @@ -685,7 +697,7 @@ pub const Column = struct { /// Each beside text's top, the newest's or not: level with what it /// speaks of where it can be; an older one in a newer one's way above it, /// or under it where there is no room above. - fn layout(col: *const Column, placed: anim.Placed, inv: sk.math.Affine, newest: ?usize, with_newest: bool, out: *[48]f32) void { + fn layout(col: *const Column, fr: *sk.Frame, placed: anim.Placed, inv: sk.math.Affine, newest: ?usize, with_newest: bool, out: *[48]f32) void { var taken: [48][2]f32 = undefined; var n_taken: usize = 0; var k = col.n; @@ -699,7 +711,7 @@ pub const Column = struct { // Only what has arrived. if (newest == null or k > newest.?) continue; const h = height(x); - var top = std.math.clamp(levelY(placed, inv, k, x.level) - bubble.first, bubble.top, bubble.bottom - h); + var top = std.math.clamp(levelY(fr, inv, k, x.level) - bubble.first, bubble.top, bubble.bottom - h); // Above what is in its way, while there is room; else under it. var tries: usize = 0; while (tries < n_taken + 1) : (tries += 1) { @@ -725,7 +737,8 @@ pub const Column = struct { fn stemBeside(_: *const Column, u: ui.Ui, inv: sk.math.Affine, x: Text, top: f32, target: Level, placed: anim.Placed) void { const v = placed.value(x.stem_v); if (v <= 0 or v >= 2) return; - const r = find(inv, target) orelse return; + // About a folded pane: its tag on the shelf. + const r = if (paneOf(target)) |pane| if (shelf_tags[@intFromEnum(pane)]) |tag| [4]f32{ tag.x, tag.y, tag.x + tag.w, tag.y + tag.h } else find(u.f, inv, target) orelse return else find(u.f, inv, target) orelse return; const y0 = top + bubble.first; const y1 = (r[1] + r[3]) / 2; const lane = theme.metric.tie.link_lane + 6; @@ -739,7 +752,7 @@ pub const Column = struct { fn stemOn(col: *const Column, u: ui.Ui, inv: sk.math.Affine, x: Text, where: [2]f32, target: Level, placed: anim.Placed) void { const v = placed.value(x.stem_v); if (v <= 0 or v >= 2) return; - const r = find(inv, target) orelse return; + const r = find(u.f, inv, target) orelse return; const w = paperWidth(u, x); const lane = column_top + m.tag + 10; const from_x = where[0] + w - 32; @@ -790,7 +803,7 @@ fn settled(s: *const anim.Frame, v: anim.Value) f32 { } /// Where a level's place is this frame, in the frame's units: left, top, right, bottom. -fn find(inv: sk.math.Affine, level: Level) ?[4]f32 { +fn find(fr: *sk.Frame, inv: sk.math.Affine, level: Level) ?[4]f32 { const place: ties.Place = switch (level) { .pc => .pc, .row => |a| .{ .row = a }, @@ -799,7 +812,7 @@ fn find(inv: sk.math.Affine, level: Level) ?[4]f32 { .block => |a| .{ .block = a }, .y => |y| return .{ 0, y - m.row / 2, theme.layout.program.x + theme.layout.program.w, y + m.row / 2 }, }; - const r = ties.find(place) orelse return null; + const r = ties.find(fr, place) orelse return null; const a = inv.apply(.{ r[0], r[1] }); const b = inv.apply(.{ r[2], r[3] }); return .{ a[0], a[1], b[0], b[1] }; @@ -811,17 +824,39 @@ fn find(inv: sk.math.Affine, level: Level) ?[4]f32 { var last_level: [48]?f32 = @splat(null); /// Once its row has gone from a pane that is drawn, or the panes have changed, a text stays where it is (`latched`). var latched: [48]bool = @splat(false); -fn levelY(_: anim.Placed, inv: sk.math.Affine, k: usize, level: Level) f32 { - if (!latched[k]) if (find(inv, level)) |r| { +fn levelY(fr: *sk.Frame, inv: sk.math.Affine, k: usize, level: Level) f32 { + if (!latched[k]) if (find(fr, inv, level)) |r| { const y = (r[1] + r[3]) / 2; last_level[k] = y; return y; }; // A row of the disassembly, gone while the pane is there (its pc drawn): the text stays. - if (last_level[k] != null and (level == .row or level == .head or level == .floor) and ties.find(.pc) != null) latched[k] = true; + if (last_level[k] != null and (level == .row or level == .head or level == .floor) and ties.find(fr, .pc) != null) latched[k] = true; return last_level[k] orelse 400; } +/// Each folded pane's tag on the shelf this frame (`drawShelf`), for a stem about a folded pane. +var shelf_tags: [parts.len]?Rect = @splat(null); + +/// The pane a level is in. +fn paneOf(level: Level) ?Part { + return switch (level) { + .pc, .row, .head, .floor => .disasm, + .block => .band, + .y => null, + }; +} + +/// A bubble still being read after its beat's steps and an 84 f hold +/// (design/README.md, `bubble`): said once, on stderr. +var flagged: [48]bool = @splat(false); +fn flag(k: usize, still: f32) void { + const i = @min(k, flagged.len) -| 1; + if (flagged[i]) return; + flagged[i] = true; + std.debug.print("column: bubble {d} is still read {d:.1} s after its beat's steps (84 f at most)\n", .{ k, still }); +} + fn height(x: Text) f32 { const n = lineCount(x.text, bubble.chars); return bubble.first * 2 + @as(f32, @floatFromInt(n - 1)) * bubble.pitch; |
