0

I am calling the drawMarker function from the mouseMoved function of the view by passing the CGPoints of the event.locationInWindow. The below code does not work. Appreciate any suggestions to be able to draw the markers where the mouse has moved on a view. I guess the issue is with the NSGraphicsContext that I cannot figure out.

    private func drawMarker(x: CGFloat, y: CGFloat, markerSize: CGFloat, markerColor: NSColor, markerOpacity: CGFloat = 0.5){
        guard let aContext = NSGraphicsContext.current else { return }
        aContext.saveGraphicsState()
        if graphType == .barGraph { return }
        let circleLayer = NSBezierPath(ovalIn: CGRect(x: x - (markerSize/2), y: y - (markerSize/2), width: markerSize, height: markerSize))
        markerColor.withAlphaComponent(markerOpacity).set()
        circleLayer.fill()
        circleLayer.stroke()
        aContext.restoreGraphicsState()
    }
Steve
  • 25
  • 1
  • 7
  • @Willeke Thank you again for directing me in the right direction, I was able to achieve the desired outcome from the details that you have shared. Will mark it as answered. – Steve Feb 06 '23 at 21:10

0 Answers0