From 4037f9c796bf455963235c43fa2dd3ca3d638394 Mon Sep 17 00:00:00 2001 From: bordun Date: Tue, 26 Nov 2019 21:04:16 +0100 Subject: [PATCH] knob: nicer pips with text --- CHANGELOG.md | 2 ++ src/client/app/widgets/common/canvas.js | 1 + src/client/app/widgets/sliders/knob.js | 43 +++++++++++++++++++++---- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 870e21bb..a76f3504 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - bug fixes - launcher: limit terminal history size to prevent slowdown/freeze +- widgets + - knob: text pips support ## 0.48.3 diff --git a/src/client/app/widgets/common/canvas.js b/src/client/app/widgets/common/canvas.js index 5cbe653d..e56cf7be 100644 --- a/src/client/app/widgets/common/canvas.js +++ b/src/client/app/widgets/common/canvas.js @@ -143,6 +143,7 @@ class Canvas extends Widget { this.colors.custom = style.getPropertyValue('--color-custom') this.colors.track = style.getPropertyValue('--color-track') this.colors.text = style.getPropertyValue('--color-text') + this.colors.textFade = style.getPropertyValue('--color-text-fade') this.colors.raised = style.getPropertyValue('--color-raised') this.colors.bg = style.getPropertyValue('--color-bg') this.colors.fg = style.getPropertyValue('--color-fg') diff --git a/src/client/app/widgets/sliders/knob.js b/src/client/app/widgets/sliders/knob.js index 5007a071..112309e6 100644 --- a/src/client/app/widgets/sliders/knob.js +++ b/src/client/app/widgets/sliders/knob.js @@ -67,6 +67,17 @@ module.exports = class Knob extends Slider { var a = (1 - Math.sin((Math.max(this.maxAngle,247.5) - 180) / 2 * Math.PI / 180)) / 3 this.lostHeightFactor = a / 4 + + if (this.getProp('pips')) { + + this.widget.classList.add('has-pips') + this.pipTexts = {} + for (var k in this.rangeKeys) { + this.pipTexts[this.rangeKeys[k]]=this.rangeLabels[k] + } + + } + } draginitHandle(e) { @@ -184,6 +195,12 @@ module.exports = class Knob extends Slider { } + if (pips) { + gaugeRadius -= this.fontSize * PXSCALE * 1.5 + gaugeWidth / 2 + knobRadius = gaugeRadius - gaugeWidth + } + + this.ctx.clearRect(0,0,this.width,this.height) this.ctx.globalAlpha = 1 @@ -191,7 +208,7 @@ module.exports = class Knob extends Slider { this.ctx.strokeStyle = this.colors.light this.ctx.lineWidth = gaugeWidth this.ctx.beginPath() - this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, min - 4 * rad - (pips ? 3 * rad : 0), max + 4 * rad + (pips ? 3 * rad : 0)) + this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, min - 4 * rad, max + 4 * rad) this.ctx.stroke() this.ctx.strokeStyle = this.colors.bg @@ -208,7 +225,7 @@ module.exports = class Knob extends Slider { this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, min, max) this.ctx.stroke() - this.ctx.globalAlpha = pips ? 0.5 : 0.7 + this.ctx.globalAlpha = 0.7 this.ctx.strokeStyle = this.colors.gauge this.ctx.lineWidth = gaugeWidth - 4.5 * PXSCALE this.ctx.beginPath() @@ -237,19 +254,20 @@ module.exports = class Knob extends Slider { if (pips) { this.ctx.globalAlpha = 1 - this.ctx.lineWidth = gaugeWidth - 4.5 * PXSCALE for (var pip of this.rangeKeys.concat(this.valueToPercent(this.originValue))) { let a = this.percentToAngle(pip) - this.ctx.lineWidth = gaugeWidth - 2 * PXSCALE - this.ctx.strokeStyle = this.colors.bg + this.ctx.lineWidth = gaugeWidth + 2 * PXSCALE this.ctx.beginPath() - this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, a - 5 * rad, a + 5 * rad) + this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, a - 4.5 * rad, a + 4.5 * rad) + this.ctx.strokeStyle = this.colors.fg + this.ctx.stroke() + this.ctx.strokeStyle = this.colors.light this.ctx.stroke() - this.ctx.lineWidth = gaugeWidth - 4.5 * PXSCALE + this.ctx.lineWidth = gaugeWidth + 1.5 * PXSCALE this.ctx.strokeStyle = this.colors.pips this.ctx.beginPath() this.ctx.arc(this.width / 2, this.height / 2, gaugeRadius, a - 2 * rad, a + 2 * rad) @@ -257,6 +275,17 @@ module.exports = class Knob extends Slider { } + var radius = gaugeRadius + this.fontSize * PXSCALE + gaugeWidth / 2 + this.ctx.fillStyle = this.colors.textFade + for (var p in this.pipTexts) { + if (this.pipTexts[p] == undefined) continue + var angle = this.percentToAngle(p), + size = this.ctx.measureText(this.pipTexts[p]), + x = this.width / 2 + radius * Math.cos(angle) - size.width / 2, + y = this.height / 2 + radius * Math.sin(angle) + this.ctx.fillText(this.pipTexts[p], x, y) + } + } // knob