mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
Small fixes
This commit is contained in:
@@ -45,6 +45,7 @@ export default class Paste extends Context {
|
||||
]
|
||||
node.addLocation(this.blueprint.compensateTranslation(locationOffset))
|
||||
node.setSelected(true)
|
||||
node.snapToGrid()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,50 @@
|
||||
import MouseClickDrag from "./MouseClickDrag"
|
||||
import Utility from "../../Utility"
|
||||
|
||||
/**
|
||||
* @typedef {import("../../graph/SelectableDraggable").default} SelectableDraggable
|
||||
*/
|
||||
export default class MouseMoveNodes extends MouseClickDrag {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {SelectableDraggable} target
|
||||
* @param {*} blueprint
|
||||
* @param {*} options
|
||||
*/
|
||||
constructor(target, blueprint, options) {
|
||||
super(target, blueprint, options)
|
||||
this.stepSize = parseInt(options?.stepSize)
|
||||
this.mousePosition = [0, 0]
|
||||
}
|
||||
|
||||
snapToGrid(location) {
|
||||
return [
|
||||
this.stepSize * Math.round(location[0] / this.stepSize),
|
||||
this.stepSize * Math.round(location[1] / this.stepSize)
|
||||
]
|
||||
this.stepSize = parseInt(options?.stepSize ?? this.blueprint.gridSize)
|
||||
this.mouseLocation = [0, 0]
|
||||
/** @type {SelectableDraggable} */
|
||||
this.target
|
||||
}
|
||||
|
||||
startDrag() {
|
||||
if (isNaN(this.stepSize) || this.stepSize <= 0) {
|
||||
this.stepSize = this.blueprint.gridSnap
|
||||
}
|
||||
// Get the current mouse position
|
||||
this.mousePosition = this.stepSize != 1 ? this.snapToGrid(this.clickedPosition) : this.clickedPosition
|
||||
this.mouseLocation = Utility.snapToGrid(this.clickedPosition, this.stepSize)
|
||||
}
|
||||
|
||||
dragTo(location, movement) {
|
||||
const mousePosition = this.stepSize != 1 ? this.snapToGrid(location) : location
|
||||
const d = [mousePosition[0] - this.mousePosition[0], mousePosition[1] - this.mousePosition[1]]
|
||||
const [mouseLocation, targetLocation] = this.stepSize > 1
|
||||
? [Utility.snapToGrid(location, this.stepSize), Utility.snapToGrid(this.target.location, this.stepSize)]
|
||||
: [location, this.target.location]
|
||||
const d = [
|
||||
mouseLocation[0] - this.mouseLocation[0],
|
||||
mouseLocation[1] - this.mouseLocation[1]
|
||||
]
|
||||
|
||||
if (d[0] == 0 && d[1] == 0) {
|
||||
return
|
||||
}
|
||||
|
||||
// Make sure it snaps on the grid
|
||||
d[0] += targetLocation[0] - this.target.location[0]
|
||||
d[1] += targetLocation[1] - this.target.location[1]
|
||||
|
||||
this.target.dispatchDragEvent(d)
|
||||
|
||||
// Reassign the position of mouse
|
||||
this.mousePosition = mousePosition
|
||||
this.mouseLocation = mouseLocation
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user