2019-03-27 02:20:54 +03:00
|
|
|
//get cursor position relative to canvas
|
|
|
|
function getCursorPosition(e) {
|
|
|
|
var x;
|
|
|
|
var y;
|
2020-03-04 17:46:25 +03:00
|
|
|
|
2019-03-27 02:20:54 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
x -= canvas.offsetLeft;
|
|
|
|
y -= canvas.offsetTop;
|
|
|
|
|
2020-03-04 17:46:25 +03:00
|
|
|
return [x,y];
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: apply the function below to every getCursorPosition call
|
|
|
|
|
2020-03-04 21:38:35 +03:00
|
|
|
// TODO: FIX THIS BELOW
|
|
|
|
|
2020-03-04 17:46:25 +03:00
|
|
|
//get cursor position relative to canvas
|
|
|
|
function getCursorPositionRelative(e, layer) {
|
|
|
|
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 -= layer.canvas.offsetLeft;
|
|
|
|
y -= layer.canvas.offsetTop;
|
|
|
|
|
2019-03-27 02:20:54 +03:00
|
|
|
return [x,y];
|
|
|
|
}
|