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

@ -1,11 +1,17 @@
# Changelog
## 0.17.5
- widgets
- **new** `rgbled` widget
## 0.17.4
- bug fixes
- broken `--blank` option fixed (false-positive detection of concurrency with `--read-only`)
- remove debug message in console when closing windows
## 0.17.3
Hot fix for `--read-only` switch.

View file

@ -21,6 +21,17 @@ Plots are tools that display other widgets' state or incomming osc messages. The
- usage: set to true use logarithmic scaling
## RgbLed
```js
{
type:'rgbled',
// etc
}
```
This one is like the `led` except it takes three arguments (red, green and blue values between 0 and 255) with an optionnal forth argument (alpha, between 0 and 1)
## Plot

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]})`)
}
}

View file

@ -1,4 +1,4 @@
.led-container {
.led-container, .rgbled-container {
width:100rem;
flex-shrink: 0;
@ -6,31 +6,18 @@
display: flex;
align-items: center;
height: 100%;
padding:10rem 0;
overflow: hidden;
padding:1rem;
div {
border-radius: 100%;
width:70%;
padding-bottom:70%;
margin: 0 auto;
width:100%;
height:100%;
background:var(--color-track);
position: relative;
span {
position: absolute;
top:0;left:0;right:0;bottom:0;
border-radius: 100%;
display:block;
background-color:var(--color-custom);
&:after {
content:"";
border-radius:100%;
position: absolute;
top:-10%;left:-10%;right:-10%;bottom:-10%;
display:block;
background-color:var(--color-custom);
opacity: 0.2;
}
}
}
}