2020-03-04 16:36:40 +03:00
|
|
|
var isRectSelecting = false;
|
2020-03-04 17:46:25 +03:00
|
|
|
let startX;
|
|
|
|
let startY;
|
2020-03-04 16:36:40 +03:00
|
|
|
|
2020-03-04 17:46:25 +03:00
|
|
|
function startRectSelection(mouseEvent) {
|
|
|
|
// Putting the vfx layer on top of everything
|
|
|
|
VFXCanvas.style.zIndex = MAX_Z_INDEX;
|
2020-03-04 16:36:40 +03:00
|
|
|
console.log("Started selecting");
|
2020-03-04 17:46:25 +03:00
|
|
|
// Saving the start coords of the rect
|
|
|
|
cursorPos = getCursorPositionRelative(mouseEvent, VFXCanvas)
|
|
|
|
startX = cursorPos[0];
|
|
|
|
startY = cursorPos[1];
|
|
|
|
|
|
|
|
// Drawing the rect
|
|
|
|
drawRect(startX, startY);
|
2020-03-04 16:36:40 +03:00
|
|
|
}
|
|
|
|
|
2020-03-04 17:46:25 +03:00
|
|
|
function updateRectSelection(mouseEvent) {
|
|
|
|
pos = getCursorPositionRelative(mouseEvent, VFXCanvas);
|
|
|
|
|
|
|
|
// Drawing the rect
|
|
|
|
drawRect(pos[0], pos[1]);
|
2020-03-04 16:36:40 +03:00
|
|
|
}
|
|
|
|
|
2020-03-04 17:46:25 +03:00
|
|
|
function endRectSelection(mouseEvent) {
|
2020-03-04 16:36:40 +03:00
|
|
|
console.log("Finished selecting");
|
2020-03-04 17:46:25 +03:00
|
|
|
// 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
|