@ -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 ) {
// Start drawing, no more waiting
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 ;
if ( state . touch . moves > config . buffer _first _touchmoves ) {
}
// At this point touch with second finger will NOT start a pan
state . touch . waiting _for _second _finger = false ;
}
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 ;
}
}
@ -416,7 +397,7 @@ function touchend(e, state, context) {
if ( state . touch . ids [ 0 ] == touch . identifier ) {
if ( state . touch . ids [ 0 ] == touch . identifier ) {
// const event = stroke_event();
// const event = stroke_event();
// await queue_event(event);
// await queue_event(event);
const stroke = geometry _prepare _stroke ( state ) ;
const stroke = geometry _prepare _stroke ( state ) ;
if ( stroke ) {
if ( stroke ) {