@ -252,14 +252,9 @@ function wheel(e, state, context) {
schedule _draw ( state , context ) ;
schedule _draw ( state , context ) ;
}
}
function touchstart ( e , state ) {
function touchstart ( e , state , context ) {
e . preventDefault ( ) ;
e . preventDefault ( ) ;
if ( state . touch . drawing ) {
// Ingore subsequent touches if we are already drawing
return ;
}
// First finger(s) down?
// First finger(s) down?
if ( state . touch . ids . length === 0 ) {
if ( state . touch . ids . length === 0 ) {
if ( e . changedTouches . length === 1 ) {
if ( e . changedTouches . length === 1 ) {
@ -269,6 +264,7 @@ function touchstart(e, state) {
state . touch . moves = 0 ;
state . touch . moves = 0 ;
state . touch . buffered . length = 0 ;
state . touch . buffered . length = 0 ;
state . touch . ids . push ( e . changedTouches [ 0 ] . identifier ) ;
state . touch . ids . push ( e . changedTouches [ 0 ] . identifier ) ;
state . touch . drawing = true ;
setTimeout ( ( ) => {
setTimeout ( ( ) => {
state . touch . waiting _for _second _finger = false ;
state . touch . waiting _for _second _finger = false ;
@ -283,6 +279,9 @@ function touchstart(e, state) {
// There are touches already
// There are touches already
if ( state . touch . waiting _for _second _finger ) {
if ( state . touch . waiting _for _second _finger ) {
if ( e . changedTouches . length === 1 ) {
if ( e . changedTouches . length === 1 ) {
geometry _clear _player ( state , context , state . me ) ; // Hide predraws of this stroke that is not means to be
fire _event ( state , clear _event ( state ) ) ; // Tell others to hide predraws of this stroke
state . touch . ids . push ( e . changedTouches [ 0 ] . identifier ) ;
state . touch . ids . push ( e . changedTouches [ 0 ] . identifier ) ;
for ( const touch of e . touches ) {
for ( const touch of e . touches ) {
@ -317,35 +316,17 @@ function touchmove(e, state, context) {
return ;
return ;
}
}
if ( ! state . touch . drawing ) {
state . touch . moves += 1 ;
// Buffer this move
state . touch . moves += 1 ;
if ( state . touch . moves > config . buffer _first _touchmoves ) {
if ( state . touch . moves > config . buffer _first _touchmoves ) {
// Start drawing, no more waiting
// At this point touch with second finger will NOT start a pan
state . touch . waiting _for _second _finger = false ;
state . touch . waiting _for _second _finger = false ;
state . touch . drawing = true ;
}
} else {
state . touch . buffered . push ( canvasp ) ;
}
} else {
// Handle buffered moves
if ( state . touch . buffered . length > 0 ) {
geometry _clear _player ( state , context , state . me ) ;
for ( const p of state . touch . buffered ) {
geometry _add _point ( state , context , state . me , p ) ;
fire _event ( state , predraw _event ( p . x , p . y ) ) ;
}
state . touch . buffered . length = 0 ;
}
geometry _add _point ( state , context , state . me , canvasp ) ;
geometry _add _point ( state , context , state . me , canvasp ) ;
fire _event ( state , predraw _event ( canvasp . x , canvasp . y ) ) ;
fire _event ( state , predraw _event ( canvasp . x , canvasp . y ) ) ;
schedule _draw ( state , context ) ;
schedule _draw ( state , context ) ;
}
return ;
return ;
}
}