xy: implement sync, send, etc
This commit is contained in:
parent
7b30e09320
commit
e0b144c169
2 changed files with 59 additions and 5 deletions
|
|
@ -2,8 +2,6 @@ var _pads_base = require('./_pads_base'),
|
|||
Fader = require('./_fake_fader'),
|
||||
{sendOsc} = require('../utils')
|
||||
|
||||
|
||||
|
||||
module.exports.options = {
|
||||
type:'xy',
|
||||
id:'auto',
|
||||
|
|
@ -40,7 +38,22 @@ var Xy = function(widgetData) {
|
|||
|
||||
_pads_base.apply(this,arguments)
|
||||
|
||||
this.value = []
|
||||
this.widget.append(`
|
||||
<div class="labels row">
|
||||
<span class="input">X</span>
|
||||
<span class="input">Y</span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="input x"></div>
|
||||
<div class="input y"></div>
|
||||
</div>
|
||||
`)
|
||||
|
||||
this.inputs = [
|
||||
this.widget.find('.x').fakeInput({align:'center'}),
|
||||
this.widget.find('.y').fakeInput({align:'center'})
|
||||
]
|
||||
|
||||
|
||||
this.faders = {
|
||||
x: new Fader({
|
||||
|
|
@ -66,18 +79,22 @@ var Xy = function(widgetData) {
|
|||
})
|
||||
}
|
||||
|
||||
this.value = [this.faders.x.value, this.faders.y.value]
|
||||
|
||||
this.wrapper.append(this.faders.x.widget)
|
||||
this.wrapper.append(this.faders.y.widget)
|
||||
|
||||
this.widget.on('sync',(e)=>{
|
||||
e.stopPropagation()
|
||||
|
||||
var {id, widget} = e
|
||||
var {id, widget, options} = e
|
||||
var v = widget.getValue()
|
||||
|
||||
if (this.value[id] != v) {
|
||||
this.value[id] = v
|
||||
this.sendValue()
|
||||
if (options.send) this.sendValue()
|
||||
this.showValue(id)
|
||||
$('body').trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -90,6 +107,24 @@ var Xy = function(widgetData) {
|
|||
this.faders.y.dragHandleProxy(e, data, traversing)
|
||||
})
|
||||
|
||||
this.inputs[0].change(()=>{
|
||||
this.faders.x.setValue(parseFloat(this.inputs[0].val()),{sync:true,send:true})
|
||||
})
|
||||
this.inputs[1].change(()=>{
|
||||
this.faders.y.setValue(parseFloat(this.inputs[1].val()),{sync:true,send:true})
|
||||
})
|
||||
|
||||
this.showValue(0)
|
||||
this.showValue(1)
|
||||
|
||||
this.widget.getValue = () => {
|
||||
return this.value
|
||||
}
|
||||
this.widget.setValue = (v,o) => {
|
||||
this.setValue(v,o)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -97,6 +132,17 @@ Xy.prototype = Object.create(_pads_base.prototype)
|
|||
|
||||
Xy.prototype.constructor = Xy
|
||||
|
||||
Xy.prototype.setValue = function(v, options){
|
||||
if (!v || v.length!=2) return
|
||||
this.faders.x.setValue(v[0], {sync: true, send:options.send})
|
||||
this.faders.y.setValue(v[1], {sync: true, send:options.send})
|
||||
}
|
||||
|
||||
|
||||
Xy.prototype.showValue = function(i){
|
||||
this.inputs[i].val(this.value[i])
|
||||
}
|
||||
|
||||
module.exports.create = function(widgetData) {
|
||||
var xy = new Xy(widgetData)
|
||||
return xy.widget
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue