multixy: assign touch points to closest handles (snap and non-snap) , yeah !
This commit is contained in:
parent
0fcedcd9b0
commit
ba10ec2d18
2 changed files with 57 additions and 35 deletions
|
|
@ -65,6 +65,9 @@ module.exports = class MultiXy extends _pads_base {
|
|||
: false
|
||||
|
||||
this.handles = []
|
||||
this.handlesPositions = []
|
||||
this.handlesToPads = []
|
||||
|
||||
this.pads = []
|
||||
|
||||
for (var i=widgetData.points-1;i>=0;i--) {
|
||||
|
|
@ -82,28 +85,54 @@ module.exports = class MultiXy extends _pads_base {
|
|||
this.pads[i].draw = ()=>{}
|
||||
this.wrapper.append(this.pads[i].widget)
|
||||
|
||||
this.handles[i] = $(`<div class="handle">${i}</div>`)
|
||||
this.handles[i] = $(`<div class="handle"></div>`)
|
||||
|
||||
this.wrapper.append(this.handles[i])
|
||||
|
||||
let pad = this.pads[i]
|
||||
pad.wrapper.on('draginit',(e)=>{
|
||||
pad.widget.addClass('active')
|
||||
})
|
||||
pad.wrapper.on('dragend',(e)=>{
|
||||
pad.widget.removeClass('active')
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
this.value = []
|
||||
|
||||
this.handles.forEach((handle, i)=>{
|
||||
handle.on('draginit drag dragend',(e, data, traversing)=>{
|
||||
if (widgetData.snap && e.type == 'draginit') {
|
||||
e.type = 'drag'
|
||||
this.pads[i].widget.addClass('active')
|
||||
this.handles.forEach((handle, index)=>{
|
||||
|
||||
handle.on('draginit',(e, data, traversing)=>{
|
||||
|
||||
handle.addClass('active')
|
||||
|
||||
var id, ndiff, diff = -1
|
||||
|
||||
for (var i in this.handles) {
|
||||
if (this.handlesToPads.indexOf(i) != -1) continue
|
||||
ndiff = Math.abs(data.offsetX - this.handlesPositions[i][0]) + Math.abs(data.offsetY - (this.handlesPositions[i][1] + this.height))
|
||||
if (diff == -1 || ndiff < diff) {
|
||||
id = i
|
||||
diff = ndiff
|
||||
}
|
||||
}
|
||||
this.pads[i].wrapper.trigger(e.type, [data, traversing])
|
||||
|
||||
this.handlesToPads[index] = id
|
||||
|
||||
if (this.pads[id]) this.pads[id].wrapper.trigger(e.type, [data, traversing])
|
||||
|
||||
})
|
||||
|
||||
handle.on('drag',(e, data, traversing)=>{
|
||||
|
||||
var id = this.handlesToPads[index]
|
||||
if (this.pads[id]) this.pads[id].wrapper.trigger(e.type, [data, traversing])
|
||||
|
||||
})
|
||||
|
||||
handle.on('dragend',(e, data, traversing)=>{
|
||||
|
||||
var id = this.handlesToPads[index]
|
||||
if (this.pads[id]) this.pads[id].wrapper.trigger(e.type, [data, traversing])
|
||||
handle.removeClass('active')
|
||||
this.handlesToPads[index] = false
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
this.wrapper.on('sync',(e)=>{
|
||||
|
|
@ -131,11 +160,10 @@ module.exports = class MultiXy extends _pads_base {
|
|||
updateHandlesPosition() {
|
||||
|
||||
for (var i=0;i<this.widgetData.points;i++) {
|
||||
this.handles[i][0].setAttribute('style',`
|
||||
transform:translate3d(${clip(this.pads[i].faders.x.percent,[0,100]) / 100 * (this.width - (this.pointSize * 2 + 2) * PXSCALE) + (this.pointSize + 1) * PXSCALE}px,
|
||||
${- clip(this.pads[i].faders.y.percent,[0,100]) / 100 * (this.height - (this.pointSize * 2 + 2) * PXSCALE) - (this.pointSize + 1) * PXSCALE}px,
|
||||
0);
|
||||
`)
|
||||
|
||||
this.handlesPositions[i] = [clip(this.pads[i].faders.x.percent,[0,100]) / 100 * (this.width - (this.pointSize * 2 + 2) * PXSCALE) + (this.pointSize + 1) * PXSCALE
|
||||
,- clip(this.pads[i].faders.y.percent,[0,100]) / 100 * (this.height - (this.pointSize * 2 + 2) * PXSCALE) - (this.pointSize + 1) * PXSCALE]
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@
|
|||
pointer-events: none;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
> .wrapper {
|
||||
padding: calc(var(--point-size) + 1rem);
|
||||
&:after {
|
||||
|
|
@ -140,13 +141,21 @@
|
|||
top:0;
|
||||
left:0;
|
||||
}
|
||||
> .pad {
|
||||
.handle {
|
||||
position: absolute;
|
||||
width:calc(100% - 2 * var(--point-size) - 2rem);
|
||||
height:calc(100% - 2 * var(--point-size) - 2rem);
|
||||
cursor: -webkit-grab;
|
||||
z-index: 1;
|
||||
&.active {
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
> .pad {
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
width:calc(100% - 2 * var(--point-size) - 2rem);
|
||||
height:calc(100% - 2 * var(--point-size) - 2rem);
|
||||
.wrapper {
|
||||
background: transparent;
|
||||
&:after {
|
||||
|
|
@ -160,21 +169,6 @@
|
|||
opacity: 0;
|
||||
}
|
||||
}
|
||||
> .handle {
|
||||
position: absolute;
|
||||
left:0;
|
||||
bottom:0;
|
||||
width:calc(var(--point-size) * 2 + 4rem);
|
||||
height: calc(var(--point-size) * 2 + 4rem);
|
||||
margin:0 0 calc(-1 * var(--point-size) - 2rem) calc(-1 * var(--point-size) - 2rem);
|
||||
text-align: center;
|
||||
line-height: calc(var(--point-size) * 2 + 4rem);
|
||||
border-radius: calc(var(--point-size) * 2 + 4rem);
|
||||
cursor: -webkit-grab;
|
||||
opacity: 0;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue