mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-21 06:05:45 +08:00
Large mouse events refactoring and cleanup
This commit is contained in:
38
js/input/USelect.js
Normal file
38
js/input/USelect.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import UMouseClickDrag from "./UMouseClickDrag"
|
||||
|
||||
export default class USelect extends UMouseClickDrag {
|
||||
|
||||
constructor(target, blueprint, options) {
|
||||
super(target, blueprint, options)
|
||||
|
||||
this.blueprint = blueprint // blueprint is needed
|
||||
this.stepSize = options?.stepSize
|
||||
this.mousePosition = [0, 0]
|
||||
}
|
||||
|
||||
clicked(e) {
|
||||
}
|
||||
|
||||
startDrag(e) {
|
||||
this.blueprint.startSelecting(this.clickedPosition)
|
||||
}
|
||||
|
||||
dragTo(e) {
|
||||
let scaleCorrection = 1 / this.blueprint.getScale()
|
||||
const targetOffset = e.target.getBoundingClientRect()
|
||||
const currentTargetOffset = e.currentTarget.getBoundingClientRect()
|
||||
let offset = [
|
||||
e.offsetX + targetOffset.x * scaleCorrection - currentTargetOffset.x * scaleCorrection,
|
||||
e.offsetY + targetOffset.y * scaleCorrection - currentTargetOffset.y * scaleCorrection
|
||||
]
|
||||
this.blueprint.doSelecting(offset)
|
||||
}
|
||||
|
||||
endDrag(e) {
|
||||
if (this.started) {
|
||||
this.blueprint.finishSelecting()
|
||||
} else {
|
||||
this.blueprint.unselectAll()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user