Copying the Die

Apparently, back in the day, most people gave up by now or everyone knew how to do all this by now, because there aren’t many topics here.

I followed the steps to copy the die. I now have three dice. The keyboard events work in all three dice and using the keyboard, I can change the spots on each die. I can select the key window with the mouse and the highlight shows which window is active. However, the double-click to “roll” the dice only works on the original die, not the other two. How can that be when they are exact duplicates? And since they were copied, how can I get the double-click to work in the other two dice since they should have the same code?

AND, interestingly enough, I just moved the original die to the third position, moving the two new dice over and now it is still the die in the first position that works with the double-click, not the last two in line. When I move the dice into a stacked position, one above the other, above the other, at first I had them on the left side of the window, and the double-click did not work on any of them. I resized the window so they were all stacked on the left side, and the double-click only works on the bottom die.

I know this has something to do with the custom view window the dice are in, but shouldn’t mouse clicks register anywhere in that window? Obviously the clicks are being registered, because I can change the key window to each of the dice. It’s just the double-click feature that isn’t working correctly.

I posted the question on StackOverflow and someone pointed out what I should have known. The locationInWindow, is not the location in the view. I should have read the documentation for locationInWindow and known to convert the event.locationInWindow to the local view location. I made the conversions in mouseUp like the book showed in mouseDown, and it works correctly now.

override func mouseDown(with event: NSEvent) {
	let pointInView = convert(event.locationInWindow, from: nil)
	if dieShape.contains(pointInView) {
		Swift.print("mouseDown CLICKCOUNT: \(event.clickCount)")
		let dieFrame = metricsForSize(size: bounds.size).dieFrame
		pressed = dieFrame.contains(pointInView)

override func mouseDragged(with event: NSEvent) {

override func mouseUp(with event: NSEvent) {
	let pointInView = self.convert(event.locationInWindow, from: nil)
	if dieShape.contains(pointInView) {
		Swift.print("mouseUp clickCount: \(event.clickCount)")
		if event.clickCount == 2 {
		pressed = false