scrpting: restore legacy touch state feature, deprecate it and replace with a more generic onTouch handler
This commit is contained in:
parent
d478de49f6
commit
24db0ed984
11 changed files with 147 additions and 65 deletions
|
|
@ -240,6 +240,32 @@ class Widget extends EventEmitter {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (this.getProp('onTouch')) {
|
||||
this.scripts.onTouch = new Script({props:{
|
||||
id: this.getProp('id') + '.onTouch',
|
||||
onEvent: this.getProp('onTouch'),
|
||||
}, builtIn: true, parent: this, context: {
|
||||
event: {},
|
||||
value: 0
|
||||
}})
|
||||
this.on('touch', (e)=>{
|
||||
var multi = Array.isArray(e.touch),
|
||||
state = multi ? e.touch[1] : e.touch
|
||||
this.scripts.onTouch.run({
|
||||
event: {type: state ? 'start' : 'stop', handle: multi ? e.touch[0] : undefined},
|
||||
value: this.value
|
||||
}, {sync: true, send: true})
|
||||
})
|
||||
}
|
||||
|
||||
// legacy touch state
|
||||
if (String(this.getProp('onValue')).includes('touch') && !this.getProp('onTouch')) {
|
||||
this.on('touch', (e)=>{
|
||||
this.scripts.onValue.setValue(this.value, {id: this.getProp('id'), touch: e.touch, sync: true, send: true})
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.style = null
|
||||
|
|
|
|||
|
|
@ -49,62 +49,67 @@ class CanvasWidget extends Canvas {
|
|||
this.valueLength = Math.max(1, parseInt(this.getProp('valueLength')) || 1)
|
||||
this.value = this.valueLength > 1 ? Array(this.valueLength).fill(0) : 0
|
||||
|
||||
this.scripts.onDraw = new Script({props:{
|
||||
id: this.getProp('id') + '.onDraw',
|
||||
onEvent: this.getProp('onDraw'),
|
||||
}, builtIn: true, parent: this, context: {
|
||||
value: 0,
|
||||
width: 100,
|
||||
height: 100,
|
||||
ctx: {},
|
||||
cssVars: {}
|
||||
}})
|
||||
this.scripts.onDraw._not_editable = true
|
||||
|
||||
|
||||
this.scripts.onTouch = new Script({props:{
|
||||
id: this.getProp('id') + '.onTouch',
|
||||
onEvent: this.getProp('onTouch'),
|
||||
}, builtIn: true, parent: this, context: {
|
||||
value: 0,
|
||||
width: 100,
|
||||
height: 100,
|
||||
event: {}
|
||||
}})
|
||||
this.scripts.onTouch._not_editable = true
|
||||
|
||||
var touchCb = (e, type)=>{
|
||||
|
||||
var event = {...e}
|
||||
delete event.firstTarget
|
||||
event.targetName = event.target.getAttribute('name')
|
||||
event.targetTagName = event.target.tagName
|
||||
var w = widgetManager.getWidgetByElement(event.target)
|
||||
if (w) event.target = w === this ? 'this' : w.getProp('id')
|
||||
else event.target = null
|
||||
event.type = type
|
||||
|
||||
this.scripts.onTouch.run({
|
||||
value: this.value,
|
||||
width: this.width,
|
||||
height: this.height,
|
||||
event: event,
|
||||
}, {sync: true, send: true})
|
||||
|
||||
this.batchDraw()
|
||||
if (this.getProp('onDraw')) {
|
||||
this.scripts.onDraw = new Script({props:{
|
||||
id: this.getProp('id') + '.onDraw',
|
||||
onEvent: this.getProp('onDraw'),
|
||||
}, builtIn: true, parent: this, context: {
|
||||
value: 0,
|
||||
width: 100,
|
||||
height: 100,
|
||||
ctx: {},
|
||||
cssVars: {}
|
||||
}})
|
||||
this.scripts.onDraw._not_editable = true
|
||||
}
|
||||
|
||||
this.on('draginit',(e)=>{
|
||||
touchCb(e, 'start')
|
||||
}, {element: this.container, multitouch: true})
|
||||
if (this.getProp('onTouch')) {
|
||||
|
||||
this.on('drag',(e)=>{
|
||||
touchCb(e, 'move')
|
||||
}, {element: this.container, multitouch: true})
|
||||
this.scripts.onTouch = new Script({props:{
|
||||
id: this.getProp('id') + '.onTouch',
|
||||
onEvent: this.getProp('onTouch'),
|
||||
}, builtIn: true, parent: this, context: {
|
||||
value: 0,
|
||||
width: 100,
|
||||
height: 100,
|
||||
event: {}
|
||||
}})
|
||||
this.scripts.onTouch._not_editable = true
|
||||
|
||||
this.on('dragend',(e)=>{
|
||||
touchCb(e, 'stop')
|
||||
}, {element: this.container, multitouch: true})
|
||||
var touchCb = (e, type)=>{
|
||||
|
||||
var event = {...e}
|
||||
delete event.firstTarget
|
||||
event.targetName = event.target.getAttribute('name')
|
||||
event.targetTagName = event.target.tagName
|
||||
var w = widgetManager.getWidgetByElement(event.target)
|
||||
if (w) event.target = w === this ? 'this' : w.getProp('id')
|
||||
else event.target = null
|
||||
event.type = type
|
||||
|
||||
this.scripts.onTouch.run({
|
||||
value: this.value,
|
||||
width: this.width,
|
||||
height: this.height,
|
||||
event: event,
|
||||
}, {sync: true, send: true})
|
||||
|
||||
this.batchDraw()
|
||||
}
|
||||
|
||||
this.on('draginit',(e)=>{
|
||||
touchCb(e, 'start')
|
||||
}, {element: this.container, multitouch: true})
|
||||
|
||||
this.on('drag',(e)=>{
|
||||
touchCb(e, 'move')
|
||||
}, {element: this.container, multitouch: true})
|
||||
|
||||
this.on('dragend',(e)=>{
|
||||
touchCb(e, 'stop')
|
||||
}, {element: this.container, multitouch: true})
|
||||
|
||||
}
|
||||
|
||||
if (this.getProp('continuous')) {
|
||||
var freq = parseInt(this.getProp('continuous')) || 30
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ module.exports = class MultiXy extends Pad {
|
|||
static defaults() {
|
||||
|
||||
|
||||
return super.defaults().extend({
|
||||
var defaults = super.defaults().extend({
|
||||
style: {
|
||||
_separator_xy_style: 'Xy style',
|
||||
pointSize: {type: 'integer', value: 20, help: 'Defines the points\' size'},
|
||||
|
|
@ -43,6 +43,10 @@ module.exports = class MultiXy extends Pad {
|
|||
}
|
||||
})
|
||||
|
||||
defaults.scripting.onTouch = {type: 'script', value: '', editor:'javascript', help: ['Script executed when the widget is touched. See <a href="https://openstagecontrol.ammd.net/docs/widgets/canvas/">documentation</a>.',]}
|
||||
|
||||
return defaults
|
||||
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ module.exports = class Rgb extends Widget {
|
|||
|
||||
static defaults() {
|
||||
|
||||
return super.defaults().extend({
|
||||
var defaults = super.defaults().extend({
|
||||
class_specific: {
|
||||
snap: {type: 'boolean', value: false, help: [
|
||||
'By default, the points are dragged from their initial position.',
|
||||
|
|
@ -32,6 +32,10 @@ module.exports = class Rgb extends Widget {
|
|||
}
|
||||
})
|
||||
|
||||
defaults.scripting.onTouch = {type: 'script', value: '', editor:'javascript', help: ['Script executed when the widget is touched. See <a href="https://openstagecontrol.ammd.net/docs/widgets/canvas/">documentation</a>.',]}
|
||||
|
||||
return defaults
|
||||
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ module.exports = class Xy extends Pad {
|
|||
|
||||
static defaults() {
|
||||
|
||||
return super.defaults().extend({
|
||||
var defaults = super.defaults().extend({
|
||||
style: {
|
||||
_separator_xy_style: 'Xy style',
|
||||
pointSize: {type: 'integer', value: 20, help: 'Defines the points\' size'},
|
||||
|
|
@ -40,6 +40,10 @@ module.exports = class Xy extends Pad {
|
|||
}
|
||||
})
|
||||
|
||||
defaults.scripting.onTouch = {type: 'script', value: '', editor:'javascript', help: ['Script executed when the widget is touched. See <a href="https://openstagecontrol.ammd.net/docs/widgets/canvas/">documentation</a>.',]}
|
||||
|
||||
return defaults
|
||||
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class Fader extends Slider {
|
|||
|
||||
static defaults() {
|
||||
|
||||
return super.defaults(Fader).extend({
|
||||
var defaults = super.defaults(Fader).extend({
|
||||
style: {
|
||||
_separator_fader_style: 'Fader style',
|
||||
design: {type: 'string', value: 'default', choices: ['default', 'round', 'compact'], help: 'Design style'},
|
||||
|
|
@ -52,6 +52,10 @@ class Fader extends Slider {
|
|||
}
|
||||
})
|
||||
|
||||
defaults.scripting.onTouch = {type: 'script', value: '', editor:'javascript', help: ['Script executed when the widget is touched. See <a href="https://openstagecontrol.ammd.net/docs/widgets/canvas/">documentation</a>.',]}
|
||||
|
||||
return defaults
|
||||
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ module.exports = class Knob extends Slider {
|
|||
|
||||
static defaults() {
|
||||
|
||||
return super.defaults(Knob).extend({
|
||||
var defaults = super.defaults(Knob).extend({
|
||||
style: {
|
||||
_separator_knob_style: 'Knob style',
|
||||
design: {type: 'string', value: 'default', choices: ['default', 'solid', 'line'], help: [
|
||||
|
|
@ -51,6 +51,10 @@ module.exports = class Knob extends Slider {
|
|||
}
|
||||
})
|
||||
|
||||
defaults.scripting.onTouch = {type: 'script', value: '', editor:'javascript', help: ['Script executed when the widget is touched. See <a href="https://openstagecontrol.ammd.net/docs/widgets/canvas/">documentation</a>.',]}
|
||||
|
||||
return defaults
|
||||
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue