From 7ce05fc83e0c5393a64cae5311607932d2619775 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sat, 10 Jun 2017 12:21:16 +0200 Subject: [PATCH] sliders: compact knob redisign; rename noPip option to pips (with backward compat) --- CHANGELOG.md | 2 + src/browser/js/app/parser.js | 7 +- src/browser/js/app/widgets/pads/rgb.js | 2 +- src/browser/js/app/widgets/sliders/fader.js | 8 +- src/browser/js/app/widgets/sliders/knob.js | 84 ++++++++++++++------- 5 files changed, 68 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a5b3ba4..d5315326 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ Sessions saved with this version will not be readable with older versions (old s - modal: changed style to fit popups' appearance; added `popupWidth` and `popupHeight` options; :warning: removed `tabs` option; added full osc support - strip: refactored widget using `panel` as base; added `stretch` and `spacing` option; now it's really cool - encoder: mousewheel support + - knob/fader: renamed `noPip` option to `pips` (inverted behaviour; backward compatible) + - knob: compact design remake - session - the root panel is now saved as a special `panel` widget (which means it has savable options) - custom module diff --git a/src/browser/js/app/parser.js b/src/browser/js/app/parser.js index 32c02b9d..c3935272 100644 --- a/src/browser/js/app/parser.js +++ b/src/browser/js/app/parser.js @@ -31,6 +31,10 @@ module.exports.widgets = function(data, parentNode, parentWidget, tab) { // Set default widget type props.type = tab ? 'tab' : props.type || 'fader' + // Backward compatibility patches + if (props.path) props.address = props.path + if (props.noPip) props.pips = !props.noPip + // Safe copy widget's options let defaults = widgets[props.type].defaults() @@ -48,9 +52,6 @@ module.exports.widgets = function(data, parentNode, parentWidget, tab) { props.id = id } - // Backward compatibility patch: path -> address - if (props.path) props.address = props.path - // Generate default address props.address = props.address == 'auto' ? '/' + props.id : props.address diff --git a/src/browser/js/app/widgets/pads/rgb.js b/src/browser/js/app/widgets/pads/rgb.js index c8fad38e..d7b78f0d 100644 --- a/src/browser/js/app/widgets/pads/rgb.js +++ b/src/browser/js/app/widgets/pads/rgb.js @@ -70,7 +70,7 @@ module.exports = class Rgb extends _pads_base { ...faderDefaults, id:'h', compact:false, - noPip:true, + pips:false, horizontal:true, snap:this.getProp('snap'), range:{min:0,max:360}, diff --git a/src/browser/js/app/widgets/sliders/fader.js b/src/browser/js/app/widgets/sliders/fader.js index af693696..e0c724b9 100644 --- a/src/browser/js/app/widgets/sliders/fader.js +++ b/src/browser/js/app/widgets/sliders/fader.js @@ -21,7 +21,7 @@ module.exports = class Fader extends _sliders_base { height:'auto', alignRight:false, horizontal:false, - noPip:false, + pips:true, compact:false, color:'auto', css:'', @@ -76,7 +76,7 @@ module.exports = class Fader extends _sliders_base { this.widget.addClass('align-right') } - if (!this.getProp('noPip') && !this.getProp('compact')) { + if (this.getProp('pips') && !this.getProp('compact')) { this.widget.addClass('has-pips') @@ -190,7 +190,7 @@ module.exports = class Fader extends _sliders_base { if (this.getProp('horizontal')) { if (this.getProp('compact')) { - if (!this.getProp('noPip')) { + if (this.getProp('pips')) { this.ctx.lineWidth = PXSCALE this.ctx.globalAlpha = 1 @@ -258,7 +258,7 @@ module.exports = class Fader extends _sliders_base { if (this.getProp('compact')) { - if (!this.getProp('noPip')) { + if (this.getProp('pips')) { this.ctx.lineWidth = PXSCALE this.ctx.globalAlpha = 0.75 diff --git a/src/browser/js/app/widgets/sliders/knob.js b/src/browser/js/app/widgets/sliders/knob.js index f595f4bd..7d780900 100644 --- a/src/browser/js/app/widgets/sliders/knob.js +++ b/src/browser/js/app/widgets/sliders/knob.js @@ -19,7 +19,7 @@ module.exports = class Knob extends _sliders_base { width:'auto', height:'auto', color:'auto', - noPip:true, + pips:true, compact:false, angle:270, css:'', @@ -57,7 +57,7 @@ module.exports = class Knob extends _sliders_base { this.margin = 0 } - if (!this.getProp('noPip')) { + if (this.getProp('pips') && !this.getProp('compact')) { this.wrapper.append(`
${this.rangeLabels[0]}
${this.rangeLabels[this.rangeLabels.length-1]}
@@ -72,7 +72,9 @@ module.exports = class Knob extends _sliders_base { this.maxAngle = this.getProp('angle') // calculate lost height factor - var a = 1 - Math.sin((Math.max(this.maxAngle,247.5) - 180) / 2 * Math.PI / 180) + var a = this.getProp('compact') ? + (1 - Math.sin((Math.max(this.maxAngle,247.5) - 180) / 2 * Math.PI / 180)) / 3 + : 1 - Math.sin((Math.max(this.maxAngle,180) - 180) / 2 * Math.PI / 180) this.lostHeightFactor = a / 4 } @@ -162,51 +164,79 @@ module.exports = class Knob extends _sliders_base { if (this.getProp('compact')) { - this.ctx.lineWidth = this.gaugeWidth - this.ctx.globalAlpha = 0.3 - this.ctx.beginPath() this.ctx.strokeStyle = this.colors.track + this.ctx.globalAlpha = 0.3 + this.ctx.lineWidth = this.gaugeWidth + this.ctx.beginPath() this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - this.gaugeWidth - this.margin * PXSCALE, min, max) this.ctx.stroke() + this.ctx.lineWidth = this.gaugeWidth this.ctx.globalAlpha = 0.2 + 0.2 * Math.abs(d-o) / (d