9
9
const sigpadMap = new Map ( ) ;
10
10
11
11
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 ) {
14
14
var b = points [ 0 ] ;
15
15
ctx . beginPath ( ) , ctx . arc ( b . x , b . y , ctx . lineWidth / 2 , 0 , Math . PI * 2 , ! 0 ) , ctx . closePath ( ) , ctx . fill ( ) ;
16
16
return
17
17
}
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
+
18
27
ctx . beginPath ( ) , ctx . moveTo ( points [ 0 ] . x , points [ 0 ] . y ) ;
19
28
// draw a bunch of quadratics, using the average of two points as the control point
20
29
var i ;
@@ -59,7 +68,6 @@ export default class Sigpad {
59
68
this . _config = this . _getConfig ( options ) ;
60
69
this . _element = element ;
61
70
this . _mousePosis = [ ] ;
62
- this . _mousePosisChanged = true ;
63
71
this . _drawing = false ;
64
72
65
73
this . _setListeners ( ) ;
@@ -222,6 +230,7 @@ export default class Sigpad {
222
230
return ;
223
231
}
224
232
233
+ data . render ( ) ;
225
234
data . _drawing = false ;
226
235
227
236
const event = new CustomEvent ( 'sigpad.finish' , { detail : data . getImage ( ) } ) ;
@@ -230,7 +239,7 @@ export default class Sigpad {
230
239
231
240
_onMove ( sender , mouseEvent ) {
232
241
if ( ! this . _drawing ) return ;
233
- mouseEvent . preventDefault ( ) ;
242
+ // mouseEvent.preventDefault();
234
243
if ( "touches" in mouseEvent ) {
235
244
mouseEvent = mouseEvent . touches [ 0 ] ;
236
245
}
@@ -244,9 +253,8 @@ export default class Sigpad {
244
253
if ( data . _drawing ) {
245
254
var pos = data . _getRelativeMousePos ( mouseEvent ) ;
246
255
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' , { } ) ;
250
258
data . _element . dispatchEvent ( event ) ;
251
259
} else {
252
260
console . log ( "OUT OF BOUNDS" )
@@ -261,15 +269,14 @@ export default class Sigpad {
261
269
if ( this . _element . width != this . _element . clientWidth ) {
262
270
this . _element . width = this . _element . clientWidth ;
263
271
}
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
+ }
268
277
}
269
278
}
270
279
271
-
272
-
273
280
const requestAnimFrame = ( function ( callback ) {
274
281
return window . requestAnimationFrame ||
275
282
window . webkitRequestAnimationFrame ||
0 commit comments