From a66fbc2fa992ec0b1fcacf804003c7381eacbae0 Mon Sep 17 00:00:00 2001 From: iamdoubz <> Date: Thu, 18 Jun 2026 09:21:27 -0500 Subject: [PATCH 1/2] Fix some odd behavior when switching between colors and tools --- src/components/ColoringRunner.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/ColoringRunner.tsx b/src/components/ColoringRunner.tsx index 5b7f0fc..779dfdf 100644 --- a/src/components/ColoringRunner.tsx +++ b/src/components/ColoringRunner.tsx @@ -49,6 +49,7 @@ export default function ColoringRunner({ meta, loggedIn, username, alreadyEarned const committedRef = useRef(null); // active layer before current stroke const undoRef = useRef<{ layerId: number; data: ImageData }[]>([]); const drawingRef = useRef<{ x: number; y: number }[] | null>(null); + const pressureRef = useRef(0.7); const saveTimer = useRef | undefined>(undefined); const [, force] = useState(0); @@ -152,12 +153,14 @@ export default function ColoringRunner({ meta, loggedIn, username, alreadyEarned if (committedRef.current) ctx.putImageData(committedRef.current, 0, 0); const pts = drawingRef.current!; if (!pts.length) return; + ctx.save(); // isolate this stroke's tool settings so they can't leak to the next stroke + strokeStyleFor(pressureRef.current); ctx.lineCap = "round"; ctx.lineJoin = "round"; ctx.beginPath(); ctx.moveTo(pts[0].x, pts[0].y); if (pts.length === 1) ctx.lineTo(pts[0].x + 0.1, pts[0].y + 0.1); else for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].y); ctx.stroke(); - ctx.globalAlpha = 1; ctx.globalCompositeOperation = "source-over"; + ctx.restore(); composite(); } @@ -196,13 +199,13 @@ export default function ColoringRunner({ meta, loggedIn, username, alreadyEarned pushUndo(); committedRef.current = active.canvas.getContext("2d")!.getImageData(0, 0, W, H); drawingRef.current = [p]; - strokeStyleFor(e.pressure && e.pressure > 0 ? e.pressure : 0.7); + pressureRef.current = e.pressure && e.pressure > 0 ? e.pressure : 0.7; renderStroke(); } function onMove(e: React.PointerEvent) { if (!drawingRef.current) return; drawingRef.current.push(pt(e)); - strokeStyleFor(e.pressure && e.pressure > 0 ? e.pressure : 0.7); + pressureRef.current = e.pressure && e.pressure > 0 ? e.pressure : 0.7; renderStroke(); } function onUp() { if (!drawingRef.current) return; drawingRef.current = null; committedRef.current = null; force((n) => n + 1); scheduleSave(); } @@ -264,7 +267,7 @@ export default function ColoringRunner({ meta, loggedIn, username, alreadyEarned } const swatch = (c: string, key: string) => ( -