Files
ueblueprint/js/input/mouse/MouseTracking.js
barsdeveloper ed43ee3edd Input refactoring (#12)
* Fix folder name typo

* Smaller fixes

* Shortcut rename to Shortcuts

* Fix quoted attributes in UE 5.3

* remove KeyboardShortcutAction

* Remove more trivial classes

* Rename IKeyboardShortcut

* Node delete shortcut
2023-08-11 02:48:50 +02:00

69 lines
2.2 KiB
JavaScript
Executable File

import Configuration from "../../Configuration.js"
import IPointing from "./IPointing.js"
export default class MouseTracking extends IPointing {
/** @type {IPointing} */
#mouseTracker = null
/** @param {MouseEvent} e */
#mousemoveHandler= e => {
e.preventDefault()
this.setLocationFromEvent(e)
this.blueprint.mousePosition[0] = this.location[0]
this.blueprint.mousePosition[1] = this.location[1]
}
/** @param {CustomEvent} e */
#trackingMouseStolenHandler = e => {
if (!this.#mouseTracker) {
e.preventDefault()
this.#mouseTracker = e.detail.tracker
this.unlistenMouseMove()
}
}
/** @param {CustomEvent} e */
#trackingMouseGaveBackHandler = e => {
if (this.#mouseTracker == e.detail.tracker) {
e.preventDefault()
this.#mouseTracker = null
this.listenMouseMove()
}
}
constructor(target, blueprint, options = {}) {
options.listenOnFocus = true
super(target, blueprint, options)
}
listenMouseMove() {
this.target.addEventListener("mousemove", this.#mousemoveHandler)
}
unlistenMouseMove() {
this.target.removeEventListener("mousemove", this.#mousemoveHandler)
}
listenEvents() {
this.listenMouseMove()
this.blueprint.addEventListener(
Configuration.trackingMouseEventName.begin,
/** @type {(e: Event) => any} */(this.#trackingMouseStolenHandler))
this.blueprint.addEventListener(
Configuration.trackingMouseEventName.end,
/** @type {(e: Event) => any} */(this.#trackingMouseGaveBackHandler))
}
unlistenEvents() {
this.unlistenMouseMove()
this.blueprint.removeEventListener(
Configuration.trackingMouseEventName.begin,
/** @type {(e: Event) => any} */(this.#trackingMouseStolenHandler))
this.blueprint.removeEventListener(
Configuration.trackingMouseEventName.end,
/** @type {(e: Event) => any} */(this.#trackingMouseGaveBackHandler)
)
}
}