pixel-editor/js/_getCursorPosition.js
unsettledgames fb1200162e Finished commenting the editor
Also cleaned a few things, removed some unused variables
2020-12-31 16:47:56 +01:00

19 lines
526 B
JavaScript

//gets cursor position relative to canvas
function getCursorPosition(e) {
var x;
var y;
if (e.pageX != undefined && e.pageY != undefined) {
x = e.pageX;
y = e.pageY;
}
else {
x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}
x -= currentLayer.canvas.offsetLeft;
y -= currentLayer.canvas.offsetTop;
return [Math.round(x), Math.round(y)];
}