Compare commits
2 Commits
b282318298
...
feat/recei
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6b41f10c8 | ||
|
|
dc78ad4a24 |
1
.vscode/settings.json
vendored
Normal file
1
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user