Skip to content

Instantly share code, notes, and snippets.

@mmuszynski
Created July 3, 2018 12:54
Show Gist options
  • Save mmuszynski/83ae452a92e7f4c2a2ef7b88b22401e9 to your computer and use it in GitHub Desktop.
Save mmuszynski/83ae452a92e7f4c2a2ef7b88b22401e9 to your computer and use it in GitHub Desktop.
//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