-
+
diff --git a/UI/ui.js b/UI/ui.js
index b9aa61d..14f3c1d 100644
--- a/UI/ui.js
+++ b/UI/ui.js
@@ -2,25 +2,70 @@
// Copyright (c) algernon (K. Algernon A. Sheppard). All rights reserved.
//
-// Function to adjust spacing.
-if (typeof lineTool.adjustSpacing !== 'function') {
- lineTool.adjustSpacing = function(event, adjustment) {
- // Adjust for modifier keys - multiplying adjustment by 10 for FP rounding.
- var finalAdjustment = adjustment;
+
+// Function to apply modifiers to distance adjustments.
+if (typeof lineTool.adjustDistance != 'function') {
+ lineTool.adjustDistance = function (event, adjustment) {
+
+ // Adjust for modifier keys.
+ let finalAdjustment = adjustment;
if (event) {
if (event.shiftKey)
- finalAdjustment *= 100;
+ finalAdjustment *= 90;
else if (!event.ctrlKey)
finalAdjustment *= 10;
}
+ return finalAdjustment;
+ }
+}
+
+// Function to implement fence mode selection.
+if (typeof lineTool.fenceMode !== 'function') {
+ lineTool.fenceMode = function () {
+ let fenceModeButton = document.getElementById("line-tool-fence");
+ let activating = !fenceModeButton.classList.contains("selected");
+ if (activating) {
+ fenceModeButton.classList.add("selected");
+
+ // Deselect random rotation.
+ document.getElementById("line-tool-rotation-random").classList.remove("selected");
+ engine.trigger('SetLineToolRandomRotation', false);
+ lineTool.setRotationVisibility(true);
+ }
+ else {
+ fenceModeButton.classList.remove("selected");
+ }
+
+ // Update control visibility.
+ lineTool.setFenceVisibility(!activating);
+ engine.trigger('SetLineToolFenceMode', activating);
+ }
+}
+
+// Function to toggle visibility of controls based on fence mode state.
+if (typeof lineTool.setFenceVisibility !== 'function') {
+ lineTool.setFenceVisibility = function (isVisible) {
+ lineTool.setDivVisiblity(isVisible, "line-tool-spacing");
+ lineTool.setDivVisiblity(isVisible, "line-tool-rotation");
+ lineTool.setDivVisiblity(isVisible, "line-tool-rotation-field");
+ lineTool.setDivVisiblity(isVisible, "line-tool-offsets");
+ }
+}
+
+// Function to adjust spacing.
+if (typeof lineTool.adjustSpacing !== 'function') {
+ lineTool.adjustSpacing = function (event, adjustment) {
+ // Adjust for modifiers.
+ let finalAdjustment = lineTool.adjustDistance(event, adjustment);
+
// Don't apply if adjutment will bring us below zero.
newSpacing = lineTool.spacing + finalAdjustment;
if (newSpacing < 1) return;
// Apply spacing.
lineTool.spacing = newSpacing;
- var roundedSpacing = newSpacing / 10;
+ let roundedSpacing = newSpacing / 10;
engine.trigger('SetLineToolSpacing', roundedSpacing);
document.getElementById("line-tool-spacing-field").innerHTML = roundedSpacing + " m";
}
@@ -33,13 +78,34 @@ if (typeof lineTool.refreshSpacing !== 'function') {
return;
}
- var spacingField = document.getElementById("line-tool-spacing-field");
+ let spacingField = document.getElementById("line-tool-spacing-field");
if (spacingField != null) {
document.getElementById("line-tool-spacing-field").innerHTML = (lineTool.spacing / 10) + " m";
}
}
}
+// Function to implement random rotation selection.
+if (typeof lineTool.randomRotation !== 'function') {
+ lineTool.randomRotation = function () {
+ let randomRotationButton = document.getElementById("line-tool-rotation-random");
+ if (randomRotationButton.classList.contains("selected")) {
+ randomRotationButton.classList.remove("selected");
+ engine.trigger('SetLineToolRandomRotation', false);
+
+ // Show rotation tools.
+ lineTool.setRotationVisibility(true);
+ }
+ else {
+ randomRotationButton.classList.add("selected");
+ engine.trigger('SetLineToolRandomRotation', true);
+
+ // Hide rotation tools.
+ lineTool.setRotationVisibility(false);
+ }
+ }
+}
+
// Function to adjust rotation.
if (typeof lineTool.adjustRotation !== 'function') {
lineTool.adjustRotation = function(event, adjustment) {
@@ -67,58 +133,46 @@ if (typeof lineTool.adjustRotation !== 'function') {
}
}
-// Function to implement fence mode selection.
-if (typeof lineTool.fenceMode !== 'function') {
- lineTool.fenceMode = function () {
- var fenceModeButton = document.getElementById("line-tool-fence");
- var randomRotationButton = document.getElementById("line-tool-rotation-random");
- if (fenceModeButton.classList.contains("selected")) {
- fenceModeButton.classList.remove("selected");
- engine.trigger('SetLineToolFenceMode', false);
-
- // Show spacing and random rotation button.
- lineTool.setSpacingVisibility(true);
- lineTool.setButtonVisibility(randomRotationButton, true);
+// Function to adjust random spacing offset.
+if (typeof lineTool.adjustRandomSpacing !== 'function') {
+ lineTool.adjustRandomSpacing = function (event, adjustment) {
+ // Adjust for modifiers.
+ let finalAdjustment = lineTool.adjustDistance(event, adjustment);
- // Show rotation, but only if random rotation is not set.
- if (!randomRotationButton.classList.contains("selected")) {
- lineTool.setRotationVisibility(true);
- }
+ // Bounds check.
+ lineTool.randomSpacing += finalAdjustment;
+ let maxSpacing = Math.round((lineTool.spacing / 3) - 1);
+ if (lineTool.randomSpacing > maxSpacing) {
+ lineTool.randomSpacing = maxSpacing;
}
- else {
- fenceModeButton.classList.add("selected");
- engine.trigger('SetLineToolFenceMode', true);
-
- // Disable random rotation and hide button.
- randomRotationButton.classList.remove("selected");
- engine.trigger('SetLineToolRandomRotation', false);
- lineTool.setButtonVisibility(randomRotationButton, false);
-
- // Hide rotation tools.
- lineTool.setSpacingVisibility(false);
- lineTool.setRotationVisibility(false);
+ if (lineTool.randomSpacing < 0) {
+ lineTool.randomSpacing = 0;
}
+
+ // Apply spacing offset.
+ engine.trigger('SetLineToolRandomSpacing', lineTool.randomSpacing / 10);
+ document.getElementById("line-tool-xOffset-field").innerHTML = (lineTool.randomSpacing / 10) + " m";
}
}
-// Function to implement random rotation selection.
-if (typeof lineTool.randomRotation !== 'function') {
- lineTool.randomRotation = function() {
- var randomRotationButton = document.getElementById("line-tool-rotation-random");
- if (randomRotationButton.classList.contains("selected")) {
- randomRotationButton.classList.remove("selected");
- engine.trigger('SetLineToolRandomRotation', false);
+// Function to adjust random lateral offset.
+if (typeof lineTool.adjustRandomOffset !== 'function') {
+ lineTool.adjustRandomOffset = function (event, adjustment) {
+ // Adjust for modifiers.
+ let finalAdjustment = lineTool.adjustDistance(event, adjustment);
- // Show rotation tools.
- lineTool.setRotationVisibility(true);
+ // Bounds check.
+ lineTool.randomOffset += finalAdjustment;
+ if (lineTool.randomOffset > 1000) {
+ lineTool.randomOffset = 1000;
}
- else {
- randomRotationButton.classList.add("selected");
- engine.trigger('SetLineToolRandomRotation', true);
-
- // Hide rotation tools.
- lineTool.setRotationVisibility(false);
+ if (lineTool.randomOffset < 0) {
+ lineTool.randomOffset = 0;
}
+
+ // Apply spacing offset.
+ engine.trigger('SetLineToolRandomOffset', lineTool.randomOffset / 10);
+ document.getElementById("line-tool-zOffset-field").innerHTML = (lineTool.randomOffset / 10) + " m";
}
}
@@ -126,7 +180,7 @@ if (typeof lineTool.randomRotation !== 'function') {
if (typeof lineTool.addTreeControl !== 'function') {
lineTool.addTreeControl = function(event, adjustment) {
if (typeof buildTreeAgeItem == 'function') {
- var modeLine = document.getElementById("line-tool-mode");
+ let modeLine = document.getElementById("line-tool-mode");
buildTreeAgeItem(modeLine, "afterend");
document.getElementById("YYTC-change-age-buttons-panel").onclick = function () { engine.trigger('LineToolTreeControlUpdated') };
}
@@ -163,16 +217,14 @@ if (typeof lineTool.handleCircleMode !== 'function') {
}
}
-// Function to set spacing selection control visibility
-if (typeof lineTool.setSpacingVisibility !== 'function') {
- lineTool.setSpacingVisibility = function (isVisible) {
- lineTool.setButtonVisibility(document.getElementById("line-tool-spacing-up"), isVisible);
- lineTool.setButtonVisibility(document.getElementById("line-tool-spacing-down"), isVisible);
+// Function to set div visibility
+if (typeof lineTool.setDivVisiblity !== 'function') {
+ lineTool.setDivVisiblity = function (isVisible, divId) {
if (isVisible) {
- document.getElementById("line-tool-spacing-field").style.visibility = "visible";
+ document.getElementById(divId).style.visibility = "visible";
}
else {
- document.getElementById("line-tool-spacing-field").style.visibility = "hidden";
+ document.getElementById(divId).style.visibility = "hidden";
}
}
}
@@ -208,13 +260,18 @@ if (typeof lineTool.setButtonVisibility !== 'function') {
}
}
-
// Set initial figures.
lineTool.adjustSpacing(null, 0);
lineTool.adjustRotation(null, 0);
+lineTool.adjustRandomOffset(null, 0);
+lineTool.adjustRandomSpacing(null, 0);
// Add button event handlers.
document.getElementById("line-tool-fence").onmousedown = () => { lineTool.fenceMode(); }
+document.getElementById("line-tool-straight").onclick = lineTool.handleStraightMode;
+document.getElementById("line-tool-simplecurve").onclick = lineTool.handleSimpleCurveMode;
+document.getElementById("line-tool-circle").onclick = lineTool.handleCircleMode;
+
document.getElementById("line-tool-spacing-down").onmousedown = (event) => { lineTool.adjustSpacing(event, -1); }
document.getElementById("line-tool-spacing-up").onmousedown = (event) => { lineTool.adjustSpacing(event, 1); }
@@ -222,6 +279,7 @@ document.getElementById("line-tool-rotation-random").onmousedown = () => { lineT
document.getElementById("line-tool-rotation-up").onmousedown = (event) => { lineTool.adjustRotation(event, 1); }
document.getElementById("line-tool-rotation-down").onmousedown = (event) => { lineTool.adjustRotation(event, -1); }
-document.getElementById("line-tool-straight").onclick = lineTool.handleStraightMode;
-document.getElementById("line-tool-simplecurve").onclick = lineTool.handleSimpleCurveMode;
-document.getElementById("line-tool-circle").onclick = lineTool.handleCircleMode;
\ No newline at end of file
+document.getElementById("line-tool-xOffset-down").onmousedown = (event) => { lineTool.adjustRandomSpacing(event, -1); }
+document.getElementById("line-tool-xOffset-up").onmousedown = (event) => { lineTool.adjustRandomSpacing(event, 1); }
+document.getElementById("line-tool-zOffset-down").onmousedown = (event) => { lineTool.adjustRandomOffset(event, -1); }
+document.getElementById("line-tool-zOffset-up").onmousedown = (event) => { lineTool.adjustRandomOffset(event, 1); }
\ No newline at end of file