diff options
Diffstat (limited to 'anim/src/root.zig')
| -rw-r--r-- | anim/src/root.zig | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/anim/src/root.zig b/anim/src/root.zig index a69cda9..6aa47de 100644 --- a/anim/src/root.zig +++ b/anim/src/root.zig @@ -99,8 +99,10 @@ pub fn enter(s: *anim.Frame, views: anytype) void { /// then the picture is still long enough to be read, a second and half a /// second for each panel, before a word is said about it. pub fn establish(s: *anim.Frame, views: anytype) void { + const start = s.cursor; enter(s, views); - s.wait(time.establish + time.establish_per_panel * @as(f32, @floatFromInt(views.len - 1))); + // The first caption at a second: the picture is read under it. + s.wait(@max(start + time.establish - s.cursor, 0)); } /// And takes them away: quicker than they came. @@ -117,17 +119,28 @@ pub fn leave(s: *anim.Frame, views: anytype) void { /// it, longer after a scene's first: the eye reads, then is shown. pub const Narrator = struct { current: ?anim.Obj = null, + /// When the caption on screen has been up long enough to be read. + read_by: f32 = 0, pub fn line(n: *Narrator, s: *anim.Frame, text: []const u8) void { const next = add(s, Caption{ .text = text }); if (n.current) |old| { + // Not before the one up has been read: what follows waits. + s.wait(@max(n.read_by - s.cursor, 0)); s.play(.{old.fadeOut()}, .{ .seconds = time.caption_out, .ease = ease.exit }); s.wait(time.caption_gap); } s.play(.{next.fadeIn()}, .{ .seconds = time.caption_in, .ease = ease.enter }); + n.read_by = s.cursor + time.caption(@intCast(std.unicode.utf8CountCodepoints(text) catch text.len)); s.wait(if (n.current == null) time.caption_lead_first else time.caption_lead); n.current = next; } + + /// A scene's close: the last picture still, and the last caption read. + pub fn close(n: *Narrator, s: *anim.Frame) void { + s.wait(time.before_cut); + s.wait(@max(n.read_by - s.cursor, 0)); + } }; /// The camera, directed: a way of reading the context, not a place to be @@ -218,6 +231,24 @@ pub const Context = struct { pub fn ties(c: Context, s: *anim.Frame) anim.Obj { return add(s, Ties{ .cursor = c.cursor, .stage = c.stage, .quiet = c.quiet }); } + + /// A scene's opening with a lens drawn from bytes (`nodes`, `array`): + /// as `establish`, and from half a second in the drawing's + /// `elements` come in, each rising 8 units, 2 f apart in address + /// order (`ties.rise`), beside their rows' quiet brackets; no lines. + pub fn establish(c: Context, s: *anim.Frame, views: anytype, elements: usize) void { + const start = s.cursor; + s.play(.{c.stage.rise.to(0)}, .{ .seconds = 0 }); + s.cursor = start; + enter(s, views); + const done = s.cursor; + s.cursor = start + time.establish_rise; + const rising = tying.riseTime(elements); + s.play(.{c.stage.rise.to(rising)}, .{ .seconds = rising, .ease = anim.ease.linear }); + s.cursor = @max(s.cursor, done); + // The first caption at a second. + s.wait(@max(start + time.establish - s.cursor, 0)); + } }; pub fn context(s: *anim.Frame, at: Cursor, options: Context.Options) Context { |
