diff options
Diffstat (limited to 'src/gui/gui.zig')
| -rw-r--r-- | src/gui/gui.zig | 112 |
1 files changed, 6 insertions, 106 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 2c2f53c4..ee565aeb 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -13,7 +13,6 @@ const look = @import("../look.zig"); const message = pardes.Messages.Message; const file_watch = @import("../file_watch.zig"); const deck = @import("deck.zig"); -const pet = @import("pet.zig"); const fonts = @import("../fonts.zig"); // the fallback faces const selection_pipe = @import("../selection_pipe.zig"); const c_heap = @import("c_heap"); @@ -240,9 +239,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 cursor's glide quad: the chrome is +// decor. +const max_overlay_vertices: usize = 6; const font_px_step: f32 = 2.0; const font_px_min: f32 = 8.0; @@ -1137,7 +1136,6 @@ const Gui = struct { words: Words = .{}, touch: Touch = .{}, - pet_state: pet.State = .{}, live_ctrl: bool = false, live_alt: bool = false, @@ -1434,7 +1432,7 @@ const Group = struct { /// standing still), a group for each track in paint order (tier 2 moving and /// opening, tier 3 closing), tier 4 (floating: the notices, then the guides /// and the debug box, which the core paints over them) and tier 5 (ink: the -/// bar cursors; the pet and the cursor's glide draw after it). Tier 1 is the +/// bar cursors; the cursor's glide draws after it). Tier 1 is the /// focus lift, which does not exist yet. const Groups = struct { items: [pardes.MAX_PANES * 2 + 4]Group = @splat(.{}), @@ -5862,7 +5860,7 @@ fn renderFrame( if (!pdf_focus) core.frames.scroll = g.glide.follow.offset; core.frames.caret = caretRow(g, surface) orelse 0; const cursors_shown = groups.tracks == 0 and !quad_mode; - var overlay_count = buildOverlay(g, core, surface, sw, sh); + var overlay_count = buildOverlay(g, surface, sw, sh); if (overlay_count != 0 and !uploadOverlayGpu(g, cmd, overlay_count)) overlay_count = 0; if (!prepareNativeImages(g, gpa, cmd, surface, &groups, sw, sh)) { @@ -9882,18 +9880,15 @@ fn cursorDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, if (box.bar) try addDecor(g, gpa, box.x0, box.y0, box.x1, box.y1, box.rgb, 1, null, win_w, win_h); } -/// The triangle overlay: the workspace pet and the cursor's glide, over -/// everything. +/// The triangle overlay: the cursor's glide, over everything. fn buildOverlay( g: *Gui, - core: *const pardes.Pardes, surface: *const pardes.Surface, sw: u32, sh: u32, ) u32 { 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, core, surface, &builder); appendCursorGlide(g, surface, &builder); return @intCast(builder.len); } @@ -9936,81 +9931,6 @@ fn appendCursorGlide(g: *Gui, surface: *const pardes.Surface, builder: *OverlayB builder.addTri(px[0][0], px[0][1], px[2][0], px[2][1], px[3][0], px[3][1], color); } -fn appendWorkspacePet(g: *Gui, core: *const pardes.Pardes, surface: *const pardes.Surface, builder: *OverlayBuilder) void { - const kind: pet.Kind = @fromBackingInt(@intCast(@backingInt(core.settings.pet))); - if (kind == .off or surface.rows == 0 or surface.cols == 0) { - g.pet_state = .{}; - return; - } - // Read only the rendered global row. No pane/column tags, status text or - // mouse targets are changed; editing the workspace tag leaves it be. - var occupied: usize = 0; - for (surface.cells[0..surface.cols], 0..) |*cell, i| { - if (cellCodepoint(cell) != ' ') occupied = i + 1; - } - const band_top: f32 = @floatFromInt(taglineBandOffset(0, builder.win_h, g.cell_h, g.tagline_height)); - const region = if (occupied >= surface.cols) null else pet.lane( - occupied, - @floatFromInt(g.tagline_width), - builder.win_w, - band_top, - @floatFromInt(g.tagline_height), - ); - // SDL's regular pump already wakes at least every 16 ms. Quantization in - // sample keeps this independent of input, render rate and scene effects, - // without creating another timer or forcing core animation ticks. - const pose = g.pet_state.sample(kind, c.SDL_GetTicks(), region) orelse return; - const ink = overlayRgb(core.chromeTheme().tag_fg); - const eye = overlayRgb(core.chromeTheme().tag_bg); - // Behind the cursor: the overlay is over the cells, so the pixels a - // cursor covers are left out. - var boxes: [max_cursors]CursorBox = undefined; - const cursors = boxes[0..cursorBoxes(g, surface, fixedCellLayout(g), builder.win_h, &boxes)]; - for (0..pet.height) |y| for (0..pet.width) |x| { - const color = pet.pixel(kind, pose, x, y); - if (color == 0) continue; - const x0 = pose.x + @as(f32, @floatFromInt(x)) * pose.scale; - const y0 = pose.y + @as(f32, @floatFromInt(y)) * pose.scale; - const covered = for (cursors) |box| { - if (x0 < box.x1 and x0 + pose.scale > box.x0 and y0 < box.y1 and y0 + pose.scale > box.y0) break true; - } else false; - if (covered) continue; - builder.addRect(x0, y0, x0 + pose.scale, y0 + pose.scale, if (color == 2) eye else ink); - }; -} - -test "pet overlay stays beyond workspace text and keeps going while its tag is edited" { - std.testing.refAllDecls(pet); - const core = try pardes.Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 }); - defer core.deinit(); - core.settings.pet = .cat; - var cells: [80]pardes.Cell = @splat(.{}); - const surface: pardes.Surface = .{ .cols = 80, .rows = 1, .cells = &cells }; - for ("Workspace Commands", 0..) |ch, i| { - cells[i].text[0] = ch; - cells[i].len = 1; - cells[i].default = false; - } - var g = testGui(10, 20, 8, 16); - var vertices: [pet.max_vertices]OverlayVertex = undefined; - var builder: OverlayBuilder = .{ .vertices = &vertices, .win_w = 800, .win_h = 480 }; - appendWorkspacePet(&g, core, &surface, &builder); - try std.testing.expect(builder.len > 0); - for (vertices[0..builder.len]) |v| { - const x = (v.x + 1) * 400; - const y = (1 - v.y) * 240; - try std.testing.expect(x >= 20 * 8 - 0.01); - try std.testing.expect(y >= 0 and y < 20); - } - const before = g.pet_state; - pardes.tagline.enterHeader(core, null); - builder.len = 0; - appendWorkspacePet(&g, core, &surface, &builder); - try std.testing.expect(builder.len > 0); - try std.testing.expectEqual(before.tick, g.pet_state.tick); - try std.testing.expectEqual(before.x, g.pet_state.x); -} - fn cursorColor(chrome: *const pardes.Chrome, cell: *const pardes.Cell, role: pardes.FontRole) [3]u8 { return if (role == .tagline) switch (cell.style.fg) { .rgb => |rgb| rgb, @@ -10018,15 +9938,6 @@ fn cursorColor(chrome: *const pardes.Chrome, cell: *const pardes.Cell, role: par } else chrome.fg orelse fg_default; } -fn overlayRgb(rgb: [3]u8) OverlayColor { - return .{ - .r = @as(f32, @floatFromInt(rgb[0])) / 255.0, - .g = @as(f32, @floatFromInt(rgb[1])) / 255.0, - .b = @as(f32, @floatFromInt(rgb[2])) / 255.0, - .a = 1, - }; -} - fn uploadOverlayGpu(g: *Gui, cmd: *c.SDL_GPUCommandBuffer, vertex_count: u32) bool { const byte_len: u32 = vertex_count * @sizeOf(OverlayVertex); const ptr = c.SDL_MapGPUTransferBuffer(g.device, g.overlay_vxfer, false) orelse return false; @@ -10088,17 +9999,6 @@ const OverlayBuilder = struct { b.addVertex(x2, y2, color); } - fn addRect(b: *OverlayBuilder, x0_in: f32, y0_in: f32, x1_in: f32, y1_in: f32, color: OverlayColor) void { - if (b.len + 6 > b.vertices.len) return; - const x0 = std.math.clamp(@min(x0_in, x1_in), 0.0, b.win_w); - const x1 = std.math.clamp(@max(x0_in, x1_in), 0.0, b.win_w); - const y0 = std.math.clamp(@min(y0_in, y1_in), 0.0, b.win_h); - const y1 = std.math.clamp(@max(y0_in, y1_in), 0.0, b.win_h); - if (x1 <= x0 or y1 <= y0) return; - b.addTri(x0, y0, x1, y0, x1, y1, color); - b.addTri(x0, y0, x1, y1, x0, y1, color); - } - }; fn envU16(env: *std.process.Environ.Map, name: []const u8) ?u16 { |
