From 9d4ebb1d1eaa22bc16b8dbb570aefc0a4aba1a37 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sat, 17 Dec 2016 15:26:58 +0100 Subject: [PATCH] :warning long commit: rewrite all widget classes using ES6 class expressions, much cleaner this sets firefox version requirement to 46 because of a bug in v45 with spread arguments --- src/browser/js/app/editor/edit-objects.js | 2 +- src/browser/js/app/managers.js | 1 + src/browser/js/app/parser.js | 2 +- src/browser/js/app/widgets.js | 8 +- src/browser/js/app/widgets/buttons/push.js | 206 ++++---- src/browser/js/app/widgets/buttons/switch.js | 102 ++-- src/browser/js/app/widgets/buttons/toggle.js | 151 +++--- .../js/app/widgets/common/_canvas_base.js | 99 ++-- .../js/app/widgets/common/_widgets_base.js | 88 ++-- .../js/app/widgets/containers/modal.js | 118 +++-- .../js/app/widgets/containers/panel.js | 81 ++- .../js/app/widgets/containers/strip.js | 73 ++- .../js/app/widgets/matrices/_matrices_base.js | 46 +- .../js/app/widgets/matrices/keyboard.js | 127 +++-- .../js/app/widgets/matrices/multifader.js | 130 +++-- .../js/app/widgets/matrices/multipush.js | 104 ++-- .../js/app/widgets/matrices/multitoggle.js | 104 ++-- .../js/app/widgets/pads/_fake_fader.js | 22 +- src/browser/js/app/widgets/pads/_pads_base.js | 34 +- src/browser/js/app/widgets/pads/multixy.js | 381 +++++++------- src/browser/js/app/widgets/pads/rgb.js | 361 +++++++------- src/browser/js/app/widgets/pads/xy.js | 326 ++++++------ .../js/app/widgets/plots/_plots_base.js | 254 +++++----- src/browser/js/app/widgets/plots/eq.js | 142 +++--- src/browser/js/app/widgets/plots/led.js | 80 ++- src/browser/js/app/widgets/plots/meter.js | 83 ++-- src/browser/js/app/widgets/plots/plot.js | 88 ++-- src/browser/js/app/widgets/plots/text.js | 84 ++-- .../js/app/widgets/plots/visualizer.js | 219 +++++---- .../js/app/widgets/sliders/_sliders_base.js | 287 ++++++----- src/browser/js/app/widgets/sliders/fader.js | 463 +++++++++--------- src/browser/js/app/widgets/sliders/knob.js | 379 +++++++------- src/browser/js/libs/jquery.fake-input.js | 4 +- 33 files changed, 2331 insertions(+), 2318 deletions(-) diff --git a/src/browser/js/app/editor/edit-objects.js b/src/browser/js/app/editor/edit-objects.js index 082ee3ce..71f2ca84 100644 --- a/src/browser/js/app/editor/edit-objects.js +++ b/src/browser/js/app/editor/edit-objects.js @@ -35,7 +35,7 @@ var editObject = function(container, data, refresh){ for (i in params) { - if (i.indexOf('separator')!=-1) { + if (i.indexOf('_')==0) { $(`
${params[i]}
`).appendTo(form) continue } else if (data[i]===undefined) { diff --git a/src/browser/js/app/managers.js b/src/browser/js/app/managers.js index 0ec37365..c915fb41 100644 --- a/src/browser/js/app/managers.js +++ b/src/browser/js/app/managers.js @@ -81,6 +81,7 @@ WidgetManager.prototype.addWidget = function(widget) { } widget.widget.abstract = widget + if (widget.container) widget.container[0].abstract = widget } diff --git a/src/browser/js/app/parser.js b/src/browser/js/app/parser.js index 945db0ca..98238e75 100644 --- a/src/browser/js/app/parser.js +++ b/src/browser/js/app/parser.js @@ -103,7 +103,7 @@ module.exports.widgets = function(data,parent) { // Set widget's undefined options to default for (i in tmpWidgetOptions[widgetData.type]) { - if (i.indexOf('separator')==-1 && widgetData[i]===undefined) widgetData[i] = tmpWidgetOptions[widgetData.type][i] + if (i.indexOf('_')!=0 && widgetData[i]===undefined) widgetData[i] = tmpWidgetOptions[widgetData.type][i] } // Genrate widget's id, based on its type diff --git a/src/browser/js/app/widgets.js b/src/browser/js/app/widgets.js index 4742d9cc..29dd0205 100644 --- a/src/browser/js/app/widgets.js +++ b/src/browser/js/app/widgets.js @@ -45,7 +45,7 @@ module.exports.categories = { module.exports.widgetOptions = function(){ var r = {} for (i in widgets) { - r[i] = widgets[i].options + r[i] = widgets[i].options() } return r }() @@ -53,7 +53,11 @@ module.exports.widgetOptions = function(){ module.exports.createWidget = function(){ var r = {} for (i in widgets) { - r[i] = widgets[i].create + let x = i, + f = function(){ + return new widgets[x](...arguments) + } + r[i] = f } return r }() diff --git a/src/browser/js/app/widgets/buttons/push.js b/src/browser/js/app/widgets/buttons/push.js index 21916241..e5371e61 100644 --- a/src/browser/js/app/widgets/buttons/push.js +++ b/src/browser/js/app/widgets/buttons/push.js @@ -2,131 +2,133 @@ var _widgets_base = require('../common/_widgets_base'), $document = $(document), osc = require('../../osc') -module.exports.options = { - type:'push', - id:'auto', - linkId:'', +module.exports = class Push extends _widgets_base { - separator1:'style', + static options() { - label:'auto', - left:'auto', - top:'auto', - width:'auto', - height:'auto', - color:'auto', - css:'', + return { + type:'push', + id:'auto', + linkId:'', - separator2:'osc', + separator1:'style', - on:1, - off:0, - norelease:false, - precision:2, - address:'auto', - preArgs:[], - target:[] -} + label:'auto', + left:'auto', + top:'auto', + width:'auto', + height:'auto', + color:'auto', + css:'', -var Push = module.exports.Push = function(widgetData,container) { + separator2:'osc', - _widgets_base.apply(this, arguments) + on:1, + off:0, + norelease:false, + precision:2, + address:'auto', + preArgs:[], + target:[] + } + } - this.widget = $(` -
-
\ - `) + constructor(widgetData) { - this.state = 0 - this.active = 0 - this.lastChanged = 'state' + var widgetHtml = ` +
+ ` - this.widget.on('drag',function(e){e.stopPropagation()}) - this.widget.on('draginit.push',()=>{ - this.widget.off('draginit.push') - this.fakeclick() - }) + super(...arguments, widgetHtml) -} + this.state = 0 + this.active = 0 + this.lastChanged = 'state' - -Push.prototype = Object.create(_widgets_base.prototype) - -Push.prototype.constructor = Push - -Push.prototype.getValue = function(){ - - return this[this.lastChanged] ? - this.widgetData.on != null && this.widgetData.on.value !== undefined ? this.widgetData.on.value : this.widgetData.on - : - this.widgetData.off != null && this.widgetData.off.value !== undefined ? this.widgetData.off.value : this.widgetData.off - -} - -Push.prototype.fakeclick = function(){ - if (!this.active) this.setValuePrivate(this.widgetData.on,{send:true,sync:true}) - $document.on('dragend.push',()=>{ - this.setValuePrivate(this.widgetData.off,{send:true,sync:true}) - $document.off('dragend.push') + this.widget.on('drag',function(e){e.stopPropagation()}) this.widget.on('draginit.push',()=>{ this.widget.off('draginit.push') this.fakeclick() }) - }) -} -Push.prototype.setValuePrivate = function(v,options={}) { - if (v===this.widgetData.on || (this.widgetData.on != null && v.value === this.widgetData.on.value && v.value !== undefined)) { - this.widget.addClass('active') - this.active = 1 - if (options.send) this.sendValue(v) - this.lastChanged = 'active' - if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options}) - } else if (v===this.widgetData.off || (this.widgetData.off != null && v.value === this.widgetData.off.value && v.value !== undefined)) { - this.widget.removeClass('active') - this.active = 0 - if (options.send) this.sendValue(v, this.widgetData.norelease) - this.lastChanged = 'active' - if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options}) } -} -Push.prototype.setValue = function(v,options={}) { - if (!options.fromExternal) { - if (options.send || options.sync) this.setValuePrivate(v,options) - return + getValue(){ + + return this[this.lastChanged] ? + this.widgetData.on != null && this.widgetData.on.value !== undefined ? this.widgetData.on.value : this.widgetData.on + : + this.widgetData.off != null && this.widgetData.off.value !== undefined ? this.widgetData.off.value : this.widgetData.off + } - if (v===this.widgetData.on || (this.widgetData.on != null && v.value === this.widgetData.on.value && v.value !== undefined)) { - this.widget.addClass('on') - this.state = 1 - if (options.send) this.sendValue(v) - this.lastChanged = 'state' - if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId,options:options}) - } else if (v===this.widgetData.off || (this.widgetData.off != null && v.value === this.widgetData.off.value && v.value !== undefined)) { - this.widget.removeClass('on') - this.state = 0 - if (options.send) this.sendValue(v) - this.lastChanged = 'state' - if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId,options:options}) + + fakeclick(){ + + if (!this.active) this.setValuePrivate(this.widgetData.on,{send:true,sync:true}) + $document.on('dragend.push',()=>{ + this.setValuePrivate(this.widgetData.off,{send:true,sync:true}) + $document.off('dragend.push') + this.widget.on('draginit.push',()=>{ + this.widget.off('draginit.push') + this.fakeclick() + }) + }) + } -} -Push.prototype.sendValue = function(v, norelease) { + setValuePrivate(v,options={}) { - var args = this.widgetData.preArgs.concat(v) + if (v===this.widgetData.on || (this.widgetData.on != null && v.value === this.widgetData.on.value && v.value !== undefined)) { + this.widget.addClass('active') + this.active = 1 + if (options.send) this.sendValue(v) + this.lastChanged = 'active' + if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options}) + } else if (v===this.widgetData.off || (this.widgetData.off != null && v.value === this.widgetData.off.value && v.value !== undefined)) { + this.widget.removeClass('active') + this.active = 0 + if (options.send) this.sendValue(v, this.widgetData.norelease) + this.lastChanged = 'active' + if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options}) + } - osc.send({ - target: this.widgetData.target, - address: this.widgetData.address, - precision: this.widgetData.precision, - args:args, - syncOnly:norelease - }) + } + + setValue(v,options={}) { + + if (!options.fromExternal) { + if (options.send || options.sync) this.setValuePrivate(v,options) + return + } + if (v===this.widgetData.on || (this.widgetData.on != null && v.value === this.widgetData.on.value && v.value !== undefined)) { + this.widget.addClass('on') + this.state = 1 + if (options.send) this.sendValue(v) + this.lastChanged = 'state' + if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId,options:options}) + } else if (v===this.widgetData.off || (this.widgetData.off != null && v.value === this.widgetData.off.value && v.value !== undefined)) { + this.widget.removeClass('on') + this.state = 0 + if (options.send) this.sendValue(v) + this.lastChanged = 'state' + if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId,options:options}) + } + + } + + sendValue(v, norelease) { + + var args = this.widgetData.preArgs.concat(v) + + osc.send({ + target: this.widgetData.target, + address: this.widgetData.address, + precision: this.widgetData.precision, + args:args, + syncOnly:norelease + }) + + } } - -module.exports.create = function(widgetData, container) { - var push = new Push(widgetData, container) - return push -} diff --git a/src/browser/js/app/widgets/buttons/switch.js b/src/browser/js/app/widgets/buttons/switch.js index 42591cbd..5d97b2e4 100644 --- a/src/browser/js/app/widgets/buttons/switch.js +++ b/src/browser/js/app/widgets/buttons/switch.js @@ -1,50 +1,51 @@ var _widgets_base = require('../common/_widgets_base'), $document = $(document) -module.exports.options = { - type:'switch', - id:'auto', - linkId:'', +module.exports = class Switch extends _widgets_base { - separator1:'style', + static options() { - label:'auto', - left:'auto', - top:'auto', - width:'auto', - height:'auto', - horizontal:false, - color:'auto', - css:'', + return { + type:'switch', + id:'auto', + linkId:'', - separator2:'osc', + _style:'style', - values:{"Value 1":1,"Value 2":2}, - value:'', - precision:2, - address:'auto', - preArgs:[], - target:[] -} + label:'auto', + left:'auto', + top:'auto', + width:'auto', + height:'auto', + horizontal:false, + color:'auto', + css:'', -var Switch = module.exports.Switch = function(widgetData,container) { + _osc:'osc', - _widgets_base.apply(this, arguments) - - this.widget = $(` -
-
- `) - - if (this.widgetData.horizontal) { - this.widget.addClass('horizontal') + values:{"Value 1":1,"Value 2":2}, + value:'', + precision:2, + address:'auto', + preArgs:[], + target:[] } + } + + constructor(widgetData) { + + var widgetHtml = ` +
+ ` + + super(...arguments, widgetHtml) + this.values = [] - for (k in this.widgetData.values) { - this.values.push(this.widgetData.values[k]) - $('
'+k+'
').data({value:this.widgetData.values[k]}).appendTo(this.widget) + for (var k in widgetData.values) { + this.values.push(widgetData.values[k]) + $('
'+k+'
').data({value:widgetData.values[k]}).appendTo(this.widget) } this.value = undefined @@ -64,28 +65,17 @@ var Switch = module.exports.Switch = function(widgetData,container) { if (value!=this.value || this.value===undefined) this.setValue(value,{sync:true,send:true}) }) - -} - - -Switch.prototype = Object.create(_widgets_base.prototype) - -Switch.prototype.constructor = Switch - - -Switch.prototype.setValue = function(v,options={}) { - var i = this.values.indexOf(v) - if (i!=-1) { - this.value = this.values[i] - this.widget.find('.on').removeClass('on') - this.widget.find('.value').eq(i).addClass('on') - if (options.send) this.sendValue(this.value) - if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options}) } -} + setValue(v,options={}) { -module.exports.create = function(widgetData, container) { - var _switch = new Switch(widgetData, container) - return _switch -} + var i = this.values.indexOf(v) + if (i!=-1) { + this.value = this.values[i] + this.widget.find('.on').removeClass('on') + this.widget.find('.value').eq(i).addClass('on') + if (options.send) this.sendValue(this.value) + if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options}) + } + + }} diff --git a/src/browser/js/app/widgets/buttons/toggle.js b/src/browser/js/app/widgets/buttons/toggle.js index 3e0437f9..e6f32404 100644 --- a/src/browser/js/app/widgets/buttons/toggle.js +++ b/src/browser/js/app/widgets/buttons/toggle.js @@ -1,101 +1,100 @@ var _widgets_base = require('../common/_widgets_base'), $document = $(document) -module.exports.options = { - type:'toggle', - id:'auto', - linkId:'', +module.exports = class Toggle extends _widgets_base { - separator1:'style', + static options() { - label:'auto', - left:'auto', - top:'auto', - width:'auto', - height:'auto', - color:'auto', - css:'', + return { + type:'toggle', + id:'auto', + linkId:'', - separator2:'osc', + _style:'style', - on:1, - off:0, - value:'', - precision:2, - address:'auto', - preArgs:[], - target:[] -} + label:'auto', + left:'auto', + top:'auto', + width:'auto', + height:'auto', + color:'auto', + css:'', -var Toggle = module.exports.Toggle = function(widgetData,container) { + _osc:'osc', - _widgets_base.apply(this, arguments) + on:1, + off:0, + value:'', + precision:2, + address:'auto', + preArgs:[], + target:[] + } - this.widget = $(` -
-
\ - `) + } - this.widget.value = this.widget.find('span') - this.widget.state = 0 + constructor() { - this.widget.on('drag',(e)=>{e.stopPropagation()}) - this.widget.on('draginit.toggle',()=>{ - this.widget.off('draginit.toggle') - this.fakeclick() - }) + var widgetHtml = ` +
+ ` + super(...arguments, widgetHtml) - this.value = this.getValue() + this.widget.value = this.widget.find('span') + this.widget.state = 0 -} - - -Toggle.prototype = Object.create(_widgets_base.prototype) - -Toggle.prototype.constructor = Toggle - -Toggle.prototype.getValue = function(){ - - return this.widget.state ? - this.widgetData.on != null && this.widgetData.on.value !== undefined ? this.widgetData.on.value : this.widgetData.on - : - this.widgetData.off != null && this.widgetData.off.value !== undefined ? this.widgetData.off.value : this.widgetData.off - -} - -Toggle.prototype.fakeclick = function(){ - var newVal = this.widget.state?this.widgetData.off:this.widgetData.on - this.setValue(newVal,{sync:true,send:true}) - $document.on('dragend.toggle',()=>{ - $document.off('dragend.toggle') + this.widget.on('drag',(e)=>{e.stopPropagation()}) this.widget.on('draginit.toggle',()=>{ this.widget.off('draginit.toggle') this.fakeclick() }) - }) -} -Toggle.prototype.setValue = function(v,options={}){ - if (v===this.widgetData.on || (this.widgetData.on != null && v.value === this.widgetData.on.value && v.value !== undefined)) { - this.widget.addClass('on') - this.widget.state = 1 - this.value = this.widgetData.on - if (options.send) this.sendValue(this.widgetData.on) - } else if (v===this.widgetData.off || (this.widgetData.off != null && v.value === this.widgetData.off.value && v.value !== undefined)) { - this.widget.removeClass('on') - this.widget.state = 0 - this.value = this.widgetData.off - if (options.send) this.sendValue(this.widgetData.off) + this.value = this.getValue() + } - if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options}) + getValue() { + + return this.widget.state ? + this.widgetData.on != null && this.widgetData.on.value !== undefined ? this.widgetData.on.value : this.widgetData.on + : + this.widgetData.off != null && this.widgetData.off.value !== undefined ? this.widgetData.off.value : this.widgetData.off + + } + + fakeclick() { + + var newVal = this.widget.state?this.widgetData.off:this.widgetData.on + this.setValue(newVal,{sync:true,send:true}) + $document.on('dragend.toggle',()=>{ + $document.off('dragend.toggle') + this.widget.on('draginit.toggle',()=>{ + this.widget.off('draginit.toggle') + this.fakeclick() + }) + }) + + } + + + setValue(v,options={}) { + + if (v===this.widgetData.on || (this.widgetData.on != null && v.value === this.widgetData.on.value && v.value !== undefined)) { + this.widget.addClass('on') + this.widget.state = 1 + this.value = this.widgetData.on + if (options.send) this.sendValue(this.widgetData.on) + } else if (v===this.widgetData.off || (this.widgetData.off != null && v.value === this.widgetData.off.value && v.value !== undefined)) { + this.widget.removeClass('on') + this.widget.state = 0 + this.value = this.widgetData.off + if (options.send) this.sendValue(this.widgetData.off) + } + + if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options}) + + } } - - -module.exports.create = function(widgetData, container) { - var toggle = new Toggle(widgetData, container) - return toggle -} diff --git a/src/browser/js/app/widgets/common/_canvas_base.js b/src/browser/js/app/widgets/common/_canvas_base.js index ef20060b..29939c0c 100644 --- a/src/browser/js/app/widgets/common/_canvas_base.js +++ b/src/browser/js/app/widgets/common/_canvas_base.js @@ -1,70 +1,71 @@ var _widgets_base = require('./_widgets_base') -var _canvas_base = module.exports = function() { +module.exports = class _canvas_base extends _widgets_base { - _widgets_base.apply(this,arguments) + constructor() { - this.canvas = this.widget.find('canvas') - this.ctx = this.canvas[0].getContext('2d') + super(...arguments) - this.height = undefined - this.width = undefined + this.canvas = this.widget.find('canvas') + this.ctx = this.canvas[0].getContext('2d') - this.visible = false + this.height = undefined + this.width = undefined - this.colors = {} - this.textColor = getComputedStyle(document.documentElement).getPropertyValue('--color-text-fade') + this.visible = false + + this.colors = {} + this.textColor = getComputedStyle(document.documentElement).getPropertyValue('--color-text-fade') - this.canvas.on('resize',this.resizeHandleProxy.bind(this)) + this.canvas.on('resize',this.resizeHandleProxy.bind(this)) - this.ctx.arc = (x, y, r, s, e, c)=>{ + this.ctx.arc = (x, y, r, s, e, c)=>{ - CanvasRenderingContext2D.prototype.arc.call(this.ctx, x, y, Math.max(0,r), s, e, c) + CanvasRenderingContext2D.prototype.arc.call(this.ctx, x, y, Math.max(0,r), s, e, c) + + } } -} - - -_canvas_base.prototype = Object.create(_widgets_base.prototype) - -_canvas_base.prototype.constructor = _canvas_base - -_canvas_base.prototype.resizeHandleProxy = function() { - this.resizeHandle.apply(this,arguments) -} - -_canvas_base.prototype.resizeHandle = function(e, width, height, checkColors){ - - var width = width, - height = height - - if (width && height) { - - this.height=height - this.width=width - - this.canvas[0].setAttribute('width',width) - this.canvas[0].setAttribute('height',height) + resizeHandleProxy() { + + this.resizeHandle(...arguments) } - if (!this.visible || checkColors) { - this.visible = true - var style = getComputedStyle(this.widget[0]) - this.colors.custom = style.getPropertyValue('--color-custom') - this.colors.text = style.getPropertyValue('--color-text') - this.colors.raised = style.getPropertyValue('--color-raised') - this.colors.bg = style.getPropertyValue('--color-bg') - this.colors.fg = style.getPropertyValue('--color-fg') - this.colors.faded = style.getPropertyValue('--color-faded') + resizeHandle(e, width, height, checkColors){ + + var width = width, + height = height + + if (width && height) { + + this.height=height + this.width=width + + this.canvas[0].setAttribute('width',width) + this.canvas[0].setAttribute('height',height) + + } + + if (!this.visible || checkColors) { + this.visible = true + var style = getComputedStyle(this.widget[0]) + this.colors.custom = style.getPropertyValue('--color-custom') + this.colors.text = style.getPropertyValue('--color-text') + this.colors.raised = style.getPropertyValue('--color-raised') + this.colors.bg = style.getPropertyValue('--color-bg') + this.colors.fg = style.getPropertyValue('--color-fg') + this.colors.faded = style.getPropertyValue('--color-faded') + } + + requestAnimationFrame(this.draw.bind(this)) + } - requestAnimationFrame(this.draw.bind(this)) + draw(){ + throw 'Calling unimplemented draw() method' + } } - -_canvas_base.prototype.draw = function(){ - // -} diff --git a/src/browser/js/app/widgets/common/_widgets_base.js b/src/browser/js/app/widgets/common/_widgets_base.js index f995c4f6..776ca0de 100644 --- a/src/browser/js/app/widgets/common/_widgets_base.js +++ b/src/browser/js/app/widgets/common/_widgets_base.js @@ -1,58 +1,72 @@ var osc = require('../../osc') -var _widget_base = module.exports = function(widgetData) { - this.widgetData = widgetData -} +module.exports = class { -_widget_base.prototype.sendValue = function() { + static options() { - var args = this.widgetData.preArgs.concat(this.value) + throw 'Calling unimplemented static options() method' - osc.send({ - target:this.widgetData.target, - address:this.widgetData.address, - precision:this.widgetData.precision, - args:args, - syncOnly:this.split?true:false - }) - - if (this.split) { - var n = 0 - for (i in this.split) { - osc.send({ - target:this.widgetData.target, - address:this.split[i], - precision:this.widgetData.precision, - args:this.widgetData.preArgs.concat(this.value[n]), - sync:false - - }) - n++ - } } -} + constructor(widgetData, widgetContainer, widgetHtml) { -_widget_base.prototype.getValue = function() { + this.container = widgetContainer + this.widget = $(widgetHtml) + this.widgetData = widgetData - if (typeof this.value == 'object') { + } - return (()=>{ + sendValue() { - var a = [] + var args = this.widgetData.preArgs.concat(this.value) - for (i in this.value) { - a.push(this.value[i]) + osc.send({ + target:this.widgetData.target, + address:this.widgetData.address, + precision:this.widgetData.precision, + args:args, + syncOnly:this.split?true:false + }) + + if (this.split) { + var n = 0 + for (i in this.split) { + osc.send({ + target:this.widgetData.target, + address:this.split[i], + precision:this.widgetData.precision, + args:this.widgetData.preArgs.concat(this.value[n]), + sync:false + + }) + n++ } + } - return a + } - })() + getValue() { - } else { + if (typeof this.value == 'object') { - return this.value + return (()=>{ + + var a = [] + + for (i in this.value) { + a.push(this.value[i]) + } + + return a + + })() + + } else { + + return this.value + + } } diff --git a/src/browser/js/app/widgets/containers/modal.js b/src/browser/js/app/widgets/containers/modal.js index a2062280..372b23ce 100644 --- a/src/browser/js/app/widgets/containers/modal.js +++ b/src/browser/js/app/widgets/containers/modal.js @@ -1,69 +1,65 @@ -var {Panel} = require('./panel') - -module.exports.options = { - type:'modal', - id:'auto', - - separator1:'style', - - label:'auto', - left:'auto', - top:'auto', - width:'auto', - height:'auto', - color:'auto', - css:'', - - separator2:'osc', - - address:'auto', - - separator3:'chilren', - - widgets:[], - tabs:[] -} - -var Modal = module.exports.Modal = function(widgetData, container) { - - Panel.apply(this,arguments) - - this.widget.removeClass('noscroll') - this.container = container - - container.append('
') - this.light = container.find('.light').first() - - this.modal = this.widget.detach() - - this.value = false - - this.light.on('fake-click',()=>{ - this.setValue(!this.value) - }) +var Panel = require('./panel'), + _widgets_base = require('../common/_widgets_base') -} +module.exports = class Modal extends Panel { -Modal.prototype = Object.create(Panel.prototype) + static options() { -Modal.prototype.constructor = Modal + return { + type:'modal', + id:'auto', + + _style:'style', + + label:'auto', + left:'auto', + top:'auto', + width:'auto', + height:'auto', + color:'auto', + css:'', + + _osc:'osc', + + address:'auto', + + _chidlren:'chilren', + + widgets:[], + tabs:[] + } + + } + + constructor(widgetData, container) { + + super(...arguments) + + this.widget.removeClass('noscroll') + this.container = container + + container.append('
') + this.light = container.find('.light').first() + + this.modal = this.widget.detach() + + this.value = false + + this.light.on('fake-click',()=>{ + this.setValue(!this.value) + }) + + + } + + setValue(v) { + + this.value = v ? true : false + this.container.toggleClass('on', this.value) + this.widget.toggleClass('on', this.value) + this.light.toggleClass('on', this.value) -Modal.prototype.setValue = function(v) { - if (v) { - this.container.addClass('on') - this.widget.addClass('on') - this.light.addClass('on') - this.value = true - } else { - this.container.removeClass('on') - this.widget.removeClass('on') - this.light.removeClass('on') - this.value = false } -} -module.exports.create = function(widgetData, container) { - var modal = new Modal(widgetData, container) - return modal } diff --git a/src/browser/js/app/widgets/containers/panel.js b/src/browser/js/app/widgets/containers/panel.js index 0524edbe..97e50c70 100644 --- a/src/browser/js/app/widgets/containers/panel.js +++ b/src/browser/js/app/widgets/containers/panel.js @@ -1,56 +1,55 @@ var _widgets_base = require('../common/_widgets_base') -module.exports.options = { - type:'panel', - id:'auto', +module.exports = class Panel extends _widgets_base { - separator1:'style', + static options() { - label:'auto', - left:'auto', - top:'auto', - width:'auto', - height:'auto', - scroll:true, - color:'auto', - css:'', + return { + type:'panel', + id:'auto', - separator2:'chilren', + _style:'style', - widgets:[], - tabs:[] -} + label:'auto', + left:'auto', + top:'auto', + width:'auto', + height:'auto', + scroll:true, + color:'auto', + css:'', -var Panel = module.exports.Panel = function(widgetData) { + _children:'chilren', - _widgets_base.apply(this,arguments) + widgets:[], + tabs:[] + } - var parsers = require('../../parser'), - parsewidgets = parsers.widgets, - parsetabs = parsers.tabs + } + + constructor(widgetData) { - this.widget = $(` -
-
- `) + var widgetHtml = ` +
+
+ ` - if (!widgetData.scroll) this.widget.addClass('noscroll') + super(...arguments, widgetHtml) - if (widgetData.tabs.length) { - parsetabs(widgetData.tabs,this.widget) - this.widget.addClass('has-tabs') - } else { - parsewidgets(widgetData.widgets,this.widget) - } + var parsers = require('../../parser'), + parsewidgets = parsers.widgets, + parsetabs = parsers.tabs + + if (widgetData.tabs.length) { + parsetabs(widgetData.tabs,this.widget) + } else { + parsewidgets(widgetData.widgets,this.widget) + } + + } } - -Panel.prototype = Object.create(_widgets_base.prototype) - -Panel.prototype.constructor = Panel - -module.exports.create = function(widgetData) { - var panel = new Panel(widgetData) - return panel -} diff --git a/src/browser/js/app/widgets/containers/strip.js b/src/browser/js/app/widgets/containers/strip.js index e75a3a4b..16e06a47 100644 --- a/src/browser/js/app/widgets/containers/strip.js +++ b/src/browser/js/app/widgets/containers/strip.js @@ -1,51 +1,50 @@ var _widgets_base = require('../common/_widgets_base') -module.exports.options = { - type:'strip', - id:'auto', +module.exports = class Strip extends _widgets_base { - separator1:'style', + static options() { - label:'auto', - left:'auto', - top:'auto', - width:'auto', - height:'auto', - horizontal:false, - color:'auto', - css:'', + return { + type:'strip', + id:'auto', - separator2:'children', + _style:'style', - widgets:[] -} + label:'auto', + left:'auto', + top:'auto', + width:'auto', + height:'auto', + horizontal:false, + color:'auto', + css:'', -var Strip = module.exports.Strip = function(widgetData, container) { + _children:'children', - _widgets_base.apply(this,arguments) + widgets:[] + } - var parsewidgets = require('../../parser').widgets - - this.widget = $(` -
-
- `) - if (widgetData.horizontal) { - container.addClass('horizontal') - } else { - container.addClass('vertical') } - parsewidgets(widgetData.widgets,this.widget) + constructor(widgetData, container) { + + var widgetHtml = ` +
+ ` + + super(...arguments, widgetHtml) + + var parsewidgets = require('../../parser').widgets + + if (widgetData.horizontal) { + container.addClass('horizontal') + } else { + container.addClass('vertical') + } + + parsewidgets(widgetData.widgets,this.widget) + + } } - -Strip.prototype = Object.create(_widgets_base.prototype) - -Strip.prototype.constructor = Strip - -module.exports.create = function(widgetData, container) { - var strip = new Strip(widgetData, container) - return strip -} diff --git a/src/browser/js/app/widgets/matrices/_matrices_base.js b/src/browser/js/app/widgets/matrices/_matrices_base.js index 0f21c19a..bd495562 100644 --- a/src/browser/js/app/widgets/matrices/_matrices_base.js +++ b/src/browser/js/app/widgets/matrices/_matrices_base.js @@ -1,33 +1,33 @@ var _widgets_base = require('../common/_widgets_base') -var _matrices_base = module.exports = function(widgetData){ +module.exports = class _matrices_base extends _widgets_base { - _widgets_base.apply(this,arguments) + constructor(widgetData) { - this.widget = $(` -
-
\ - `) + var widgetHtml = ` +
+ ` - this.value = [] + super(...arguments, widgetHtml) - widgetData.start = parseInt(widgetData.start) - this.widget.on('sync',function(e){ - if (e.id==this.widgetData.id) return - this.value[e.widget.parent().index()] = e.widget.abstract.getValue() - this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget}) - }.bind(this)) + this.value = [] + widgetData.start = parseInt(widgetData.start) + + this.widget.on('sync',(e)=>{ + + if (e.id==widgetData.id) return + this.value[e.widget.parent().index()] = e.widget.abstract.getValue() + this.widget.trigger({type:'sync',id:widgetData.id,widget:this.widget}) + + }) + + } + + + getValue() { + return this.value + } } - - - -_matrices_base.prototype = Object.create(_widgets_base.prototype) - -_matrices_base.prototype.constructor = _matrices_base - -_matrices_base.prototype.getValue = function(){ - return this.value -} diff --git a/src/browser/js/app/widgets/matrices/keyboard.js b/src/browser/js/app/widgets/matrices/keyboard.js index 5a6ec1c6..bd468447 100644 --- a/src/browser/js/app/widgets/matrices/keyboard.js +++ b/src/browser/js/app/widgets/matrices/keyboard.js @@ -1,99 +1,96 @@ var _matrices_base = require('./_matrices_base') -module.exports.options = { - type:'keyboard', - id:'auto', +module.exports = class Keyboard extends _matrices_base { - separator0: 'Matrix', + static options() { - keys: 24, - start:60, + return { + type:'keyboard', + id:'auto', - separator1:'style', + _matrix: 'Matrix', - label:'auto', - left:'auto', - top:'auto', - width:'auto', - height:'auto', - color:'auto', - css:'', + keys: 24, + start:60, - separator2:'behaviour', + _style:'style', - traversing:true, + label:'auto', + left:'auto', + top:'auto', + width:'auto', + height:'auto', + color:'auto', + css:'', - separator3:'osc', + _behaviour:'behaviour', - on:1, - off:0, - precision:2, - address:'auto', - preArgs:[], - split:false, - target:[] -} + traversing:true, + _osc:'osc', -var Keyboard = module.exports.Keyboard = function(widgetData) { + on:1, + off:0, + precision:2, + address:'auto', + preArgs:[], + split:false, + target:[] + } - _matrices_base.apply(this,arguments) + } - widgetData.keys = parseInt(widgetData.keys) + constructor(widgetData) { - var strData = JSON.stringify(widgetData), + super(...arguments) + + widgetData.keys = parseInt(widgetData.keys) + + var strData = JSON.stringify(widgetData), pattern = 'wbwbwwbwbwbw', wCount = 0 - var parsers = require('../../parser'), + var parsers = require('../../parser'), parsewidgets = parsers.widgets - for (var i=widgetData.start;i -
- + constructor() { + + var widgetHtml = ` +
+
+ +
-
- `) - this.wrapper = this.widget.find('.wrapper') - _canvas_base.apply(this, arguments) + ` - -} - -_pads_base.prototype = Object.create(_canvas_base.prototype) - -_pads_base.prototype.constructor = _pads_base - - -_pads_base.prototype.setValue = function(v,options={}) { - if (typeof v != 'number') return + super(...arguments, widgetHtml) + + this.wrapper = this.widget.find('.wrapper') + + } } diff --git a/src/browser/js/app/widgets/pads/multixy.js b/src/browser/js/app/widgets/pads/multixy.js index 64e85faa..04096289 100644 --- a/src/browser/js/app/widgets/pads/multixy.js +++ b/src/browser/js/app/widgets/pads/multixy.js @@ -1,211 +1,210 @@ var _pads_base = require('./_pads_base'), - {Xy} = require('./xy'), + Xy = require('./xy'), {clip} = require('../utils') -module.exports.options = { - type:'xy', - id:'auto', - linkId:'', +module.exports = class MultiXy extends _pads_base { - separator1:'multi xy', + static options() { - points: 2, - pointSize: 20, - snap:false, - spring:false, + return { + type:'xy', + id:'auto', + linkId:'', - separator2:'style', + _mutlixy:'multi xy', - label:'auto', - left:'auto', - top:'auto', - width:'auto', - height:'auto', - color:'auto', - css:'', + points: 2, + pointSize: 20, + snap:false, + spring:false, - separator3:'osc', + _style:'style', - rangeX:{min:0,max:1}, - rangeY:{min:0,max:1}, - logScaleX:false, - logScaleY:false, - value:'', - precision:2, - address:'auto', - preArgs:[], - split:false, - target:[] -} + label:'auto', + left:'auto', + top:'auto', + width:'auto', + height:'auto', + color:'auto', + css:'', -var MultiXy = module.exports.MultiXy = function(widgetData) { + _osc:'osc', - _pads_base.apply(this,arguments) - - this.pointSize = parseInt(this.widgetData.pointSize) - this.widget[0].style.setProperty("--point-size",this.pointSize + 'rem') - - this.split = this.widgetData.split? - typeof this.widgetData.split == 'object'? - this.widgetData.split - : (()=>{ - var s={}; - for (var i=0; i=0;i--) { - this.pads[i] = new Xy({ - snap:widgetData.snap, - spring:widgetData.spring, - value:widgetData.value.length == widgetData.points * 2 ? [widgetData.value[i*2], widgetData.value[i*2 + 1]] : '', - rangeX:widgetData.rangeX, - rangeY:widgetData.rangeY, - precision:widgetData.precision, - logScaleX:widgetData.logScaleX, - logScaleY:widgetData.logScaleY - }) - this.pads[i].sendValue = ()=>{} - this.pads[i].draw = ()=>{} - this.wrapper.append(this.pads[i].widget) - - this.handles[i] = $(`
${i}
`) - this.wrapper.append(this.handles[i]) - - let pad = this.pads[i] - pad.wrapper.on('draginit',(e)=>{ - pad.widget.addClass('active') - }) - pad.wrapper.on('dragend',(e)=>{ - pad.widget.removeClass('active') - }) - } - - this.wrapper.addClass('snap') - - this.value = [] - - - this.handles.forEach((handle, i)=>{ - handle.on('draginit drag dragend',(e, data, traversing)=>{ - if (this.widgetData.snap && e.type == 'draginit') { - e.type = 'drag' - this.pads[i].widget.addClass('active') - } - this.pads[i].wrapper.trigger(e.type, [data, traversing]) - }) - }) - - this.wrapper.on('sync',(e)=>{ - e.stopPropagation() - this.setValue(this.getValue(), e.options) - }) - - - var v = [] - for (var i=0;i{ + var s={}; + for (var i=0; i=0;i--) { + this.pads[i] = new Xy({ + snap:widgetData.snap, + spring:widgetData.spring, + value:widgetData.value.length == widgetData.points * 2 ? [widgetData.value[i*2], widgetData.value[i*2 + 1]] : '', + rangeX:widgetData.rangeX, + rangeY:widgetData.rangeY, + precision:widgetData.precision, + logScaleX:widgetData.logScaleX, + logScaleY:widgetData.logScaleY + }, false) + this.pads[i].sendValue = ()=>{} + this.pads[i].draw = ()=>{} + this.wrapper.append(this.pads[i].widget) + + this.handles[i] = $(`
${i}
`) + this.wrapper.append(this.handles[i]) + + let pad = this.pads[i] + pad.wrapper.on('draginit',(e)=>{ + pad.widget.addClass('active') + }) + pad.wrapper.on('dragend',(e)=>{ + pad.widget.removeClass('active') + }) + } + + this.value = [] + + this.handles.forEach((handle, i)=>{ + handle.on('draginit drag dragend',(e, data, traversing)=>{ + if (widgetData.snap && e.type == 'draginit') { + e.type = 'drag' + this.pads[i].widget.addClass('active') + } + this.pads[i].wrapper.trigger(e.type, [data, traversing]) + }) + }) + + this.wrapper.on('sync',(e)=>{ + e.stopPropagation() + this.setValue(this.getValue(), e.options) + }) + + + var v = [] + for (var i=0;i -
- R - G - B -
-
-
-
-
-
- `) - - this.hueWrapper = this.widget.find('.hue-wrapper') - - this.faders = { - h: new Fader({ - id:'h', - compact:false, - noPip:true, - horizontal:true, - snap:widgetData.snap, - range:{min:0,max:360}, - precision:2 - }), - s: new Fader({ - id:'s', - compact:true, - horizontal:true, - snap:widgetData.snap, - range:{min:0,max:100}, - precision:2 - - },true), - b: new Fader({ - id:'b', - compact:true, - horizontal:false, - snap:widgetData.snap, - range:{min:0,max:100}, - precision:2 - },true) } - this.faders.h.margin = 0 + constructor(widgetData) { - this.inputs = [ - this.widget.find('.r').fakeInput({align:'center'}), - this.widget.find('.g').fakeInput({align:'center'}), - this.widget.find('.b').fakeInput({align:'center'}) - ] + super(...arguments) - this.value = [] - this.hsb = {h:0,s:0,b:0} + this.split = widgetData.split? + typeof widgetData.split == 'object'? + widgetData.split + : {r: widgetData.address + '/r', g: widgetData.address + '/g', b: widgetData.address + '/b'} + : false - this.wrapper.append(this.faders.s.widget) - this.wrapper.append(this.faders.b.widget) + this.widget.append(` +
+
+ R + G + B +
+
+
+
+
+
+ `) - this.hueWrapper.append(this.faders.h.widget) + this.hueWrapper = this.widget.find('.hue-wrapper') - this.wrapper.on('sync',(e)=>{ - e.stopPropagation() - }) + this.faders = { + h: new Fader({ + id:'h', + compact:false, + noPip:true, + horizontal:true, + snap:widgetData.snap, + range:{min:0,max:360}, + precision:2 + }, false), + s: new Fader({ + id:'s', + compact:true, + horizontal:true, + snap:widgetData.snap, + range:{min:0,max:100}, + precision:2 - this.faders.h.widget.on('sync',(e)=>{ - e.stopPropagation() - this.dragHandle(true) - }) + }, true), + b: new Fader({ + id:'b', + compact:true, + horizontal:false, + snap:widgetData.snap, + range:{min:0,max:100}, + precision:2 + }, true) + } - this.wrapper.on('draginit',(e, data, traversing)=>{ - this.faders.s.draginitHandleProxy(e, data, traversing) - this.faders.b.draginitHandleProxy(e, data, traversing) - this.dragHandle() - }) - this.wrapper.on('drag',(e, data, traversing)=>{ - this.faders.s.dragHandleProxy(e, data, traversing) - this.faders.b.dragHandleProxy(e, data, traversing) - this.dragHandle() - }) + this.faders.h.margin = 0 + this.inputs = [ + this.widget.find('.r').fakeInput({align:'center'}), + this.widget.find('.g').fakeInput({align:'center'}), + this.widget.find('.b').fakeInput({align:'center'}) + ] - this.inputs.forEach(function(input,i){ - input.change(()=>{ - this.value[i] = parseFloat(clip(this.inputs[i].val(),[0,255])) - this.setValue(this.value,{send:true,sync:true}) + this.value = [] + this.hsb = {h:0,s:0,b:0} + + this.wrapper.append(this.faders.s.widget) + this.wrapper.append(this.faders.b.widget) + + this.hueWrapper.append(this.faders.h.widget) + + this.wrapper.on('sync',(e)=>{ + e.stopPropagation() + }) + + this.faders.h.widget.on('sync',(e)=>{ + e.stopPropagation() + this.dragHandle(true) + }) + + this.wrapper.on('draginit',(e, data, traversing)=>{ + this.faders.s.draginitHandleProxy(e, data, traversing) + this.faders.b.draginitHandleProxy(e, data, traversing) + this.dragHandle() + }) + this.wrapper.on('drag',(e, data, traversing)=>{ + this.faders.s.dragHandleProxy(e, data, traversing) + this.faders.b.dragHandleProxy(e, data, traversing) + this.dragHandle() }) - },this) - this.setValue([0,0,0]) -} + this.inputs.forEach(function(input,i){ + input.change(()=>{ + this.value[i] = parseFloat(clip(this.inputs[i].val(),[0,255])) + this.setValue(this.value,{send:true,sync:true}) + }) + },this) -Rgb.prototype = Object.create(_pads_base.prototype) + this.setValue([0,0,0]) -Rgb.prototype.constructor = Rgb + } -Rgb.prototype.dragHandle = function(hue){ - var h =this.faders.h.value, + dragHandle(hue) { + var h =this.faders.h.value, s = this.faders.s.value, b = this.faders.b.value - if (h != this.hsb.h ||s != this.hsb.s || b != this.hsb.b) { + if (h != this.hsb.h ||s != this.hsb.s || b != this.hsb.b) { - this.hsb.h = this.faders.h.value - this.hsb.s = this.faders.s.value - this.hsb.b = this.faders.b.value + this.hsb.h = this.faders.h.value + this.hsb.s = this.faders.s.value + this.hsb.b = this.faders.b.value - this.update({nohue:!hue}) + this.update({nohue:!hue}) - var rgb = hsbToRgb(this.hsb) - if (rgb.r != this.value[0] || rgb.g != this.value[1] || rgb.b != this.value[2]) { - this.setValue([rgb.r, rgb.g, rgb.b],{send:true,sync:true,dragged:true,nohue:!hue}) + var rgb = hsbToRgb(this.hsb) + if (rgb.r != this.value[0] || rgb.g != this.value[1] || rgb.b != this.value[2]) { + this.setValue([rgb.r, rgb.g, rgb.b],{send:true,sync:true,dragged:true,nohue:!hue}) + } } + } -} + setValue(v, options={}) { -Rgb.prototype.setValue = function(v, options={}){ + if (!v || v.length!=3) return - if (!v || v.length!=3) return + for (i in [0,1,2]) { + v[i] = clip(v[i],[0,255]) + } + + var hsb = rgbToHsb({r:v[0],g:v[1],b:v[2]}) + + if (!options.dragged) { + this.faders.s.setValue(hsb.s, {sync: false, send:false, dragged:false}) + this.faders.b.setValue(hsb.b, {sync: false, send:false, dragged:false}) + } + + this.hsb = hsb + this.value = v + + if (options.send) this.sendValue() + if (options.sync) this.widget.trigger({type:'sync', id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options}) + + this.update({dragged:options.dragged, nohue:options.nohue || (v[0]==v[1]&&v[1]==v[2])}) - for (i in [0,1,2]) { - v[i] = clip(v[i],[0,255]) } - var hsb = rgbToHsb({r:v[0],g:v[1],b:v[2]}) + update(options={}) { + + if (!options.nohue && !options.dragged) { + var hue = hsbToRgb({h:this.hsb.h,s:100,b:100}) + this.hue = `rgb(${Math.round(hue.r)},${Math.round(hue.g)},${Math.round(hue.b)})` + this.wrapper[0].setAttribute('style',`background:${this.hue}`) + this.faders.h.setValue(this.hsb.h, {sync: false, send:false, dragged:false}) + } + + for (i in this.inputs) [ + this.inputs[i].val(this.value[i].toFixed(this.widgetData.precision)) + ] + + this.draw() - if (!options.dragged) { - this.faders.s.setValue(hsb.s, {sync: false, send:false, dragged:false}) - this.faders.b.setValue(hsb.b, {sync: false, send:false, dragged:false}) } - this.hsb = hsb - this.value = v + draw() { - if (options.send) this.sendValue() - if (options.sync) this.widget.trigger({type:'sync', id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options}) - - this.update({dragged:options.dragged, nohue:options.nohue || (v[0]==v[1]&&v[1]==v[2])}) -} - -Rgb.prototype.update = function(options={}) { - - if (!options.nohue && !options.dragged) { - var hue = hsbToRgb({h:this.hsb.h,s:100,b:100}) - this.hue = `rgb(${Math.round(hue.r)},${Math.round(hue.g)},${Math.round(hue.b)})` - this.wrapper[0].setAttribute('style',`background:${this.hue}`) - this.faders.h.setValue(this.hsb.h, {sync: false, send:false, dragged:false}) - } - - for (i in this.inputs) [ - this.inputs[i].val(this.value[i].toFixed(this.widgetData.precision)) - ] - - this.draw() - -} - -Rgb.prototype.draw = function(){ - - var x = clip(this.faders.s.percent / 100 * this.width,[0,this.width]), + var x = clip(this.faders.s.percent / 100 * this.width,[0,this.width]), y = clip((1 - this.faders.b.percent / 100) * this.height,[0,this.height]), color = this.hsb.b > 70 && this.hsb.s < 30 ? '#555' : 'white' - this.ctx.clearRect(0,0,this.width,this.height) + this.ctx.clearRect(0,0,this.width,this.height) - this.ctx.fillStyle = color - this.ctx.strokeStyle = color - this.ctx.lineWidth = PXSCALE + this.ctx.fillStyle = color + this.ctx.strokeStyle = color + this.ctx.lineWidth = PXSCALE - this.ctx.globalAlpha = 0.3 + this.ctx.globalAlpha = 0.3 - this.ctx.beginPath() - this.ctx.arc(x, y, 10 * PXSCALE, Math.PI * 2, false) - this.ctx.fill() + this.ctx.beginPath() + this.ctx.arc(x, y, 10 * PXSCALE, Math.PI * 2, false) + this.ctx.fill() - this.ctx.globalAlpha = 0.1 + this.ctx.globalAlpha = 0.1 - this.ctx.beginPath() - this.ctx.moveTo(0,y) - this.ctx.lineTo(this.width,y) - this.ctx.moveTo(x,0) - this.ctx.lineTo(x,this.height) - this.ctx.stroke() + this.ctx.beginPath() + this.ctx.moveTo(0,y) + this.ctx.lineTo(this.width,y) + this.ctx.moveTo(x,0) + this.ctx.lineTo(x,this.height) + this.ctx.stroke() - this.ctx.globalAlpha = 1 + this.ctx.globalAlpha = 1 + + this.ctx.beginPath() + this.ctx.arc(x, y, 4 * PXSCALE, Math.PI * 2, false) + this.ctx.fill() + + } - this.ctx.beginPath() - this.ctx.arc(x, y, 4 * PXSCALE, Math.PI * 2, false) - this.ctx.fill() -} - -module.exports.create = function(widgetData) { - var rgb = new Rgb(widgetData) - return rgb } diff --git a/src/browser/js/app/widgets/pads/xy.js b/src/browser/js/app/widgets/pads/xy.js index 7b1af261..ecd3ced7 100644 --- a/src/browser/js/app/widgets/pads/xy.js +++ b/src/browser/js/app/widgets/pads/xy.js @@ -2,206 +2,204 @@ var _pads_base = require('./_pads_base'), Fader = require('./_fake_fader'), {clip} = require('../utils') -module.exports.options = { - type:'xy', - id:'auto', - linkId:'', +module.exports = class Xy extends _pads_base { - separator1:'style', + static options() { - label:'auto', - left:'auto', - top:'auto', - width:'auto', - height:'auto', - color:'auto', - css:'', + return { + type:'xy', + id:'auto', + linkId:'', - separator2:'behaviour', + _style:'style', - snap:false, - spring:false, + label:'auto', + left:'auto', + top:'auto', + width:'auto', + height:'auto', + color:'auto', + css:'', - separator3:'osc', + _behaviour:'behaviour', - rangeX:{min:0,max:1}, - rangeY:{min:0,max:1}, - logScaleX:false, - logScaleY:false, - value:'', - precision:2, - address:'auto', - preArgs:[], - split:false, - target:[] -} + snap:false, + spring:false, -var Xy = module.exports.Xy = function(widgetData) { + _osc:'osc', - _pads_base.apply(this,arguments) + rangeX:{min:0,max:1}, + rangeY:{min:0,max:1}, + logScaleX:false, + logScaleY:false, + value:'', + precision:2, + address:'auto', + preArgs:[], + split:false, + target:[] + } - this.split = this.widgetData.split? - typeof this.widgetData.split == 'object'? - this.widgetData.split - : {x: this.widgetData.address + '/x', y: this.widgetData.address + '/y'} - : false - - this.widget.append(` -
- X - Y -
-
-
-
-
- `) - - this.faders = { - x: new Fader({ - id:0, - compact:true, - horizontal:true, - height:'100%', - width:'100%', - value:widgetData.value.length==2?widgetData.value[0]:'', - snap:widgetData.snap, - range:widgetData.rangeX, - origin:'auto', - precision:widgetData.precision, - logScale:widgetData.logScaleX - }, true), - y: new Fader({ - id:1, - compact:true, - horizontal:false, - height:'100%', - width:'100%', - value:widgetData.value.length==2?widgetData.value[1]:'', - snap:widgetData.snap, - range:widgetData.rangeY, - origin:'auto', - precision:widgetData.precision, - logScale:widgetData.logScaleY - - }, true) } - this.inputs = [ - this.widget.find('.x').replaceWith(this.faders.x.input), - this.widget.find('.y').replaceWith(this.faders.y.input) - ] + constructor(widgetData) { - this.value = [this.faders.x.value, this.faders.y.value] + super(...arguments) - this.wrapper.append(this.faders.x.widget) - this.wrapper.append(this.faders.y.widget) + this.split = widgetData.split? + typeof widgetData.split == 'object'? + widgetData.split + : {x: widgetData.address + '/x', y: widgetData.address + '/y'} + : false - this.wrapper.on('sync',(e)=>{ - e.stopPropagation() - }) + this.widget.append(` +
+ X + Y +
+
+
+
+
+ `) - this.wrapper.on('draginit',(e, data, traversing)=>{ - this.faders.x.draginitHandleProxy(e, data, traversing) - this.faders.y.draginitHandleProxy(e, data, traversing) - this.dragHandle() - }) - this.wrapper.on('drag',(e, data, traversing)=>{ - this.faders.x.dragHandleProxy(e, data, traversing) - this.faders.y.dragHandleProxy(e, data, traversing) - this.dragHandle() - }) + this.faders = { + x: new Fader({ + id:0, + compact:true, + horizontal:true, + height:'100%', + width:'100%', + value:widgetData.value.length==2?widgetData.value[0]:'', + snap:widgetData.snap, + range:widgetData.rangeX, + origin:'auto', + precision:widgetData.precision, + logScale:widgetData.logScaleX + }, true), + y: new Fader({ + id:1, + compact:true, + horizontal:false, + height:'100%', + width:'100%', + value:widgetData.value.length==2?widgetData.value[1]:'', + snap:widgetData.snap, + range:widgetData.rangeY, + origin:'auto', + precision:widgetData.precision, + logScale:widgetData.logScaleY - if (this.widgetData.spring) { - this.wrapper.on('dragend', ()=>{ - this.setValue([this.faders.x.springValue,this.faders.y.springValue],{sync:true,send:true,fromLocal:true}) + }, true) + } + + this.inputs = [ + this.widget.find('.x').replaceWith(this.faders.x.input), + this.widget.find('.y').replaceWith(this.faders.y.input) + ] + + 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.wrapper.on('sync',(e)=>{ + e.stopPropagation() }) + + this.wrapper.on('draginit',(e, data, traversing)=>{ + this.faders.x.draginitHandleProxy(e, data, traversing) + this.faders.y.draginitHandleProxy(e, data, traversing) + this.dragHandle() + }) + this.wrapper.on('drag',(e, data, traversing)=>{ + this.faders.x.dragHandleProxy(e, data, traversing) + this.faders.y.dragHandleProxy(e, data, traversing) + this.dragHandle() + }) + + if (widgetData.spring) { + this.wrapper.on('dragend', ()=>{ + this.setValue([this.faders.x.springValue,this.faders.y.springValue],{sync:true,send:true,fromLocal:true}) + }) + } + + this.faders.x.input.change(()=>{ + var v = [this.faders.x.value, this.faders.y.value] + this.setValue(v,{send:true,sync:true}) + }) + this.faders.y.input.change(()=>{ + var v = [this.faders.x.value, this.faders.y.value] + this.setValue(v,{send:true,sync:true}) + }) + + } + + dragHandle(){ + + var x = this.faders.x.value, + y = this.faders.y.value + + + if (x != this.value[0] || y != this.value[1]) { + this.setValue([x, y],{send:true,sync:true,dragged:true}) + } + } + setValue(v, options={}) { - this.faders.x.input.change(()=>{ - var v = [this.faders.x.value, this.faders.y.value] - this.setValue(v,{send:true,sync:true}) - }) - this.faders.y.input.change(()=>{ - var v = [this.faders.x.value, this.faders.y.value] - this.setValue(v,{send:true,sync:true}) - }) + if (!v || v.length!=2) return + if (!options.dragged) { + this.faders.x.setValue(v[0], {sync: false, send:false, dragged:false}) + this.faders.y.setValue(v[1], {sync: false, send:false, dragged:false}) + } -} + this.value = [ + this.faders.x.value, + this.faders.y.value + ] + if (options.send) this.sendValue() + if (options.sync) this.widget.trigger({type:'sync', id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options}) -Xy.prototype = Object.create(_pads_base.prototype) + this.draw() -Xy.prototype.constructor = Xy - -Xy.prototype.dragHandle = function(){ - var x = this.faders.x.value, - y = this.faders.y.value - - - if (x != this.value[0] || y != this.value[1]) { - this.setValue([x, y],{send:true,sync:true,dragged:true}) - } -} - - -Xy.prototype.setValue = function(v, options={}){ - - if (!v || v.length!=2) return - - if (!options.dragged) { - this.faders.x.setValue(v[0], {sync: false, send:false, dragged:false}) - this.faders.y.setValue(v[1], {sync: false, send:false, dragged:false}) } - this.value = [ - this.faders.x.value, - this.faders.y.value - ] + draw() { - if (options.send) this.sendValue() - if (options.sync) this.widget.trigger({type:'sync', id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options}) - - this.draw() -} - -Xy.prototype.draw = function(){ - - var x = clip(this.faders.x.percent / 100 * this.width,[0,this.width]), + var x = clip(this.faders.x.percent / 100 * this.width,[0,this.width]), y = clip((1 - this.faders.y.percent / 100) * this.height,[0,this.height]) - this.ctx.clearRect(0,0,this.width,this.height) + this.ctx.clearRect(0,0,this.width,this.height) - this.ctx.fillStyle = this.faders.x.colors.custom - this.ctx.lineWidth = PXSCALE - this.ctx.strokeStyle = this.faders.x.colors.custom + this.ctx.fillStyle = this.faders.x.colors.custom + this.ctx.lineWidth = PXSCALE + this.ctx.strokeStyle = this.faders.x.colors.custom - this.ctx.globalAlpha = 0.3 + this.ctx.globalAlpha = 0.3 - this.ctx.beginPath() - this.ctx.arc(x, y, 10 * PXSCALE, Math.PI * 2, false) - this.ctx.fill() + this.ctx.beginPath() + this.ctx.arc(x, y, 10 * PXSCALE, Math.PI * 2, false) + this.ctx.fill() - this.ctx.globalAlpha = 0.1 + this.ctx.globalAlpha = 0.1 - this.ctx.beginPath() - this.ctx.moveTo(0,y) - this.ctx.lineTo(this.width,y) - this.ctx.moveTo(x,0) - this.ctx.lineTo(x,this.height) - this.ctx.stroke() + this.ctx.beginPath() + this.ctx.moveTo(0,y) + this.ctx.lineTo(this.width,y) + this.ctx.moveTo(x,0) + this.ctx.lineTo(x,this.height) + this.ctx.stroke() - this.ctx.globalAlpha = 1 + this.ctx.globalAlpha = 1 + + this.ctx.beginPath() + this.ctx.arc(x, y, 4 * PXSCALE, Math.PI * 2, false) + this.ctx.fill() + } - this.ctx.beginPath() - this.ctx.arc(x, y, 4 * PXSCALE, Math.PI * 2, false) - this.ctx.fill() -} - -module.exports.create = function(widgetData) { - var xy = new Xy(widgetData) - return xy } diff --git a/src/browser/js/app/widgets/plots/_plots_base.js b/src/browser/js/app/widgets/plots/_plots_base.js index 541dea08..67bba049 100644 --- a/src/browser/js/app/widgets/plots/_plots_base.js +++ b/src/browser/js/app/widgets/plots/_plots_base.js @@ -2,151 +2,163 @@ var {mapToScale} = require('../utils'), _canvas_base = require('../common/_canvas_base'), {widgetManager} = require('../../managers') -var _plots_base = module.exports = function(){ +module.exports = class _plots_base extends _canvas_base { - this.widget = $(` -
- -
- `) + constructor(widgetData) { - _canvas_base.apply(this,arguments) + var widgetHtml = ` +
+ +
+ ` - this.data = [] - this.linkedWidgets = [] - this.rangeX = this.widgetData.rangeX || {min:0,max:1} - this.rangeY = this.widgetData.rangeY || {min:0,max:1} - this.pips = { - x : { - min: Math.abs(this.rangeX.min)>=1000?this.rangeY.min/1000+'k':this.rangeX.min, - max: Math.abs(this.rangeX.max)>=1000?this.rangeY.max/1000+'k':this.rangeX.max - }, - y : { - min: Math.abs(this.rangeY.min)>=1000?this.rangeY.min/1000+'k':this.rangeY.min, - max: Math.abs(this.rangeY.max)>=1000?this.rangeY.max/1000+'k':this.rangeY.max + super(...arguments, widgetHtml) + + this.data = [] + this.linkedWidgets = [] + this.rangeX = widgetData.rangeX || {min:0,max:1} + this.rangeY = widgetData.rangeY || {min:0,max:1} + this.pips = { + x : { + min: Math.abs(this.rangeX.min)>=1000?this.rangeY.min/1000+'k':this.rangeX.min, + max: Math.abs(this.rangeX.max)>=1000?this.rangeY.max/1000+'k':this.rangeX.max + }, + y : { + min: Math.abs(this.rangeY.min)>=1000?this.rangeY.min/1000+'k':this.rangeY.min, + max: Math.abs(this.rangeY.max)>=1000?this.rangeY.max/1000+'k':this.rangeY.max + } } - } - $('body').on('sync',this.syncHandleProxy.bind(this)) - -} - -_plots_base.prototype = Object.create(_canvas_base.prototype) - -_plots_base.prototype.constructor = _plots_base - -_plots_base.prototype.syncHandleProxy = function() { - this.syncHandle.apply(this,arguments) -} - -_plots_base.prototype.syncHandle = function(e) { - if (this.linkedWidgets.indexOf(e.id)==-1 || !widgetManager.getWidgetById(e.id).length) return - this.updateData() - requestAnimationFrame(this.draw.bind(this)) -} - -_plots_base.prototype.resizeHandle = function(){ - this.updateData() - _canvas_base.prototype.resizeHandle.apply(this, arguments) -} - -_plots_base.prototype.draw = function() { - - this.ctx.clearRect(0,0,this.width,this.height) - this.ctx.beginPath() - - this.draw_data() - - this.ctx.lineWidth = 1*PXSCALE - this.ctx.strokeStyle = this.colors.custom - this.ctx.stroke() - - - - if (this.widgetData.origin !== false) { - - var origin = mapToScale(this.widgetData.origin||this.rangeY.min,[this.rangeY.min,this.rangeY.max],[this.height,0],0,this.widgetData.logScaleY,true) - - this.ctx.globalAlpha = 0.1 - this.ctx.fillStyle = this.colors.custom - this.ctx.lineTo(this.width,origin) - this.ctx.lineTo(0,origin) - this.ctx.closePath() - this.ctx.fill() - this.ctx.globalAlpha = 1 + $('body').on('sync',this.syncHandleProxy.bind(this)) } + syncHandleProxy() { - this.ctx.font = PXSCALE * 10 + 'px sans-serif' - this.ctx.fillStyle = this.colors.text - - if (this.pips.x) { - - this.ctx.textBaseline = "bottom" - this.ctx.textAlign = 'left' - this.ctx.fillText(this.pips.x.min,(this.pips.y?12:2)*PXSCALE,this.height) - this.ctx.textAlign = 'right' - this.ctx.fillText(this.pips.x.max,this.width-2*PXSCALE,this.height) + this.syncHandle(...arguments) } - if (this.pips.y) { + syncHandle(e) { - this.ctx.save() - this.ctx.translate(0, this.height) - this.ctx.rotate(-Math.PI/2) - - this.ctx.textBaseline = "top" - this.ctx.textAlign = 'left' - this.ctx.fillText(this.pips.y.min,(this.pips.x?12:2)*PXSCALE,2*PXSCALE) - this.ctx.textAlign = 'right' - this.ctx.fillText(this.pips.y.max,this.height-2*PXSCALE,2*PXSCALE) - this.ctx.rotate(Math.PI/2) - this.ctx.restore() + if (this.linkedWidgets.indexOf(e.id)==-1 || !widgetManager.getWidgetById(e.id).length) return + this.updateData() + this.draw() } -} + resizeHandle() { -_plots_base.prototype.draw_data = function() { - var first = true - var point = [] - for (i in this.data) { + this.updateData() + super.resizeHandle(...arguments) - if (this.data[i][1]>this.rangeY.max || this.data[i][1]this.rangeX.max || this.data[i][0]this.rangeY.max || this.data[i][1]this.rangeX.max || this.data[i][0]
- `), - this.led = this.widget.find('span') + ` + super(...arguments, widgetHtml) - this.setValue(this.widgetData.range.min) + this.led = this.widget.find('span') + + this.setValue(widgetData.range.min) + + } + + setValue(v) { + + if (typeof v != 'number') return + this.led.css('opacity',mapToScale(v,[this.widgetData.range.min,this.widgetData.range.max],[0,1],false,this.widgetData.logScale,true)) + + } } - - -Led.prototype = Object.create(_widgets_base.prototype) - -Led.prototype.constructor = Led - -Led.prototype.setValue = function(v){ - - if (typeof v != 'number') return - this.led.css('opacity',mapToScale(v,[this.widgetData.range.min,this.widgetData.range.max],[0,1],false,this.widgetData.logScale,true)) - -} - -module.exports.create = function(widgetData, container) { - var led = new Led(widgetData, container) - return led -} diff --git a/src/browser/js/app/widgets/plots/meter.js b/src/browser/js/app/widgets/plots/meter.js index 9633f509..d8c5bc20 100644 --- a/src/browser/js/app/widgets/plots/meter.js +++ b/src/browser/js/app/widgets/plots/meter.js @@ -1,59 +1,54 @@ -var {Fader} = require('../sliders/fader') +var Fader = require('../sliders/fader') -module.exports.options = { - type:'fader', - id:'auto', +module.exports = class Meter extends Fader { - separator1:'style', + static options() { - label:'auto', - unit:'', - left:'auto', - top:'auto', - width:'auto', - height:'auto', - horizontal:false, - color:'auto', - css:'', + return { + type:'fader', + id:'auto', - separator3:'osc', + _style:'style', - range:{min:0,max:1}, - logScale:false, - origin:'auto', - value:'', - address:'auto', - preArgs:[] -} + label:'auto', + unit:'', + left:'auto', + top:'auto', + width:'auto', + height:'auto', + horizontal:false, + color:'auto', + css:'', + _osc:'osc', -var {Fader} = require('../sliders/fader') + range:{min:0,max:1}, + logScale:false, + origin:'auto', + value:'', + address:'auto', + preArgs:[] + } -var Meter = module.exports.Meter = function(widgetData, container){ + } - var data = widgetData - data.compact = true + constructor(widgetData) { - Fader.apply(this, arguments) + widgetData.compact = true - this.input.hide() + super(...arguments) - this.widget.addClass('meter') + this.input.hide() - this.widget.off('mousewheel') - this.canvas.off('draginit') - this.canvas.off('drag') + this.widget.addClass('meter') + .off('mousewheel') + + this.canvas.off('draginit drag') + + } + + sendValue() { + // disabled + } } - -Meter.prototype = Object.create(Fader.prototype) - -Meter.prototype.constructor = Meter - -Meter.prototype.sendValue = ()=>{} - -module.exports.create = function(widgetData,container) { - - var meter = new Meter(widgetData, container) - return meter -} diff --git a/src/browser/js/app/widgets/plots/plot.js b/src/browser/js/app/widgets/plots/plot.js index 3df3d6df..4c8e1075 100644 --- a/src/browser/js/app/widgets/plots/plot.js +++ b/src/browser/js/app/widgets/plots/plot.js @@ -2,58 +2,67 @@ var {mapToScale} = require('../utils'), _plots_base = require('./_plots_base'), {widgetManager} = require('../../managers') -module.exports.options = { - type:'plot', - id:'auto', +module.exports = class Plot extends _plots_base { - separator1:'style', + static options() { - label:'auto', - left:'auto', - top:'auto', - width:'auto', - height:'auto', - color:'auto', - css:'', + return { + type:'plot', + id:'auto', - separator2:'plot', + _style:'style', - points:[], - rangeX: {min:0,max:1}, - rangeY: {min:0,max:1}, - origin: 'auto', - logScaleX: false, - logScaleY: false, + label:'auto', + left:'auto', + top:'auto', + width:'auto', + height:'auto', + color:'auto', + css:'', - separator3:'osc', + _plot:'plot', - address:'auto', - preArgs:[], + points:[], + rangeX: {min:0,max:1}, + rangeY: {min:0,max:1}, + origin: 'auto', + logScaleX: false, + logScaleY: false, -} + _osc:'osc', -var Plot = module.exports.Plot = function(widgetData) { + address:'auto', + preArgs:[], - _plots_base.call(this,widgetData) + } - if (typeof widgetData.points=='string') { + } - this.linkedWidgets.push(widgetData.points) + constructor(widgetData) { - } else if (typeof widgetData.points=='object') { + super(...arguments) - for (i in widgetData.points) { - for (j in widgetData.points[i]) { - if (typeof widgetData.points[i][j] == 'string') { - this.linkedWidgets.push(widgetData.points[i][j]) + if (typeof widgetData.points=='string') { + + this.linkedWidgets.push(widgetData.points) + + } else if (typeof widgetData.points=='object') { + + for (i in widgetData.points) { + for (j in widgetData.points[i]) { + if (typeof widgetData.points[i][j] == 'string') { + this.linkedWidgets.push(widgetData.points[i][j]) + } } } } + } - this.updateData = function(){ + updateData() { + var data = [], - points = widgetData.points, + points = this.widgetData.points, widget = widgetManager.getWidgetById(points) if (typeof points=='string' && widget.length) { @@ -66,7 +75,7 @@ var Plot = module.exports.Plot = function(widgetData) { data[i] = [] - for (k in [0,1]) { + for (var k in [0,1]) { let widget = widgetManager.getWidgetById(points[i][k]) if (typeof points[i][k] == 'string' && widget.length) { data[i][k] = widget[widget.length-1].getValue() @@ -80,14 +89,7 @@ var Plot = module.exports.Plot = function(widgetData) { } if (data.length) this.data = data + } -} - -Plot.prototype = Object.create(_plots_base.prototype) - -Plot.prototype.constructor = Plot - -module.exports.create = function(widgetData) { - var plot = new Plot(widgetData) - return plot + } diff --git a/src/browser/js/app/widgets/plots/text.js b/src/browser/js/app/widgets/plots/text.js index 71fbb48c..522d0b07 100644 --- a/src/browser/js/app/widgets/plots/text.js +++ b/src/browser/js/app/widgets/plots/text.js @@ -1,66 +1,60 @@ var {iconify} = require('../../utils'), _widgets_base = require('../common/_widgets_base') +module.exports = class Text extends _widgets_base { -module.exports.options = { - type:'text', - id:'auto', + static options() { - separator1:'style', + return { + type:'text', + id:'auto', - label:'auto', - left:'auto', - top:'auto', - width:'auto', - height:'auto', - vertical:false, - color:'auto', - css:'', + _style:'style', - separator2:'osc', + label:'auto', + left:'auto', + top:'auto', + width:'auto', + height:'auto', + vertical:false, + color:'auto', + css:'', - value:'', - preArgs:[], - address:'auto', -} + _osc:'osc', -var Text = module.exports.Text = function(widgetData,container) { + value:'', + preArgs:[], + address:'auto', + } - _widgets_base.apply(this,arguments) + } + constructor(widgetData) { - this.widget = $(` -
+ var widgetHtml = ` +
- `) + ` - this.defaultValue = widgetData.label===false? - widgetData.id: - widgetData.label=='auto'? + super(...arguments, widgetHtml) + + this.defaultValue = widgetData.label===false? widgetData.id: - widgetData.label + widgetData.label=='auto'? + widgetData.id: + widgetData.label - this.value = this.defaultValue + this.value = this.defaultValue + this.setValue(this.value) - if (this.widgetData.vertical) this.widget.addClass('vertical') + } - this.setValue(this.value) + setValue(v) { + + this.value = typeof v=='object' && !v.length ? this.defaultValue : v + this.widget.html(iconify(this.value)) + + } } - -Text.prototype = Object.create(_widgets_base.prototype) - -Text.prototype.constructor = Text - -Text.prototype.setValue = function(v){ - - this.value = typeof v=='object' && !v.length ? this.defaultValue : v - this.widget.html(iconify(this.value)) - -} - -module.exports.create = function(widgetData, container) { - var text = new Text(widgetData, container) - return text -} diff --git a/src/browser/js/app/widgets/plots/visualizer.js b/src/browser/js/app/widgets/plots/visualizer.js index eccde76b..d8ce4a3e 100644 --- a/src/browser/js/app/widgets/plots/visualizer.js +++ b/src/browser/js/app/widgets/plots/visualizer.js @@ -2,129 +2,134 @@ var {mapToScale, clip} = require('../utils'), _plots_base = require('./_plots_base'), {widgetManager} = require('../../managers') +module.exports = class Visualizer extends _plots_base { -module.exports.options = { - type:'visualizer', - id:'auto', + static options() { - separator1:'style', + return { + type:'visualizer', + id:'auto', - label:'auto', - left:'auto', - top:'auto', - width:'auto', - height:'auto', - color:'auto', - css:'', + _style:'style', - separator2:'plot', + label:'auto', + left:'auto', + top:'auto', + width:'auto', + height:'auto', + color:'auto', + css:'', - widgetId:'', - duration:1, - range: {min:0,max:1}, - origin: 'auto', - logScale: false, + _plot:'plot', - separator3:'osc', + widgetId:'', + duration:1, + range: {min:0,max:1}, + origin: 'auto', + logScale: false, - value:'', - address:'auto', - preArgs:[], -} - -var Visualizer = module.exports.Visualizer = function(widgetData) { - - _plots_base.call(this,widgetData) - - this.pips.y.min = Math.abs(widgetData.range.min)>=1000?widgetData.range.min/1000+'k':widgetData.range.min - this.pips.y.max = Math.abs(widgetData.range.max)>=1000?widgetData.range.max/1000+'k':widgetData.range.max - this.pips.x = false - this.length = Math.round(clip(60*widgetData.duration,[8,4096])) - this.data = new Array(this.length) - this.value = widgetData.range.min - this.cancel = false - this.loop = false - -} - -Visualizer.prototype = Object.create(_plots_base.prototype) - -Visualizer.prototype.constructor = Visualizer - -Visualizer.prototype.syncHandle = function(e) { - if (this.widgetData.widgetId!=e.id || !widgetManager.getWidgetById(e.id).length) return - this.startLoop() -} - -Visualizer.prototype.startLoop = function(){ - - if (this.cancel) clearTimeout(this.cancel) - - this.cancel = setTimeout(function(){ - clearInterval(this.loop) - this.loop = false - this.cancel = false - },1000*this.widgetData.duration) - - if (this.loop) return - - this.loop = setInterval(function(){ - this.updateData() - this.draw() - }.bind(this),1000*this.widgetData.duration/this.length) -} - - -Visualizer.prototype.draw_data = function(){ - - var first = true - var point = [] - - for (var i=0;i=1000?widgetData.range.min/1000+'k':widgetData.range.min + this.pips.y.max = Math.abs(widgetData.range.max)>=1000?widgetData.range.max/1000+'k':widgetData.range.max + this.pips.x = false + this.length = Math.round(clip(60*widgetData.duration,[8,4096])) + this.data = new Array(this.length) + this.value = widgetData.range.min + this.cancel = false + this.loop = false + + } + + syncHandle(e) { + + if (this.widgetData.widgetId!=e.id || !widgetManager.getWidgetById(e.id).length) return + this.startLoop() + + } + + startLoop() { + + if (this.cancel) clearTimeout(this.cancel) + + this.cancel = setTimeout(function(){ + clearInterval(this.loop) + this.loop = false + this.cancel = false + },1000*this.widgetData.duration) + + if (this.loop) return + + this.loop = setInterval(()=>{ + + this.updateData() + this.draw() + + },1000*this.widgetData.duration/this.length) + + } -Visualizer.prototype.updateData = function(){ - var id = this.widgetData.widgetId, + draw_data() { + + var first = true + var point = [] + + for (var i=0;i -
- + constructor(widgetData) { + + var widgetHtml = ` +
+
+ +
+
-
-
- `) + ` - _canvas_base.apply(this, arguments) + super(...arguments, widgetHtml) - this.wrapper = this.widget.find('.wrapper') - this.input = this.widget.find('.input').fakeInput({align:'center'}) - this.value = undefined - this.percent = 0 + this.wrapper = this.widget.find('.wrapper') + this.input = this.widget.find('.input').fakeInput({align:'center'}) + this.value = undefined + this.percent = 0 - this.unit = this.widgetData.unit ? ' ' + this.widgetData.unit : '' + this.unit = widgetData.unit ? ' ' + widgetData.unit : '' - this.rangeKeys = [] - this.rangeVals = [] - this.rangeLabels = [] + this.rangeKeys = [] + this.rangeVals = [] + this.rangeLabels = [] - for (k in this.widgetData.range) { - var key = k=='min'?0:k=='max'?100:parseInt(k), - val = typeof this.widgetData.range[k] == 'object'? - this.widgetData.range[k][Object.keys(this.widgetData.range[k])[0]]: - this.widgetData.range[k], - label = typeof this.widgetData.range[k] == 'object'? - Object.keys(this.widgetData.range[k])[0]: - val + for (var k in widgetData.range) { + var key = k=='min'?0:k=='max'?100:parseInt(k), + val = typeof widgetData.range[k] == 'object'? + widgetData.range[k][Object.keys(widgetData.range[k])[0]]: + widgetData.range[k], + label = typeof widgetData.range[k] == 'object'? + Object.keys(widgetData.range[k])[0]: + val - this.rangeKeys.push(key) - this.rangeVals.push(val) - this.rangeLabels.push(label) - } - this.rangeValsMax = Math.max.apply(Math, this.rangeVals), - this.rangeValsMin = Math.min.apply(Math, this.rangeVals) - - this.originValue = this.widgetData.origin=='auto'? - this.rangeValsMin: - clip(this.widgetData.origin,[this.rangeValsMin,this.rangeValsMax]) - this.springValue = this.widgetData.value != '' ? this.widgetData.value :  this.originValue - - this.widget.on('fake-right-click',function(e){ - if (!EDITING) { - e.stopPropagation() - e.preventDefault() - this.input.focus() + this.rangeKeys.push(key) + this.rangeVals.push(val) + this.rangeLabels.push(label) } - }.bind(this)) + this.rangeValsMax = Math.max(...this.rangeVals), + this.rangeValsMin = Math.min(...this.rangeVals) - this.widget.on('mousewheel',this.mousewheelHandleProxy.bind(this)) - this.canvas.on('draginit',this.draginitHandleProxy.bind(this)) - this.canvas.on('drag',this.dragHandleProxy.bind(this)) + this.originValue = widgetData.origin=='auto'? + this.rangeValsMin: + clip(widgetData.origin,[this.rangeValsMin,this.rangeValsMax]) + this.springValue = widgetData.value != '' ? widgetData.value :  this.originValue + + this.widget.on('fake-right-click',function(e){ + if (!EDITING) { + e.stopPropagation() + e.preventDefault() + this.input.focus() + } + }.bind(this)) + + 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.input.change(()=>{ + + this.setValue(parseFloat(this.input.val()),{sync:true,send:true}) - if (this.widgetData.spring) { - this.canvas.on('dragend', ()=>{ - this.setValue(this.springValue,{sync:true,send:true,fromLocal:true}) }) + + this.setValue(this.originValue) + } - this.input.change(function(){ - this.setValue(parseFloat(this.input.val()),{sync:true,send:true}) - }.bind(this)) + mousewheelHandleProxy() { + + this.mousewheelHandle(...arguments) + + } + + draginitHandleProxy() { + + this.draginitHandle(...arguments) + + } + + dragHandleProxy() { + + this.dragHandle(...arguments) + + } - this.setValue(this.originValue) + mousewheelHandle(e, data, traversing) { -} + if (e.originalEvent.wheelDeltaX) return -_sliders_base.prototype = Object.create(_canvas_base.prototype) + e.preventDefault() + e.stopPropagation() -_sliders_base.prototype.constructor = _sliders_base - - -_sliders_base.prototype.mousewheelHandleProxy = function() { - this.mousewheelHandle.apply(this,arguments) -} - -_sliders_base.prototype.draginitHandleProxy = function() { - this.draginitHandle.apply(this,arguments) -} - -_sliders_base.prototype.dragHandleProxy = function() { - this.dragHandle.apply(this,arguments) -} - - -_sliders_base.prototype.mousewheelHandle = function(e, data, traversing) { - if (e.originalEvent.wheelDeltaX) return - - e.preventDefault() - e.stopPropagation() - - var direction = e.originalEvent.wheelDelta / Math.abs(e.originalEvent.wheelDelta), + var direction = e.originalEvent.wheelDelta / Math.abs(e.originalEvent.wheelDelta), increment = e.ctrlKey?0.25:1 - this.percent = clip(this.percent + Math.max(increment,10/Math.pow(10,this.widgetData.precision)) * direction ,[0,100]) + this.percent = clip(this.percent + Math.max(increment,10/Math.pow(10,this.widgetData.precision)) * direction ,[0,100]) - this.setValue(this.percentToValue(this.percent), {sync:true,send:true,dragged:true}) + this.setValue(this.percentToValue(this.percent), {sync:true,send:true,dragged:true}) - -} - -_sliders_base.prototype.draginitHandle = function(e, data, traversing) { - -} - -_sliders_base.prototype.dragHandle = function(e, data, traversing) { - -} - - -_sliders_base.prototype.resizeHandle = function(e, width, height, checkColors) { - if (!this.visible || checkColors) { - var style = getComputedStyle(this.widget[0]) - this.colors.track = style.getPropertyValue('--color-track') - this.colors.gauge = style.getPropertyValue('--color-gauge') - this.colors.knob = style.getPropertyValue('--color-knob') } - _canvas_base.prototype.resizeHandle.apply(this, arguments) -} + draginitHandle(e, data, traversing) { -_sliders_base.prototype.percentToValue = function(percent) { - var h = clip(percent,[0,100]) - for (var i=0;i= this.rangeKeys[i]) { - return mapToScale(h,[this.rangeKeys[i],this.rangeKeys[i+1]],[this.rangeVals[i],this.rangeVals[i+1]],false,this.widgetData.logScale) + } + + dragHandle(e, data, traversing) { + + } + + resizeHandle(e, width, height, checkColors) { + + if (!this.visible || checkColors) { + var style = getComputedStyle(this.widget[0]) + this.colors.track = style.getPropertyValue('--color-track') + this.colors.gauge = style.getPropertyValue('--color-gauge') + this.colors.knob = style.getPropertyValue('--color-knob') } + + super.resizeHandle(...arguments) + } -} -_sliders_base.prototype.valueToPercent = function(value) { - for (var i=0;i= this.rangeVals[i]) { - return mapToScale(value,[this.rangeVals[i],this.rangeVals[i+1]],[this.rangeKeys[i],this.rangeKeys[i+1]],false,this.widgetData.logScale,true) + + + percentToValue(percent) { + + var h = clip(percent,[0,100]) + for (var i=0;i= this.rangeKeys[i]) { + return mapToScale(h,[this.rangeKeys[i],this.rangeKeys[i+1]],[this.rangeVals[i],this.rangeVals[i+1]],false,this.widgetData.logScale) + } } + } -} - -_sliders_base.prototype.setValue = function(v,options={}) { - if (typeof v != 'number') return - - var value = clip(v,[this.rangeValsMin,this.rangeValsMax]) - - if ((options.dragged || options.fromLocal) && this.value.toFixed(this.widgetData.precision) == value.toFixed(this.widgetData.precision)) options.send = false - - this.value = value - - if (!options.dragged) this.percent = this.valueToPercent(this.value) - - if (!this.noDraw) this.draw() - - this.showValue() - - if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options}) - if (options.send) this.sendValue(v) -} - -_sliders_base.prototype.showValue = function() { - this.input.val(this.value.toFixed(this.widgetData.precision) + this.unit) + + valueToPercent(value) { + + for (var i=0;i= this.rangeVals[i]) { + return mapToScale(value,[this.rangeVals[i],this.rangeVals[i+1]],[this.rangeKeys[i],this.rangeKeys[i+1]],false,this.widgetData.logScale,true) + } + } + + } + + setValue(v,options={}) { + + if (typeof v != 'number') return + + var value = clip(v,[this.rangeValsMin,this.rangeValsMax]) + + if ((options.dragged || options.fromLocal) && this.value.toFixed(this.widgetData.precision) == value.toFixed(this.widgetData.precision)) options.send = false + + this.value = value + + if (!options.dragged) this.percent = this.valueToPercent(this.value) + + if (!this.noDraw) this.draw() + + this.showValue() + + if (options.sync) this.widget.trigger({type:'sync',id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options}) + if (options.send) this.sendValue(v) + + } + + showValue() { + + this.input.val(this.value.toFixed(this.widgetData.precision) + this.unit) + + } + } diff --git a/src/browser/js/app/widgets/sliders/fader.js b/src/browser/js/app/widgets/sliders/fader.js index e885b877..c4b59223 100644 --- a/src/browser/js/app/widgets/sliders/fader.js +++ b/src/browser/js/app/widgets/sliders/fader.js @@ -2,303 +2,302 @@ var {clip, mapToScale} = require('../utils'), _sliders_base = require('./_sliders_base') -module.exports.options = { - type:'fader', - id:'auto', - linkId:'', +module.exports = class Fader extends _sliders_base { - separator1:'style', + static options() { - label:'auto', - unit:'', - left:'auto', - top:'auto', - width:'auto', - height:'auto', - alignRight:false, - horizontal:false, - noPip:false, - compact:false, - color:'auto', - css:'', + return { + type:'fader', + id:'auto', + linkId:'', - separator2:'behaviour', + _style:'style', - snap:false, - spring:false, + label:'auto', + unit:'', + left:'auto', + top:'auto', + width:'auto', + height:'auto', + alignRight:false, + horizontal:false, + noPip:false, + compact:false, + color:'auto', + css:'', - separator3:'osc', + _behaviour:'behaviour', - range:{min:0,max:1}, - origin: 'auto', - value:'', - logScale:false, - precision:2, - meter:false, - address:'auto', - preArgs:[], - target:[] -} + snap:false, + spring:false, -var Fader = module.exports.Fader = function(widgetData, container){ + _osc:'osc', - _sliders_base.apply(this,arguments) - this.widget.addClass('fader') - this.margin = 20 - - - if (widgetData.horizontal) { - this.widget.add(container).addClass('horizontal') - if (widgetData.width == 'auto' && widgetData.left != 'auto') { - container.css({'width':'auto', 'right':'0'}) - } - } else { - if (widgetData.height == 'auto' && widgetData.top != 'auto') { - container.css({'height':'auto', 'bottom':'0'}) - } - } - - if (widgetData.compact) { - this.widget.addClass('compact') - this.margin = 0 - } - - if (widgetData.alignRight && !widgetData.horizontal) { - this.widget.addClass('align-right') - } - - if (!widgetData.noPip&&!widgetData.compact) { - - this.widget.addClass('has-pips') - - var pips = $('
').appendTo(this.widget.find('.wrapper')) - var pipTexts = {} - for (k in this.rangeKeys) { - pipTexts[this.rangeKeys[k]]=this.rangeLabels[k] + range:{min:0,max:1}, + origin: 'auto', + value:'', + logScale:false, + precision:2, + meter:false, + address:'auto', + preArgs:[], + target:[] } - var pipsInner = '' - for (var i=0;i<=100;i++) { - if (pipTexts[i]==undefined) continue + } - var pos = widgetData.horizontal?'left':'bottom'; + constructor(widgetData) { - var piptext = `${Math.abs(pipTexts[i])>=1000?pipTexts[i]/1000+'k':pipTexts[i]}` + super(...arguments) - var add = ` -
${piptext}
+ this.widget.addClass('fader') + this.margin = 20 + + + if (widgetData.horizontal) { + this.widget.add(container).addClass('horizontal') + if (widgetData.width == 'auto' && widgetData.left != 'auto') { + this.container.css({'width':'auto', 'right':'0'}) + } + } else { + if (widgetData.height == 'auto' && widgetData.top != 'auto') { + this.container.css({'height':'auto', 'bottom':'0'}) + } + } + + if (widgetData.compact) { + this.widget.addClass('compact') + this.margin = 0 + } + + if (widgetData.alignRight && !widgetData.horizontal) { + this.widget.addClass('align-right') + } + + if (!widgetData.noPip&&!widgetData.compact) { + + this.widget.addClass('has-pips') + + var pips = $('
').appendTo(this.widget.find('.wrapper')) + var pipTexts = {} + for (var k in this.rangeKeys) { + pipTexts[this.rangeKeys[k]]=this.rangeLabels[k] + } + + var pipsInner = '' + for (var i=0;i<=100;i++) { + if (pipTexts[i]==undefined) continue + + var pos = widgetData.horizontal?'left':'bottom'; + + var piptext = `${Math.abs(pipTexts[i])>=1000?pipTexts[i]/1000+'k':pipTexts[i]}` + + var add = ` +
${piptext}
` - pipsInner = pipsInner + add + pipsInner = pipsInner + add + } + pips[0].innerHTML = pipsInner } - pips[0].innerHTML = pipsInner + + + if (widgetData.meter) { + var parsewidgets = require('../../parser').widgets + var data = { + type:'meter', + id: widgetData.id + '/meter', + label:false, + horizontal:widgetData.horizontal, + range:widgetData.range, + logScale:widgetData.logScale, + address:widgetData.address + '/meter', + preArgs:widgetData.preArgs, + color:widgetData.color + } + var element = parsewidgets([data],this.widget.find('.wrapper')) + element[0].classList.add('not-editable') + this.widget[0].classList.add('has-meter') + } + } + draginitHandle(e, data, traversing) { - if (widgetData.meter) { - var parsewidgets = require('../../parser').widgets - var data = { - type:'meter', - id: widgetData.id + '/meter', - label:false, - horizontal:widgetData.horizontal, - range:widgetData.range, - logScale:widgetData.logScale, - address:widgetData.address + '/meter', - preArgs:widgetData.preArgs, - color:widgetData.color - } - var element = parsewidgets([data],this.widget.find('.wrapper')) - element[0].classList.add('not-editable') - this.widget[0].classList.add('has-meter') - } + this.percent = clip(this.percent,[0,100]) + if (!(traversing || this.widgetData.snap)) return - -} - -Fader.prototype = Object.create(_sliders_base.prototype) - -Fader.prototype.constructor = Fader - -Fader.prototype.draginitHandle = function(e, data, traversing){ - - this.percent = clip(this.percent,[0,100]) - - if (!(traversing || this.widgetData.snap)) return - - this.percent = this.widgetData.horizontal? + this.percent = this.widgetData.horizontal? (data.offsetX - this.margin * PXSCALE) / (this.width - (this.margin * PXSCALE * 2)) * 100: (this.height - data.offsetY - this.margin * PXSCALE) / (this.height - (this.margin * PXSCALE * 2)) * 100 // this.percent = clip(this.percent,[0,100]) - this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true}) + this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true}) -} + } -Fader.prototype.dragHandle = function(e, data) { + dragHandle(e, data) { - this.percent = this.widgetData.horizontal? + 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 - this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true}) - -} - -Fader.prototype.percentToCoord = function(percent) { - if (this.widgetData.horizontal) { - return clip(percent / 100,[0,1]) * (this.width - 2 * PXSCALE * this.margin) - } else { - return (this.height - this.margin * PXSCALE) - clip(percent / 100, [0,1]) * (this.height - 2 * PXSCALE * this.margin) + this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true}) + + } + + percentToCoord(percent) { + + if (this.widgetData.horizontal) { + return clip(percent / 100,[0,1]) * (this.width - 2 * PXSCALE * this.margin) + } else { + return (this.height - this.margin * PXSCALE) - clip(percent / 100, [0,1]) * (this.height - 2 * PXSCALE * this.margin) + } } -} -Fader.prototype.draw = function(){ + draw() { - var d = Math.round(this.percentToCoord(this.percent)), + var d = Math.round(this.percentToCoord(this.percent)), o = Math.round(this.percentToCoord(this.valueToPercent(this.originValue))), m = Math.round(this.widgetData.horizontal ? this.height / 2 : this.width / 2) - this.ctx.clearRect(0,0,this.width,this.height) + this.ctx.clearRect(0,0,this.width,this.height) - if (this.widgetData.horizontal) { - if (this.widgetData.compact) { + if (this.widgetData.horizontal) { + if (this.widgetData.compact) { - this.ctx.globalAlpha = 0.2 + 0.2 * Math.abs(d-o) / (d -
${this.rangeLabels[0]}
${this.rangeLabels[this.rangeLabels.length-1]}
-
- `) + constructor(widgetData) { + + super(...arguments) + + this.widget.addClass('knob') + + this.margin = 5 + + if (widgetData.compact) { + this.widget.addClass('compact') + this.margin = 0 + } + + if (!widgetData.noPip) { + this.wrapper.append(` +
+
${this.rangeLabels[0]}
${this.rangeLabels[this.rangeLabels.length-1]}
+
+ `) + } + + this.lastOffsetX = 0 + this.lastOffsetY = 0 + this.minDimension = 0 + + this.maxAngle = widgetData.angle + + // calculate lost height factor + var a = this.maxAngle <= 180 ? + 1 : 1 - Math.sin((this.maxAngle - 180) / 2 * Math.PI / 180) + this.lostHeightFactor = a / 4 + } - this.lastOffsetX = 0 - this.lastOffsetY = 0 - this.minDimension = 0 + draginitHandle(e, data, traversing) { - this.maxAngle = widgetData.angle + this.percent = clip(this.percent,[0,100]) - // calculate lost height factor - var a = this.maxAngle <= 180 ? - 1 : 1 - Math.sin((this.maxAngle - 180) / 2 * Math.PI / 180) - this.lostHeightFactor = a / 4 + this.lastOffsetX = data.offsetX + this.lastOffsetY = data.offsetY -} + if (!(traversing || this.widgetData.snap)) return + this.percent = this.angleToPercent(this.coordsToAngle(data.offsetX, data.offsetY)) -Knob.prototype = Object.create(_sliders_base.prototype) + this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true}) -Knob.prototype.constructor = Knob - -Knob.prototype.draginitHandle = function(e, data, traversing){ - - this.percent = clip(this.percent,[0,100]) - - this.lastOffsetX = data.offsetX - this.lastOffsetY = data.offsetY - - if (!(traversing || this.widgetData.snap)) return - - this.percent = this.angleToPercent(this.coordsToAngle(data.offsetX, data.offsetY)) - - this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true}) - -} - -Knob.prototype.dragHandle = function(e, data, traversing) { - - - if (!(traversing || this.widgetData.snap)) { - - this.percent = -100*data.speedY/this.height + this.percent - - } else { - - this.lastOffsetX = this.lastOffsetX + data.speedX - this.lastOffsetY = this.lastOffsetY + data.speedY - this.percent = this.angleToPercent(this.coordsToAngle(this.lastOffsetX, this.lastOffsetY)) } - this.percent = this.percent,[0,100] + dragHandle(e, data, traversing) { - this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true}) + if (!(traversing || this.widgetData.snap)) { -} + this.percent = -100*data.speedY/this.height + this.percent -Knob.prototype.coordsToAngle = function(x,y) { - var xToCenter = x - this.width /2, + } else { + + this.lastOffsetX = this.lastOffsetX + data.speedX + this.lastOffsetY = this.lastOffsetY + data.speedY + this.percent = this.angleToPercent(this.coordsToAngle(this.lastOffsetX, this.lastOffsetY)) + } + + this.percent = this.percent,[0,100] + + this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true}) + + } + + coordsToAngle(x,y) { + + var xToCenter = x - this.width /2, yToCenter = y - this.height / 2, angle = Math.atan2(-yToCenter, -xToCenter) * 180 / Math.PI + 90 - return angle<0?360+angle:angle -} + return angle<0?360+angle:angle -Knob.prototype.angleToPercent = function(angle) { - return clip(angle - (360 - this.maxAngle) / 2, [0, this.maxAngle]) / this.maxAngle * 100 -} - -Knob.prototype.percentToAngle = function(percent) { - var percent = clip(percent, [0, 100]) - return 2 * Math.PI * percent / 100 * (this.maxAngle / 360) // angle relative to maxAngle - + Math.PI / 2 // quarter circle offset - + Math.PI * (1 - this.maxAngle / 360) // centering offset depending on maxAngle -} - -Knob.prototype.resizeHandle = function() { - _sliders_base.prototype.resizeHandle.apply(this, arguments) - this.minDimension = Math.min(this.width, this.height) - this.gaugeWidth = this.minDimension / 8 - if (this.widgetData.compact) { - this.canvas[0].style.top = this.input[0].style.marginTop = (this.minDimension) * this.lostHeightFactor - this.gaugeWidth / 4 + 'px' - } else { - this.canvas[0].style.top = Math.min((this.minDimension) * this.lostHeightFactor - this.margin * PXSCALE / 2, this.input.outerHeight() * .5) + 'px' } -} + + angleToPercent(angle) { + + return clip(angle - (360 - this.maxAngle) / 2, [0, this.maxAngle]) / this.maxAngle * 100 + + } + + percentToAngle(percent) { + + var percent = clip(percent, [0, 100]) + return 2 * Math.PI * percent / 100 * (this.maxAngle / 360) // angle relative to maxAngle + + Math.PI / 2 // quarter circle offset + + Math.PI * (1 - this.maxAngle / 360) // centering offset depending on maxAngle + + } + + resizeHandle() { + + super.resizeHandle(...arguments) + + this.minDimension = Math.min(this.width, this.height) + this.gaugeWidth = this.minDimension / 8 + if (this.widgetData.compact) { + this.canvas[0].style.top = this.input[0].style.marginTop = (this.minDimension) * this.lostHeightFactor - this.gaugeWidth / 4 + 'px' + } else { + this.canvas[0].style.top = Math.min((this.minDimension) * this.lostHeightFactor - this.margin * PXSCALE / 2, this.input.outerHeight() * .5) + 'px' + } + + } + + draw() { + + var o = this.percentToAngle(this.valueToPercent(this.originValue)), + d = this.percentToAngle(this.percent), + min = this.percentToAngle(0), + max = this.percentToAngle(100) + + this.ctx.clearRect(0,0,this.width,this.height) + + if (this.widgetData.compact) { + + this.ctx.lineWidth = this.gaugeWidth * PXSCALE + this.ctx.globalAlpha = 0.3 + this.ctx.beginPath() + this.ctx.strokeStyle = this.colors.track + this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (this.gaugeWidth + this.margin) * PXSCALE, min, max) + this.ctx.stroke() + + this.ctx.globalAlpha = 0.2 + 0.2 * Math.abs(d-o) / (d