diff --git a/js/Input.js b/js/Input.js index 7aad689..4409a37 100644 --- a/js/Input.js +++ b/js/Input.js @@ -1,24 +1,24 @@ const Input = (() => { let spaceKeyPressed = false; let dragging = false; + let currentMouseEvent = undefined; // Hotkeys when pressing a key Events.on("keydown", document, KeyPress); - // Update held keys when releasing a key - Events.on("keyup", window, function (e) { - if (e.keyCode == 32) spaceKeyPressed = false; - }); + Events.on("keyup", window, function (e) {if (e.keyCode == 32) spaceKeyPressed = false;}); // Update variables on mouse clicks Events.on("mousedown", window, onMouseDown); Events.on("mouseup", window, onMouseUp); function onMouseDown(event) { + currentMouseEvent = event; dragging = true; } function onMouseUp(event) { + currentMouseEvent = event; dragging = false; } @@ -148,8 +148,13 @@ const Input = (() => { return dragging; } + function getCurrMouseEvent() { + return currentMouseEvent; + } + return { spacePressed, - isDragging + isDragging, + getCurrMouseEvent } })(); \ No newline at end of file diff --git a/js/Startup.js b/js/Startup.js index 56b053b..d816248 100644 --- a/js/Startup.js +++ b/js/Startup.js @@ -130,7 +130,7 @@ const Startup = (() => { TMPLayer = new Layer(width, height, 'tmp-canvas'); // Pixel grid - pixelGrid = new Layer(width, height, pixelGridCanvas); + pixelGrid = new Layer(width, height, "pixel-grid"); // Setting the general canvasSize canvasSize = currentLayer.canvasSize; diff --git a/js/_editorMode.js b/js/_editorMode.js index ffcc7a3..560f734 100644 --- a/js/_editorMode.js +++ b/js/_editorMode.js @@ -1,8 +1,5 @@ // REFACTOR: move everything in EditorState? -var pixelEditorMode = "Basic"; -switchMode(pixelEditorMode); - let modes = { 'Basic' : { description: 'Basic mode is perfect if you want to create simple sprites or try out palettes.' diff --git a/js/_mouseEvents.js b/js/_mouseEvents.js index 0f69592..b2712d6 100644 --- a/js/_mouseEvents.js +++ b/js/_mouseEvents.js @@ -1,10 +1,7 @@ -var currentMouseEvent; var lastMouseMovePos; //mousedown - start drawing window.addEventListener("mousedown", function (mouseEvent) { - // Saving the event in case something else needs it - currentMouseEvent = mouseEvent; canDraw = true; //if no document has been created yet, or this is a dialog open, or the currentLayer is locked @@ -67,9 +64,6 @@ window.addEventListener("mousedown", function (mouseEvent) { //mouseup - end drawing window.addEventListener("mouseup", function (mouseEvent) { - // Saving the event in case something else needs it - currentMouseEvent = mouseEvent; - TopMenuModule.closeMenu(); if (currentLayer != null && !Util.isChildOfByClass(mouseEvent.target, "layers-menu-entry")) { @@ -204,8 +198,6 @@ function draw (mouseEvent) { if (!Dialogue.isOpen()) { lastMouseMovePos = getCursorPosition(mouseEvent); - // Saving the event in case something else needs it - currentMouseEvent = mouseEvent; var cursorLocation = lastMouseMovePos; diff --git a/js/_pixelGrid.js b/js/_pixelGrid.js index 83295eb..775327c 100644 --- a/js/_pixelGrid.js +++ b/js/_pixelGrid.js @@ -4,8 +4,6 @@ let pixelGridColor = "#000000"; let lineDistance = 12; // The grid is visible by default let pixelGridVisible = false; -// Saving the canvas containing the pixel grid -pixelGridCanvas = document.getElementById("pixel-grid"); /** Shows or hides the pixel grid depening on its current visibility @@ -13,7 +11,6 @@ pixelGridCanvas = document.getElementById("pixel-grid"); * */ function togglePixelGrid(newState) { - console.log('toggling pixel grid', newState) // Getting the button because I have to change its text let button = document.getElementById("toggle-pixelgrid-button"); @@ -25,12 +22,12 @@ function togglePixelGrid(newState) { // If it was visible, I hide it if (pixelGridVisible) { button.innerHTML = "Hide pixel grid"; - pixelGridCanvas.style.display = "inline-block"; + pixelGrid.canvas.style.display = "inline-block"; } // Otherwise, I show it else { button.innerHTML = "Show pixel grid"; - pixelGridCanvas.style.display = "none"; + pixelGrid.canvas.style.display = "none"; } } @@ -38,17 +35,17 @@ function togglePixelGrid(newState) { * */ function fillPixelGrid() { - let context = pixelGridCanvas.getContext("2d"); + let context = pixelGrid.context; let originalSize = layers[0].canvasSize; // The pixelGridCanvas is lineDistance times bigger so that the lines don't take 1 canvas pixel // (which would cover the whole canvas with the pixelGridColour), but they take 1/lineDistance canvas pixels - pixelGridCanvas.width = originalSize[0] * lineDistance; - pixelGridCanvas.height = originalSize[1] * lineDistance; + pixelGrid.canvas.width = originalSize[0] * lineDistance; + pixelGrid.canvas.height = originalSize[1] * lineDistance; // OPTIMIZABLE, could probably be a bit more elegant // Draw horizontal lines - for (let i=0; i