From 999bdcaf132f7d8baeb38882653147b76cfcef5c Mon Sep 17 00:00:00 2001 From: bordun Date: Wed, 25 Mar 2020 11:31:27 +0100 Subject: [PATCH] knob: rm alternate design and tweak main design --- src/client/widgets/sliders/encoder.js | 16 +- src/client/widgets/sliders/knob.js | 202 +++++++++++++------------- 2 files changed, 117 insertions(+), 101 deletions(-) diff --git a/src/client/widgets/sliders/encoder.js b/src/client/widgets/sliders/encoder.js index f04b11b3..582c5d7f 100644 --- a/src/client/widgets/sliders/encoder.js +++ b/src/client/widgets/sliders/encoder.js @@ -219,6 +219,12 @@ module.exports = class Encoder extends StaticProperties(Knob, {angle: 360, range this.clear() + if (this.minDimension < 40) { + minRadius /= 2 + gaugeWidth = maxRadius - minRadius + gaugeRadius = maxRadius - gaugeWidth / 2 + } + // fill this.ctx.globalAlpha = this.cssVars.alphaFill this.ctx.strokeStyle = this.cssVars.colorFill @@ -244,10 +250,12 @@ module.exports = class Encoder extends StaticProperties(Knob, {angle: 360, range this.ctx.strokeStyle = this.cssVars.colorStroke this.ctx.lineWidth = PXSCALE - this.ctx.beginPath() - this.ctx.arc(this.width / 2, this.height / 2, minRadius, 0, 2 * Math.PI) - this.ctx.stroke() - + 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() diff --git a/src/client/widgets/sliders/knob.js b/src/client/widgets/sliders/knob.js index f38bd2b3..2d6888e0 100644 --- a/src/client/widgets/sliders/knob.js +++ b/src/client/widgets/sliders/knob.js @@ -15,7 +15,6 @@ module.exports = class Knob extends Slider { _knob:'knob', - design: {type: 'string', value: 'default', choices: ['default', 'classic'], help: 'Design style'}, 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,117 +181,126 @@ module.exports = class Knob extends Slider { this.clear() - if (this.getProp('design') === 'default') { + // if (this.getProp('design') === 'default') { - // fill - this.ctx.strokeStyle = this.cssVars.colorFill - this.ctx.lineWidth = gaugeWidth - this.gaugePadding * 2 + if (this.minDimension < 40) { + minRadius /= 2 + gaugeWidth = maxRadius - minRadius + gaugeRadius = maxRadius - gaugeWidth / 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() - } + // fill + this.ctx.strokeStyle = this.cssVars.colorFill + this.ctx.lineWidth = gaugeWidth - this.gaugePadding * 2 - if (dashed) this.ctx.setLineDash([1.5 * PXSCALE, 1.5 * 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.stroke() + } - 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([1.5 * PXSCALE, 1.5 * PXSCALE]) - if (dashed) this.ctx.setLineDash([]) + 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 + // stroke - this.ctx.globalAlpha = this.cssVars.alphaStroke - this.ctx.strokeStyle = this.cssVars.colorStroke - this.ctx.lineWidth = PXSCALE + 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.colorPanel - 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() - - } + 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.colorPanel + // 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