mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
b7d5f603b1
Must fix bug that happens when creating a new layer after resizing the canvas
19 lines
521 B
JavaScript
19 lines
521 B
JavaScript
//get 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)];
|
|
} |