From cdabbb4a5cfad650af8ffaeac0712a0352bdeb83 Mon Sep 17 00:00:00 2001 From: Nicola <47360416+unsettledgames@users.noreply.github.com> Date: Mon, 31 Jan 2022 23:12:28 +0100 Subject: [PATCH] Added tool size in the top bar --- css/_main-menu.scss | 9 +++++++- js/InputComponents.js | 16 ++++++++++++++- js/Tool.js | 31 ++++------------------------ js/TopMenuModule.js | 24 +++++++++++++++++++++- js/pixel-editor.js | 6 ++++-- js/tools/ResizableTool.js | 43 +++++++++++++++++++++++++++++++++++++++ views/main-menu.hbs | 2 +- 7 files changed, 98 insertions(+), 33 deletions(-) diff --git a/css/_main-menu.scss b/css/_main-menu.scss index 73c5352..ea7181f 100644 --- a/css/_main-menu.scss +++ b/css/_main-menu.scss @@ -123,9 +123,16 @@ li#editor-info { padding: 5px; color:$basetext; } - input[type=text] { + input[type=number] { + appearance:none; + -moz-appearance: text; width:25px; height:15px; } + input::-webkit-outer-spin-button, + input::-webkit-inner-spin-button { + -webkit-appearance: none; + margin: 0; + } } } \ No newline at end of file diff --git a/js/InputComponents.js b/js/InputComponents.js index bc75392..add8e9b 100644 --- a/js/InputComponents.js +++ b/js/InputComponents.js @@ -16,6 +16,19 @@ const InputComponents = (() => { event.target.classList.add("checked"); } + function createNumber(id, label) { + let element = document.createElement("label"); + let inputEl = document.createElement("input"); + + inputEl.id = id; + inputEl.type = "number"; + element.innerHTML = label; + + element.appendChild(inputEl); + + return element; + } + function createCheckbox(id, label) { let element = document.createElement("div"); let inner = document.createElement("div"); @@ -54,6 +67,7 @@ const InputComponents = (() => { return { updated, - createCheckbox + createCheckbox, + createNumber } })(); diff --git a/js/Tool.js b/js/Tool.js index 647cf77..1f5345d 100644 --- a/js/Tool.js +++ b/js/Tool.js @@ -21,8 +21,6 @@ class Tool { // HTML elements mainButton = undefined; - biggerButton = undefined; - smallerButton = undefined; brushPreview = document.getElementById("brush-preview"); // Tool tutorial @@ -35,8 +33,6 @@ class Tool { this.cursorType = options; this.mainButton = document.getElementById(name + "-button"); - this.biggerButton = document.getElementById(name + "-bigger-button"); - this.smallerButton = document.getElementById(name + "-smaller-button"); if (this.mainButton != undefined) { // Timer to show the tutorial @@ -60,12 +56,7 @@ class Tool { showTutorial() { let tutorialRect = this.toolTutorial.getBoundingClientRect(); - console.log("Top button: " + (this.mainButton.getBoundingClientRect().top - 48 + (tutorialRect.bottom - tutorialRect.top))); - console.log("Tutorial height: " + (tutorialRect.bottom - tutorialRect.top)); - console.log("Screen height: " + window.innerHeight); - if ((this.mainButton.getBoundingClientRect().top - 48 + (tutorialRect.bottom - tutorialRect.top)) > window.innerHeight) { - console.log("YO"); this.toolTutorial.style.top = window.innerHeight - 48 - (tutorialRect.bottom - tutorialRect.top) + "px"; } else { @@ -101,6 +92,7 @@ class Tool { this.mainButton.parentElement.classList.add("selected"); this.isSelected = true; + // Update the cursor switch (this.cursorType.type) { case 'html': currFile.canvasView.style.cursor = 'none'; @@ -112,6 +104,9 @@ class Tool { default: break; } + + // Reset the topbar + TopMenuModule.resetInfos(); } updateCursor() { @@ -168,22 +163,4 @@ class Tool { onEnd(mousePos, mouseTarget) { this.endMousePos = mousePos; } - - increaseSize() { - if (this.currSize < 128) { - this.currSize++; - this.updateCursor(); - } - } - - decreaseSize() { - if (this.currSize > 1) { - this.currSize--; - this.updateCursor(); - } - } - - get size() { - return this.currSize; - } } \ No newline at end of file diff --git a/js/TopMenuModule.js b/js/TopMenuModule.js index b39b054..3b70d64 100644 --- a/js/TopMenuModule.js +++ b/js/TopMenuModule.js @@ -1,6 +1,8 @@ const TopMenuModule = (() => { const mainMenuItems = document.getElementById('main-menu').children; + let infoList = document.getElementById('editor-info'); + let infoElements = {}; initMenu(); @@ -106,7 +108,27 @@ const TopMenuModule = (() => { } } + function resetInfos() { + infoList.innerHTML = "