Fix window hover detection; add redaction tool
Window detection was broken by wrong CG-to-AppKit coordinate conversion
of the cursor and highlight rects — both now go through the same
cgToAppKit mapping. The draw toolbar gains a Pen/Redact toggle: redact
drags cover content with a solid black bar (participates in undo/redo
and export like pen strokes).
💘 Generated with Crush
Assisted-by: Crush:deepseek-v4-flash-0731
This commit is contained in:
@@ -96,6 +96,8 @@ final class CaptureModel: ObservableObject {
|
||||
@Published var redoStack: [Stroke] = []
|
||||
/// Whether the pen is active (drag draws instead of selecting)
|
||||
@Published var isDrawing = false
|
||||
/// Whether drawing redacts (black bar) instead of pen strokes
|
||||
@Published var isRedacting = false
|
||||
/// Current drawing color
|
||||
@Published var drawColor: NSColor = .systemRed
|
||||
/// Stroke thickness in points (image space)
|
||||
@@ -105,6 +107,7 @@ final class CaptureModel: ObservableObject {
|
||||
let points: [CGPoint]
|
||||
let width: CGFloat
|
||||
let color: NSColor
|
||||
var isRedaction: Bool = false
|
||||
}
|
||||
|
||||
enum CaptureMode {
|
||||
@@ -159,14 +162,29 @@ final class CaptureModel: ObservableObject {
|
||||
ctx.setLineJoin(.round)
|
||||
for stroke in strokes {
|
||||
guard stroke.points.count > 1 else { continue }
|
||||
stroke.color.setStroke()
|
||||
ctx.setLineWidth(stroke.width)
|
||||
ctx.beginPath()
|
||||
ctx.move(to: stroke.points[0])
|
||||
for point in stroke.points.dropFirst() {
|
||||
ctx.addLine(to: point)
|
||||
if stroke.isRedaction {
|
||||
// Redaction bar: filled black rect covering the stroke bounds,
|
||||
// padded so it fully covers text.
|
||||
let xs = stroke.points.map { $0.x }
|
||||
let ys = stroke.points.map { $0.y }
|
||||
let bar = NSRect(
|
||||
x: xs.min()! - 2,
|
||||
y: ys.min()! - 2,
|
||||
width: (xs.max()! - xs.min()!) + 4,
|
||||
height: max(stroke.width, ys.max()! - ys.min()!) + 4
|
||||
)
|
||||
NSColor.black.setFill()
|
||||
NSBezierPath(rect: bar).fill()
|
||||
} else {
|
||||
stroke.color.setStroke()
|
||||
ctx.setLineWidth(stroke.width)
|
||||
ctx.beginPath()
|
||||
ctx.move(to: stroke.points[0])
|
||||
for point in stroke.points.dropFirst() {
|
||||
ctx.addLine(to: point)
|
||||
}
|
||||
ctx.strokePath()
|
||||
}
|
||||
ctx.strokePath()
|
||||
}
|
||||
ctx.restoreGState()
|
||||
NSGraphicsContext.restoreGraphicsState()
|
||||
@@ -175,7 +193,13 @@ final class CaptureModel: ObservableObject {
|
||||
|
||||
func addStroke(_ points: [CGPoint]) {
|
||||
guard points.count > 1 else { return }
|
||||
strokes.append(Stroke(points: points, width: strokeWidth, color: drawColor))
|
||||
if isRedacting {
|
||||
// Redaction: a filled black bar from start to end, as thick as the
|
||||
// current stroke width (drawn as a rect for clean edges).
|
||||
strokes.append(Stroke(points: points, width: max(strokeWidth, 12), color: .black, isRedaction: true))
|
||||
} else {
|
||||
strokes.append(Stroke(points: points, width: strokeWidth, color: drawColor))
|
||||
}
|
||||
redoStack = []
|
||||
}
|
||||
|
||||
@@ -351,31 +375,37 @@ struct ResultView: View {
|
||||
// Draw toolbar (only when drawing)
|
||||
if model.isDrawing {
|
||||
HStack(spacing: 14) {
|
||||
Label("Draw", systemImage: "pencil.tip")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
|
||||
Divider().frame(height: 18)
|
||||
|
||||
HStack(spacing: 6) {
|
||||
Image(systemName: "circle.fill").font(.system(size: 4))
|
||||
Image(systemName: "circle.fill").font(.system(size: 7))
|
||||
Image(systemName: "circle.fill").font(.system(size: 10))
|
||||
Picker("", selection: $model.isRedacting) {
|
||||
Label("Pen", systemImage: "pencil.tip").tag(false)
|
||||
Label("Redact", systemImage: "rectangle.fill").tag(true)
|
||||
}
|
||||
.foregroundStyle(.secondary)
|
||||
Slider(value: $model.strokeWidth, in: 1...12, step: 0.5)
|
||||
.frame(width: 120)
|
||||
.help("Stroke thickness")
|
||||
.pickerStyle(.segmented)
|
||||
.fixedSize()
|
||||
.help("Pen draws strokes; Redact covers text with a black bar")
|
||||
|
||||
Divider().frame(height: 18)
|
||||
|
||||
ColorPicker("", selection: Binding(
|
||||
get: { Color(nsColor: model.drawColor) },
|
||||
set: { model.drawColor = NSColor($0) }
|
||||
), supportsOpacity: false)
|
||||
.labelsHidden()
|
||||
.frame(width: 28)
|
||||
.help("Drawing color")
|
||||
if !model.isRedacting {
|
||||
HStack(spacing: 6) {
|
||||
Image(systemName: "circle.fill").font(.system(size: 4))
|
||||
Image(systemName: "circle.fill").font(.system(size: 7))
|
||||
Image(systemName: "circle.fill").font(.system(size: 10))
|
||||
}
|
||||
.foregroundStyle(.secondary)
|
||||
Slider(value: $model.strokeWidth, in: 1...12, step: 0.5)
|
||||
.frame(width: 120)
|
||||
.help("Stroke thickness")
|
||||
|
||||
Divider().frame(height: 18)
|
||||
|
||||
ColorPicker("", selection: Binding(
|
||||
get: { Color(nsColor: model.drawColor) },
|
||||
set: { model.drawColor = NSColor($0) }
|
||||
), supportsOpacity: false)
|
||||
.labelsHidden()
|
||||
.frame(width: 28)
|
||||
.help("Drawing color")
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
@@ -515,12 +545,24 @@ struct ScreenshotPane: View {
|
||||
Canvas { context, _ in
|
||||
for stroke in model.strokes {
|
||||
guard stroke.points.count > 1 else { continue }
|
||||
var path = Path()
|
||||
path.move(to: CGPoint(x: origin.x + stroke.points[0].x * scale, y: origin.y + stroke.points[0].y * scale))
|
||||
for point in stroke.points.dropFirst() {
|
||||
path.addLine(to: CGPoint(x: origin.x + point.x * scale, y: origin.y + point.y * scale))
|
||||
if stroke.isRedaction {
|
||||
let xs = stroke.points.map { $0.x }
|
||||
let ys = stroke.points.map { $0.y }
|
||||
let bar = CGRect(
|
||||
x: origin.x + (xs.min()! - 2) * scale,
|
||||
y: origin.y + (ys.min()! - 2) * scale,
|
||||
width: ((xs.max()! - xs.min()!) + 4) * scale,
|
||||
height: (max(stroke.width, ys.max()! - ys.min()!) + 4) * scale
|
||||
)
|
||||
context.fill(Path(bar), with: .color(.black))
|
||||
} else {
|
||||
var path = Path()
|
||||
path.move(to: CGPoint(x: origin.x + stroke.points[0].x * scale, y: origin.y + stroke.points[0].y * scale))
|
||||
for point in stroke.points.dropFirst() {
|
||||
path.addLine(to: CGPoint(x: origin.x + point.x * scale, y: origin.y + point.y * scale))
|
||||
}
|
||||
context.stroke(path, with: .color(Color(nsColor: stroke.color)), lineWidth: stroke.width)
|
||||
}
|
||||
context.stroke(path, with: .color(Color(nsColor: stroke.color)), lineWidth: stroke.width)
|
||||
}
|
||||
}
|
||||
.allowsHitTesting(false)
|
||||
|
||||
Reference in New Issue
Block a user