summaryrefslogtreecommitdiff
path: root/dev/macos/Sources/PardesView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'dev/macos/Sources/PardesView.swift')
-rw-r--r--dev/macos/Sources/PardesView.swift104
1 files changed, 55 insertions, 49 deletions
diff --git a/dev/macos/Sources/PardesView.swift b/dev/macos/Sources/PardesView.swift
index 8dbaea0e..0a429428 100644
--- a/dev/macos/Sources/PardesView.swift
+++ b/dev/macos/Sources/PardesView.swift
@@ -1206,6 +1206,11 @@ final class PardesView: NSView {
drawBodyLayers(ctx, hideCursor:hideCursor)
drawTagLayers(ctx, hideCursor:hideCursor, canonical:cells, cols:cols, rows:rows)
} else {
+ for layer in presentedBodyLayers {
+ layer.cells.withUnsafeBufferPointer { cells in
+ if let base = cells.baseAddress { drawBodyLayer(ctx, values:layer.values, cells:base, hideCursor:true) }
+ }
+ }
for layer in presentedTagLayers {
layer.cells.withUnsafeBufferPointer { tagCells in
if let base = tagCells.baseAddress {
@@ -1215,11 +1220,6 @@ final class PardesView: NSView {
}
drawTagGrip(ctx, values: layer.values, canonical: cells, cols: cols, rows: rows)
}
- for layer in presentedBodyLayers {
- layer.cells.withUnsafeBufferPointer { cells in
- if let base = cells.baseAddress { drawBodyLayer(ctx, values:layer.values, cells:base, hideCursor:true) }
- }
- }
drawTagRules(ctx, layers: presentedTagLayers.map { $0.values })
}
drawHoverGlass(ctx, cells: cells, cols: cols, rows: rows)
@@ -1230,10 +1230,10 @@ final class PardesView: NSView {
private func snapshotTagLayers() -> [FrozenBodyLayer] {
var result: [FrozenBodyLayer] = []
for index in 0..<pardes_tag_layer_limit() {
- let values = (0...12).map { Int(pardes_tag_layer_value(index, UInt32($0))) }
+ let values = (0...13).map { Int(pardes_tag_layer_value(index, UInt32($0))) }
if values[0] == 0 { continue }
if let cells = pardes_tag_layer_cells(index) {
- result.append(FrozenBodyLayer(values: values, cells: Array(UnsafeBufferPointer(start: cells, count: values[0]))))
+ result.append(FrozenBodyLayer(values: values, cells: Array(UnsafeBufferPointer(start: cells, count: values[0] * values[7]))))
}
}
return result
@@ -1242,16 +1242,14 @@ final class PardesView: NSView {
private func drawTagLayers(_ ctx: CGContext, hideCursor: Bool, canonical: UnsafePointer<pardes_cell_s>, cols: Int, rows: Int) {
var layers: [[Int]] = []
for index in 0..<pardes_tag_layer_limit() {
- let values = (0...12).map { Int(pardes_tag_layer_value(index, UInt32($0))) }
- if values[0] == 0 { continue }
+ let values = (0...13).map { Int(pardes_tag_layer_value(index, UInt32($0))) }
+ guard values[0] > 0, let cells = pardes_tag_layer_cells(index) else { continue }
layers.append(values)
// The layer's full-row fill must land before the grip: the row
// background now spans the anchor columns, and the grip glyph
// and the anchor fills have to come back on top of it.
- if let cells = pardes_tag_layer_cells(index) {
- drawTagLayer(ctx, values: values, cells: cells, hideCursor: hideCursor,
- canonical: canonical, cols: cols)
- }
+ drawTagLayer(ctx, values: values, cells: cells, hideCursor: hideCursor,
+ canonical: canonical, cols: cols)
drawTagGrip(ctx, values: values, canonical: canonical, cols: cols, rows: rows)
}
drawTagRules(ctx, layers: layers)
@@ -1261,12 +1259,14 @@ final class PardesView: NSView {
/// one-point rules above the full-row tag backgrounds as well.
private func drawTagRules(_ ctx: CGContext, layers: [[Int]]) {
let pixel = CGFloat(1)
- for values in layers where values[1] != 0 {
- let kind = values[1]
- let bottom = kind == 2 && values[11] != 0
+ let picker = layers.first { $0[1] == 5 }
+ for values in layers where values[1] == 2 {
+ let bottom = values[11] != 0
let left = CGFloat(max(0, values[4] - Int(pardes_tag_text_inset()))) * cellWidth
let right = CGFloat(values[4] + values[6]) * cellWidth
- let y = CGFloat(values[5] + (bottom ? 0 : 1)) * cellHeight - (bottom ? 0 : pixel)
+ let tagEnd = values[5] + values[7]
+ let pickerEnd = picker.flatMap { $0[2] == values[2] ? $0[5] + $0[7] : nil }
+ let y = CGFloat(bottom ? values[5] : max(tagEnd, pickerEnd ?? tagEnd)) * cellHeight - (bottom ? 0 : pixel)
fillBackground(ctx, CGRect(x: left, y: y, width: right-left, height: pixel),
UInt32(values[12]), backgroundAlpha)
}
@@ -1328,7 +1328,6 @@ final class PardesView: NSView {
private func drawTagLayer(_ ctx: CGContext, values: [Int], cells: UnsafePointer<pardes_cell_s>,
hideCursor: Bool, canonical: UnsafePointer<pardes_cell_s>, cols: Int) {
let left = CGFloat(values[4]) * cellWidth
- let y = CGFloat(values[5]) * cellHeight + taglines.top(row: values[5], canvasHeight: bounds.height)
// SDL gives the tag a full body-row background; only its glyphs
// and per-cell highlights use the compact band. The band spans the
// row's whole extent, not just its text: the grip and the mode box
@@ -1336,10 +1335,12 @@ final class PardesView: NSView {
// own fills cover only the compact band — a row background that
// stops at the text leaves holes of ground under those anchors.
// The rule in drawTagRules spans exactly this left-to-right range.
- let rowLeft = CGFloat(max(0, values[4] - Int(pardes_tag_text_inset()))) * cellWidth
+ // Workspace words and inline notices already start at their own left edge.
+ let inset = values[1] == 0 || values[1] == 3 ? 0 : Int(pardes_tag_text_inset())
+ let rowLeft = CGFloat(max(0, values[4] - inset)) * cellWidth
let rowRight = CGFloat(values[4] + values[6]) * cellWidth
let viewport = CGRect(x: rowLeft, y: CGFloat(values[5]) * cellHeight,
- width: rowRight - rowLeft, height: cellHeight)
+ width: rowRight - rowLeft, height: CGFloat(values[7]) * cellHeight)
ctx.saveGState()
ctx.clip(to: viewport)
fillBackground(ctx, viewport, UInt32(values[10]), backgroundAlpha)
@@ -1355,35 +1356,39 @@ final class PardesView: NSView {
if style.visible { fillBackground(ctx, square.integral, style.bg, backgroundAlpha) }
}
- for pass in 0...1 {
- for col in 0..<values[0] {
- var cell = cells[col]
- let isCursor = !hideCursor && col == values[8]
- let block = isCursor && values[9] == 0
- let style = resolve(cell, block: block, ground: UInt32(values[10]), clearGround: false)
- let x = left + CGFloat(col) * taglines.width
- if pass == 0 {
- fillBackground(ctx, CGRect(x: x, y: y, width: taglines.width, height: taglines.height),
- style.bg, block ? 1 : backgroundAlpha)
- continue
- }
- let text = withUnsafeBytes(of: &cell.text) { String(decoding: $0.prefix(Int(cell.len)), as: UTF8.self) }
- if style.visible && !text.isEmpty && text != " " {
- let face = Face(bold: cell.attrs & UInt16(PARDES_ATTR_BOLD) != 0, italic: cell.attrs & UInt16(PARDES_ATTR_ITALIC) != 0)
- ctx.saveGState()
- ctx.translateBy(x: 0, y: bounds.height)
- ctx.scaleBy(x: 1, y: -1)
- let baseline = bounds.height - y - taglines.ascent
- drawRules(ctx, cell, style, x: x, width: taglines.width, baseline: baseline)
- setFill(ctx, style.fg, style.alpha)
- ctx.textPosition = CGPoint(x: x, y: baseline)
- let line = NSAttributedString(string: text, attributes: [fontAttribute: taglines.fonts[face.rawValue],
- NSAttributedString.Key(kCTForegroundColorFromContextAttributeName as String): true])
- CTLineDraw(CTLineCreateWithAttributedString(line as CFAttributedString), ctx)
- ctx.restoreGState()
- }
- if isCursor && values[9] != 0 {
- fill(ctx, CGRect(x: x, y: y, width: max(1, taglines.width / 8), height: taglines.height), style.fg, 1)
+ for row in 0..<values[7] {
+ let gridRow = values[5] + row
+ let y = CGFloat(gridRow) * cellHeight + taglines.top(row: gridRow, canvasHeight: bounds.height)
+ for pass in 0...1 {
+ for col in 0..<values[0] {
+ var cell = cells[row * values[0] + col]
+ let isCursor = !hideCursor && col == values[8] && row == values[13]
+ let block = isCursor && values[9] == 0
+ let style = resolve(cell, block: block, ground: UInt32(values[10]), clearGround: false)
+ let x = left + CGFloat(col) * taglines.width
+ if pass == 0 {
+ fillBackground(ctx, CGRect(x: x, y: y, width: taglines.width, height: taglines.height),
+ style.bg, block ? 1 : backgroundAlpha)
+ continue
+ }
+ let text = withUnsafeBytes(of: &cell.text) { String(decoding: $0.prefix(Int(cell.len)), as: UTF8.self) }
+ if style.visible && !text.isEmpty && text != " " {
+ let face = Face(bold: cell.attrs & UInt16(PARDES_ATTR_BOLD) != 0, italic: cell.attrs & UInt16(PARDES_ATTR_ITALIC) != 0)
+ ctx.saveGState()
+ ctx.translateBy(x: 0, y: bounds.height)
+ ctx.scaleBy(x: 1, y: -1)
+ let baseline = bounds.height - y - taglines.ascent
+ drawRules(ctx, cell, style, x: x, width: taglines.width, baseline: baseline)
+ setFill(ctx, style.fg, style.alpha)
+ ctx.textPosition = CGPoint(x: x, y: baseline)
+ let line = NSAttributedString(string: text, attributes: [fontAttribute: taglines.fonts[face.rawValue],
+ NSAttributedString.Key(kCTForegroundColorFromContextAttributeName as String): true])
+ CTLineDraw(CTLineCreateWithAttributedString(line as CFAttributedString), ctx)
+ ctx.restoreGState()
+ }
+ if isCursor && values[9] != 0 {
+ fill(ctx, CGRect(x: x, y: y, width: max(1, taglines.width / 8), height: taglines.height), style.fg, 1)
+ }
}
}
}
@@ -1395,6 +1400,7 @@ final class PardesView: NSView {
/// shared by the fill in drawTagLayer and the glyph in drawTagGrip so
/// the two can never disagree.
private func anchorSquare(values: [Int]) -> CGRect? {
+ guard values[1] == 1 || values[1] == 2 else { return nil }
let anchorX = max(0, values[4] - Int(pardes_tag_text_inset()))
guard anchorX < values[4] else { return nil }
let pad = (cellHeight - taglines.height) / 2