Connected events to rect selection

_rectSelect.js now knows when the user started and finished drawing a rect and is able to edit a preview.
This commit is contained in:
unsettledgames
2020-03-04 14:36:40 +01:00
parent cba4e5c87e
commit efaa8e3c34
7 changed files with 67 additions and 24 deletions

View File

@@ -57,29 +57,27 @@ window.addEventListener("mouseup", function (mouseEvent) {
console.log(newColor);
var colors = document.getElementsByClassName('color-button');
for (var i = 0; i < colors.length; i++) {
console.log(colors[i].jscolor.toString());
//if picked color matches this color
if (newColor == colors[i].jscolor.toString()) {
console.log('color found');
//remove current color selection
var selectedColor = document.querySelector("#colors-menu li.selected")
if (selectedColor) selectedColor.classList.remove("selected");
//set current color
context.fillStyle = '#'+newColor;
//make color selected
colors[i].parentElement.classList.add('selected');
//hide eyedropper
eyedropperPreview.style.display = 'none';
}
}
for (var i = 0; i < colors.length; i++) {
console.log(colors[i].jscolor.toString());
//if picked color matches this color
if (newColor == colors[i].jscolor.toString()) {
console.log('color found');
//remove current color selection
var selectedColor = document.querySelector("#colors-menu li.selected")
if (selectedColor) selectedColor.classList.remove("selected");
//set current color
context.fillStyle = '#'+newColor;
//make color selected
colors[i].parentElement.classList.add('selected');
//hide eyedropper
eyedropperPreview.style.display = 'none';
}
}
}
else if (currentTool == 'fill' && mouseEvent.target == currentLayer.canvas) {
console.log('filling')
@@ -111,6 +109,9 @@ window.addEventListener("mouseup", function (mouseEvent) {
layers[i].copyData(layers[0]);
}
}
else if (currentTool == 'rectselect') {
endRectSelection();
}
dragging = false;
currentTool = currentToolTemp;
@@ -237,6 +238,15 @@ function draw (mouseEvent) {
updateCursor();
}
else if (currentTool == 'rectselect') {
if (dragging && !isRectSelecting) {
isRectSelecting = true;
startRectSelection();
}
else if (dragging && isRectSelecting) {
updateRectSelection();
}
}
}
//mousewheel scrroll