From 6d4baa38dd0ee7f674dafb126e1753fe34b3a0b8 Mon Sep 17 00:00:00 2001 From: bordun Date: Wed, 2 Sep 2020 16:05:52 +0200 Subject: [PATCH] knob: add solid & line designs --- CHANGELOG.md | 5 + src/client/widgets/sliders/knob.js | 252 ++++++++++++++++------------- src/scss/widgets/sliders.scss | 3 +- 3 files changed, 148 insertions(+), 112 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42273a88..7e00cf2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## next + +- widgets + - knob: add `solid` & `line` designs + ## 1.1.0 - bug fixes diff --git a/src/client/widgets/sliders/knob.js b/src/client/widgets/sliders/knob.js index 2e983d4d..c9f101ba 100644 --- a/src/client/widgets/sliders/knob.js +++ b/src/client/widgets/sliders/knob.js @@ -15,6 +15,10 @@ module.exports = class Knob extends Slider { _class_specific: 'knob', + design: {type: 'string', value: 'default', choices: ['default', 'solid', 'line'], help: [ + 'Design style', + 'Note: "solid" design uses "colorStroke" for the central knob color.' + ]}, mode: {type: 'string', value: 'vertical', choices: ['vertical', 'circular', 'snap'], help: [ '- `circular`: relative move in circular motion', '- `snap`: snap to touch position and move in vertical motion', @@ -182,126 +186,154 @@ module.exports = class Knob extends Slider { this.clear() - // if (this.getProp('design') === 'default') { + if (this.getProp('design') === 'default') { - if (this.minDimension < 40) { - minRadius /= 2 - gaugeWidth = maxRadius - minRadius - gaugeRadius = maxRadius - gaugeWidth / 2 - } + if (this.minDimension < 40) { + minRadius /= 2 + gaugeWidth = maxRadius - minRadius + gaugeRadius = maxRadius - gaugeWidth / 2 + } - // fill - this.ctx.strokeStyle = this.cssVars.colorFill - this.ctx.lineWidth = gaugeWidth - this.gaugePadding * 2 + // fill + this.ctx.strokeStyle = this.cssVars.colorFill + this.ctx.lineWidth = gaugeWidth - this.gaugePadding * 2 + + if (this.cssVars.alphaFillOff) { + this.ctx.globalAlpha = this.cssVars.alphaFillOff + this.ctx.beginPath() + this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, min, max) + this.ctx.stroke() + } + + if (dashed) this.ctx.setLineDash(dashed) + + if (this.cssVars.alphaFillOn) { + this.ctx.globalAlpha = this.cssVars.alphaFillOn + this.ctx.beginPath() + this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, o, d, o > d) + this.ctx.stroke() + } + + if (dashed) this.ctx.setLineDash([]) + + + // stroke + + this.ctx.globalAlpha = this.cssVars.alphaStroke + this.ctx.strokeStyle = this.cssVars.colorStroke + this.ctx.lineWidth = PXSCALE - if (this.cssVars.alphaFillOff) { - this.ctx.globalAlpha = this.cssVars.alphaFillOff this.ctx.beginPath() - this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, min, max) + this.ctx.arc(this.width / 2, this.height / 2, maxRadius, 0, 2 * Math.PI) this.ctx.stroke() - } - if (dashed) this.ctx.setLineDash(dashed) - if (this.cssVars.alphaFillOn) { - this.ctx.globalAlpha = this.cssVars.alphaFillOn + // knob + + this.ctx.globalAlpha = 1 + this.ctx.strokeStyle = this.cssVars.colorFill + this.ctx.lineWidth = 2.5 * PXSCALE + + let r1 = minRadius + this.gaugePadding, + r2 = maxRadius - this.gaugePadding, + a = 2 * Math.PI - d + this.ctx.beginPath() - this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, o, d, o > d) + this.ctx.moveTo(r1 * Math.cos(a) + this.width / 2, this.height / 2 - r1 * Math.sin(a)) + this.ctx.lineTo(r2 * Math.cos(a) + this.width / 2, this.height / 2 - r2 * Math.sin(a)) this.ctx.stroke() + + } else if (this.getProp('design') === 'solid') { + + // center + + this.ctx.globalAlpha = this.cssVars.alphaStroke + this.ctx.fillStyle = this.cssVars.colorStroke + + this.ctx.beginPath() + this.ctx.arc(this.width / 2, this.height / 2, maxRadius / 1.25, 0, 2 * Math.PI) + this.ctx.fill() + + // fill + this.ctx.strokeStyle = this.cssVars.colorFill + this.ctx.lineWidth = 2 * PXSCALE + + if (this.cssVars.alphaFillOff) { + this.ctx.globalAlpha = this.cssVars.alphaFillOff + this.ctx.beginPath() + this.ctx.arc(this.width / 2, this.height / 2, maxRadius, min, max) + this.ctx.stroke() + } + + if (dashed) this.ctx.setLineDash(dashed) + + if (this.cssVars.alphaFillOn) { + this.ctx.globalAlpha = this.cssVars.alphaFillOn + this.ctx.beginPath() + this.ctx.arc(this.width / 2, this.height / 2, maxRadius, o, d, o > d) + this.ctx.stroke() + } + + if (dashed) this.ctx.setLineDash([]) + + // knob + + this.ctx.globalAlpha = 1 + this.ctx.strokeStyle = this.cssVars.colorBg + this.ctx.lineWidth = 2.5 * PXSCALE + + let r1 = minRadius, + r2 = maxRadius / 1.25 + PXSCALE , + a = 2 * Math.PI - d + + this.ctx.beginPath() + this.ctx.moveTo(r1 * Math.cos(a) + this.width / 2, this.height / 2 - r1 * Math.sin(a)) + this.ctx.lineTo(r2 * Math.cos(a) + this.width / 2, this.height / 2 - r2 * Math.sin(a)) + this.ctx.stroke() + + + + } else { + + // fill + this.ctx.strokeStyle = this.cssVars.colorFill + this.ctx.lineWidth = 2 * PXSCALE + + if (this.cssVars.alphaFillOff) { + this.ctx.globalAlpha = this.cssVars.alphaFillOff + this.ctx.beginPath() + this.ctx.arc(this.width / 2, this.height / 2, maxRadius, min, max) + this.ctx.stroke() + } + + if (dashed) this.ctx.setLineDash(dashed) + + if (this.cssVars.alphaFillOn) { + this.ctx.globalAlpha = this.cssVars.alphaFillOn + this.ctx.beginPath() + this.ctx.arc(this.width / 2, this.height / 2, maxRadius, o, d, o > d) + this.ctx.stroke() + } + + if (dashed) this.ctx.setLineDash([]) + + // knob + + this.ctx.globalAlpha = 1 + this.ctx.strokeStyle = this.cssVars.colorFill + this.ctx.lineWidth = 2.5 * PXSCALE + + let r1 = minRadius * 1.5, + r2 = maxRadius + 0.5 * PXSCALE, + a = 2 * Math.PI - d + + this.ctx.beginPath() + this.ctx.moveTo(r1 * Math.cos(a) + this.width / 2, this.height / 2 - r1 * Math.sin(a)) + this.ctx.lineTo(r2 * Math.cos(a) + this.width / 2, this.height / 2 - r2 * Math.sin(a)) + this.ctx.stroke() + } - if (dashed) this.ctx.setLineDash([]) - - - // stroke - - this.ctx.globalAlpha = this.cssVars.alphaStroke - this.ctx.strokeStyle = this.cssVars.colorStroke - this.ctx.lineWidth = PXSCALE - // - // if (this.minDimension > 40) { - // this.ctx.beginPath() - // this.ctx.arc(this.width / 2, this.height / 2, minRadius, 0, 2 * Math.PI) - // this.ctx.stroke() - // } - - - this.ctx.beginPath() - this.ctx.arc(this.width / 2, this.height / 2, maxRadius, 0, 2 * Math.PI) - this.ctx.stroke() - - - // knob - - this.ctx.globalAlpha = 1 - this.ctx.strokeStyle = this.cssVars.colorFill - this.ctx.lineWidth = 1.5 * PXSCALE - - let r1 = minRadius + this.gaugePadding, - r2 = maxRadius - this.gaugePadding, - a = 2 * Math.PI - d - - this.ctx.beginPath() - this.ctx.moveTo(r1 * Math.cos(a) + this.width / 2, this.height / 2 - r1 * Math.sin(a)) - this.ctx.lineTo(r2 * Math.cos(a) + this.width / 2, this.height / 2 - r2 * Math.sin(a)) - this.ctx.stroke() - - // } else { - // - // // fill - // this.ctx.strokeStyle = this.cssVars.colorFill - // this.ctx.lineWidth = 2 * PXSCALE - // - // if (this.cssVars.alphaFillOff) { - // this.ctx.globalAlpha = this.cssVars.alphaFillOff - // this.ctx.beginPath() - // this.ctx.arc(this.width / 2, this.height / 2, maxRadius, min, max) - // this.ctx.stroke() - // } - // - // if (dashed) this.ctx.setLineDash([1.5 * PXSCALE, 1.5 * PXSCALE]) - // - // if (this.cssVars.alphaFillOn) { - // this.ctx.globalAlpha = this.cssVars.alphaFillOn - // this.ctx.beginPath() - // this.ctx.arc(this.width / 2, this.height / 2, maxRadius, o, d, o > d) - // this.ctx.stroke() - // } - // - // if (dashed) this.ctx.setLineDash([]) - // - // - // - // // center - // this.ctx.fillStyle = this.cssVars.colorBg - // this.ctx.strokeStyle = this.cssVars.colorStroke - // this.ctx.lineWidth = 1 * PXSCALE - // - // this.ctx.beginPath() - // this.ctx.arc(this.width / 2, this.height / 2, maxRadius - (2 + this.cssVars.padding) * PXSCALE, 0, 2 * Math.PI) - // this.ctx.globalAlpha = this.cssVars.alphaStroke - // this.ctx.stroke() - // this.ctx.globalAlpha = 1 - // // this.ctx.fill() - // - // - // - // // knob - // this.ctx.globalAlpha = 1 - // this.ctx.fillStyle = this.cssVars.colorFill - // this.ctx.lineWidth = 1.5 * PXSCALE - // - // let r1 = maxRadius - (8 + this.cssVars.padding) * PXSCALE, - // a = 2 * Math.PI - d - // - // this.ctx.beginPath() - // this.ctx.arc(r1 * Math.cos(a) + this.width / 2, this.height / 2 - r1 * Math.sin(a), 1.5 * PXSCALE, 0, 2*Math.PI) - // this.ctx.fill() - // - // - // } - - // pips @@ -313,7 +345,7 @@ module.exports = class Knob extends Slider { for (var pip of this.rangeKeys) { - let r1 = maxRadius + 2 * PXSCALE, + let r1 = maxRadius + 3 * PXSCALE, r2 = r1 + 4 * PXSCALE, a = 2 * Math.PI - this.percentToAngle(pip) diff --git a/src/scss/widgets/sliders.scss b/src/scss/widgets/sliders.scss index ff761fa6..59e4d029 100644 --- a/src/scss/widgets/sliders.scss +++ b/src/scss/widgets/sliders.scss @@ -52,8 +52,7 @@ --widget-padding: 1rem; --alpha-stroke: 0.75; - &.design-classic { - --alpha-stroke: 0.5; + &.design-solid, &.design-line { --alpha-fill-off: 0.25; --alpha-fill-on: 1; }