summaryrefslogtreecommitdiff
path: root/examples/live/src
diff options
context:
space:
mode:
Diffstat (limited to 'examples/live/src')
-rw-r--r--examples/live/src/main.zig26
1 files changed, 16 insertions, 10 deletions
diff --git a/examples/live/src/main.zig b/examples/live/src/main.zig
index 6e0f7e3..65bf6cd 100644
--- a/examples/live/src/main.zig
+++ b/examples/live/src/main.zig
@@ -278,6 +278,10 @@ const picture_pipeline: gpu.Pipeline = .{
pub fn draw(s: *const State, ss: *Session, f: *sk.Frame) void {
if (f.in.jumped) syn.forget();
+ // The canvas is the window's own pixels: text lands on whole pixels
+ // of the display, where a fixed canvas the window scales would blur it.
+ const room: [2]f32 = .{ @max(f.in.window_width, 640), @max(f.in.window_height, 360) };
+ f.canvas(@intFromFloat(room[0]), @intFromFloat(room[1]));
f.clear(0x000000);
if (!f.host.gpu()) {
f.text(16, 16, 2, "live needs a GPU: the host has none.", 0xff8080);
@@ -285,9 +289,11 @@ pub fn draw(s: *const State, ss: *Session, f: *sk.Frame) void {
}
// A tape past 64 instructions is drawn at half resolution: at 1280x720
// 128 instructions took 2.7 ms of the GPU, at half 0.85 (the probe).
+ // A window taller than 720 has the picture at 720 rows, scaled up, so
+ // the GPU's time stays that.
const seen = if (s.probe.len > 0) &s.probe else &s.color;
- const half: u32 = if (seen.len > 64) 2 else 1;
- const size: [2]u32 = .{ width / half, height / half };
+ const rows = @min(room[1], 720) / @as(f32, if (seen.len > 64) 2 else 1);
+ const size: [2]u32 = .{ @intFromFloat(@round(room[0] * rows / room[1])), @intFromFloat(rows) };
if (!std.meta.eql(ss.size, size)) {
if (ss.picture != .none) f.host.freeImage(ss.picture);
ss.picture = f.host.newImage(size[0], size[1]);
@@ -306,14 +312,14 @@ pub fn draw(s: *const State, ss: *Session, f: *sk.Frame) void {
.size = .{ @floatFromInt(size[0]), @floatFromInt(size[1]) },
}) }},
});
- f.image(ss.picture, .{ .x = 0, .y = 0, .w = width, .h = height }, .{});
- sound(s, ss, f);
- code(s, f);
+ f.image(ss.picture, .{ .x = 0, .y = 0, .w = room[0], .h = room[1] }, .{});
+ sound(s, ss, f, room);
+ code(s, f, room);
}
/// The out tape over the sample clock, as much as keeps the host's lead
/// queued, streamed from the GPU's block; and read back for the scope.
-fn sound(s: *const State, ss: *Session, f: *sk.Frame) void {
+fn sound(s: *const State, ss: *Session, f: *sk.Frame, room: [2]f32) void {
const in = f.in;
for (in.downloads) |d| if (d.key == stream) {
const samples = f.scratch.alloc(f32, d.bytes.len / 4) catch continue;
@@ -365,8 +371,8 @@ fn sound(s: *const State, ss: *Session, f: *sk.Frame) void {
ss.heard = heard.*;
}
ss.scope.draw(f, .{
- .oscilloscope = .{ .rect = .{ .x = 16, .y = height - 104, .w = 480, .h = 88 }, .samples = 1024 },
- .spectrum = .{ .x = 512, .y = height - 104, .w = 480, .h = 88 },
+ .oscilloscope = .{ .rect = .{ .x = 16, .y = room[1] - 104, .w = 480, .h = 88 }, .samples = 1024 },
+ .spectrum = .{ .x = 512, .y = room[1] - 104, .w = 480, .h = 88 },
});
}
@@ -419,7 +425,7 @@ fn box(at: []const sk.text.Caret, i: usize, space: f32) sk.Rect {
/// select, a bar in insert), the mode's name in the corner; the problem as
/// a red mark under its byte and its words under the text. Every place is
/// measured: one layout gives each byte's, another draws.
-fn code(s: *const State, f: *sk.Frame) void {
+fn code(s: *const State, f: *sk.Frame, room: [2]f32) void {
const text = s.ed.bytes(f.scratch) catch return;
const ranges = f.scratch.create([pe.max_selections]pe.Selection) catch return;
const got = s.ed.ranges(f.scratch, ranges) catch return;
@@ -467,7 +473,7 @@ fn code(s: *const State, f: *sk.Frame) void {
.paused => "paused",
};
const lead = @as(f32, @floatFromInt(f.in.lead)) / @as(f32, @floatFromInt(f.in.sample_rate)) * 1000;
- f.print(width - 300, 12, 1, ink, "{s} {s} {d:.1} s lead {d:.1} ms", .{ switch (s.ed.mode()) {
+ f.print(room[0] - 300, 12, 1, ink, "{s} {s} {d:.1} s lead {d:.1} ms", .{ switch (s.ed.mode()) {
.normal => "NOR",
.insert => "INS",
.select => "SEL",