Compare commits

..

2 Commits

Author SHA1 Message Date
OlgunR
e6b41f10c8 Merge branch 'feat/receiver-ui' of http://git.dd:3000/AppStd/EnvelopeGenerator into feat/receiver-ui 2025-12-10 11:16:27 +01:00
OlgunR
dc78ad4a24 Improve canvas mouse position accuracy; add settings.json
Refactored mouse event handling in pdfInterop.js to use a new getPos helper, ensuring accurate coordinate mapping on scaled or resized canvases. Updated start and move functions to use this helper. Added an empty settings.json file.
2025-12-10 11:16:13 +01:00
2 changed files with 17 additions and 6 deletions

1
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1 @@
{}

View File

@@ -233,18 +233,28 @@
lastY: 0, lastY: 0,
}; };
function getPos(evt) {
const rect = canvas.getBoundingClientRect();
const scaleX = rect.width ? canvas.width / rect.width : 1;
const scaleY = rect.height ? canvas.height / rect.height : 1;
return {
x: (evt.clientX - rect.left) * scaleX,
y: (evt.clientY - rect.top) * scaleY,
};
}
function start(e) { function start(e) {
padState.drawing = true; padState.drawing = true;
const rect = canvas.getBoundingClientRect(); const pos = getPos(e);
padState.lastX = e.clientX - rect.left; padState.lastX = pos.x;
padState.lastY = e.clientY - rect.top; padState.lastY = pos.y;
} }
function move(e) { function move(e) {
if (!padState.drawing) return; if (!padState.drawing) return;
const rect = canvas.getBoundingClientRect(); const pos = getPos(e);
const x = e.clientX - rect.left; const x = pos.x;
const y = e.clientY - rect.top; const y = pos.y;
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(padState.lastX, padState.lastY); ctx.moveTo(padState.lastX, padState.lastY);
ctx.lineTo(x, y); ctx.lineTo(x, y);