sliders: add touchAddress option (issue #61)

This commit is contained in:
jean-emmanuel 2017-05-19 15:45:09 +02:00
parent 568ec10245
commit 030c700236
7 changed files with 59 additions and 12 deletions

View file

@ -10,6 +10,7 @@
- javascript object are now stringifyied before beeing sent
- widgets
- maths: add `condition` option to [`formula`]http://osc.ammd.net/user-guide/widgets-specifics/maths/#formula)
- sliders: add `touchAddress` option
## 0.17.7

View file

@ -24,12 +24,20 @@ module.exports = class _widgets_base {
}
sendValue() {
sendValue(overrides) {
osc.send({
var data = {
h:this.hash,
v:this.value
})
}
if (overrides) {
for (var k in overrides) {
data[k] = overrides[k]
}
}
osc.send(data)
}

View file

@ -60,12 +60,7 @@ module.exports = class _sliders_base extends _canvas_base {
this.widget.on('mousewheel',this.mousewheelHandleProxy.bind(this))
this.canvas.on('draginit',this.draginitHandleProxy.bind(this))
this.canvas.on('drag',this.dragHandleProxy.bind(this))
if (widgetData.spring) {
this.canvas.on('dragend', ()=>{
this.setValue(this.springValue,{sync:true,send:true,fromLocal:true})
})
}
this.canvas.on('dragend',this.dragendHandleProxy.bind(this))
this.input.change(()=>{
@ -95,6 +90,11 @@ module.exports = class _sliders_base extends _canvas_base {
}
dragendHandleProxy() {
this.dragendHandle(...arguments)
}
mousewheelHandle(e, data, traversing) {
@ -113,13 +113,30 @@ module.exports = class _sliders_base extends _canvas_base {
}
draginitHandle(e, data, traversing) {
if (this.widgetData.touchAddress && this.widgetData.touchAddress.length)
this.sendValue({
address:this.widgetData.touchAddress,
v:1
})
}
dragHandle(e, data, traversing) {
}
dragendHandle(e, data, traversing) {
if (this.widgetData.spring)
this.setValue(this.springValue,{sync:true,send:true,fromLocal:true})
if (this.widgetData.touchAddress && this.widgetData.touchAddress.length)
this.sendValue({
address:this.widgetData.touchAddress,
v:0
})
}
resizeHandle(e, width, height, checkColors) {
if (!this.visible || checkColors) {

View file

@ -72,6 +72,7 @@ module.exports = class Encoder extends _widgets_base {
release:'',
precision:2,
address:'auto',
touchAddress:'',
preArgs:[],
target:[]
}
@ -140,15 +141,29 @@ module.exports = class Encoder extends _widgets_base {
})
this.wrapper.on('draginit', (e)=>{
if (this.widgetData.touchAddress && this.widgetData.touchAddress.length
&& e.target == this.wrapper[0])
this.sendValue({
address:this.widgetData.touchAddress,
v:1
})
})
this.wrapper.on('dragend', (e)=>{
if (widgetData.release !== '' && this.value !== widgetData.release) {
this.knob.setValue(this.ticks/2)
this.display.setValue(this.ticks/2)
this.setValue(widgetData.release, {sync:true, send:true, dragged:false})
}
if (this.widgetData.touchAddress && this.widgetData.touchAddress.length
&& e.target == this.wrapper[0])
this.sendValue({
address:this.widgetData.touchAddress,
v:0
})
})
}
setValue(v,options={}) {

View file

@ -40,6 +40,7 @@ module.exports = class Fader extends _sliders_base {
precision:2,
meter:false,
address:'auto',
touchAddress:'',
preArgs:[],
target:[]
}
@ -123,6 +124,8 @@ module.exports = class Fader extends _sliders_base {
draginitHandle(e, data, traversing) {
super.draginitHandle(...arguments)
this.percent = clip(this.percent,[0,100])
if (!(traversing || this.widgetData.snap)) return
@ -139,6 +142,8 @@ module.exports = class Fader extends _sliders_base {
dragHandle(e, data) {
super.dragHandle(...arguments)
this.percent = this.widgetData.horizontal?
this.percent + ( data.speedX/(this.width - this.margin * PXSCALE * 2)) * 100:
this.percent + (-data.speedY/(this.height - this.margin * PXSCALE * 2)) * 100

View file

@ -37,6 +37,7 @@ module.exports = class Knob extends _sliders_base {
logScale:false,
precision:2,
address:'auto',
touchAddress:'',
preArgs:[],
target:[]
}

View file

@ -52,7 +52,7 @@
padding: 6rem 7rem 4rem;
// border:1rem solid var(--color-bg);
// border-bottom: 1rem solid var(--color-bg);
min-width: 25%;
min-width: 29%;
box-shadow: 1rem 0 0 0 var(--color-bg) inset;
margin-top: 1rem;
}