Created
July 3, 2018 12:54
-
-
Save mmuszynski/83ae452a92e7f4c2a2ef7b88b22401e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Creating the view | |
override func mouseDown(with event: NSEvent) { | |
let click = event.locationInWindow | |
let point = self.convert(click, from: nil) | |
self.addDot(at: point) | |
NotificationCenter.default.post(name: .pointsChanged, object: nil) | |
} | |
func addDot(at locationInView: CGPoint) { | |
let dot = DotView(frame: NSRect(origin: .zero, size: pointSize)) | |
dot.center = locationInView | |
dot.number = self.subviews.count | |
self.addSubview(dot) | |
} | |
//The mouse methods in the subview | |
override func mouseDown(with event: NSEvent) { | |
location = self.frame.origin | |
} | |
override func mouseDragged(with event: NSEvent) { | |
self.center = self.superview!.convert(event.locationInWindow, from: nil) | |
} | |
override func mouseUp(with event: NSEvent) { | |
location = self.frame.origin | |
nextResponder?.mouseUp(with: event) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment