From 708a2b07587c25292cfe0d3575bde39531bec7ba Mon Sep 17 00:00:00 2001 From: dscyrescotti Date: Sun, 7 Jul 2024 14:11:18 +0700 Subject: [PATCH] feat: add mouse touch event for stroke drawing --- .../View/Bridge/Views/DrawingView.swift | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Memola/Canvas/View/Bridge/Views/DrawingView.swift b/Memola/Canvas/View/Bridge/Views/DrawingView.swift index be3a87a..73e7ff2 100644 --- a/Memola/Canvas/View/Bridge/Views/DrawingView.swift +++ b/Memola/Canvas/View/Bridge/Views/DrawingView.swift @@ -38,7 +38,26 @@ class DrawingView: Platform.View { } #if os(macOS) - #warning("TODO: to implement touch events") + override func mouseDown(with event: NSEvent) { + super.mouseDown(with: event) + let pointInLeftBottomOrigin = convert(event.locationInWindow, from: nil) + let point = CGPoint(x: pointInLeftBottomOrigin.x, y: bounds.height - pointInLeftBottomOrigin.y) + touchBegan(at: point) + } + + override func mouseDragged(with event: NSEvent) { + super.mouseDragged(with: event) + let pointInLeftBottomOrigin = convert(event.locationInWindow, from: nil) + let point = CGPoint(x: pointInLeftBottomOrigin.x, y: bounds.height - pointInLeftBottomOrigin.y) + touchMoved(to: point) + } + + override func mouseUp(with event: NSEvent) { + super.mouseUp(with: event) + let pointInLeftBottomOrigin = convert(event.locationInWindow, from: nil) + let point = CGPoint(x: pointInLeftBottomOrigin.x, y: bounds.height - pointInLeftBottomOrigin.y) + touchEnded(at: point) + } #else override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { !canvas.hasValidStroke