From 2c505c7e500af5578828c25d6c9b612688cc5283 Mon Sep 17 00:00:00 2001 From: Dawn <93628226+DawnTheWitch@users.noreply.github.com> Date: Wed, 18 Oct 2023 11:58:32 -0400 Subject: [PATCH] Silly little rectangles --- src/AtomMode.ts | 28 +++++++++++++++++----------- src/index.html | 12 ++++++++++++ src/index.ts | 2 +- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/AtomMode.ts b/src/AtomMode.ts index 1cabe3dc..48c18395 100644 --- a/src/AtomMode.ts +++ b/src/AtomMode.ts @@ -19,6 +19,10 @@ const ctx: CanvasRenderingContext2D = res; //HTML letter display const atomDisplay = document.getElementById("atomDisplay"); +//HTML bounding box check +const atomCheckBox = document.getElementById("atomBox"); +const atomCheckBoxes = document.getElementById("atomBoxes"); + //Allows font measurement in pixels to creature atom bounding box. let atomMetrics: TextMetrics; @@ -59,9 +63,9 @@ export function atomMouseDown(event: MouseEvent) { ctx.clearRect(0, 0, canvas.width, canvas.height); redrawCut(tree.sheet, offset); if (tree.canInsert(currentAtom)) { - drawAtom(currentAtom, "#00FF00"); + drawAtom(currentAtom, "#00FF00", true); } else { - drawAtom(currentAtom, "#FF0000"); + drawAtom(currentAtom, "#FF0000", true); } } @@ -81,9 +85,9 @@ export function atomMouseMove(event: MouseEvent) { redrawCut(tree.sheet, offset); if (!wasOut) { if (tree.canInsert(currentAtom)) { - drawAtom(currentAtom, "#00FF00"); + drawAtom(currentAtom, "#00FF00", true); } else { - drawAtom(currentAtom, "#FF0000"); + drawAtom(currentAtom, "#FF0000", true); } } } @@ -120,18 +124,20 @@ export function atomMouseOut() { * @param thisAtom the atomMode to be drawn. * @param color the color of the atom. */ -export function drawAtom(thisAtom: AtomNode, color: string) { +export function drawAtom(thisAtom: AtomNode, color: string, currentAtom: Boolean) { ctx.textBaseline = "bottom"; atomMetrics = ctx.measureText(thisAtom.identifier); ctx.fillStyle = color; ctx.strokeStyle = color; ctx.beginPath(); ctx.fillText(thisAtom.identifier, thisAtom.origin.x + offset.x, thisAtom.origin.y + offset.y); - ctx.rect( - thisAtom.origin.x + offset.x, - thisAtom.origin.y + offset.y - atomMetrics.actualBoundingBoxAscent, - thisAtom.width, - thisAtom.height - ); + if (atomCheckBoxes.checked || (atomCheckBox.checked && currentAtom)) { + ctx.rect( + thisAtom.origin.x + offset.x, + thisAtom.origin.y + offset.y - atomMetrics.actualBoundingBoxAscent, + thisAtom.width, + thisAtom.height + ); + } ctx.stroke(); } diff --git a/src/index.html b/src/index.html index 02e35e6f..945bc224 100644 --- a/src/index.html +++ b/src/index.html @@ -74,6 +74,18 @@

+
+

Show Current Bounding Box

+
+
+ +
+
+

Show All Bounding Boxes

+
+
+ +
diff --git a/src/index.ts b/src/index.ts index a2b2c88c..6a2a24b6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -289,7 +289,7 @@ export function redrawCut(incomingNode: CutNode, offset: Point) { * @param offset The difference between the actual graph and the current canvas */ function redrawAtom(incomingNode: AtomNode) { - drawAtom(incomingNode, "#000000"); + drawAtom(incomingNode, "#000000", false); } /**