sliders/pads: implement osc touch state as a mixin #61

This commit is contained in:
jean-emmanuel 2017-05-28 15:15:47 +02:00
parent 61c48eefef
commit 03b698f98a
6 changed files with 42 additions and 13 deletions

View file

@ -0,0 +1,28 @@
module.exports = (self, element)=>{
self._touched = 0
element.on('draginit',(e)=>{
self._touched += 1
if (self._touched == 1)
self.sendValue({
address:self.widgetData.touchAddress,
v:1,
split:false
})
})
element.on('dragend', (e, data, traversing)=>{
if (self._touched == 1) {
self._touched = 0
self.sendValue({
address:self.widgetData.touchAddress,
v:0,
split:false
})
} else if (self._touched > 1){
self._touched -= 1
if (traversing) self._touched = 1
}
})
}

View file

@ -1,4 +1,5 @@
var _canvas_base = require('../common/_canvas_base')
var _canvas_base = require('../common/_canvas_base'),
osctouchstate = require('../mixins/osctouchstate')
module.exports = class _pads_base extends _canvas_base {
@ -16,6 +17,9 @@ module.exports = class _pads_base extends _canvas_base {
this.wrapper = this.widget.find('.wrapper')
if (this.widgetData.touchAddress && this.widgetData.touchAddress.length)
osctouchstate(this, this.wrapper)
}
}

View file

@ -37,6 +37,7 @@ module.exports = class MultiXy extends _pads_base {
value:'',
precision:2,
address:'auto',
touchAddress:'',
preArgs:[],
split:false,
target:[]

View file

@ -30,6 +30,7 @@ module.exports = class Rgb extends _pads_base {
value:'',
precision:0,
address:'auto',
touchAddress:'',
preArgs:[],
split:false,
target:[]

View file

@ -35,6 +35,7 @@ module.exports = class Xy extends _pads_base {
value:'',
precision:2,
address:'auto',
touchAddress:'',
preArgs:[],
split:false,
target:[]

View file

@ -1,5 +1,6 @@
var {clip, mapToScale} = require('../utils'),
_canvas_base = require('../common/_canvas_base')
_canvas_base = require('../common/_canvas_base'),
osctouchstate = require('../mixins/osctouchstate')
module.exports = class _sliders_base extends _canvas_base {
@ -57,6 +58,9 @@ module.exports = class _sliders_base extends _canvas_base {
}
}.bind(this))
if (this.widgetData.touchAddress && this.widgetData.touchAddress.length)
osctouchstate(this, this.canvas)
this.widget.on('mousewheel',this.mousewheelHandleProxy.bind(this))
this.canvas.on('draginit',this.draginitHandleProxy.bind(this))
this.canvas.on('drag',this.dragHandleProxy.bind(this))
@ -113,11 +117,7 @@ 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) {
@ -129,12 +129,6 @@ module.exports = class _sliders_base extends _canvas_base {
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) {