plots: add rgbled widget

This commit is contained in:
jean-emmanuel 2017-04-04 00:42:54 +02:00
parent 1edb3ef104
commit b272990cae
5 changed files with 112 additions and 19 deletions

View file

@ -21,6 +21,7 @@ var widgets = {
// plots
led: require('./widgets/plots/led'),
rgbled: require('./widgets/plots/rgbled'),
plot: require('./widgets/plots/plot'),
eq: require('./widgets/plots/eq'),
visualizer: require('./widgets/plots/visualizer'),
@ -45,7 +46,7 @@ module.exports.categories = {
'Buttons':['toggle','push','switch'],
'Pads':['xy','rgb','multixy'],
'Matrices':['multifader','multitoggle','multipush', 'keyboard'],
'Plots':['plot','eq','visualizer','led','meter','text'],
'Plots':['plot','eq','visualizer','led', 'rgbled','meter','text'],
'Containers':['panel','strip','modal'],
'Switchers':['switcher','crossfader'],
'Maths':['formula']

View file

@ -0,0 +1,88 @@
var {mapToScale} = require('../utils'),
_widgets_base = require('../common/_widgets_base'),
{widgetManager} = require('../../managers'),
{clip} = require('../utils')
module.exports = class Led extends _widgets_base {
static options() {
return {
type:'rgbled',
id:'auto',
_style:'style',
label:'auto',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
css:'',
_plot:'plot',
widgetId:'',
_osc:'osc',
value:'',
preArgs:[],
address:'auto'
}
}
constructor(widgetData) {
var widgetHtml = `
<div class="led">
<div><span></span></div>
</div>
`
super(...arguments, widgetHtml)
this.led = this.widget.find('span')
if (widgetData.widgetId.length) $('body').on(`sync.${this.hash}`,this.syncHandle.bind(this))
this.setValue([0,0,0])
}
onRemove() {
$('body').off(`sync.${this.hash}`)
}
syncHandle(e) {
if (this.widgetData.widgetId!=e.id || !widgetManager.getWidgetById(e.id).length) return
var widget = widgetManager.getWidgetById(e.id),
value
for (var i=widget.length-1; i>=0; i--) {
if (widget[i].getValue) {
this.setValue(widget[i].getValue())
return
}
}
}
setValue(v) {
if (!v || !v.length || v.length<3) return
for (i in [0,1,2]) {
v[i] = parseInt(clip(v[i],[0,255]))
}
v[3] = clip(v[3]||1,[0,1])
this.led[0].style.setProperty('--color-custom',`rgba(${v[0]}, ${v[1]}, ${v[2]}, ${v[3]})`)
}
}