@@ -851,7 +851,7 @@ function pointer(p5, fn){
851
851
* </div>
852
852
*/
853
853
fn . touches = [ ] ;
854
- fn . _activeTouches = new Map ( ) ;
854
+ fn . _activePointers = new Map ( ) ;
855
855
856
856
/**
857
857
* A `Boolean` system variable that's `true` if the mouse is pressed and
@@ -920,7 +920,7 @@ function pointer(p5, fn){
920
920
921
921
if ( e . pointerType == 'touch' ) {
922
922
const touches = [ ] ;
923
- for ( const touch of this . _activeTouches . values ( ) ) {
923
+ for ( const touch of this . _activePointers . values ( ) ) {
924
924
touches . push ( getTouchInfo ( canvas , sx , sy , touch ) ) ;
925
925
}
926
926
this . touches = touches ;
@@ -969,11 +969,19 @@ function pointer(p5, fn){
969
969
id : touch . pointerId ,
970
970
} ;
971
971
}
972
- fn . _setMouseButton = function ( e ) {
973
- this . mouseButton . left = ( e . buttons & 1 ) !== 0 ;
974
- this . mouseButton . center = ( e . buttons & 4 ) !== 0 ;
975
- this . mouseButton . right = ( e . buttons & 2 ) !== 0 ;
976
- } ;
972
+
973
+ fn . _setMouseButton = function ( e ) {
974
+ // Check all active touches to determine button states
975
+ this . mouseButton . left = Array . from ( this . _activePointers . values ( ) ) . some ( touch =>
976
+ ( touch . buttons & 1 ) !== 0
977
+ ) ;
978
+ this . mouseButton . center = Array . from ( this . _activePointers . values ( ) ) . some ( touch =>
979
+ ( touch . buttons & 4 ) !== 0
980
+ ) ;
981
+ this . mouseButton . right = Array . from ( this . _activePointers . values ( ) ) . some ( touch =>
982
+ ( touch . buttons & 2 ) !== 0
983
+ ) ;
984
+ } ;
977
985
978
986
/**
979
987
* A function that's called when the mouse moves.
@@ -1152,10 +1160,9 @@ function pointer(p5, fn){
1152
1160
const context = this . _isGlobal ? window : this ;
1153
1161
let executeDefault ;
1154
1162
this . _updatePointerCoords ( e ) ;
1155
-
1156
- if ( e . pointerType === 'touch' ) {
1157
- this . _activeTouches . set ( e . pointerId , e ) ;
1158
- }
1163
+ this . _activePointers . set ( e . pointerId , e ) ;
1164
+ this . _setMouseButton ( e ) ;
1165
+
1159
1166
1160
1167
if ( ! this . mouseIsPressed && typeof context . mouseMoved === 'function' ) {
1161
1168
executeDefault = context . mouseMoved ( e ) ;
@@ -1167,8 +1174,6 @@ function pointer(p5, fn){
1167
1174
if ( executeDefault === false ) {
1168
1175
e . preventDefault ( ) ;
1169
1176
}
1170
- } else {
1171
- this . _setMouseButton ( e ) ;
1172
1177
}
1173
1178
} ;
1174
1179
@@ -1319,13 +1324,9 @@ function pointer(p5, fn){
1319
1324
let executeDefault ;
1320
1325
this . mouseIsPressed = true ;
1321
1326
1322
- if ( e . pointerType === 'touch' ) {
1323
- this . _activeTouches . set ( e . pointerId , e ) ;
1324
- } else {
1325
- this . _setMouseButton ( e ) ;
1326
- }
1327
-
1328
- this . _updatePointerCoords ( e ) ;
1327
+ this . _activePointers . set ( e . pointerId , e ) ;
1328
+ this . _setMouseButton ( e ) ;
1329
+ this . _updatePointerCoords ( e ) ;
1329
1330
1330
1331
if ( typeof context . mousePressed === 'function' ) {
1331
1332
executeDefault = context . mousePressed ( e ) ;
@@ -1483,11 +1484,8 @@ function pointer(p5, fn){
1483
1484
let executeDefault ;
1484
1485
this . mouseIsPressed = false ;
1485
1486
1486
- if ( e . pointerType == 'touch' ) {
1487
- this . _activeTouches . delete ( e . pointerId ) ;
1488
- } else {
1489
- this . _setMouseButton ( e ) ;
1490
- }
1487
+ this . _activePointers . delete ( e . pointerId ) ;
1488
+ this . _setMouseButton ( e ) ;
1491
1489
1492
1490
this . _updatePointerCoords ( e ) ;
1493
1491
0 commit comments