96 lines
2.6 KiB
JavaScript
96 lines
2.6 KiB
JavaScript
'use strict';
|
|
|
|
var _const = require('../ticker/const.js');
|
|
var Ticker = require('../ticker/Ticker.js');
|
|
|
|
"use strict";
|
|
class EventsTickerClass {
|
|
constructor() {
|
|
/** The frequency that fake events will be fired. */
|
|
this.interactionFrequency = 10;
|
|
this._deltaTime = 0;
|
|
this._didMove = false;
|
|
this._tickerAdded = false;
|
|
this._pauseUpdate = true;
|
|
}
|
|
/**
|
|
* Initializes the event ticker.
|
|
* @param events - The event system.
|
|
*/
|
|
init(events) {
|
|
this.removeTickerListener();
|
|
this.events = events;
|
|
this.interactionFrequency = 10;
|
|
this._deltaTime = 0;
|
|
this._didMove = false;
|
|
this._tickerAdded = false;
|
|
this._pauseUpdate = true;
|
|
}
|
|
/** Whether to pause the update checks or not. */
|
|
get pauseUpdate() {
|
|
return this._pauseUpdate;
|
|
}
|
|
set pauseUpdate(paused) {
|
|
this._pauseUpdate = paused;
|
|
}
|
|
/** Adds the ticker listener. */
|
|
addTickerListener() {
|
|
if (this._tickerAdded || !this.domElement) {
|
|
return;
|
|
}
|
|
Ticker.Ticker.system.add(this._tickerUpdate, this, _const.UPDATE_PRIORITY.INTERACTION);
|
|
this._tickerAdded = true;
|
|
}
|
|
/** Removes the ticker listener. */
|
|
removeTickerListener() {
|
|
if (!this._tickerAdded) {
|
|
return;
|
|
}
|
|
Ticker.Ticker.system.remove(this._tickerUpdate, this);
|
|
this._tickerAdded = false;
|
|
}
|
|
/** Sets flag to not fire extra events when the user has already moved there mouse */
|
|
pointerMoved() {
|
|
this._didMove = true;
|
|
}
|
|
/** Updates the state of interactive objects. */
|
|
_update() {
|
|
if (!this.domElement || this._pauseUpdate) {
|
|
return;
|
|
}
|
|
if (this._didMove) {
|
|
this._didMove = false;
|
|
return;
|
|
}
|
|
const rootPointerEvent = this.events["_rootPointerEvent"];
|
|
if (this.events.supportsTouchEvents && rootPointerEvent.pointerType === "touch") {
|
|
return;
|
|
}
|
|
globalThis.document.dispatchEvent(new PointerEvent("pointermove", {
|
|
clientX: rootPointerEvent.clientX,
|
|
clientY: rootPointerEvent.clientY,
|
|
pointerType: rootPointerEvent.pointerType,
|
|
pointerId: rootPointerEvent.pointerId
|
|
}));
|
|
}
|
|
/**
|
|
* Updates the state of interactive objects if at least {@link interactionFrequency}
|
|
* milliseconds have passed since the last invocation.
|
|
*
|
|
* Invoked by a throttled ticker update from {@link Ticker.system}.
|
|
* @param ticker - The throttled ticker.
|
|
*/
|
|
_tickerUpdate(ticker) {
|
|
this._deltaTime += ticker.deltaTime;
|
|
if (this._deltaTime < this.interactionFrequency) {
|
|
return;
|
|
}
|
|
this._deltaTime = 0;
|
|
this._update();
|
|
}
|
|
}
|
|
const EventsTicker = new EventsTickerClass();
|
|
|
|
exports.EventsTicker = EventsTicker;
|
|
//# sourceMappingURL=EventTicker.js.map
|