patchbay: interaction and rendering issues + use draginit instead of fast-click

This commit is contained in:
jean-emmanuel 2026-03-01 11:12:34 +01:00
parent e682455872
commit bfc1d182be
2 changed files with 24 additions and 12 deletions

View file

@ -200,31 +200,42 @@ class PatchBay extends Container(Canvas) {
this.connecting = []
this.mousePosition = []
this.dragging = false
this.on('fast-click', (e)=>{
this.on('draginit', (e)=>{
this.toggleConnection(e.target)
e.stopPropagation()
if (e.target === this.canvas) {
this.mousePosition = [e.offsetX, e.offsetY]
} else {
if (this.inputNodes.includes(e.target)) {
this.mousePosition = [e.offsetX - e.target.offsetWidth, e.offsetY + e.target.offsetTop]
} else {
this.mousePosition = [e.offsetX + this.canvas.offsetWidth, e.offsetY + e.target.offsetTop]
}
}
}, {element: this.widget})
this.mousePosition = []
this.on('drag', (e)=>{
if (!this.connecting.length) {
this.toggleConnection(e.target)
}
if (e.target === this.canvas) {
this.mousePosition = [e.offsetX, e.offsetY]
} else if (this.mousePosition.length) {
this.mousePosition[0] += e.movementX
this.mousePosition[1] += e.movementY
}
this.mousePosition[0] += e.movementX
this.mousePosition[1] += e.movementY
this.dragging = true
this.batchDraw()
}, {element: this.widget})
this.on('dragend', (e)=>{
if (this.mousePosition.length) {
if (this.dragging) {
// touch hover fix
var node = e.isTouch ? document.elementFromPoint(e.clientX, e.clientY) : e.target
this.mousePosition = []
this.toggleConnection(e.target)
this.toggleConnection(node)
}
this.dragging = false
}, {element: this.widget})