sliders: compact knob redisign; rename noPip option to pips (with backward compat)
This commit is contained in:
parent
ae45ba1092
commit
7ce05fc83e
5 changed files with 68 additions and 35 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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},
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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(`
|
||||
<div class="pips">
|
||||
<div>${this.rangeLabels[0]}</div><div>${this.rangeLabels[this.rangeLabels.length-1]}</div>
|
||||
|
|
@ -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<o?o-min:max-o)
|
||||
this.ctx.beginPath()
|
||||
this.ctx.strokeStyle = this.colors.gauge
|
||||
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - this.gaugeWidth - this.margin * PXSCALE, Math.min(o,d), Math.max(o,d))
|
||||
this.ctx.stroke()
|
||||
|
||||
this.ctx.lineWidth = 1 * PXSCALE
|
||||
this.ctx.beginPath()
|
||||
this.ctx.strokeStyle = this.colors.track
|
||||
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - this.gaugeWidth/2 - this.margin * PXSCALE, min, max)
|
||||
this.ctx.stroke()
|
||||
if (this.getProp('pips')) {
|
||||
this.ctx.globalAlpha = 1
|
||||
|
||||
this.ctx.strokeStyle = this.colors.fg
|
||||
this.ctx.lineWidth = 2 * PXSCALE
|
||||
|
||||
for (var pip of this.rangeKeys.concat(this.valueToPercent(this.originValue))) {
|
||||
if ((pip == 0 || pip == 100) && this.maxAngle < 360) continue
|
||||
let r1 = this.minDimension / 2 - this.gaugeWidth/2 - this.margin * PXSCALE,
|
||||
r2 = this.minDimension / 2 - this.gaugeWidth * 1.5 - this.margin * PXSCALE,
|
||||
a = 2 * Math.PI - this.percentToAngle(pip)
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
// knob
|
||||
this.ctx.fillStyle = this.colors.fg
|
||||
this.ctx.beginPath()
|
||||
this.ctx.globalAlpha = 1
|
||||
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - this.gaugeWidth * 1.25, 0, Math.PI * 2)
|
||||
this.ctx.fill()
|
||||
|
||||
this.ctx.beginPath()
|
||||
|
||||
this.ctx.strokeStyle = this.colors.knob
|
||||
this.ctx.lineWidth = 1 * PXSCALE
|
||||
|
||||
let r1 = this.minDimension / 2 - this.gaugeWidth/2 - this.margin * PXSCALE,
|
||||
r2 = this.minDimension / 2 - this.gaugeWidth * 1.5 - this.margin * PXSCALE,
|
||||
a = 2 * Math.PI - 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()
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.fillStyle = this.colors.raised
|
||||
this.ctx.strokeStyle = this.colors.raised
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.globalAlpha = 1
|
||||
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - this.gaugeWidth * 1.5, 0, Math.PI * 2)
|
||||
this.ctx.fill()
|
||||
|
||||
this.ctx.globalAlpha = 1
|
||||
this.ctx.beginPath()
|
||||
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - this.gaugeWidth * 2, 0, Math.PI * 2)
|
||||
this.ctx.fill()
|
||||
this.ctx.lineWidth = 1 * PXSCALE
|
||||
this.ctx.stroke()
|
||||
this.ctx.globalAlpha = 0.3
|
||||
this.ctx.lineWidth = 1.1 * PXSCALE
|
||||
this.ctx.stroke()
|
||||
|
||||
// cursor
|
||||
this.ctx.globalAlpha = 0.75
|
||||
this.ctx.strokeStyle = this.colors.knob
|
||||
this.ctx.lineWidth = 2 * PXSCALE
|
||||
|
||||
let r1 = this.minDimension / 2 - this.gaugeWidth * 2 - this.margin * PXSCALE + 1.1 * PXSCALE,
|
||||
r2 = this.minDimension / 2 - this.gaugeWidth * 1.5 - this.margin * 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 {
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue