summaryrefslogtreecommitdiff
path: root/anim/src/descent.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/src/descent.zig')
-rw-r--r--anim/src/descent.zig44
1 files changed, 44 insertions, 0 deletions
diff --git a/anim/src/descent.zig b/anim/src/descent.zig
index ad3a5c5..96f6f2d 100644
--- a/anim/src/descent.zig
+++ b/anim/src/descent.zig
@@ -71,6 +71,50 @@ pub fn step(cur: cursors.Cursor, s: *anim.Frame, by: Recording.Stop) void {
cur.step(s, to, plan, plan.total);
}
+/// A caller's window standing alone (the introduction, motion.md II2: the
+/// first code on screen): a descent's head row (the function, its file
+/// ranged right) over its call, the row the call returns to and the next,
+/// each said as a place (`row`) for an aim, a call's callee named where the
+/// annotation goes. `in` (frames): the head, then the rows 2 f apart, 12 f
+/// each; `faint` (0 to 1): to half, as it stays under what follows.
+pub const Caller = struct {
+ rec: *const Recording,
+ at: u64,
+ /// The call instruction's address.
+ call: u64,
+ box: Rect,
+ in: anim.Value,
+ faint: anim.Value,
+
+ pub fn draw(r: *const Caller, fr: *sk.Frame, placed: anim.Placed) void {
+ const clock = placed.value(r.in);
+ if (clock < 0) return;
+ const u = (ui.Ui{ .f = fr, .at = placed }).moved(r.box.x, r.box.y).faded(1 - 0.5 * std.math.clamp(placed.value(r.faint), 0, 1));
+ const moment = r.rec.moment(r.at);
+ var name_buf: [128]u8 = undefined;
+ const head = u.faded(std.math.clamp(clock / 12, 0, 1));
+ const name = (moment.string(r.call, &name_buf) catch null) orelse "";
+ head.fill(.{ .x = theme.stroke.rule, .y = 0, .w = r.box.w - 2 * theme.stroke.rule, .h = theme.stroke.rule }, theme.color.rule);
+ head.text(.sans_medium, theme.size.sans.micro, c.address, 18, u.print("{s}", .{name[0 .. std.mem.indexOfScalar(u8, name, '+') orelse name.len]}), t.primary);
+ head.text(.sans, theme.size.sans.micro, r.box.w - 12 - head.width(.sans, theme.size.sans.micro, r.rec.file), 18, r.rec.file, t.faint);
+ var addr = r.call;
+ var buf: [256]u8 = undefined;
+ for (0..3) |n| {
+ const insn = r.rec.instruction(r.at, addr, &buf) orelse return;
+ const y = m.row * @as(f32, @floatFromInt(n + 1));
+ const rv = u.faded(std.math.clamp((clock - 12 - 2 * @as(f32, @floatFromInt(n))) / 12, 0, 1));
+ _ = rv.address(c.address, rows.baseline(y), addr, .{ .ink = ui.rgb(theme.color.region.code_) });
+ const row: Insn = .{ .addr = addr, .len = insn.len, .text = insn.text, .line = insn.line };
+ disasm.bareRow(rv, row, y);
+ if (disasm.target(row)) |to| if (std.mem.startsWith(u8, insn.text, "call")) {
+ if (moment.string(to, &name_buf) catch null) |callee| rv.text(.mono, size, c.annotation, rows.baseline(y), ui.symbol(rv, callee[0 .. std.mem.indexOfScalar(u8, callee, '+') orelse callee.len]), t.primary);
+ };
+ ties.anchor(u, .{ .row = addr }, .{ .x = 0, .y = y, .w = r.box.w, .h = m.row });
+ addr += insn.len;
+ }
+ }
+};
+
/// The key of the head row over function `name`'s window (a `ties.Place.row`).
pub fn headKey(name: []const u8) u64 {
return std.hash.Wyhash.hash(0, name) | 1 << 63;