diff options
Diffstat (limited to 'src/surface.zig')
| -rw-r--r-- | src/surface.zig | 144 |
1 files changed, 12 insertions, 132 deletions
diff --git a/src/surface.zig b/src/surface.zig index a5dbea8e..73789dce 100644 --- a/src/surface.zig +++ b/src/surface.zig @@ -2,6 +2,7 @@ //! the image placements laid over them, and the Surface that holds a frame. const pardes = @import("pardes.zig"); const std = @import("std"); +const plain = @import("plain"); const layout = @import("layout.zig"); const uucode = @import("uucode"); const vaxis = @import("vaxis"); @@ -11,56 +12,16 @@ const MAX_PANES = pardes.MAX_PANES; const Layer = @import("Layer.zig"); const MAX_TAG_LAYERS = pardes.MAX_TAG_LAYERS; -pub const Color = union(enum) { default, index: u8, rgb: [3]u8 }; - -pub const FontRole = enum(u8) { body, tagline }; - -pub const CellStyle = struct { - fg: Color = .default, - bg: Color = .default, - bold: bool = false, - dim: bool = false, - italic: bool = false, - blink: bool = false, - reverse: bool = false, - invisible: bool = false, - strikethrough: bool = false, - ul: enum(u3) { off, single, double, curly, dotted, dashed } = .off, - font_role: FontRole = .body, -}; - -pub const Cell = struct { - text: [7]u8 = @splat(' '), - len: u8 = 1, - style: CellStyle = .{}, - default: bool = true, - - pub fn grapheme(c: *const Cell) []const u8 { - return c.text[0..c.len]; - } - - pub fn visuallyEqual(a: *const Cell, b: *const Cell) bool { - if (a.default or b.default) return a.default and b.default; - return a.len == b.len and - std.mem.eql(u8, a.grapheme(), b.grapheme()) and - std.meta.eql(a.style, b.style); - } - - pub fn printableAscii(c: *const Cell) ?u8 { - if (c.default) return ' '; - if (c.len != 1) return null; - const byte = c.text[0]; - return if (byte >= ' ' and byte <= '~') byte else null; - } -}; - -/// A rectangle in pixels. -pub const RectPx = struct { - x: u32 = 0, - y: u32 = 0, - w: u32 = 0, - h: u32 = 0, -}; +// The plain records (src/plain/plain.zig) both the core and the terminal +// name, under the names the core has always called them. +pub const Color = plain.Color; +pub const FontRole = plain.FontRole; +pub const CellStyle = plain.CellStyle; +pub const Cell = plain.Cell; +pub const RectPx = plain.RectPx; +pub const RectCell = plain.RectCell; +pub const Raster = plain.Raster; +pub const Placement = plain.Placement; pub const PixelPoint = struct { x: u32, y: u32 }; @@ -113,73 +74,8 @@ pub fn containGeometry(iw: usize, ih: usize, max_w: u32, max_h: u32) ?NativeGeom return .{ .src = .{ .w = src_w, .h = src_h }, .dst = dst }; } -/// A rectangle in the frame's cells. -pub const RectCell = struct { x: u16 = 0, y: u16 = 0, w: u16 = 0, h: u16 = 0 }; - -/// The pixels a placement shows: RGBA, straight alpha, `stride` bytes a -/// row. They are the pane's, and stay put until its next frame. -pub const Raster = struct { - ptr: [*]const u8, - w: u32, - h: u32, - stride: u32, - - pub fn of(rgba: []const u8, w: usize, h: usize) Raster { - return .{ .ptr = rgba.ptr, .w = @intCast(w), .h = @intCast(h), .stride = @intCast(w * 4) }; - } - - pub fn bytes(r: Raster) []const u8 { - return r.ptr[0 .. @as(usize, r.stride) * r.h]; - } -}; -/// A picture over the frame's cells, which a frontend realises: the window -/// as a texture kept by `key`, the tty as a kitty image, or either as glyph -/// art in `dst`'s cells (Art.zig, the frontends' own) where it cannot show -/// pixels or the pane asks for art. The frame lists them a pane at a time, -/// lowest first. -pub const Placement = struct { - pane: u8, - raster: Raster, - /// The part of `raster` shown. - src: RectPx, - /// The cells it lies over, which clip it. - dst: RectCell, - /// Where it goes in `dst`, in pixels from `dst`'s top left corner; - /// null: the frontend fits `src` there, no larger than it is, at the - /// top left (as glyph art, centred). - at: ?RectPx = null, - /// The pixels' identity (`keyOf`): one key is one picture, so a - /// frontend keeps what it uploaded under it. - key: u64, - /// A terminal program's kitty `z=`: below 0 it is under the text, - /// which a tty passes on to the terminal outside. - z: i32 = 0, - /// Rows of `raster` that alone differ from the picture under the key - /// `from`: a frontend still holding that one updates those rows. - dirty: ?Dirty = null, - art: Art = .{}, - - pub const Dirty = struct { from: u64, y: u32, h: u32 }; - /// How the pane wants it drawn as glyph art: the Petscii, Palette and - /// Ascii words on an image pane, Petscii and TermImages on a terminal. - pub const Art = struct { - /// Glyph art even where pixels could be shown (Petscii on). - glyph: bool = false, - palette: Palette = .commodore, - /// Letters and signs among the glyphs, not only blocks and lines. - ascii: bool = true, - - pub const Palette = enum { commodore, terminal }; - }; - - /// A pane's picture `page` (a PDF's page, a terminal's image id; 0 for - /// an image) as of `revision`. - pub fn keyOf(serial: u32, page: u32, revision: u32) u64 { - return std.hash.Wyhash.hash(0, std.mem.asBytes(&[3]u32{ serial, page, revision })); - } -}; /// One part of the frame and where it is, placed once by `draw.place` /// before anything is painted: every painter and every shell reads the @@ -205,8 +101,6 @@ pub const Region = struct { /// A column below the workspace tag, its bar and panes: its left /// edge is the spine a pixel shell rules down it. column, - /// A drag's guide or a seam's hover hint, drawn over the panes. - guide, /// The debug stats box, drawn over the panes. debug, }; @@ -244,15 +138,9 @@ pub const Region = struct { /// it shows, in pixels. Its placements are laid at the whole pixel; a /// pixel frontend draws them the fraction higher. scroll_px: f64 = 0, - /// Cells the column-move rail takes off the right edge while it runs - /// there: layers and pixel shells stop short of them, the grid does not. - clip: u16 = 0, }; -/// Guides a frame can draw: a run of a column-move rail per pane it skips -/// the tags of, and a handful of border and hover dashes. -pub const MAX_GUIDES = MAX_PANES + 4; -pub const MAX_REGIONS = 1 + MAX_PANES * (4 + panes.Pane.Notices.max) + pardes.MAX_COLS * 3 + 1 + MAX_GUIDES + 1; +pub const MAX_REGIONS = 1 + MAX_PANES * (4 + panes.Pane.Notices.max) + pardes.MAX_COLS * 3 + 1 + 1; /// The colours a pixel shell draws its chrome in (rules, rails, grips, the /// tag underlay), resolved by the core each frame, so a frontend attached @@ -472,14 +360,6 @@ pub const Surface = struct { while (xx < x + w) : (xx += 1) s.at(xx, yy).* = .{}; } } - - /// swap ONLY the glyph, keeping the cell's colors — the resize-handle hint - pub fn overlayDash(s: *Surface, x: u16, y: u16, glyph: []const u8) void { - const c = s.at(x, y); - @memcpy(c.text[0..glyph.len], glyph); - c.len = @intCast(glyph.len); - c.default = false; - } }; test "cell visual equality ignores dead grapheme tail bytes" { |
