mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
65 lines
1.7 KiB
JavaScript
Executable File
65 lines
1.7 KiB
JavaScript
Executable File
import DragMove from "../input/DragMove"
|
|
import GraphElement from "./GraphElement"
|
|
|
|
export default class SelectableDraggable extends GraphElement {
|
|
|
|
constructor(...args) {
|
|
super(...args)
|
|
this.dragObject = null
|
|
this.location = [0, 0]
|
|
this.selected = false
|
|
/** @type {import("../template/SelectableDraggableTemplate").default} */
|
|
this.template
|
|
|
|
let self = this
|
|
this.dragHandler = (e) => {
|
|
self.addLocation(e.detail.value)
|
|
}
|
|
}
|
|
|
|
createInputObjects() {
|
|
return [
|
|
new DragMove(this, this.blueprint, {
|
|
looseTarget: true
|
|
}),
|
|
]
|
|
}
|
|
|
|
setLocation(value = [0, 0]) {
|
|
this.location = value
|
|
this.template.applyLocation(this)
|
|
}
|
|
|
|
addLocation(value) {
|
|
this.setLocation([this.location[0] + value[0], this.location[1] + value[1]])
|
|
}
|
|
|
|
setSelected(value = true) {
|
|
if (this.selected == value) {
|
|
return
|
|
}
|
|
this.selected = value
|
|
if (this.selected) {
|
|
this.blueprint.addEventListener("ueb-node-drag", this.dragHandler)
|
|
} else {
|
|
this.blueprint.removeEventListener("ueb-node-drag", this.dragHandler)
|
|
}
|
|
this.template.applySelected(this)
|
|
}
|
|
|
|
dispatchDragEvent(value) {
|
|
if (!this.selected) {
|
|
this.blueprint.unselectAll()
|
|
this.setSelected(true)
|
|
}
|
|
let dragEvent = new CustomEvent("ueb-node-drag", {
|
|
detail: {
|
|
instigator: this,
|
|
value: value
|
|
},
|
|
cancelable: true
|
|
})
|
|
this.blueprint.dispatchEvent(dragEvent)
|
|
}
|
|
}
|