mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
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:
parent
cba4e5c87e
commit
efaa8e3c34
@ -63,6 +63,11 @@ svg {
|
|||||||
background:transparent;
|
background:transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pixel-canvas {
|
||||||
|
z-index:1000;
|
||||||
|
background:transparent;
|
||||||
|
}
|
||||||
|
|
||||||
#eyedropper-preview {
|
#eyedropper-preview {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 45px;
|
width: 45px;
|
||||||
|
@ -57,29 +57,27 @@ window.addEventListener("mouseup", function (mouseEvent) {
|
|||||||
console.log(newColor);
|
console.log(newColor);
|
||||||
|
|
||||||
var colors = document.getElementsByClassName('color-button');
|
var colors = document.getElementsByClassName('color-button');
|
||||||
for (var i = 0; i < colors.length; i++) {
|
for (var i = 0; i < colors.length; i++) {
|
||||||
console.log(colors[i].jscolor.toString());
|
console.log(colors[i].jscolor.toString());
|
||||||
|
|
||||||
//if picked color matches this color
|
//if picked color matches this color
|
||||||
if (newColor == colors[i].jscolor.toString()) {
|
if (newColor == colors[i].jscolor.toString()) {
|
||||||
console.log('color found');
|
console.log('color found');
|
||||||
|
|
||||||
//remove current color selection
|
//remove current color selection
|
||||||
var selectedColor = document.querySelector("#colors-menu li.selected")
|
var selectedColor = document.querySelector("#colors-menu li.selected")
|
||||||
if (selectedColor) selectedColor.classList.remove("selected");
|
if (selectedColor) selectedColor.classList.remove("selected");
|
||||||
|
|
||||||
//set current color
|
//set current color
|
||||||
context.fillStyle = '#'+newColor;
|
context.fillStyle = '#'+newColor;
|
||||||
|
|
||||||
//make color selected
|
//make color selected
|
||||||
colors[i].parentElement.classList.add('selected');
|
colors[i].parentElement.classList.add('selected');
|
||||||
|
|
||||||
//hide eyedropper
|
//hide eyedropper
|
||||||
eyedropperPreview.style.display = 'none';
|
eyedropperPreview.style.display = 'none';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (currentTool == 'fill' && mouseEvent.target == currentLayer.canvas) {
|
else if (currentTool == 'fill' && mouseEvent.target == currentLayer.canvas) {
|
||||||
console.log('filling')
|
console.log('filling')
|
||||||
@ -111,6 +109,9 @@ window.addEventListener("mouseup", function (mouseEvent) {
|
|||||||
layers[i].copyData(layers[0]);
|
layers[i].copyData(layers[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (currentTool == 'rectselect') {
|
||||||
|
endRectSelection();
|
||||||
|
}
|
||||||
|
|
||||||
dragging = false;
|
dragging = false;
|
||||||
currentTool = currentToolTemp;
|
currentTool = currentToolTemp;
|
||||||
@ -237,6 +238,15 @@ function draw (mouseEvent) {
|
|||||||
|
|
||||||
updateCursor();
|
updateCursor();
|
||||||
}
|
}
|
||||||
|
else if (currentTool == 'rectselect') {
|
||||||
|
if (dragging && !isRectSelecting) {
|
||||||
|
isRectSelecting = true;
|
||||||
|
startRectSelection();
|
||||||
|
}
|
||||||
|
else if (dragging && isRectSelecting) {
|
||||||
|
updateRectSelection();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//mousewheel scrroll
|
//mousewheel scrroll
|
||||||
|
@ -1,13 +1,21 @@
|
|||||||
|
|
||||||
function newPixel (width, height, palette) {
|
function newPixel (width, height, palette) {
|
||||||
|
// Setting the current layer
|
||||||
currentLayer = new Canvas(width, height, canvas);
|
currentLayer = new Canvas(width, height, canvas);
|
||||||
currentLayer.initialize();
|
currentLayer.initialize();
|
||||||
|
|
||||||
|
// Adding the checkerboard behind it
|
||||||
checkerBoard = new Canvas(width, height, checkerBoardCanvas);
|
checkerBoard = new Canvas(width, height, checkerBoardCanvas);
|
||||||
checkerBoard.initialize();
|
checkerBoard.initialize();
|
||||||
|
|
||||||
|
// Creating the vfx layer on top of everything
|
||||||
|
VFXLayer = new Canvas(width, height, VFXCanvas);
|
||||||
|
VFXLayer.initialize();
|
||||||
|
|
||||||
canvasSize = currentLayer.canvasSize;
|
canvasSize = currentLayer.canvasSize;
|
||||||
|
|
||||||
|
// Adding the first layer and the checkerboard to the list of layers
|
||||||
|
layers.push(VFXLayer);
|
||||||
layers.push(currentLayer);
|
layers.push(currentLayer);
|
||||||
layers.push(checkerBoard);
|
layers.push(checkerBoard);
|
||||||
|
|
||||||
|
13
js/_rectSelect.js
Normal file
13
js/_rectSelect.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
var isRectSelecting = false;
|
||||||
|
|
||||||
|
function startRectSelection() {
|
||||||
|
console.log("Started selecting");
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateRectSelection() {
|
||||||
|
console.log("Editing selecting");
|
||||||
|
}
|
||||||
|
|
||||||
|
function endRectSelection() {
|
||||||
|
console.log("Finished selecting");
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
@ -59,6 +59,7 @@
|
|||||||
//=include _clickedColor.js
|
//=include _clickedColor.js
|
||||||
//=include _fileMenu.js
|
//=include _fileMenu.js
|
||||||
//=include _createButton.js
|
//=include _createButton.js
|
||||||
|
//=include _rectSelect.js
|
||||||
|
|
||||||
|
|
||||||
/**onload**/
|
/**onload**/
|
||||||
|
@ -103,6 +103,7 @@
|
|||||||
<div id="brush-preview"></div>
|
<div id="brush-preview"></div>
|
||||||
|
|
||||||
<div id="canvas-view">
|
<div id="canvas-view">
|
||||||
|
<canvas id="vfx-canvas" class = "drawingCanvas"></canvas>
|
||||||
<canvas id="pixel-canvas" class = "drawingCanvas"></canvas>
|
<canvas id="pixel-canvas" class = "drawingCanvas"></canvas>
|
||||||
<canvas id="checkerboard" class = "drawingCanvas"></canvas>
|
<canvas id="checkerboard" class = "drawingCanvas"></canvas>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user