Skip to content

Commit 737d288

Browse files
committed
whiteboard: when drawing use even better canvas scaling.
1 parent b83febd commit 737d288

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

src/packages/frontend/frame-editors/whiteboard-editor/canvas.tsx

+5-10
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ import { aspectRatioToNumber } from "./tools/frame";
9898

9999
import Cursors from "./cursors";
100100

101-
// I can't get this to work! :-(
102-
// When I can, this should be window.devicePixelRatio
103-
const penDPIFactor = 1;
101+
const penDPIFactor = window.devicePixelRatio;
104102

105103
const MIDDLE_MOUSE_BUTTON = 1;
106104

@@ -183,12 +181,6 @@ export default function Canvas({
183181
} | null>(null);
184182

185183
const penCanvasRef = useRef<any>(null);
186-
useEffect(() => {
187-
const canvas = penCanvasRef.current;
188-
if (canvas == null) return;
189-
const ctx = canvas.getContext("2d");
190-
ctx.scale(penDPIFactor, penDPIFactor);
191-
}, []);
192184

193185
// Whenever the data <--> window transform params change,
194186
// ensure the current center of the viewport is preserved,
@@ -864,9 +856,12 @@ export default function Canvas({
864856
if (canvas == null) return;
865857
const ctx = canvas.getContext("2d");
866858
if (ctx == null) return;
859+
ctx.restore();
860+
ctx.save();
861+
ctx.scale(penDPIFactor, penDPIFactor);
867862
const path: Point[] = [];
868863
for (const point of mousePath.current.slice(
869-
mousePath.current.length - 3
864+
mousePath.current.length - 2
870865
)) {
871866
path.push({
872867
x: point.x * canvasScaleRef.current,

src/packages/frontend/frame-editors/whiteboard-editor/elements/pen.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function Pen({ element }: Props) {
2323
// are right on the edge of the canvas don't get partially truncated.
2424
// I tried doing this at various points in "the pipeline", and here at
2525
// the renderer is optimal.
26-
const pad = 2 * (element.data?.["radius"] ?? 1);
26+
const pad = 2 * (element.data?.["radius"] ?? 1) * scaleRef.current;
2727

2828
useEffect(() => {
2929
const canvas = canvasRef.current;

0 commit comments

Comments
 (0)