Skip to content

Commit

Permalink
Merge pull request #7378 from diyaayay/Event-ordering
Browse files Browse the repository at this point in the history
Event Ordering for touch and mouse events
  • Loading branch information
davepagurek authored Dec 3, 2024
2 parents e986778 + 4632483 commit bc5db33
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 908 deletions.
19 changes: 11 additions & 8 deletions src/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class p5 {
this._initializeInstanceVariables();
this._events = {
// keep track of user-events for unregistering later
mousemove: null,
mousedown: null,
mouseup: null,
pointerdown: null,
pointerup: null,
pointermove: null,
dragend: null,
dragover: null,
click: null,
Expand All @@ -72,16 +72,11 @@ class p5 {
keyup: null,
keypress: null,
wheel: null,
touchstart: null,
touchmove: null,
touchend: null,
resize: null,
blur: null
};
this._millisStart = -1;
this._recording = false;
this._touchstart = false;
this._touchend = false;

// States used in the custom random generators
this._lcg_random_state = null; // NOTE: move to random.js
Expand Down Expand Up @@ -233,6 +228,14 @@ class p5 {
// unhide any hidden canvases that were created
const canvases = document.getElementsByTagName('canvas');

// Apply touchAction = 'none' to canvases if pointer events exist
if (Object.keys(this._events).some(event => event.startsWith('pointer'))) {
for (const k of canvases) {
k.style.touchAction = 'none';
}
}


for (const k of canvases) {
if (k.dataset.hidden === 'true') {
k.style.visibility = '';
Expand Down
6 changes: 2 additions & 4 deletions src/events/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import acceleration from './acceleration.js';
import keyboard from './keyboard.js';
import mouse from './mouse.js';
import touch from './touch.js';
import pointer from './pointer.js';

export default function(p5){
p5.registerAddon(acceleration);
p5.registerAddon(keyboard);
p5.registerAddon(mouse);
p5.registerAddon(touch);
p5.registerAddon(pointer);
}
Loading

0 comments on commit bc5db33

Please sign in to comment.