mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
c714f5c004
When the rectangle selection tool is selected, a rect preview is drawn on the vfx layer. There's also a function that gets the selected pixels, next step is moving them around.
43 lines
960 B
JavaScript
43 lines
960 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 -= canvas.offsetLeft;
|
|
y -= canvas.offsetTop;
|
|
|
|
return [x,y];
|
|
}
|
|
|
|
// TODO: apply the function below to every getCursorPosition call
|
|
|
|
// TODO: FIX THIS BELOW
|
|
|
|
//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;
|
|
|
|
return [x,y];
|
|
} |