rgb: add range property (#252)

This commit is contained in:
jean-emmanuel 2018-03-22 13:33:41 +01:00
parent 694a9596f5
commit d63dc0b388
3 changed files with 31 additions and 6 deletions

View file

@ -5,7 +5,8 @@
- widgets
- matrices: support setting `split` property as a string to allow using children's indexes in their address (`$` is replaced with the index number)
- text: `wrap` property doesn't break words by default anymore
- rgb: added `range` property
## 0.27.2
- bug fixes

View file

@ -54,7 +54,7 @@ Pads are multidimensional widgets that output multiple values.
### `doubleTap`
- type: `boolean|string`
- default: `false`
- usage: set to `true` to make the fader reset to its `default` value when receiving a double tap. `doubleTap` can also be an osc address, which case the widget will just send an osc message (`/<doubleTap> <preArgs>`),
- usage: set to `true` to make the fader reset to its `default` value when receiving a double tap. `doubleTap` can also be an osc address, which case the widget will just send an osc message (`/<doubleTap> <preArgs>`),
### `split`
@ -149,9 +149,15 @@ RGB is a variant of XY, it outputs rgb values between 0 and 255.
- default: `false`
- usage: by default, dragging the widget will modify it's value starting from its last value. Setting this to true will make it snap directly to the mouse/touch position.
### `range`
- type: `object`
- default: `{"min":0,"max":255}`
- usage: `range` defines the widget's output scale.
### `split`
- type: `boolean|object`
- default: `false`
- usage:
- set to `true` to send separate osc messages for `r` and `g` & `b`. The `address` will be the same as the widget's with `/r`, `/g` or `/b` appended to it
- can be set as an object to specify a different `address` : `['/r', '/b', '/b']`
- note: the widget will only respond to its original osc address, not to the splitted version

View file

@ -33,6 +33,7 @@ module.exports = class Rgb extends Pad {
input: true,
snap:false,
spring:false,
range: {min:0,max:255},
_value: 'value',
default: '',
@ -122,7 +123,7 @@ module.exports = class Rgb extends Pad {
}
this.setValue([0,0,0])
this.setValue([this.getProp('range').min, this.getProp('range').min, this.getProp('range').min])
}
@ -139,7 +140,15 @@ module.exports = class Rgb extends Pad {
this.update({nohue:!hue})
var rgb = hsbToRgb(this.hsb)
var rgb = hsbToRgb(this.hsb),
{min, max} = this.getProp('range')
if (min !== 0 || max !== 255) {
for (var k in rgb) {
rgb[k] = min + max * rgb[k] / 255
}
}
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})
}
@ -153,10 +162,19 @@ module.exports = class Rgb extends Pad {
if (this.touched && !options.dragged) return this.setValueTouchedQueue = [v, options]
for (let i in [0,1,2]) {
v[i] = clip(v[i],[0,255])
v[i] = clip(v[i],[this.getProp('range').min, this.getProp('range').max])
}
var hsb = rgbToHsb({r:v[0],g:v[1],b:v[2]})
var rgb = {r:v[0],g:v[1],b:v[2]},
{min, max} = this.getProp('range')
if (min !== 0 || max !== 255) {
for (var k in rgb) {
rgb[k] = (rgb[k] - min ) * 255 / max
}
}
var hsb = rgbToHsb(rgb)
if (!options.dragged) {
this.pad.setValue([hsb.s, hsb.b], {sync: false, send:false, dragged:false})