mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
![unsettledgames](/assets/img/avatar_default.png)
At the moment there's a bug in the getCursorPos function, may have something to do with offsets. The rect is correctly drawn, but with a weird offset. Added vfx canvas for tools previews.
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
var isRectSelecting = false;
|
|
let startX;
|
|
let startY;
|
|
|
|
function startRectSelection(mouseEvent) {
|
|
// Putting the vfx layer on top of everything
|
|
VFXCanvas.style.zIndex = MAX_Z_INDEX;
|
|
console.log("Started selecting");
|
|
// Saving the start coords of the rect
|
|
cursorPos = getCursorPositionRelative(mouseEvent, VFXCanvas)
|
|
startX = cursorPos[0];
|
|
startY = cursorPos[1];
|
|
|
|
// Drawing the rect
|
|
drawRect(startX, startY);
|
|
}
|
|
|
|
function updateRectSelection(mouseEvent) {
|
|
pos = getCursorPositionRelative(mouseEvent, VFXCanvas);
|
|
|
|
// Drawing the rect
|
|
drawRect(pos[0], pos[1]);
|
|
}
|
|
|
|
function endRectSelection(mouseEvent) {
|
|
console.log("Finished selecting");
|
|
// Putting the vfx layer behind everything
|
|
//VFXCanvas.style.zIndex = MIN_Z_INDEX;
|
|
isRectSelecting = false;
|
|
}
|
|
|
|
function drawRect(x, y) {
|
|
console.log("Currently selecting");
|
|
// Getting the vfx context
|
|
let vfxContext = VFXCanvas.getContext("2d");
|
|
|
|
// Clearing the vfx canvas
|
|
vfxContext.clearRect(0, 0, VFXCanvas.width, VFXCanvas.height);
|
|
// Drawing the rect
|
|
vfxContext.beginPath();
|
|
vfxContext.rect(startX, startY, x - startX, y - startY);
|
|
vfxContext.stroke();
|
|
}
|
|
|
|
// TODO: esc to exit selection mode
|