Skip to content

Commit 98e9614

Browse files
Merge pull request #35 from CodeGod911/smoothandboundless
Performance and Acuraccy Improvements
2 parents 0384794 + 73f7ab1 commit 98e9614

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

SignaturePad/wwwroot/sigpad.interop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Sigpad from "./sigpad.min.js?ver=8.1.0"
1+
import Sigpad from "./sigpad.min.js?ver=8.1.1"
22
var dotNetHelper;
33

44
export function setup(id, reference, options, image) {

SignaturePad/wwwroot/sigpad.min.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@
99
const sigpadMap = new Map();
1010

1111
function drawPoints(ctx, points) {
12-
// draw a basic circle instead
13-
if (points.length < 6) {
12+
// draw a point instead
13+
if (points.length == 1) {
1414
var b = points[0];
1515
ctx.beginPath(), ctx.arc(b.x, b.y, ctx.lineWidth / 2, 0, Math.PI * 2, !0), ctx.closePath(), ctx.fill();
1616
return
1717
}
18+
19+
// draw line for just two points
20+
if (points.length == 2) {
21+
ctx.beginPath(), ctx.moveTo(points[0].x, points[0].y);
22+
ctx.lineTo(points[1].x, points[1].y);
23+
ctx.stroke();
24+
return
25+
}
26+
1827
ctx.beginPath(), ctx.moveTo(points[0].x, points[0].y);
1928
// draw a bunch of quadratics, using the average of two points as the control point
2029
var i;
@@ -59,7 +68,6 @@ export default class Sigpad {
5968
this._config = this._getConfig(options);
6069
this._element = element;
6170
this._mousePosis = [];
62-
this._mousePosisChanged = true;
6371
this._drawing = false;
6472

6573
this._setListeners();
@@ -222,6 +230,7 @@ export default class Sigpad {
222230
return;
223231
}
224232

233+
data.render();
225234
data._drawing = false;
226235

227236
const event = new CustomEvent('sigpad.finish', { detail: data.getImage() });
@@ -230,7 +239,7 @@ export default class Sigpad {
230239

231240
_onMove(sender, mouseEvent) {
232241
if (!this._drawing) return;
233-
mouseEvent.preventDefault();
242+
//mouseEvent.preventDefault();
234243
if ("touches" in mouseEvent) {
235244
mouseEvent = mouseEvent.touches[0];
236245
}
@@ -244,9 +253,8 @@ export default class Sigpad {
244253
if (data._drawing) {
245254
var pos = data._getRelativeMousePos(mouseEvent);
246255
if (pos != null) {
247-
data._mousePosis[0].push(pos)
248-
data._mousePosisChanged = true;
249-
const event = new CustomEvent('sigpad.move', { detail: data.getImage() });
256+
data._mousePosis[0].push(pos);
257+
const event = new CustomEvent('sigpad.move', {});
250258
data._element.dispatchEvent(event);
251259
} else {
252260
console.log("OUT OF BOUNDS")
@@ -261,15 +269,14 @@ export default class Sigpad {
261269
if (this._element.width != this._element.clientWidth) {
262270
this._element.width = this._element.clientWidth;
263271
}
264-
var ctx = this._element.getContext("2d");
265-
ctx.clearRect(0, 0, this._element.width, this._element.height);
266-
this._applyOptions(ctx);
267-
this._mousePosis.filter((stroke) => stroke.length > 2).forEach((stroke) => drawPoints(ctx, stroke));
272+
if (this._drawing) {
273+
var ctx = this._element.getContext("2d");
274+
this._applyOptions(ctx);
275+
this._mousePosis.filter((stroke) => stroke.length > 0).forEach((stroke) => drawPoints(ctx, stroke));
276+
}
268277
}
269278
}
270279

271-
272-
273280
const requestAnimFrame = (function (callback) {
274281
return window.requestAnimationFrame ||
275282
window.webkitRequestAnimationFrame ||

0 commit comments

Comments
 (0)