MouseDown location from MTKView wrapped NSVieRepresentable

Hi Devs,

Anyone know how to get the local mouse click position of a UIKit view that is wrapped in a NSViewRepresentable and drawn using SwiftUI.

No matter what I do it always returns the entire window view, and I am after the location relative to the MTKView.

I am overriding the MTKView's, mouseDown function, and wanting to get the local position from the mouseDown event.

using self.convert(event.locationInWindow, to:self), returns the same position as event.locationInWindow

The reason I need the local position inside the MTKView, is I will be sampling an idBuffer at that point.

Any help would be greatly appreciated, Thanks Simon

Answered by SimonAN in 769766022

I figured it out. Looks like I was converting to, when I should have been converting from

self.convert(event.locationInWindow, from: nil)

This solved my problem.

Accepted Answer

I figured it out. Looks like I was converting to, when I should have been converting from

self.convert(event.locationInWindow, from: nil)

This solved my problem.

MouseDown location from MTKView wrapped NSVieRepresentable
 
 
Q