xy: remove old widget, add new one

This commit is contained in:
jean-emmanuel 2016-10-20 18:25:25 +02:00
parent 559999153a
commit 5acb8414c8
2 changed files with 2 additions and 212 deletions

View file

@ -9,8 +9,7 @@ var widgets = {
push: require('./widgets/push'),
// pads
test: require('./widgets/pads/xy'),
xy: require('./widgets/xy'),
xy: require('./widgets/pads/xy'),
rgb: require('./widgets/rgb'),
// matrices
@ -34,7 +33,7 @@ var widgets = {
module.exports.categories = {
'Sliders':['fader','knob'],
'Buttons':['toggle','push','switch'],
'Pads':['test','xy','rgb'],
'Pads':['xy','rgb'],
'Matrices':['multifader','multitoggle','multipush'],
'Plots':['plot','eq','visualizer','led','meter','text'],
'Containers':['panel','strip']

View file

@ -1,209 +0,0 @@
var utils = require('./utils'),
clip = utils.clip,
mapToScale = utils.mapToScale,
sendOsc = utils.sendOsc
module.exports.options = {
type:'xy',
id:'auto',
linkId:'',
separator1:'style',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
color:'auto',
css:'',
separator2:'behaviour',
snap:false,
separator3:'osc',
rangeX:{min:0,max:1},
rangeY:{min:0,max:1},
logScaleX:false,
logScaleY:false,
precision:2,
path:'auto',
preArgs:[],
split:false,
target:[]
}
module.exports.create = function(widgetData,container) {
var widget = $(`
<div class="xy-wrapper">
<div class="xy">
<div class="handle"></div>
</div>
<div class="value">
<div class="input disabled">X</div><div class="input disabled">Y</div>
<div class="input x"></div><div class="input y"></div>
</div>
</div>
`),
handle = widget.find('.handle'),
pad = widget.find('.xy'),
value = {x:widget.find('.x').fakeInput({align:'center'}),y:widget.find('.y').fakeInput({align:'center'})},
range = {x:widgetData.rangeX,y:widgetData.rangeY},
snap = widgetData.snap,
split = widgetData.split?
typeof widgetData.split == 'object'?
widgetData.split:{x:widgetData.path+'/x',y:widgetData.path+'/y'}
:false;
logScaleX = widgetData.logScaleX,
logScaleY = widgetData.logScaleY,
roundFactor = Math.pow(10,widgetData.precision)
if (widgetData.height!='auto') widget.addClass('manual-height')
pad.width = 0
pad.height = 0
handle.height = 0
handle.width = 0
widget.value = undefined
pad.resize(function(){
var width = pad.innerWidth(),
height = pad.innerHeight()
if (!width || (pad.height==height && pad.width==width)) return
pad.width = width
pad.height = height
widget.updateUi(handle.width,handle.height)
})
var off = {x:0,y:0}
pad.on('draginit',function(e,data,traversing){
if (snap || traversing) {
var h = ((pad.height-data.offsetY) * 100 / pad.height),
w = (data.offsetX * 100 / pad.width)
widget.updateUi(w,h)
handle.height = h
handle.width = w
var v = widget.getValue()
if (v<widget.value||v>widget.value) {
widget.value = v
widget.sendValue(v)
widget.showValue(v)
widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId, options})
}
}
off = {x:handle.width,y:handle.height}
})
pad.on('drag',function(e,data){
var h = clip((-data.deltaY)*100/pad.height+off.y,[0,100]),
w = clip((data.deltaX)*100/pad.width+off.x,[0,100])
widget.updateUi(w,h)
handle.height = h
handle.width = w
var v = widget.getValue()
if (v<widget.value||v>widget.value) {
widget.value = v
widget.sendValue(v)
widget.showValue(v)
widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId, options})
}
})
widget.updateUi = function(w,h) {
handle[0].setAttribute('style',`transform:translate3d(${pad.width*w/100}px, -${pad.height*h/100}px,0)`)
}
widget.getValue = function() {
var x = mapToScale(handle.width,[0,100],[range.x.min,range.x.max],widgetData.precision,logScaleX),
y = mapToScale(handle.height,[0,100],[range.y.min,range.y.max],widgetData.precision,logScaleY)
return [x,y]
}
widget.setValue = function(v,options={}) {
if (!v || v.length!=2) return
for (i in [0,1]) {
v[i] = clip(Math.round(v[i]*roundFactor)/roundFactor,[range[['x','y'][i]].min,range[['x','y'][i]].max])
}
var w = mapToScale(v[0],[range.x.min,range.x.max],[0,100],false,logScaleX,true)
h = mapToScale(v[1],[range.y.min,range.y.max],[0,100],false,logScaleY,true),
widget.updateUi(w,h)
handle.height = h
handle.width = w
widget.value = v
widget.showValue(v)
if (options.sync) widget.trigger({type:'sync',id:widgetData.id,widget:widget, linkId:widgetData.linkId, options})
if (options.send) widget.sendValue(v)
}
widget.sendValue = function(v) {
var args = widgetData.preArgs.concat(v)
sendOsc({
target:split?false:widgetData.target,
path:widgetData.path,
args:args,
precision:widgetData.precision,
})
if (split) {
sendOsc({
target:widgetData.target,
path:split.x,
args:widgetData.preArgs.concat(v[0]),
precision:widgetData.precision,
sync:false
})
sendOsc({
target:widgetData.target,
path:split.y,
args:widgetData.preArgs.concat(v[1]),
precision:widgetData.precision,
sync:false
})
}
}
widget.showValue = function(v) {
value.x.val(v[0])
value.y.val(v[1])
}
value.x.change(function(){
var v = widget.getValue()
v[0] = clip(value.x.val(),[range.x.min,range.x.max])
widget.setValue(v,{sync:true,send:true})
})
value.y.change(function(){
var v = widget.getValue()
v[1] = clip(value.y.val(),[range.y.min,range.y.max])
widget.setValue(v,{sync:true,send:true})
})
widget.setValue([range.x.min,range.y.min])
return widget
}