Skip to content

Instantly share code, notes, and snippets.

@janily
Created July 26, 2020 15:44
Show Gist options
  • Save janily/a0106f1a0b25c41821500e95fa75c4d4 to your computer and use it in GitHub Desktop.
Save janily/a0106f1a0b25c41821500e95fa75c4d4 to your computer and use it in GitHub Desktop.
mouse location
function mouseInCanvasViewForDocument(document) {
var mouseInWindow = document.documentWindow().convertScreenToBase(NSEvent.mouseLocation());
return document.contentDrawView().convertPoint_fromView(mouseInWindow,null);
}
function CGPointToObject(point) {
return {
x: point.x.doubleValue(),
y: point.y.doubleValue()
}
}
// Alternative approach with the same result
/*
function CGPointToObject(point) {
return {
x: point.x + 0,
y: point.y + 0
}
}
*/
var point = CGPointToObject(mouseInCanvasViewForDocument(context.document));
print(point);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment