mirror of
https://github.com/dscyrescotti/Memola.git
synced 2026-03-24 18:31:23 +01:00
bug: remove eraser stroke adding into graphic context
This commit is contained in:
@@ -159,7 +159,8 @@ extension GraphicContext {
|
||||
createdAt: .now,
|
||||
thickness: pen.thickness
|
||||
)
|
||||
withPersistence(\.backgroundContext) { [graphicContext = object, _stroke = eraserStroke] context in
|
||||
eraserStroke.graphicContext = self
|
||||
withPersistence(\.backgroundContext) { [_stroke = eraserStroke] context in
|
||||
let stroke = EraserObject(\.backgroundContext)
|
||||
stroke.bounds = _stroke.bounds
|
||||
stroke.color = _stroke.color
|
||||
@@ -168,11 +169,9 @@ extension GraphicContext {
|
||||
stroke.createdAt = _stroke.createdAt
|
||||
stroke.quads = []
|
||||
stroke.strokes = .init()
|
||||
graphicContext?.strokes.add(stroke)
|
||||
_stroke.object = stroke
|
||||
try context.saveIfNeeded()
|
||||
}
|
||||
eraserStroke.graphicContext = self
|
||||
stroke = eraserStroke
|
||||
}
|
||||
currentStroke = stroke
|
||||
@@ -219,17 +218,16 @@ extension GraphicContext {
|
||||
if let stroke = currentStroke {
|
||||
switch stroke.style {
|
||||
case .marker:
|
||||
guard !tree.isEmpty else { return }
|
||||
let _stroke = tree.remove(stroke.anyStroke, in: stroke.strokeBox)
|
||||
guard let _stroke = stroke.stroke(as: PenStroke.self) else { break }
|
||||
withPersistence(\.backgroundContext) { [graphicContext = object, _stroke] context in
|
||||
if let stroke = _stroke?.stroke(as: PenStroke.self)?.object {
|
||||
if let stroke = _stroke.object {
|
||||
graphicContext?.strokes.remove(stroke)
|
||||
context.delete(stroke)
|
||||
}
|
||||
try context.saveIfNeeded()
|
||||
}
|
||||
case .eraser:
|
||||
guard let eraserStroke = stroke.stroke(as: EraserStroke.self) else { return }
|
||||
guard let eraserStroke = stroke.stroke(as: EraserStroke.self) else { break }
|
||||
eraserStrokes.remove(eraserStroke)
|
||||
withPersistence(\.backgroundContext) { [eraserStroke] context in
|
||||
if let stroke = eraserStroke.object {
|
||||
@@ -238,7 +236,6 @@ extension GraphicContext {
|
||||
try context.saveIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
currentStroke = nil
|
||||
currentPoint = nil
|
||||
|
||||
@@ -59,7 +59,7 @@ extension Canvas {
|
||||
let graphicContext = canvas.graphicContext
|
||||
self?.graphicContext.object = graphicContext
|
||||
self?.graphicContext.loadStrokes(bounds)
|
||||
context.refresh(canvas, mergeChanges: false)
|
||||
context.refreshAllObjects()
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
self?.state = .loaded
|
||||
}
|
||||
|
||||
@@ -194,7 +194,6 @@ struct PenDock: View {
|
||||
.stroke(Color.gray, lineWidth: 0.4)
|
||||
}
|
||||
.padding(0.2)
|
||||
.drawingGroup()
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.hoverEffect(.lift)
|
||||
@@ -302,7 +301,6 @@ struct PenDock: View {
|
||||
.resizable()
|
||||
.renderingMode(.template)
|
||||
}
|
||||
.drawingGroup()
|
||||
.foregroundStyle(.black.opacity(0.2))
|
||||
.blur(radius: 3)
|
||||
if let tip = pen.style.icon.tip {
|
||||
|
||||
@@ -68,8 +68,8 @@ struct MemosView: View {
|
||||
memoObject.updatedAt = .now
|
||||
|
||||
let canvasObject = CanvasObject(context: managedObjectContext)
|
||||
canvasObject.width = 4_000
|
||||
canvasObject.height = 4_000
|
||||
canvasObject.width = 8_000
|
||||
canvasObject.height = 8_000
|
||||
|
||||
let toolObject = ToolObject(\.viewContext)
|
||||
toolObject.pens = []
|
||||
|
||||
Reference in New Issue
Block a user