2019-03-27 02:20:54 +03:00
|
|
|
//get cursor position relative to canvas
|
|
|
|
function getCursorPosition(e) {
|
2020-04-04 10:41:56 +03:00
|
|
|
var x;
|
|
|
|
var y;
|
2020-09-17 17:11:00 +03:00
|
|
|
|
2020-04-04 10:41:56 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-09-15 14:06:31 +03:00
|
|
|
x -= currentLayer.canvas.offsetLeft;
|
|
|
|
y -= currentLayer.canvas.offsetTop;
|
2020-04-04 10:41:56 +03:00
|
|
|
|
2020-07-22 00:36:12 +03:00
|
|
|
return [Math.round(x), Math.round(y)];
|
2020-07-21 23:30:46 +03:00
|
|
|
}
|