2020-09-26 13:32:31 +03:00
|
|
|
let pixelGridColor = "#0000FF";
|
|
|
|
let lineDistance = 12;
|
2020-09-26 13:40:03 +03:00
|
|
|
let pixelGridVisible = false;
|
2020-09-26 12:51:18 +03:00
|
|
|
pixelGridCanvas = document.getElementById("pixel-grid");
|
|
|
|
|
2020-09-26 13:40:03 +03:00
|
|
|
function togglePixelGrid(event) {
|
|
|
|
let button = document.getElementById("toggle-pixelgrid-button");
|
|
|
|
|
|
|
|
pixelGridVisible = !pixelGridVisible;
|
|
|
|
|
|
|
|
if (pixelGridVisible) {
|
|
|
|
button.innerHTML = "Hide pixel grid";
|
|
|
|
pixelGridCanvas.style.display = "inline-block";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
button.innerHTML = "Show pixel grid";
|
|
|
|
pixelGridCanvas.style.display = "none";
|
|
|
|
}
|
|
|
|
}
|
2020-09-26 13:32:31 +03:00
|
|
|
|
2020-09-26 12:51:18 +03:00
|
|
|
function fillPixelGrid() {
|
2020-09-26 13:32:31 +03:00
|
|
|
let context = pixelGridCanvas.getContext("2d");
|
|
|
|
let originalSize = layers[0].canvasSize;
|
|
|
|
|
|
|
|
pixelGridCanvas.width = originalSize[0] * lineDistance;
|
|
|
|
pixelGridCanvas.height = originalSize[1] * lineDistance;
|
|
|
|
|
|
|
|
// OPTIMIZABLE, could probably be a bit more elegant
|
|
|
|
// Draw horizontal lines
|
|
|
|
for (let i=0; i<pixelGridCanvas.width / lineDistance; i++) {
|
2020-09-29 20:10:50 +03:00
|
|
|
context.strokeStyle = settings.pixelGridColour;
|
2020-09-26 13:32:31 +03:00
|
|
|
|
|
|
|
context.beginPath();
|
|
|
|
context.moveTo(i * lineDistance + 0.5, 0);
|
|
|
|
context.lineTo(i * lineDistance + 0.5, originalSize[1] * lineDistance);
|
|
|
|
context.stroke();
|
|
|
|
context.closePath();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw vertical lines
|
|
|
|
for (let i=0; i<pixelGridCanvas.height / lineDistance; i++) {
|
|
|
|
context.beginPath();
|
|
|
|
context.moveTo(0, i * lineDistance + 0.5);
|
|
|
|
context.lineTo(originalSize[0] * lineDistance, i * lineDistance + 0.5);
|
|
|
|
context.stroke();
|
|
|
|
context.closePath();
|
|
|
|
}
|
2020-09-26 13:40:03 +03:00
|
|
|
|
|
|
|
if (!pixelGridVisible) {
|
|
|
|
pixelGridCanvas.style.display = 'none';
|
|
|
|
}
|
2020-09-26 12:51:18 +03:00
|
|
|
}
|