mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-23 15:24:45 +08:00
Organizing input actions in device folders
This commit is contained in:
25
js/input/mouse/Pointing.js
Executable file
25
js/input/mouse/Pointing.js
Executable file
@@ -0,0 +1,25 @@
|
||||
import Context from "../Context"
|
||||
import Utility from "../../Utility"
|
||||
|
||||
export default class Pointing extends Context {
|
||||
|
||||
constructor(target, blueprint, options) {
|
||||
super(target, blueprint, options)
|
||||
this.movementSpace = this.blueprint?.getGridDOMElement() ?? document.documentElement
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {MouseEvent} mouseEvent
|
||||
* @returns
|
||||
*/
|
||||
getLocation(mouseEvent) {
|
||||
const scaleCorrection = 1 / Utility.getScale(this.target)
|
||||
const targetOffset = this.movementSpace.getBoundingClientRect()
|
||||
let location = [
|
||||
Math.round((mouseEvent.clientX - targetOffset.x) * scaleCorrection),
|
||||
Math.round((mouseEvent.clientY - targetOffset.y) * scaleCorrection)
|
||||
]
|
||||
return location
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user