feat: disable user interaction for drawing view when hand tool is selected

This commit is contained in:
dscyrescotti
2024-07-17 19:53:50 +07:00
parent e45eba52fe
commit 7950ce05eb
2 changed files with 11 additions and 14 deletions

View File

@@ -48,7 +48,6 @@ final class CanvasViewController: Platform.ViewController {
}
#if os(macOS)
override func viewWillAppear() {
super.viewWillAppear()
resizeDocumentView()
@@ -462,14 +461,12 @@ extension CanvasViewController {
enablesDrawing = false
enablesPhotoInsertion = true
}
#if os(macOS)
#warning("TODO: implement for macos")
#else
scrollView.isScrollEnabled = enablesScrolling
drawingView.isUserInteractionEnabled = enablesDrawing
photoInsertGesture?.isEnabled = enablesPhotoInsertion
enablesDrawing ? drawingView.enableUserInteraction() : drawingView.disableUserInteraction()
#if os(iOS)
scrollView.isScrollEnabled = enablesScrolling
#endif
enablesDrawing ? drawingView.enableUserInteraction() : drawingView.disableUserInteraction()
}
}
@@ -483,14 +480,6 @@ extension CanvasViewController {
#endif
}
private func lockModeChanged(_ state: Bool) {
#if os(macOS)
#warning("TODO: implement for macos")
#else
scrollView.pinchGestureRecognizer?.isEnabled = !state
#endif
}
private func gridModeChanged(_ mode: GridMode) {
drawingView.disableUserInteraction()
renderer.setRedrawsGraphicRender()

View File

@@ -21,6 +21,10 @@ final class DrawingView: Platform.View {
private var lastDrawTime: CFTimeInterval = 0
private let minDrawInterval: CFTimeInterval = 1.0 / 60.0
#if os(macOS)
var isUserInteractionEnabled: Bool = true
#endif
required init(tool: Tool, canvas: Canvas, history: History) {
self.tool = tool
self.canvas = canvas
@@ -58,6 +62,10 @@ final class DrawingView: Platform.View {
let point = CGPoint(x: pointInLeftBottomOrigin.x, y: bounds.height - pointInLeftBottomOrigin.y)
touchEnded(at: point)
}
override func hitTest(_ point: NSPoint) -> NSView? {
isUserInteractionEnabled ? super.hitTest(point) : nil
}
#else
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
!canvas.hasValidStroke