diff options
Diffstat (limited to 'src/gui/gui.zig')
| -rw-r--r-- | src/gui/gui.zig | 535 |
1 files changed, 13 insertions, 522 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 24b15b35..4f82d246 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -425,10 +425,8 @@ const CellInstance = extern struct { br: f32, bg: f32, bb: f32, - /// The flags (the high bits, ui.vert.glsl), and the theme's dots' - /// offset (G13's parallax) as a float's bits. + /// The flags (the high bits, ui.vert.glsl). effect: u32 = 0, - serial: u32 = 0, /// A clip rectangle in target pixels; x1 < x0 is none (ui.vert.glsl). clip_x0: f32 = 0, clip_y0: f32 = 0, @@ -457,14 +455,7 @@ const ImageInstance = extern struct { v1: f32, }; -const clear_bg_bit: u32 = 0x4000_0000; const opaque_bg_bit: u32 = 0x2000_0000; -/// Decor that is a checker (decor.frag.glsl). -const checker_bit: u32 = 0x0800_0000; -/// A cell on the page's ground under the theme's dots, and a file name's -/// cell that casts the theme's shadow (ui.frag.glsl, Chrome.decor_*). -const dotted_bit: u32 = 0x1000_0000; -const title_bit: u32 = 0x0800_0000; const PreparedImage = struct { place: pardes.ImagePlace, @@ -472,9 +463,9 @@ const PreparedImage = struct { }; test "the shader instance ABI: the flags after the colours, the clip after them" { - try std.testing.expectEqual(@as(usize, 80), @sizeOf(CellInstance)); + try std.testing.expectEqual(@as(usize, 76), @sizeOf(CellInstance)); try std.testing.expectEqual(@as(usize, 56), @offsetOf(CellInstance, "effect")); - try std.testing.expectEqual(@as(usize, 64), @offsetOf(CellInstance, "clip_x0")); + try std.testing.expectEqual(@as(usize, 60), @offsetOf(CellInstance, "clip_x0")); try std.testing.expectEqual(@as(usize, 32), @sizeOf(ImageInstance)); } @@ -949,10 +940,6 @@ const Gui = struct { device: *c.SDL_GPUDevice, swapchain_format: c.SDL_GPUTextureFormat, pipeline: *c.SDL_GPUGraphicsPipeline, - /// The cell pipeline, blending premultiplied over what is drawn under: - /// for a frame with a theme's tag plaques, whose blank tag cells let - /// them show (tagPlaques). - pipeline_over: *c.SDL_GPUGraphicsPipeline, decor_pipeline: *c.SDL_GPUGraphicsPipeline, overlay_pipeline: *c.SDL_GPUGraphicsPipeline, image_pipeline: *c.SDL_GPUGraphicsPipeline, @@ -1283,9 +1270,6 @@ const Group = struct { image_count: u32 = 0, decor_start: u32 = 0, decor_count: u32 = 0, - /// The first `under_count` of the group's decor are drawn before its - /// cells, under them (a theme's tag plaques, whose cells let them show). - under_count: u32 = 0, }; /// The frame's draw groups, bottom to top: the page and the panes, the @@ -1562,7 +1546,6 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, di const atlas_xfer = c.SDL_CreateGPUTransferBuffer(device, &ax_info) orelse return error.GpuCreate; const pipeline = try makePipeline(device, swapchain_format, vert_spv, frag_spv, 1, 1, cell_input, std.mem.zeroes(c.SDL_GPUColorTargetBlendState)); - const pipeline_over = try makePipeline(device, swapchain_format, vert_spv, frag_spv, 1, 1, cell_input, premultipliedBlend()); const decor_pipeline = try makePipeline(device, swapchain_format, vert_spv, decor_frag_spv, 0, 1, cell_input, backgroundLayerBlend()); const overlay_pipeline = try makePipeline(device, swapchain_format, overlay_vert_spv, overlay_frag_spv, 0, 1, overlay_input, backgroundLayerBlend()); const image_pipeline = try makePipeline(device, swapchain_format, image_vert_spv, image_frag_spv, 1, 1, image_input, backgroundLayerBlend()); @@ -1587,7 +1570,6 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, di .device = device, .swapchain_format = swapchain_format, .pipeline = pipeline, - .pipeline_over = pipeline_over, .decor_pipeline = decor_pipeline, .overlay_pipeline = overlay_pipeline, .image_pipeline = image_pipeline, @@ -1629,7 +1611,6 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, di // regrown to; the image ones are released below. defer { c.SDL_ReleaseGPUGraphicsPipeline(device, g.pipeline); - c.SDL_ReleaseGPUGraphicsPipeline(device, g.pipeline_over); c.SDL_ReleaseGPUGraphicsPipeline(device, g.decor_pipeline); c.SDL_ReleaseGPUGraphicsPipeline(device, g.overlay_pipeline); c.SDL_ReleaseGPUTexture(device, g.atlas_tex); @@ -5422,32 +5403,6 @@ fn renderFrame( // this frame against the last (the glide follows it from there). if (g.glide.pending) g.glide.measure(gpa, surface); if (g.glide.moving()) g.glide.advance(g.glide.now_ns, g.glide.motion); - cell_decor = CellDecor.of(chrome); - plaque_through_len = 0; - // G13: a body's dots follow its text at a quarter of its speed: its - // first line, and a glide's picture offset, in rows. - if (chrome.fx & 8 != 0 and chrome.decor_dots != null) for (surface.regionList()) |region| { - if (region.kind != .body or cell_decor.nbodies == cell_decor.bodies.len) continue; - var rows: f32 = @floatFromInt(region.line); - if (g.glide.moving() and g.glide.pane == region.owner) rows += g.glide.follow.offset; - const period = cell_decor.uniforms[4]; - cell_decor.bodies[cell_decor.nbodies] = bodyPixels(region, layout); - cell_decor.shifts[cell_decor.nbodies] = @mod(-rows * layout.h * 0.25, period); - cell_decor.nbodies += 1; - }; - // Plaques need an opaque window: with WindowOpacity under 100 the cells - // are drawn as they are, and the plaques not at all. - cell_decor.plaques_off = backgroundOpacity(g.applied_window_opacity) < 1; - if (chrome.decor_box_border != null and !cell_decor.plaques_off) { - cell_decor.grounds = .{ chrome.tag_bg, chrome.tag_focus_bg }; - for (surface.regionList()) |region| { - if (region.kind != .tag and region.kind != .column_tag and region.kind != .workspace_tag) continue; - if (cell_decor.nplaques == cell_decor.plaques.len) break; - const plaque = plaqueBox(g, chrome, surface.regionList(), region, layout, win_w, win_h) orelse continue; - cell_decor.plaques[cell_decor.nplaques] = plaque.band; - cell_decor.nplaques += 1; - } - } var groups: Groups = .{}; // While the cursor glides or blinks the cells' cursors are not drawn; // the focused one is the overlay's quad. One or the other every frame @@ -5592,25 +5547,6 @@ fn renderFrame( const scrolling: ?usize = if (g.glide.follow.offset != 0) g.glide.pane else g.scroll_pane; const held: u16 = if (scrolling) |id| if (core.panes[id]) |pane| pane.context_rows else 0 else 0; shifted = emitScrollRows(g, instances, cell_total, surface, layout, win_w, win_h, page, held); - // Over a theme's plaques a see-through cell with no ink blends to - // the plaque under it, so it draws nothing: its quad goes, and the - // cells are drawn unblended (a third of the GPU's frame at 4K) - // unless one see-through cell does have ink, or the page itself is - // see-through. - if (cell_decor.nplaques != 0) { - const space_u = @as(f32, @floatFromInt(g.space_slot.u)) / @as(f32, @floatFromInt(atlas_w)); - const space_v = @as(f32, @floatFromInt(g.space_slot.v)) / @as(f32, @floatFromInt(atlas_h)); - if (plaque_through_len > plaque_through.len) cell_decor.inked_clear = true; - for (plaque_through[0..@min(plaque_through_len, plaque_through.len)]) |at| { - const instance = &instances[at]; - // A grip's button takes its cell's ground back (emitSurfaceCell). - if (instance.effect & clear_bg_bit == 0) continue; - if (instance.u0 == space_u and instance.v0 == space_v) { - instance.x1 = instance.x0; - instance.y1 = instance.y0; - } else cell_decor.inked_clear = true; - } - } @memcpy(instances[cell_total + shifted ..][0..decor_len], g.decor.items); c.SDL_UnmapGPUTransferBuffer(g.device, g.vxfer.?); @@ -5631,18 +5567,9 @@ fn renderFrame( const whole = c.SDL_Rect{ .x = 0, .y = 0, .w = @intCast(sw), .h = @intCast(sh) }; const decor_base = cell_total + shifted; for (groups.items[0..groups.len], 0..) |group, index| { - if (group.under_count != 0 and g.vbuf != null) { - c.SDL_BindGPUGraphicsPipeline(rp, g.decor_pipeline); - pushLayerOpacity(cmd, rp, background_opacity); - const binding = c.SDL_GPUBufferBinding{ .buffer = g.vbuf.?, .offset = (decor_base + group.decor_start) * @sizeOf(CellInstance) }; - c.SDL_BindGPUVertexBuffers(rp, 0, &binding, 1); - c.SDL_DrawGPUPrimitives(rp, 6, group.under_count, 0, 0); - } const has_shifted = index == 0 and shifted != 0; if ((group.cell_count != 0 or has_shifted) and g.vbuf != null) { - // Blended over what is under: a theme's plaques show through - // blank tag cells. - c.SDL_BindGPUGraphicsPipeline(rp, if (cell_decor.inked_clear) g.pipeline_over else g.pipeline); + c.SDL_BindGPUGraphicsPipeline(rp, g.pipeline); const samp_binding = c.SDL_GPUTextureSamplerBinding{ .texture = g.atlas_tex, .sampler = g.atlas_sampler }; c.SDL_BindGPUFragmentSamplers(rp, 0, &samp_binding, 1); if (group.cell_count != 0) { @@ -5660,13 +5587,13 @@ fn renderFrame( } } if (group.image_count != 0) drawNativeImagesGpu(g, rp, group, whole); - if (group.decor_count > group.under_count and g.vbuf != null) { + if (group.decor_count != 0 and g.vbuf != null) { c.SDL_BindGPUGraphicsPipeline(rp, g.decor_pipeline); // Ink keeps its colour at any WindowOpacity. pushLayerOpacity(cmd, rp, if (index == groups.ink) 1 else background_opacity); - const binding = c.SDL_GPUBufferBinding{ .buffer = g.vbuf.?, .offset = (decor_base + group.decor_start + group.under_count) * @sizeOf(CellInstance) }; + const binding = c.SDL_GPUBufferBinding{ .buffer = g.vbuf.?, .offset = (decor_base + group.decor_start) * @sizeOf(CellInstance) }; c.SDL_BindGPUVertexBuffers(rp, 0, &binding, 1); - c.SDL_DrawGPUPrimitives(rp, 6, group.decor_count - group.under_count, 0, 0); + c.SDL_DrawGPUPrimitives(rp, 6, group.decor_count, 0, 0); } } drawOverlayGpu(g, cmd, rp, overlay_count); @@ -5898,9 +5825,6 @@ fn emitTagLayer(g: *Gui, instances: [*]CellInstance, next: *u32, layer: *const p const y = layer.viewport.y + @as(u16, @intCast(index)); const top = @as(f32, @floatFromInt(y)) * bh; emitInstance(g, instances, next.*, 0, y, .{ .w = band_right - left, .h = bh, .x_off = left, .y_off = slide }, win_w, win_h, .body, (&background)[0..1], 0, null, false, page); - // A theme's plaque is drawn under the band: the band's own ground - // lets it show (tagPlaques). - if (cell_decor.nplaques != 0 and cell_decor.inPlaque(left + 0.5, top + 0.5)) plaqueThrough(instances, next.*); if (slide != 0) clipInstance(&instances[next.*], .{ -1e9, top, 1e9, 1e9 }, win_w, win_h); next.* += 1; const cells = layer.cells[index * layer.cols ..][0..layer.cols]; @@ -6067,13 +5991,6 @@ fn emitSurfaceCell( // this underlay at tagline height leaves page-colored gutters between // adjacent workspace, column and pane tags at TaglineSize < 100. emitInstance(g, instances, next.*, col, row, body_layout, win_w, win_h, .body, (&band_base)[0..1], 0, null, false, page); - // Over a theme's plaque the underlay lets it show (tagPlaques), - // in a grip's cell too where the plaque reaches into it past the - // button (which is drawn over the cells). - const cell_x = @as(f32, @floatFromInt(col)) * body_layout.w + body_layout.x_off; - const cell_y = @as(f32, @floatFromInt(row)) * body_layout.h + body_layout.y_off + 0.5; - if (cell_decor.nplaques != 0 and cell_decor.inPlaque(if (here.grip) cell_x + body_layout.w - 0.5 else cell_x + 0.5, cell_y)) - plaqueThrough(instances, next.*); next.* += 1; // Tag glyphs keep their font size inside a full physical-width grip. // A pane's grip cells are the cell shells' form (a dirty `*`): the @@ -6134,7 +6051,6 @@ fn emitSurfaceCell( base.bg = own[1]; base.bb = own[2]; } - base.effect &= ~clear_bg_bit; clipInstance(base, .{ b[0], -1e9, b[2], 1e9 }, win_w, win_h); // Over it, only its own glyph; the band round it and the ring // are decor (gripDecor). @@ -6144,12 +6060,10 @@ fn emitSurfaceCell( instances[next.*].v0 = @as(f32, @floatFromInt(g.space_slot.v)) / atlas_h; instances[next.*].v1 = @as(f32, @floatFromInt(g.space_slot.v + g.tagline_height)) / atlas_h; } - // Its ground is the fill again (a see-through ground would be - // written, not blended, in an opaque window). + // Its ground is the fill again. instances[next.*].br = base.br; instances[next.*].bg = base.bg; instances[next.*].bb = base.bb; - instances[next.*].effect &= ~clear_bg_bit; clipInstance(&instances[next.*], b, win_w, win_h); } else if (inset > 0) { instances[next.*].x0 += @as(f32, @floatFromInt(inset)) / win_w * 2; @@ -6334,27 +6248,6 @@ fn emitInstance( // A block cursor is foreground UI ink, even though its color is carried // in the reversed cell background. Keep it visible at WindowOpacity 0. if (is_cursor) instances[idx].effect |= opaque_bg_bit; - // The theme's ornament (cell_decor): dots on the page's own ground, a - // shadow under a file name's letters. Never on a cursor. - if (!is_cursor) { - // A blank cell on a tag's ground inside a plaque: the plaque shows. - if (cell_decor.nplaques != 0 and resolved.role == .tagline and cellCodepoint(&line[at]) == ' ' and - (std.mem.eql(u8, &resolved.bg, &cell_decor.grounds[0]) or std.mem.eql(u8, &resolved.bg, &cell_decor.grounds[1])) and - (cell_decor.inPlaque(px0 + 0.5, py0 + 0.5) or cell_decor.inPlaque(px0 + layout.w - 0.5, py0 + 0.5))) - plaqueThrough(instances, idx); - if (cell_decor.dots) |dotted| { - if (std.mem.eql(u8, &resolved.bg, &dotted)) { - instances[idx].effect |= dotted_bit; - // G13: the dots under a body move with its text, a quarter - // as far; the serial slot carries it (the shader reads it - // as the dots' offset alone). - instances[idx].serial = @bitCast(cell_decor.parallaxAt(px0 + 0.5, py0 + 0.5)); - } - } - if (cell_decor.title) |inks| { - if (resolved.role == .tagline and (std.mem.eql(u8, &resolved.fg, &inks[0]) or std.mem.eql(u8, &resolved.fg, &inks[1]))) instances[idx].effect |= title_bit; - } - } } test "block cursor alone overrides transparent cell background" { @@ -6367,125 +6260,6 @@ test "block cursor alone overrides transparent cell background" { } } -test "lapis dots only the page's own ground and shadows only a file name, never a cursor" { - var g = testGui(10, 20, 8, 16); - const page: [3]u8 = .{ 0x0a, 0x10, 0x30 }; - const name: [3]u8 = .{ 0xe8, 0xc4, 0x6a }; - var chrome: pardes.Chrome = .{ .page = page, .decor_dots = .{ 1, 2, 3 }, .decor_dot_alpha = 0x22, .decor_title = .{ 4, 5, 6 }, .name_ink = name, .active_name_ink = name }; - cell_decor = CellDecor.of(&chrome); - defer cell_decor = .{}; - const on_page: pardes.Cell = .{ .default = false, .style = .{ .fg = .{ .rgb = .{ 200, 200, 200 } }, .bg = .{ .rgb = page } } }; - const selected: pardes.Cell = .{ .default = false, .style = .{ .fg = .{ .rgb = .{ 0, 0, 0 } }, .bg = .{ .rgb = name } } }; - const title: pardes.Cell = .{ .default = false, .style = .{ .fg = .{ .rgb = name }, .bg = .{ .rgb = .{ 0x0f, 0x1a, 0x4a } }, .font_role = .tagline } }; - const plain_tag: pardes.Cell = .{ .default = false, .style = .{ .fg = .{ .rgb = .{ 0x9a, 0xa6, 0xd9 } }, .bg = .{ .rgb = .{ 0x0f, 0x1a, 0x4a } }, .font_role = .tagline } }; - var instances: [1]CellInstance = undefined; - const Case = struct { cell: pardes.Cell, role: pardes.FontRole, cursor: bool, dotted: bool, shadowed: bool }; - for ([_]Case{ - .{ .cell = on_page, .role = .body, .cursor = false, .dotted = true, .shadowed = false }, - .{ .cell = on_page, .role = .body, .cursor = true, .dotted = false, .shadowed = false }, - .{ .cell = selected, .role = .body, .cursor = false, .dotted = false, .shadowed = false }, - .{ .cell = title, .role = .tagline, .cursor = false, .dotted = false, .shadowed = true }, - .{ .cell = title, .role = .tagline, .cursor = true, .dotted = false, .shadowed = false }, - .{ .cell = plain_tag, .role = .tagline, .cursor = false, .dotted = false, .shadowed = false }, - }) |case| { - emitInstance(&g, &instances, 0, 0, 0, fixedCellLayout(&g), 800, 480, case.role, (&case.cell)[0..1], 0, null, case.cursor, page); - try std.testing.expectEqual(case.dotted, instances[0].effect & dotted_bit != 0); - try std.testing.expectEqual(case.shadowed, instances[0].effect & title_bit != 0); - } - // A theme without decor marks nothing. - chrome = .{ .page = page }; - cell_decor = CellDecor.of(&chrome); - emitInstance(&g, &instances, 0, 0, 0, fixedCellLayout(&g), 800, 480, .body, (&on_page)[0..1], 0, null, false, page); - try std.testing.expectEqual(@as(u32, 0), instances[0].effect & (dotted_bit | title_bit)); -} - -test "lapis plaques stay in their tag's band, clear of every grip; only the focused one is striped" { - const gpa = std.testing.allocator; - const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 }); - defer core.deinit(); - _ = try core.newShell(1, ""); - try std.testing.expect(pardes.layout.splitColumn(core, 0, 1, false)); - try std.testing.expect(core.executeBuiltinLine(0, "Theme lapis")); - for (0..40) |_| core.update(.tick); - core.sync(); - const s = try core.render(core.scratch.allocator()); - try std.testing.expect(s.chrome.decor_box_border != null and s.chrome.decor_checker != null and s.chrome.decor_dots != null and s.chrome.decor_title != null); - var g = testGui(16, 32, 12, 22); - defer g.decor.deinit(gpa); - display_scale = 1; - var groups: Groups = .{}; - try buildDecor(&g, gpa, s, &groups, fixedCellLayout(&g), 1280, 768, true); - const layout = fixedCellLayout(&g); - const under = g.decor.items[groups.items[0].decor_start..][0..groups.items[0].under_count]; - try std.testing.expect(under.len != 0); - var stripes: usize = 0; - var shadows: usize = 0; - for (under) |item| { - const r: [4]f32 = .{ (item.x0 + 1) / 2 * 1280, (1 - item.y0) / 2 * 768, (item.x1 + 1) / 2 * 1280, (1 - item.y1) / 2 * 768 }; - // Inside one tag's band, whole: never on a body, a grip or the - // next pane. A box stacked under another tag's lays its top frame - // over their shared edge, its own width up into the band above. - const home = for (s.regionList()) |region| { - if (region.kind != .tag and region.kind != .column_tag and region.kind != .workspace_tag) continue; - const band = plaqueBox(&g, &s.chrome, s.regionList(), region, layout, 1280, 768) orelse continue; - if (r[0] >= band.band[0] - 0.01 and r[1] >= band.band[1] - band.border - 0.01 and r[2] <= band.band[2] + 0.01 and r[3] <= band.band[3] + 0.01) break region; - } else return error.PlaqueOutsideItsBand; - // Clear of every grip's button: a plaque starts flush against it, - // in the gap between it and the text. - for (s.regionList()) |grip| { - if (grip.kind != .grip and grip.kind != .column_grip) continue; - const column = scrollColumn(&g, &s.chrome, grip.rect.x, layout); - const gx0 = column[0]; - const gx1 = column[1]; - const gy0 = @as(f32, @floatFromInt(grip.rect.y)) * 32; - const gy1 = @as(f32, @floatFromInt(grip.rect.y + grip.rect.h)) * 32; - try std.testing.expect(r[2] <= gx0 + 0.01 or r[0] >= gx1 - 0.01 or r[3] <= gy0 + 0.01 or r[1] >= gy1 - 0.01); - } - if (item.effect & checker_bit != 0) { - try std.testing.expect(home.kind == .tag and home.active); - stripes += 1; - } - const rgb: [3]u8 = .{ @intFromFloat(@round(item.br * 255)), @intFromFloat(@round(item.bg * 255)), @intFromFloat(@round(item.bb * 255)) }; - if (std.mem.eql(u8, &rgb, &s.chrome.decor_box_shadow.?)) shadows += 1; - } - try std.testing.expectEqual(@as(usize, 1), stripes); - try std.testing.expect(shadows >= 2); - // Stacked boxes share an edge and line up: a column's box spans its - // first pane's across, runs down to the edge that pane's frame lies - // over, and no shadow reaches the next column. - var stacks: usize = 0; - for (s.regionList()) |column| { - if (column.kind != .column_tag) continue; - const upper = plaqueBox(&g, &s.chrome, s.regionList(), column, layout, 1280, 768).?; - for (s.regionList()) |tag| { - if (tag.kind != .tag or tag.rect.y != column.rect.y + column.rect.h or tag.rect.x + tag.rect.w != column.rect.x + column.rect.w) continue; - const lower = plaqueBox(&g, &s.chrome, s.regionList(), tag, layout, 1280, 768).?; - try std.testing.expectEqual(upper.box[0], lower.box[0]); - // Flush against the grips' buttons, which line up too. - const grip = for (s.regionList()) |part| { - if (part.kind == .grip and part.owner == tag.owner) break part; - } else unreachable; - try std.testing.expectEqual(scrollColumn(&g, &s.chrome, grip.rect.x, layout)[1], lower.box[0]); - try std.testing.expectEqual(upper.box[2], lower.box[2]); - try std.testing.expectEqual(upper.band[3], upper.box[3]); - try std.testing.expectEqual(lower.band[1] - lower.border, lower.box[1]); - try std.testing.expectEqual(@as(f32, 0), upper.shadow[1]); - if (lower.band[2] < 1280) try std.testing.expect(lower.box[2] + lower.shadow[0] < lower.band[2]); - stacks += 1; - } - } - try std.testing.expectEqual(@as(usize, 2), stacks); - // The scroll track is chequered. - var checkers: usize = 0; - for (g.decor.items[groups.items[0].decor_start + groups.items[0].under_count ..]) |item| checkers += @intFromBool(item.effect & checker_bit != 0); - try std.testing.expect(checkers >= 1); - // No other theme draws any of it. - try std.testing.expect(core.executeBuiltinLine(0, "Theme forge")); - for (0..40) |_| core.update(.tick); - const plain = try core.render(core.scratch.allocator()); - try std.testing.expect(plain.chrome.decor_box_border == null and plain.chrome.decor_checker == null and plain.chrome.decor_dots == null and plain.chrome.decor_title == null); -} - fn cellCodepoint(cell: *const pardes.Cell) u32 { const grapheme = cell.grapheme(); return if (cell.default or grapheme.len == 0) ' ' else firstCp(grapheme); @@ -6785,7 +6559,6 @@ fn testGui(cell_w: u32, cell_h: u32, tagline_width: u32, tagline_height: u32) Gu .device = undefined, .swapchain_format = undefined, .pipeline = undefined, - .pipeline_over = undefined, .decor_pipeline = undefined, .overlay_pipeline = undefined, .image_pipeline = undefined, @@ -7276,7 +7049,7 @@ const cell_input: VertexInput = .{ .pitch = @sizeOf(CellInstance), .rate = c.SDL .{ .location = 1, .buffer_slot = 0, .format = c.SDL_GPU_VERTEXELEMENTFORMAT_FLOAT4, .offset = @offsetOf(CellInstance, "u0") }, .{ .location = 2, .buffer_slot = 0, .format = c.SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3, .offset = @offsetOf(CellInstance, "fr") }, .{ .location = 3, .buffer_slot = 0, .format = c.SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3, .offset = @offsetOf(CellInstance, "br") }, - .{ .location = 4, .buffer_slot = 0, .format = c.SDL_GPU_VERTEXELEMENTFORMAT_UINT2, .offset = @offsetOf(CellInstance, "effect") }, + .{ .location = 4, .buffer_slot = 0, .format = c.SDL_GPU_VERTEXELEMENTFORMAT_UINT, .offset = @offsetOf(CellInstance, "effect") }, .{ .location = 5, .buffer_slot = 0, .format = c.SDL_GPU_VERTEXELEMENTFORMAT_FLOAT4, .offset = @offsetOf(CellInstance, "clip_x0") }, } }; @@ -7329,20 +7102,6 @@ pub fn makePipeline( return c.SDL_CreateGPUGraphicsPipeline(device, &info) orelse error.GpuCreate; } -/// Premultiplied over: an opaque cell writes itself exactly, a see-through -/// one only its ink. -fn premultipliedBlend() c.SDL_GPUColorTargetBlendState { - var blend = std.mem.zeroes(c.SDL_GPUColorTargetBlendState); - blend.src_color_blendfactor = c.SDL_GPU_BLENDFACTOR_ONE; - blend.dst_color_blendfactor = c.SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; - blend.color_blend_op = c.SDL_GPU_BLENDOP_ADD; - blend.src_alpha_blendfactor = c.SDL_GPU_BLENDFACTOR_ONE; - blend.dst_alpha_blendfactor = c.SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; - blend.alpha_blend_op = c.SDL_GPU_BLENDOP_ADD; - blend.enable_blend = true; - return blend; -} - fn backgroundLayerBlend() c.SDL_GPUColorTargetBlendState { var blend = std.mem.zeroes(c.SDL_GPUColorTargetBlendState); blend.src_color_blendfactor = c.SDL_GPU_BLENDFACTOR_SRC_ALPHA; @@ -7672,24 +7431,6 @@ fn addDecor(g: *Gui, gpa: std.mem.Allocator, x0_in: f32, y0_in: f32, x1_in: f32, }); } -/// A checker (decor.frag.glsl): squares of `px` window pixels in `a` and -/// `b` from the quad's corner (lapis's scroll track); `stripes`, bands of -/// `px` across it instead (lapis's focused title bar), `a` first. -fn addPattern(g: *Gui, gpa: std.mem.Allocator, x0: f32, y0: f32, x1: f32, y1: f32, a: [3]u8, b: [3]u8, px: f32, stripes: bool, win_w: f32, win_h: f32) !void { - const first = g.decor.items.len; - try addDecor(g, gpa, x0, y0, x1, y1, a, 1, win_w, win_h); - if (g.decor.items.len == first) return; - const instance = &g.decor.items[first]; - instance.u0 = px; - instance.u1 = px; - instance.v0 = if (stripes) 1 else 0; - instance.v1 = if (stripes) 1 else 0; - instance.fr = @as(f32, @floatFromInt(b[0])) / 255.0; - instance.fg = @as(f32, @floatFromInt(b[1])) / 255.0; - instance.fb = @as(f32, @floatFromInt(b[2])) / 255.0; - instance.effect |= checker_bit; -} - /// A body region in window pixels. fn bodyPixels(region: pardes.Region, layout: CellLayout) [4]f32 { return .{ @@ -7711,9 +7452,6 @@ fn buildDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, g for (groups.items[0..groups.len], 0..) |*group, index| { group.decor_start = @intCast(g.decor.items.len); defer group.decor_count = @as(u32, @intCast(g.decor.items.len)) - group.decor_start; - // Under the cells: a theme's tag plaques. - if (index == 0) try tagPlaques(g, gpa, regions, chrome, layout, win_w, win_h); - group.under_count = @as(u32, @intCast(g.decor.items.len)) - group.decor_start; if (index == 0) { // The grips' buttons before any rule: the rules over their rows // cut them, and the band round them never covers a rule. @@ -7833,10 +7571,7 @@ fn paneDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, ti // the track edges it. const column = scrollColumn(g, chrome, rail.rect.x, layout); try addDecor(g, gpa, x0, y0, x0 + layout.w, y1, page, 1, win_w, win_h); - if (chrome.decor_checker) |gold| - try addPattern(g, gpa, column[0], y0, column[1], y1, chrome.scroll_track, gold, dp(@floatFromInt(@max(1, chrome.decor_checker_px))), false, win_w, win_h) - else - try addDecor(g, gpa, column[0], y0, column[1], y1, chrome.scroll_track, 1, win_w, win_h); + try addDecor(g, gpa, column[0], y0, column[1], y1, chrome.scroll_track, 1, win_w, win_h); if (rail.thumb_h != 0 and rail.thumb_span > 0) { // In pixels, not rows, and with the picture while it glides // or lags behind the core's rows (both in rows of the body). @@ -7899,235 +7634,11 @@ fn updateDisplayScale(window: *c.SDL_Window) void { display_scale = std.math.clamp(display_scale, 1, 4); } -/// A theme's ornament as the cell shader draws it (Chrome.decor_*), for the -/// frame being built: renderFrame sets it, writing a cell marks the cells -/// it falls on, and pushLayerOpacity hands the shader its colours and -/// sizes. ponytail: one window per process, as display_scale. -var cell_decor: CellDecor = .{}; -/// The cells this frame lets a plaque show through, by instance, for -/// renderFrame to drop the ones with no ink. Past its length the frame's -/// cells are blended instead. -var plaque_through: [16384]u32 = undefined; -var plaque_through_len: usize = 0; - -fn plaqueThrough(instances: [*]CellInstance, at: u32) void { - instances[at].effect |= clear_bg_bit; - if (plaque_through_len < plaque_through.len) plaque_through[plaque_through_len] = at; - plaque_through_len += 1; -} -const CellDecor = struct { - /// The page's ground, when the theme dots it. - dots: ?[3]u8 = null, - /// A file name's inks in a tag, when the theme shadows it. - title: ?[2][3]u8 = null, - /// UiUniforms after background_opacity (ui.frag.glsl): the dots' colour - /// and strength, their period and radii, the shadow's colour and offset. - uniforms: [12]f32 = @splat(0), - /// The tag plaques' bands (window pixels) and the tag grounds: a blank - /// tag cell there lets its plaque show through (tagPlaques). - plaques: [pardes.MAX_TAG_LAYERS][4]f32 = undefined, - nplaques: usize = 0, - grounds: [2][3]u8 = .{ .{ 0, 0, 0 }, .{ 0, 0, 0 } }, - plaques_off: bool = false, - /// A see-through cell over the plaques has ink of its own, so this - /// frame's cells are blended (renderFrame). - inked_clear: bool = false, - - /// G13: each body's rectangle and how far its dots have moved. - bodies: [pardes.MAX_PANES][4]f32 = undefined, - shifts: [pardes.MAX_PANES]f32 = undefined, - nbodies: usize = 0, - - fn parallaxAt(decor: *const CellDecor, x: f32, y: f32) f32 { - for (decor.bodies[0..decor.nbodies], decor.shifts[0..decor.nbodies]) |band, shift| - if (x >= band[0] and x < band[2] and y >= band[1] and y < band[3]) return shift; - return 0; - } - - fn inPlaque(decor: *const CellDecor, x: f32, y: f32) bool { - for (decor.plaques[0..decor.nplaques]) |band| - if (x >= band[0] and x < band[2] and y >= band[1] and y < band[3]) return true; - return false; - } - - fn of(chrome: *const pardes.Chrome) CellDecor { - var out: CellDecor = .{}; - if (chrome.decor_dots) |rgb| if (chrome.page) |page| { - out.dots = page; - out.uniforms[0..4].* = .{ unit(rgb[0]), unit(rgb[1]), unit(rgb[2]), unit(chrome.decor_dot_alpha) }; - out.uniforms[4..8].* = .{ dp(@floatFromInt(@max(2, chrome.decor_dot_px))), 0.75 * display_scale, 1.25 * display_scale, 0 }; - }; - if (chrome.decor_title) |rgb| { - out.title = .{ chrome.name_ink, chrome.active_name_ink }; - out.uniforms[8..12].* = .{ unit(rgb[0]), unit(rgb[1]), unit(rgb[2]), dp(@floatFromInt(@max(1, chrome.decor_title_px))) }; - } - return out; - } - - fn unit(v: u8) f32 { - return @as(f32, @floatFromInt(v)) / 255; - } -}; - /// A logical pixel size in the display's pixels: rounded, at least one. fn dp(logical: f32) f32 { return @max(1, @round(logical * display_scale)); } -/// A theme's tag plaques (Chrome.decor_box_*), drawn under the cells of -/// group `index`: each pane tag, and with the still panes the column and -/// workspace tags, becomes a framed box inside its own band with a hard -/// shadow down and right that stays inside the band too, so it never falls -/// on a body, a grip or the next pane. The focused pane's box is striped, -/// its words on plates of the tag's ground (their cells stay opaque; the -/// spaces between let the stripes through, emitInstance); a column or the -/// workspace takes a quieter box, a one-pixel frame and a two-pixel shadow. -fn tagPlaques(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, chrome: *const pardes.Chrome, layout: CellLayout, win_w: f32, win_h: f32) !void { - const border_rgb = chrome.decor_box_border orelse return; - if (cell_decor.plaques_off) return; - const page = chrome.page orelse bg_default; - // The workspace and column plaques first: a pane's plaque right under - // them shares their bottom edge (plaqueBox) and draws its frame last. - for ([_]bool{ false, true }) |panes| for (regions) |tag| { - const pane = tag.kind == .tag; - if (pane != panes) continue; - if (!pane and tag.kind != .column_tag and tag.kind != .workspace_tag) continue; - if (tag.rect.w == 0 or tag.rect.h == 0) continue; - const plaque = plaqueBox(g, chrome, regions, tag, layout, win_w, win_h) orelse continue; - const b = plaque.border; - const sh = plaque.shadow; - const fill = if (tag.active) chrome.tag_focus_bg else chrome.tag_bg; - // The band's own ground, then the shadow, the frame and the fill, - // each only where the ones over it leave it showing: all four are - // opaque, so that is the same picture drawn once, not four times. - const shadow: [4]f32 = .{ plaque.box[0] + sh[0], plaque.box[1] + sh[1], plaque.box[2] + sh[0], plaque.box[3] + sh[1] }; - const inner: [4]f32 = .{ plaque.box[0] + b, plaque.box[1] + b, plaque.box[2] - b, plaque.box[3] - b }; - try addDecorExcept(g, gpa, plaque.band, &.{ plaque.box, shadow }, page, win_w, win_h); - const shadow_rgb = chrome.decor_box_shadow orelse border_rgb; - try addDecorExcept(g, gpa, shadow, &.{plaque.box}, if (pane) shadow_rgb else mixRgb(shadow_rgb, page), win_w, win_h); - try addDecorExcept(g, gpa, plaque.box, &.{inner}, border_rgb, win_w, win_h); - if (pane and tag.active and chrome.decor_box_stripe != null) - try addPattern(g, gpa, inner[0], inner[1], inner[2], inner[3], chrome.decor_box_stripe.?, fill, dp(@floatFromInt(@max(1, chrome.decor_box_stripe_px))), true, win_w, win_h) - else - try addDecor(g, gpa, inner[0], inner[1], inner[2], inner[3], fill, 1, win_w, win_h); - }; -} - -/// Flat decor over `rect` (window pixels) less each of `holes`: up to four -/// strips round the first hole's part of it, each less the rest. -fn addDecorExcept(g: *Gui, gpa: std.mem.Allocator, rect: [4]f32, holes: []const [4]f32, rgb: [3]u8, win_w: f32, win_h: f32) std.mem.Allocator.Error!void { - if (rect[0] >= rect[2] or rect[1] >= rect[3]) return; - if (holes.len == 0) return addDecor(g, gpa, rect[0], rect[1], rect[2], rect[3], rgb, 1, win_w, win_h); - const hole = holes[0]; - const x0 = @max(rect[0], hole[0]); - const y0 = @max(rect[1], hole[1]); - const x1 = @min(rect[2], hole[2]); - const y1 = @min(rect[3], hole[3]); - if (x0 >= x1 or y0 >= y1) return addDecorExcept(g, gpa, rect, holes[1..], rgb, win_w, win_h); - for ([_][4]f32{ - .{ rect[0], rect[1], rect[2], y0 }, - .{ rect[0], y1, rect[2], rect[3] }, - .{ rect[0], y0, x0, y1 }, - .{ x1, y0, rect[2], y1 }, - }) |strip| try addDecorExcept(g, gpa, strip, holes[1..], rgb, win_w, win_h); -} - -test "decor less its holes covers each pixel of the rest once and none of the holes" { - const gpa = std.testing.allocator; - var g = testGui(1, 1, 1, 1); - defer g.decor.deinit(gpa); - const holes = [_][4]f32{ .{ 3, 2, 9, 6 }, .{ 5, 4, 12, 8 }, .{ 30, 30, 40, 40 } }; - try addDecorExcept(&g, gpa, .{ 1, 1, 11, 10 }, &holes, .{ 1, 2, 3 }, 16, 12); - for (0..12) |y| for (0..16) |x| { - const px: f32 = @as(f32, @floatFromInt(x)) + 0.5; - const py: f32 = @as(f32, @floatFromInt(y)) + 0.5; - var hits: usize = 0; - for (g.decor.items) |item| { - const r: [4]f32 = .{ (item.x0 + 1) / 2 * 16, (1 - item.y0) / 2 * 12, (item.x1 + 1) / 2 * 16, (1 - item.y1) / 2 * 12 }; - hits += @intFromBool(px > r[0] and px < r[2] and py > r[1] and py < r[3]); - } - const in_rect = px > 1 and px < 11 and py > 1 and py < 10; - const in_hole = for (holes) |h| { - if (px > h[0] and px < h[2] and py > h[1] and py < h[3]) break true; - } else false; - try std.testing.expectEqual(@as(usize, @intFromBool(in_rect and !in_hole)), hits); - }; -} - -const Plaque = struct { band: [4]f32, box: [4]f32, border: f32, shadow: [2]f32 }; - -/// A tag's plaque in window pixels: its band (the rows, from after the -/// grip to the end), the framed box round the tagline's text, and the -/// frame's and the shadow's widths, the shadow cut to what the band's slack -/// below the text and its right end leave. Null where there is no room. -/// Tags stacked on each other (the workspace's over the columns', a -/// column's over its first pane's) share one edge, the ruled one between -/// their bands: the upper box runs down to it and casts no shadow down, the -/// lower one's frame lies over it. Every box in a column spans the same -/// pixels across, right of the grips, its shadow short of the next column. -fn plaqueBox(g: *const Gui, chrome: *const pardes.Chrome, regions: []const pardes.Region, tag: pardes.Region, layout: CellLayout, win_w: f32, win_h: f32) ?Plaque { - const pane = tag.kind == .tag; - const first = tag.rect.y; - const last = tag.rect.y + tag.rect.h - 1; - // Flush against its grip's button, so the two read as one piece: the - // gap between button and text (the scroll gap) is the plaque's, and so - // is the cell before its text, so its frame is never under the first - // letter. A column's plaque starts where the pane's under it does. - const grip_kind: pardes.Region.Kind = if (tag.kind == .column_tag) .column_grip else .grip; - const x0 = for (regions) |grip| { - if (tag.kind != .workspace_tag and grip.kind == grip_kind and grip.owner == tag.owner) - break scrollColumn(g, chrome, grip.rect.x, layout)[1]; - } else @as(f32, @floatFromInt(tag.rect.x)) * layout.w; - const x1_cells = @as(f32, @floatFromInt(tag.rect.x + tag.rect.w)) * layout.w; - const window_edge = win_w - x1_cells < layout.w; - const x1 = if (window_edge) @max(x1_cells, win_w) else x1_cells; - const stacked_on = tagBandAt(regions, tag, .above); - const stacked_under = tagBandAt(regions, tag, .below); - const row_top = @as(f32, @floatFromInt(first)) * layout.h; - const row_bottom = @as(f32, @floatFromInt(last + 1)) * layout.h; - const text_top = row_top + @as(f32, @floatFromInt(taglineBandOffset(first, win_h, g.cell_h, g.tagline_height))); - const text_bottom = @as(f32, @floatFromInt(last)) * layout.h + @as(f32, @floatFromInt(taglineBandOffset(last, win_h, g.cell_h, g.tagline_height) + g.tagline_height)); - const border = @min(if (pane) dp(@floatFromInt(@max(1, chrome.decor_box_border_px))) else dp(1), @floor(text_top - row_top)); - if (border < 1) return null; - // The shadow's full offset to the right; down, what the slack under the - // text leaves (a pixel or three at a tagline under the body's size). - const want: f32 = if (pane) dp(@floatFromInt(chrome.decor_box_shadow_px)) else dp(2); - const drop = if (stacked_under) 0 else std.math.clamp(@floor(row_bottom - text_bottom - border), 0, want); - // Every box ends where a pane's does, short of the next column's rule - // by a pane frame's width past its shadow, so no shadow meets the rule - // and a column's box lines up with its panes'; the window's edge needs - // no gap. - const pane_shadow = dp(@floatFromInt(chrome.decor_box_shadow_px)); - const gap = @max(0, pane_shadow - want) + if (window_edge) 0 else dp(@floatFromInt(@max(1, chrome.decor_box_border_px))); - if (x1 - x0 < 4 * border + want + gap) return null; - return .{ - .band = .{ x0, row_top, x1, row_bottom }, - .box = .{ - x0, - if (stacked_on) row_top - border else text_top - border, - x1 - want - gap, - if (stacked_under) row_bottom else text_bottom + border, - }, - .border = border, - .shadow = .{ want, drop }, - }; -} - -/// Whether another tag's band (the workspace's, a column's, a pane's) meets -/// `tag`'s right above or below it, across some of its width. -fn tagBandAt(regions: []const pardes.Region, tag: pardes.Region, side: enum { above, below }) bool { - for (regions) |other| { - if (other.kind != .tag and other.kind != .column_tag and other.kind != .workspace_tag) continue; - if (other.rect.h == 0 or std.meta.eql(other.rect, tag.rect)) continue; - const meets = switch (side) { - .above => other.rect.y + other.rect.h == tag.rect.y, - .below => tag.rect.y + tag.rect.h == other.rect.y, - }; - if (meets and other.rect.x < tag.rect.x + tag.rect.w and tag.rect.x < other.rect.x + other.rect.w) return true; - } - return false; -} - /// The two short bars on each row of a grip with no mode glyph there, /// centered in its anchor. fn gripDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, cells: []const pardes.Cell, chrome: *const pardes.Chrome, layout: CellLayout, cols: u16, rows: u16, win_w: f32, win_h: f32) !void { @@ -8142,13 +7653,7 @@ fn gripDecor(g: *Gui, gpa: std.mem.Allocator, regions: []const pardes.Region, ce const left = @as(f32, @floatFromInt(grip.rect.x)) * layout.w; const right = @as(f32, @floatFromInt(grip.rect.x + grip.rect.w)) * layout.w; try addDecor(g, gpa, left, button[1], button[0], button[3], band, 1, win_w, win_h); - // Right of it, a theme's plaque starts flush against it (plaqueBox). - const plaqued = chrome.decor_box_border != null and !cell_decor.plaques_off; - if (!plaqued) try addDecor(g, gpa, button[2], button[1], right, button[3], band, 1, win_w, win_h); - // Its cells over the plaque's reach are let through (emitInstance): - // under the button's row, the band goes on as far as the plaque. - if (plaqued and grip.rect.h > 1) - try addDecor(g, gpa, left, button[3], button[2], @as(f32, @floatFromInt(grip.rect.y + grip.rect.h)) * layout.h, band, 1, win_w, win_h); + try addDecor(g, gpa, button[2], button[1], right, button[3], band, 1, win_w, win_h); if (grip.kind != .grip) continue; // acme's button ring, two pixels (ButtonBorder) inside the button: // the focused one's in its own fill. An unfocused dirty one keeps a @@ -8453,31 +7958,18 @@ test "decor is read from the regions" { try std.testing.expectEqual(@as(u32, 0), groups.items[groups.notices].decor_count); } -test "a body tells its first line, and lapis's dots under it move a quarter as far" { +test "a body tells its first line" { const gpa = std.testing.allocator; const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 }); defer core.deinit(); const pane = try core.setTestFile(std.mem.asBytes(&@as([80][5]u8, @splat("line\n".*)))); pane.scrollBy(8); - try std.testing.expect(core.executeBuiltinLine(0, "Theme lapis")); - core.settings.parallax = true; - for (0..40) |_| core.update(.tick); core.sync(); const s = try core.render(core.scratch.allocator()); const body = for (s.regionList()) |region| { if (region.kind == .body) break region; } else return error.NoBody; try std.testing.expectEqual(@as(i32, 8), body.line); - try std.testing.expect(s.chrome.fx & 8 != 0); - // The shift the cell shader is handed: a quarter of 8 rows of 20 px, - // upward, within the dots' period. - var decor = CellDecor.of(&s.chrome); - const period = decor.uniforms[4]; - decor.bodies[0] = .{ 0, 0, 800, 480 }; - decor.shifts[0] = @mod(-8.0 * 20.0 * 0.25, period); - decor.nbodies = 1; - try std.testing.expectApproxEqAbs(@mod(-40.0, period), decor.parallaxAt(10, 10), 1e-4); - try std.testing.expectEqual(@as(f32, 0), decor.parallaxAt(900, 10)); } const CursorBox = struct { x0: f32, y0: f32, x1: f32, y1: f32, rgb: [3]u8, bar: bool }; @@ -8635,8 +8127,7 @@ fn uploadOverlayGpu(g: *Gui, cmd: *c.SDL_GPUCommandBuffer, vertex_count: u32) bo } fn pushLayerOpacity(cmd: *c.SDL_GPUCommandBuffer, pass: ?*c.SDL_GPURenderPass, opacity: f32) void { - var uniforms = [4]f32{ opacity, 0, 0, 0 } ++ @as([12]f32, @splat(0)); - uniforms[4..].* = cell_decor.uniforms; + const uniforms = [4]f32{ opacity, 0, 0, 0 }; c.SDL_PushGPUFragmentUniformData(cmd, 0, &uniforms, @sizeOf(@TypeOf(uniforms))); // The source alpha is geometric/image coverage, not window opacity. Its // alpha contribution is multiplied by this constant separately, so a |
