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.
This commit is contained in:
@@ -233,18 +233,28 @@
|
||||
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) {
|
||||
padState.drawing = true;
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
padState.lastX = e.clientX - rect.left;
|
||||
padState.lastY = e.clientY - rect.top;
|
||||
const pos = getPos(e);
|
||||
padState.lastX = pos.x;
|
||||
padState.lastY = pos.y;
|
||||
}
|
||||
|
||||
function move(e) {
|
||||
if (!padState.drawing) return;
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
const x = e.clientX - rect.left;
|
||||
const y = e.clientY - rect.top;
|
||||
const pos = getPos(e);
|
||||
const x = pos.x;
|
||||
const y = pos.y;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(padState.lastX, padState.lastY);
|
||||
ctx.lineTo(x, y);
|
||||
|
||||
Reference in New Issue
Block a user