From f6c390c8dd37e59406a3fe3a36655cb04ce8085c Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sat, 3 Nov 2018 15:30:32 +0100 Subject: [PATCH] pads: clean rgb, add active state hint, add --point-opacity --- CHANGELOG.md | 4 ++-- src/client/app/widgets/pads/pad.js | 1 + src/client/app/widgets/pads/rgb.js | 36 ++++++++++++++++++------------ src/client/app/widgets/pads/xy.js | 25 +++++++++++++++------ src/scss/widgets/pads.scss | 5 +++-- 5 files changed, 46 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2a3fe90..23a123c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,9 @@ - widgets - multiXy: added `.pad-N` class to inner xy pads to help with css customization - - xy/multiXy: added css variables `--background`, `--color-pips` and `--pips-opacity` + - xy/multiXy: added css variables `--background`, `--color-pips`, `--pips-opacity` and `--point-opacity` - rgb: added `alphaChannel` option - - xy/multiXy/rgb: slight design impovements + - xy/multiXy/rgb: design impovements; - sliders: new `steps` option ## 0.39.3 diff --git a/src/client/app/widgets/pads/pad.js b/src/client/app/widgets/pads/pad.js index a8eb8454..02851e8f 100644 --- a/src/client/app/widgets/pads/pad.js +++ b/src/client/app/widgets/pads/pad.js @@ -28,6 +28,7 @@ class Pad extends Canvas { this.colors.pips = style.getPropertyValue('--color-pips') || this.colors.custom this.colors.pipsOpacity = style.getPropertyValue('--pips-opacity') + this.colors.pointOpacity = style.getPropertyValue('--point-opacity') } diff --git a/src/client/app/widgets/pads/rgb.js b/src/client/app/widgets/pads/rgb.js index d0bf17e0..91f9d8df 100644 --- a/src/client/app/widgets/pads/rgb.js +++ b/src/client/app/widgets/pads/rgb.js @@ -57,6 +57,10 @@ module.exports = class Rgb extends Pad { }, cancelDraw: false, parent: this}) this.hue.sendValue = ()=>{} this.hueWrapper.appendChild(this.hue.widget) + this.hue.on('change',(e)=>{ + e.stopPropagation = true + this.dragHandle(true) + }) this.pad = new Xy({props:{ ...xyDefaults, @@ -71,16 +75,6 @@ module.exports = class Rgb extends Pad { }, parent: this}) this.pad.sendValue = ()=>{} this.wrapper.appendChild(this.pad.widget) - - - this.value = [] - this.hsb = {h:0,s:0,b:0} - - this.hue.on('change',(e)=>{ - e.stopPropagation = true - this.dragHandle(true) - }) - this.pad.on('change',(e)=>{ e.stopPropagation = true this.dragHandle() @@ -124,6 +118,10 @@ module.exports = class Rgb extends Pad { } + this.value = [] + + this.hsb = {h:0,s:0,b:0} + this.setValue([this.getProp('range').min, this.getProp('range').min, this.getProp('range').min]) } @@ -147,7 +145,12 @@ module.exports = class Rgb extends Pad { } 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}) + this.setValue([rgb.r, rgb.g, rgb.b], { + send: true, + sync: true, + dragged: true, + nohue: !hue + }) } } @@ -157,7 +160,12 @@ module.exports = class Rgb extends Pad { var alpha = this.alpha.value if (alpha !== this.value[3]) { - this.setValue([this.value[0], this.value[1], this.value[2], alpha],{send:true,sync:true,dragged:true,nohue:true}) + this.setValue([this.value[0], this.value[1], this.value[2], alpha], { + send: true, + sync: true, + dragged: true, + nohue: true + }) } @@ -182,8 +190,8 @@ module.exports = class Rgb extends Pad { }) if (!options.dragged) { - this.pad.setValue([hsb.s, hsb.b], {sync: false, send:false, dragged:false}) - if (value.length === 4) this.alpha.setValue(value[3], {sync: false, send:false, dragged:false}) + this.pad.setValue([hsb.s, hsb.b]) + if (value.length === 4) this.alpha.setValue(value[3]) } this.hsb = hsb diff --git a/src/client/app/widgets/pads/xy.js b/src/client/app/widgets/pads/xy.js index 1abdd86e..0d270a06 100644 --- a/src/client/app/widgets/pads/xy.js +++ b/src/client/app/widgets/pads/xy.js @@ -44,6 +44,7 @@ module.exports = class Xy extends Pad { '- `--background: background;`: sets the dragging area\'s background', '- `--pips-color: color;`', '- `--pips-opacity: number;`', + '- `--point-opacity: number;`', ]} }) @@ -105,9 +106,11 @@ module.exports = class Xy extends Pad { }) touchstate(this, {element: this.wrapper}) + this.active = false this.on('draginit',(e)=>{ e.stopPropagation = true + this.active = true this.faders.x.trigger('draginit', e) this.faders.y.trigger('draginit', e) this.dragHandle() @@ -121,10 +124,13 @@ module.exports = class Xy extends Pad { this.on('dragend', (e)=>{ e.stopPropagation = true + this.active = false this.faders.x.trigger('dragend', e) this.faders.y.trigger('dragend', e) if (this.getProp('spring')) { this.setValue([this.faders.x.springValue,this.faders.y.springValue],{sync:true,send:true}) + } else { + this.batchDraw() } }, {element: this.wrapper}) @@ -175,6 +181,8 @@ module.exports = class Xy extends Pad { if (x != this.value[0] || y != this.value[1]) { this.setValue([x, y],{send:true,sync:true,dragged:true}) + } else { + this.batchDraw() } } @@ -219,11 +227,12 @@ module.exports = class Xy extends Pad { if (this.getProp('pips')) { this.ctx.strokeStyle = this.colors.pips - this.ctx.globalAlpha = this.colors.pipsOpacity + this.ctx.globalAlpha = 0.1 this.ctx.beginPath() this.ctx.rect(margin + 0.5, margin + 0.5, this.width - margin * 2 - 1, this.height - margin * 2 - 1) this.ctx.stroke() + this.ctx.globalAlpha = this.colors.pipsOpacity this.ctx.beginPath() for (var pip of this.faders.x.rangeKeys.concat(this.faders.x.valueToPercent(this.faders.x.originValue))) { if (pip == 0 || pip == 100) continue @@ -241,24 +250,26 @@ module.exports = class Xy extends Pad { } else { - this.clearRect = [x - margin, y - margin, margin * 2, margin * 2] + this.clearRect = [x - margin - PXSCALE, y - margin - PXSCALE, (margin + PXSCALE) * 2, (margin + PXSCALE) * 2] } this.ctx.strokeStyle = this.colors.custom - this.ctx.globalAlpha = 0.7 - + this.ctx.globalAlpha = this.active ? 1 : 0.7 + this.ctx.lineWidth = 2 * PXSCALE this.ctx.beginPath() this.ctx.arc(x, y, pointSize, Math.PI * 2, false) this.ctx.stroke() - this.ctx.globalAlpha = 1 - this.ctx.lineWidth = 1.5 * PXSCALE + + this.ctx.fillStyle = this.colors.custom + this.ctx.globalAlpha = this.colors.pointOpacity this.ctx.beginPath() this.ctx.arc(x, y, pointSize / 1.5, Math.PI * 2, false) - this.ctx.stroke() + this.ctx.fill() + } diff --git a/src/scss/widgets/pads.scss b/src/scss/widgets/pads.scss index bb5482ec..d7da9817 100644 --- a/src/scss/widgets/pads.scss +++ b/src/scss/widgets/pads.scss @@ -1,10 +1,11 @@ .xy-container, .rgb-container, .multixy-container { width:200rem; height:230rem; - padding:1rem; + padding:2rem; --background: var(--color-track); - --pips-opacity: 0.1; + --pips-opacity: 0.2; + --point-opacity: 0.3; .label { flex-shrink: 0;