From 546e36aba35ec114b695db78c3d618c60204cbf4 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sun, 5 Apr 2020 10:17:50 -0400 Subject: [PATCH] Add a button to center the current entity; disable entity-specific buttons without a selection --- macrovision.css | 9 +++++++++ macrovision.html | 7 +++++-- macrovision.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/macrovision.css b/macrovision.css index b365f916..0eedcbd6 100644 --- a/macrovision.css +++ b/macrovision.css @@ -673,6 +673,10 @@ i.far { background: #ffffff66; } +.scroll-button:disabled { + background: #ffffff11; +} + #zoom-out { left: 0%; top: 0%; @@ -700,4 +704,9 @@ i.far { #grow { right: 0%; top: 50%; +} + +#fit { + right: 0%; + top: 75%; } \ No newline at end of file diff --git a/macrovision.html b/macrovision.html index 19297d4b..300d42ce 100644 --- a/macrovision.html +++ b/macrovision.html @@ -219,12 +219,15 @@ - - +
diff --git a/macrovision.js b/macrovision.js index e74a9f0b..a827b7fd 100644 --- a/macrovision.js +++ b/macrovision.js @@ -535,6 +535,10 @@ function deselect() { clearViewOptions(); document.querySelector("#delete-entity").disabled = true; + + document.querySelector("#grow").disabled = true; + document.querySelector("#shrink").disabled = true; + document.querySelector("#fit").disabled = true; } function select(target) { @@ -553,6 +557,10 @@ function select(target) { configViewOptions(selectedEntity, selectedEntity.view); document.querySelector("#delete-entity").disabled = false; + + document.querySelector("#grow").disabled = false; + document.querySelector("#shrink").disabled = false; + document.querySelector("#fit").disabled = false; } function configViewList(entity, selectedView) { @@ -1684,6 +1692,28 @@ document.addEventListener("DOMContentLoaded", () => { sizeHandle = null; }); + document.querySelector("#fit").addEventListener("click", e => { + const x = parseFloat(selected.dataset.x); + + Object.keys(entities).forEach(id => { + const element = document.querySelector("#entity-" + id); + const newX = parseFloat(element.dataset.x) - x + 0.5; + element.dataset.x = newX; + }); + + const entity = entities[selected.dataset.key]; + const height = math.multiply(entity.views[entity.view].height, 1.1); + setWorldHeight(config.height, height); + }); + + document.querySelector("#fit").addEventListener("mousedown", e => { + e.stopPropagation(); + }); + + document.querySelector("#fit").addEventListener("touchstart", e => { + e.stopPropagation(); + }); + document.querySelector("#options-world-fit").addEventListener("click", () => fitWorld(true)); document.querySelector("#options-world-autofit").addEventListener("input", e => {