mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-18 18:11:24 +01:00
EDIT style text label stroke color
This commit is contained in:
parent
a2e1004734
commit
7ff5d1053f
3 changed files with 26 additions and 4 deletions
|
|
@ -1121,6 +1121,13 @@
|
||||||
<label for="gridCellNumbers" class="checkbox-label">Show cell numbers</label>
|
<label for="gridCellNumbers" class="checkbox-label">Show cell numbers</label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr data-tip="Set the color of grid cell numbers">
|
||||||
|
<td>Cell num color</td>
|
||||||
|
<td>
|
||||||
|
<input id="gridCellNumbersStrokeColor" type="color" value="#000000" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
||||||
<tbody id="styleCompass">
|
<tbody id="styleCompass">
|
||||||
|
|
|
||||||
|
|
@ -1447,14 +1447,11 @@ function drawGrid() {
|
||||||
.attr("fill", "url(" + pattern + ")")
|
.attr("fill", "url(" + pattern + ")")
|
||||||
.attr("stroke", "none");
|
.attr("stroke", "none");
|
||||||
|
|
||||||
// Check both the attribute and the checkbox state
|
|
||||||
if (gridOverlay.attr("cell-numbers") === "true" || document.getElementById("gridCellNumbers").checked) {
|
if (gridOverlay.attr("cell-numbers") === "true" || document.getElementById("gridCellNumbers").checked) {
|
||||||
drawCellNumbers();
|
drawCellNumbers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function drawCellNumbers() {
|
function drawCellNumbers() {
|
||||||
const pattern = gridOverlay.attr("type") || "pointyHex";
|
const pattern = gridOverlay.attr("type") || "pointyHex";
|
||||||
const scale = +gridOverlay.attr("scale") || 1;
|
const scale = +gridOverlay.attr("scale") || 1;
|
||||||
|
|
@ -1471,6 +1468,8 @@ function drawCellNumbers() {
|
||||||
const columns = Math.ceil(maxWidth / patternWidth);
|
const columns = Math.ceil(maxWidth / patternWidth);
|
||||||
const rows = Math.ceil(maxHeight / patternHeight);
|
const rows = Math.ceil(maxHeight / patternHeight);
|
||||||
|
|
||||||
|
const labelStyle = gridOverlay.attr("data-label-style") || "stroke: #000000;";
|
||||||
|
|
||||||
for (let row = 0; row < rows; row++) {
|
for (let row = 0; row < rows; row++) {
|
||||||
for (let col = 0; col < columns; col++) {
|
for (let col = 0; col < columns; col++) {
|
||||||
const x = col * patternWidth + dx;
|
const x = col * patternWidth + dx;
|
||||||
|
|
@ -1484,6 +1483,8 @@ function drawCellNumbers() {
|
||||||
.attr("text-anchor", "middle")
|
.attr("text-anchor", "middle")
|
||||||
.attr("dominant-baseline", "central")
|
.attr("dominant-baseline", "central")
|
||||||
.attr("font-size", Math.min(patternWidth, patternHeight) / 4)
|
.attr("font-size", Math.min(patternWidth, patternHeight) / 4)
|
||||||
|
.attr("fill", "none") // Set fill to none so only stroke is visible
|
||||||
|
.attr("style", labelStyle)
|
||||||
.text(cellNumber);
|
.text(cellNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -201,6 +201,8 @@ function selectStyleElement() {
|
||||||
|
|
||||||
if (gridCellNumbers) {
|
if (gridCellNumbers) {
|
||||||
gridCellNumbers.checked = el.attr("cell-numbers") === "true";
|
gridCellNumbers.checked = el.attr("cell-numbers") === "true";
|
||||||
|
styleStroke.style.display = "block";
|
||||||
|
styleStrokeInput.value = styleStrokeOutput.value = gridOverlay.attr("data-label-style")?.match(/stroke: ([^;]+)/)?.[1] || "#000000";
|
||||||
gridCellNumbers.addEventListener("change", function() {
|
gridCellNumbers.addEventListener("change", function() {
|
||||||
el.attr("cell-numbers", this.checked);
|
el.attr("cell-numbers", this.checked);
|
||||||
drawGrid();
|
drawGrid();
|
||||||
|
|
@ -208,6 +210,7 @@ function selectStyleElement() {
|
||||||
} else {
|
} else {
|
||||||
console.warn("gridCellNumbers element not found");
|
console.warn("gridCellNumbers element not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (styleElement === "compass") {
|
if (styleElement === "compass") {
|
||||||
|
|
@ -542,10 +545,21 @@ styleGridNumbers.on("change", function () {
|
||||||
|
|
||||||
byId("gridCellNumbers")?.addEventListener("change", function() {
|
byId("gridCellNumbers")?.addEventListener("change", function() {
|
||||||
gridOverlay.attr("cell-numbers", this.checked);
|
gridOverlay.attr("cell-numbers", this.checked);
|
||||||
// drawGrid(); // without condition of if layerIsOn.
|
updateGridCellNumbersStyle();
|
||||||
if (layerIsOn("toggleGrid")) drawGrid();
|
if (layerIsOn("toggleGrid")) drawGrid();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById("gridCellNumbersColor").addEventListener("input", updateGridCellNumbersStyle);
|
||||||
|
|
||||||
|
function updateGridCellNumbersStyle() {
|
||||||
|
const color = document.getElementById("gridCellNumbersColor").value;
|
||||||
|
|
||||||
|
const style = `stroke: ${color};`;
|
||||||
|
gridOverlay.attr("data-label-style", style);
|
||||||
|
|
||||||
|
if (layerIsOn("toggleGrid")) drawGrid();
|
||||||
|
}
|
||||||
|
|
||||||
styleRescaleMarkers.on("change", function () {
|
styleRescaleMarkers.on("change", function () {
|
||||||
markers.attr("rescale", +this.checked);
|
markers.attr("rescale", +this.checked);
|
||||||
invokeActiveZooming();
|
invokeActiveZooming();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue