summaryrefslogtreecommitdiff
path: root/src/gui/gui.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/gui.zig')
-rw-r--r--src/gui/gui.zig77
1 files changed, 72 insertions, 5 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index e5ca645d..c2a4cb4e 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -14,6 +14,7 @@ const message = pardes.Messages.Message;
const file_watch = @import("../file_watch.zig");
const deck = @import("deck.zig");
const pet = @import("pet.zig");
+const JumpTrail = @import("../jump_trail.zig");
const fonts = @import("../fonts.zig"); // the fallback faces
const selection_pipe = @import("../selection_pipe.zig");
const c_heap = @import("c_heap");
@@ -240,9 +241,9 @@ const LoadedFallback = struct {
const max_touch_points: usize = 16;
const touch_scroll_tick: f32 = 0.02;
-// The triangle overlay holds only the pet and the cursor's glide quad: the
-// chrome is decor.
-const max_overlay_vertices: usize = pet.max_vertices + 6;
+// The triangle overlay holds only the pet, a jump's trail and the cursor's
+// glide quad: the chrome is decor.
+const max_overlay_vertices: usize = pet.max_vertices + 5 * 6 + 6;
const font_px_step: f32 = 2.0;
const font_px_min: f32 = 8.0;
@@ -994,6 +995,8 @@ const Gui = struct {
touch: Touch = .{},
/// The workspace tag's pet (Pet), on the window's own clock.
pet_state: pet.State = .{},
+ /// The cursor's jump trail (JumpTrail), on the window's own clock.
+ trail: JumpTrail = .{},
live_ctrl: bool = false,
live_alt: bool = false,
@@ -4553,7 +4556,7 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void {
const glide = &g.glide;
// The glide runs on the core's continuous path: frames every loop, and
// a virtual clock carried on.
- defer core.shell_continuous = glide.moving();
+ defer core.shell_continuous = glide.moving() or g.trail.active;
const notch = g.scroll_notch;
g.scroll_notch = 0;
var wheeled: ?usize = null;
@@ -5421,7 +5424,9 @@ fn renderFrame(
if (!pdf_focus) core.frames.scroll = g.glide.follow.offset;
core.frames.caret = caretRow(g, surface) orelse 0;
const cursors_shown = !quad_mode;
- var overlay_count = buildOverlay(g, core.settings.pet, surface, sw, sh);
+ var overlay_count = buildOverlay(g, core.settings.pet, core.settings.jump_trail and core.settings.motion != .off, surface, sw, sh);
+ // A trail fading asks for the frames it fades through.
+ if (g.trail.active) core.shell_continuous = true;
if (overlay_count != 0 and !uploadOverlayGpu(g, cmd, overlay_count))
overlay_count = 0;
if (!prepareNativeImages(g, gpa, cmd, surface, &groups, sw, sh)) {
@@ -8060,6 +8065,7 @@ fn cursorDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface,
fn buildOverlay(
g: *Gui,
which: pardes.config.Runtime.Pet,
+ trail_on: bool,
surface: *const pardes.Surface,
sw: u32,
sh: u32,
@@ -8067,10 +8073,71 @@ fn buildOverlay(
if (g.overlay_vertices.len == 0 or sw == 0 or sh == 0) return 0;
var builder = OverlayBuilder{ .vertices = g.overlay_vertices, .win_w = @floatFromInt(sw), .win_h = @floatFromInt(sh) };
appendWorkspacePet(g, which, surface, &builder);
+ appendJumpTrail(g, trail_on, surface, monoNs(), &builder);
appendCursorGlide(g, surface, &builder);
return @intCast(builder.len);
}
+/// A jump's trail (jump_trail.zig): the cells behind the cursor in its
+/// body, on the page's own ground, drawn over toward the text's colour.
+fn appendJumpTrail(g: *Gui, on: bool, surface: *const pardes.Surface, now_ns: u64, builder: *OverlayBuilder) void {
+ var at: [5]JumpTrail.Cell = undefined;
+ const lit = g.trail.see(if (surface.cursor) |cu| .{ cu.x, cu.y } else null, on, now_ns, &at);
+ if (lit.len == 0) return;
+ const cursor = surface.cursor.?;
+ const body = for (surface.regionList()) |region| {
+ if (region.kind == .body and cursor.x >= region.rect.x and cursor.x < @as(u32, region.rect.x) + region.rect.w and
+ cursor.y >= region.rect.y and cursor.y < @as(u32, region.rect.y) + region.rect.h) break region.rect;
+ } else return;
+ const page = surface.chrome.page orelse bg_default;
+ const w: f32 = @floatFromInt(g.cell_w);
+ const h: f32 = @floatFromInt(g.cell_h);
+ for (lit) |cell| {
+ if (cell.x < body.x or cell.y < body.y or cell.x >= @as(i32, body.x) + body.w or cell.y >= @as(i32, body.y) + body.h) continue;
+ const under = &surface.cells[@as(usize, @intCast(cell.y)) * surface.cols + @as(usize, @intCast(cell.x))];
+ // On the page's own ground alone: never a selection or a match.
+ const ground: [3]u8 = if (under.default) page else switch (under.style.bg) {
+ .rgb => |rgb| rgb,
+ else => page,
+ };
+ if (!std.mem.eql(u8, &ground, &page)) continue;
+ var color = overlayRgb(surface.chrome.fg orelse fg_default);
+ color.a = cell.strength;
+ const x0 = @as(f32, @floatFromInt(cell.x)) * w;
+ const y0 = @as(f32, @floatFromInt(cell.y)) * h;
+ builder.addRect(x0, y0, x0 + w, y0 + h, color);
+ }
+}
+
+test "a jump's trail is drawn behind the cursor in its body, and gone by 120 ms" {
+ var cells: [80 * 4]pardes.Cell = @splat(.{});
+ var surface: pardes.Surface = .{ .cols = 80, .rows = 4, .cells = &cells };
+ surface.regions[0] = .{ .kind = .body, .rect = .{ .x = 2, .y = 0, .w = 78, .h = 4 } };
+ surface.nregions = 1;
+ var g = testGui(10, 20, 8, 16);
+ var vertices: [5 * 6]OverlayVertex = undefined;
+ var builder: OverlayBuilder = .{ .vertices = &vertices, .win_w = 800, .win_h = 80 };
+ const ms = std.time.ns_per_ms;
+ surface.cursor = .{ .x = 4, .y = 1 };
+ appendJumpTrail(&g, true, &surface, 1000 * ms, &builder);
+ try std.testing.expectEqual(@as(usize, 0), builder.len);
+ surface.cursor = .{ .x = 14, .y = 1 };
+ appendJumpTrail(&g, true, &surface, 1016 * ms, &builder);
+ try std.testing.expect(builder.len >= 3 * 6 and builder.len <= 5 * 6);
+ // On the cursor's row, behind it, never its own cell.
+ for (vertices[0..builder.len]) |v| {
+ const x = (v.x + 1) * 400;
+ const y = (1 - v.y) * 40;
+ try std.testing.expect(y >= 20 - 0.01 and y <= 40 + 0.01);
+ try std.testing.expect(x >= 50 - 0.01 and x <= 140 + 0.01);
+ }
+ try std.testing.expect(g.trail.active);
+ builder.len = 0;
+ appendJumpTrail(&g, true, &surface, 1150 * ms, &builder);
+ try std.testing.expectEqual(@as(usize, 0), builder.len);
+ try std.testing.expect(!g.trail.active);
+}
+
/// The workspace tag's pet (the Pet setting, gui/pet.zig): in the blank
/// end of the grid's first row, past the tag's text, in the tag's colours,
/// on the window's own clock. Nothing of it reaches the core.