Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event Ordering for touch and mouse events #7378

Merged
merged 13 commits into from
Dec 3, 2024
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
Loading