mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-24 07:44:42 +08:00
Input system further simplified
This commit is contained in:
23
js/input/UPointing.js
Normal file
23
js/input/UPointing.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import Utility from "../Utility"
|
||||
|
||||
export default class UPointing {
|
||||
|
||||
constructor(target, blueprint, options) {
|
||||
/** @type {HTMLElement} */
|
||||
this.target = target
|
||||
/** @type {import("../UEBlueprint").default}" */
|
||||
this.blueprint = blueprint
|
||||
this.moveEverywhere = options?.moveEverywhere ?? false
|
||||
this.movementSpace = this.blueprint?.getGridDOMElement() ?? document.documentElement
|
||||
}
|
||||
|
||||
getLocation(mouseEvent) {
|
||||
const scaleCorrection = 1 / Utility.getScale(this.target)
|
||||
const targetOffset = this.movementSpace.getBoundingClientRect()
|
||||
let location = [
|
||||
(mouseEvent.clientX - targetOffset.x) * scaleCorrection,
|
||||
(mouseEvent.clientY - targetOffset.y) * scaleCorrection
|
||||
]
|
||||
return location
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user