ui: new design (wip), simpler color scheme, unified knob design, cool faders (inspired by budislavTVP design)

This commit is contained in:
jean-emmanuel 2017-06-20 18:49:10 +02:00
parent 759e8c331e
commit cdb5032266
29 changed files with 684 additions and 660 deletions

View file

@ -35,7 +35,7 @@ module.exports = class Push extends _widgets_base {
constructor(options) {
super({...options, html: '<div class="light"></div>'})
super({...options, html: '<div class="toggle"><div class="light"></div></div>'})
this.state = 0
this.active = 0

View file

@ -34,7 +34,7 @@ module.exports = class Toggle extends _widgets_base {
constructor(options) {
super({...options, html: '<div class="light"></div>'})
super({...options, html: '<div class="toggle"><div class="light"></div></div>'})
this.widget.value = this.widget.find('span')
this.widget.state = 0

View file

@ -64,6 +64,7 @@ module.exports = class _canvas_base extends _widgets_base {
this.colors.bg = style.getPropertyValue('--color-bg')
this.colors.fg = style.getPropertyValue('--color-fg')
this.colors.faded = style.getPropertyValue('--color-faded')
this.colors.light = style.getPropertyValue('--color-light')
}
requestAnimationFrame(this.draw.bind(this))

View file

@ -79,7 +79,7 @@ module.exports = class Modal extends Panel {
this.setValue(0, {sync:true, send:true})
})
this.light = $('<div class="light"></div>').appendTo(this.container)
this.light = $('<div class="toggle"><div class="light"></div></div>').appendTo(this.container)
if (this.getProp('doubleTap')) {
doubletabreset(this.light, ()=>{
@ -107,7 +107,7 @@ module.exports = class Modal extends Panel {
}
this.fixScrolling()
this.popup.toggle(this.value?true:false)
this.container.toggleClass('on', this.value?true:false)

View file

@ -58,6 +58,10 @@ module.exports = class Multifader extends _matrices_base {
if (this.getProp('horizontal')) {
this.widget.addClass('horizontal')
}
if (this.getProp('compact')) {
this.widget.addClass('compact')
}
var strData = JSON.stringify(options.props)

View file

@ -69,7 +69,7 @@ module.exports = class Rgb extends _pads_base {
h: new Fader({props:{
...faderDefaults,
id:'h',
compact:false,
compact:true,
pips:false,
horizontal:true,
snap:this.getProp('snap'),

View file

@ -148,6 +148,7 @@ module.exports = class _sliders_base extends _canvas_base {
this.colors.track = style.getPropertyValue('--color-track')
this.colors.gauge = style.getPropertyValue('--color-gauge')
this.colors.knob = style.getPropertyValue('--color-knob')
this.colors.pips = style.getPropertyValue('--color-pips')
}
super.resizeHandle(...arguments)

View file

@ -54,7 +54,7 @@ module.exports = class Fader extends _sliders_base {
super(options)
this.widget.addClass('fader')
this.margin = 15
this.margin = 16
if (this.getProp('horizontal')) {
@ -158,7 +158,7 @@ module.exports = class Fader extends _sliders_base {
percentToCoord(percent) {
if (this.getProp('horizontal')) {
return clip(percent / 100,[0,1]) * (this.width - 2 * PXSCALE * this.margin)
return clip(percent / 100,[0,1]) * (this.width - 2 * PXSCALE * this.margin) + this.margin * PXSCALE
} else {
return (this.height - this.margin * PXSCALE) - clip(percent / 100, [0,1]) * (this.height - 2 * PXSCALE * this.margin)
}
@ -176,6 +176,11 @@ module.exports = class Fader extends _sliders_base {
}
}
if (this.getProp('horizontal')) {
this.ctx.rotate(-Math.PI/2)
this.ctx.translate(-this.height, 0)
}
if (CANVAS_SCALING != 1) this.ctx.scale(CANVAS_SCALING, CANVAS_SCALING)
}
@ -183,152 +188,117 @@ module.exports = class Fader extends _sliders_base {
draw() {
var d = Math.round(this.percentToCoord(this.percent)),
o = Math.round(this.percentToCoord(this.valueToPercent(this.originValue))),
m = Math.round(this.getProp('horizontal') ? this.height / 2 : this.width / 2)
var width = this.getProp('horizontal') ? this.height : this.width,
height = !this.getProp('horizontal') ? this.height : this.width
var d = this.percentToCoord(this.percent),
o = this.percentToCoord(this.valueToPercent(this.originValue)),
m = this.getProp('horizontal') ? this.height / 2 : this.width / 2
this.clear()
if (this.getProp('horizontal')) {
if (this.getProp('compact')) {
if (this.getProp('compact')) {
this.ctx.globalAlpha = 0.2 + 0.2 * Math.abs(d-o) / (d<o?o:height-o)
this.ctx.strokeStyle = this.colors.gauge
this.ctx.beginPath()
this.ctx.moveTo(m, d)
this.ctx.lineTo(m, o)
this.ctx.lineWidth = width + 2 * PXSCALE
this.ctx.stroke()
if (this.getProp('pips') && this.rangeKeys.length > 2) {
this.ctx.globalAlpha = 1
var y,
min = Math.min(d,o),
max = Math.max(d,o)
this.ctx.globalAlpha = 0.2 + 0.2 * Math.abs(d-o) / (d<o?o:this.width-o)
this.ctx.strokeStyle = this.colors.gauge
this.ctx.beginPath()
this.ctx.moveTo(d, m)
this.ctx.lineTo(o, m)
this.ctx.lineWidth = this.height + 1
this.ctx.stroke()
if (this.getProp('pips') && this.rangeKeys.length > 2) {
this.ctx.lineWidth = 1 * PXSCALE
this.ctx.globalAlpha = 1
this.ctx.strokeStyle = this.colors.bg
var x,
min = Math.min(d,o),
max = Math.max(d,o)
this.ctx.beginPath()
for (var i = 1;i < this.rangeKeys.length - 1;i++) {
x = Math.round(this.percentToCoord(this.rangeKeys[i])) + 0.5
this.ctx.moveTo(x, 0)
this.ctx.lineTo(x, 4 * PXSCALE)
this.ctx.moveTo(x, this.height - 4 * PXSCALE)
this.ctx.lineTo(x, this.height)
}
this.ctx.stroke()
for (var i = 1;i < this.rangeKeys.length - 1;i++) {
y = this.percentToCoord(this.rangeKeys[i])
this.ctx.rect(0, y - PXSCALE, 4.5 * PXSCALE, 2 * PXSCALE)
this.ctx.rect(width - 4.5 * PXSCALE, y - PXSCALE, 4.5 * PXSCALE, 2 * PXSCALE)
}
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.knob
this.ctx.rect(Math.min(d,this.width-PXSCALE), 0, PXSCALE, this.height)
this.ctx.fillStyle = this.colors.pips
this.ctx.fill()
} else {
this.ctx.lineWidth = Math.round(2 * PXSCALE)
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.light
this.ctx.fill()
this.ctx.lineWidth = 1 * PXSCALE
this.ctx.strokeStyle = this.colors.track
this.ctx.moveTo(this.margin * PXSCALE, m)
this.ctx.lineTo(this.width - this.margin * PXSCALE, m )
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.gauge
this.ctx.moveTo(d + this.margin * PXSCALE, m)
this.ctx.lineTo(o + this.margin * PXSCALE, m)
this.ctx.stroke()
this.ctx.fillStyle = this.colors.knob
this.ctx.globalAlpha = 0.3
this.ctx.arc(d + this.margin * PXSCALE, m, 10 * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.arc(d + this.margin * PXSCALE, m, 4 * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
this.clearRect = [0, this.height / 2 - 11 * PXSCALE, this.width, 22 * PXSCALE]
}
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.knob
this.ctx.rect(0, Math.min(d, height - PXSCALE), width, PXSCALE)
this.ctx.fill()
this.clearRect = [0, 0, width, height]
} else {
if (this.getProp('compact')) {
this.ctx.lineWidth = 6 * PXSCALE
this.ctx.globalAlpha = 0.2 + 0.2 * Math.abs(d-o) / (d<o?o:this.height-o)
this.ctx.strokeStyle = this.colors.gauge
this.ctx.beginPath()
this.ctx.moveTo(m, d)
this.ctx.lineTo(m, o)
this.ctx.lineWidth = this.width + 1
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.globalAlpha = 1
this.ctx.strokeStyle = this.colors.light
this.ctx.moveTo(m, this.margin * PXSCALE - 2 * PXSCALE)
this.ctx.lineTo(m, height - this.margin * PXSCALE + 2 * PXSCALE)
this.ctx.stroke()
if (this.getProp('pips') && this.rangeKeys.length > 2) {
this.ctx.lineWidth = 1 * PXSCALE
this.ctx.globalAlpha = 1
this.ctx.strokeStyle = this.colors.bg
this.ctx.lineWidth = 4 * PXSCALE
var y,
min = Math.min(d,o),
max = Math.max(d,o)
this.ctx.beginPath()
this.ctx.globalAlpha = 1
this.ctx.strokeStyle = this.colors.bg
this.ctx.moveTo(m, this.margin * PXSCALE - PXSCALE)
this.ctx.lineTo(m, height - this.margin * PXSCALE + PXSCALE)
this.ctx.stroke()
this.ctx.beginPath()
for (var i = 1;i < this.rangeKeys.length - 1;i++) {
y = Math.round(this.percentToCoord(this.rangeKeys[i])) + 0.5
this.ctx.moveTo(0, y)
this.ctx.lineTo(4 * PXSCALE, y)
this.ctx.moveTo(this.width - 4 * PXSCALE, y)
this.ctx.lineTo(this.width, y)
}
this.ctx.stroke()
}
this.ctx.lineWidth = 2 * PXSCALE
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.knob
this.ctx.rect(0, Math.min(d, this.height - PXSCALE), this.width, PXSCALE)
this.ctx.fill()
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.track
this.ctx.moveTo(m, this.margin * PXSCALE)
this.ctx.lineTo(m, height - this.margin * PXSCALE)
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.globalAlpha = 1
this.ctx.strokeStyle = this.colors.gauge
this.ctx.moveTo(m, d)
this.ctx.lineTo(m, o)
this.ctx.stroke()
} else {
this.ctx.globalAlpha = 1
this.ctx.lineWidth = Math.round(2 * PXSCALE)
this.ctx.beginPath()
this.ctx.rect(m - 9 * PXSCALE, d - 15 * PXSCALE, 18 * PXSCALE, 30 * PXSCALE)
this.ctx.lineWidth = PXSCALE
this.ctx.fillStyle = this.colors.track
this.ctx.fill()
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.track
this.ctx.moveTo(m, this.margin * PXSCALE)
this.ctx.lineTo(m, this.height - this.margin * PXSCALE)
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.rect(m - 8 * PXSCALE, d - 14 * PXSCALE, 16 * PXSCALE, 28 * PXSCALE)
this.ctx.fillStyle = this.colors.raised
this.ctx.fill()
this.ctx.lineWidth = PXSCALE
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.gauge
this.ctx.moveTo(m, d)
this.ctx.lineTo(m, o)
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.rect(m - 7 * PXSCALE, d - 13 * PXSCALE, 14 * PXSCALE, 26 * PXSCALE)
this.ctx.lineWidth = PXSCALE
this.ctx.strokeStyle = this.colors.light
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.rect(m - 4 * PXSCALE, d, 8 * PXSCALE, PXSCALE)
this.ctx.fillStyle = this.colors.knob
this.ctx.fill()
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.knob
this.ctx.globalAlpha = 0.3
this.ctx.arc(m, d, 10 * PXSCALE, Math.PI * 2,false)
this.ctx.fill()
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.arc(m, d, 4 * PXSCALE, Math.PI * 2,false)
this.ctx.fill()
this.clearRect = [this.width / 2 - 11 * PXSCALE, 0, 22 * PXSCALE, this.height]
}
this.clearRect = [width / 2 - 11 * PXSCALE, 0, 22 * PXSCALE, height]
}
}

View file

@ -20,7 +20,6 @@ module.exports = class Knob extends _sliders_base {
height:'auto',
color:'auto',
pips:true,
compact:false,
angle:270,
css:'',
@ -53,12 +52,9 @@ module.exports = class Knob extends _sliders_base {
this.margin = 5
if (this.getProp('compact')) {
this.widget.addClass('compact')
this.margin = 0
}
this.widget.addClass('compact')
if (this.getProp('pips') && !this.getProp('compact')) {
if (this.getProp('pips')) {
this.wrapper.append(`
<div class="pips">
<div>${this.rangeLabels[0]}</div><div>${this.rangeLabels[this.rangeLabels.length-1]}</div>
@ -73,9 +69,7 @@ module.exports = class Knob extends _sliders_base {
this.maxAngle = this.getProp('angle')
// calculate lost height factor
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)
var a = (1 - Math.sin((Math.max(this.maxAngle,247.5) - 180) / 2 * Math.PI / 180)) / 3
this.lostHeightFactor = a / 4
}
@ -144,13 +138,9 @@ module.exports = class Knob extends _sliders_base {
super.resizeHandle(...arguments)
this.minDimension = Math.min(this.width, this.height)
this.gaugeWidth = this.minDimension / 8
this.gaugeWidth = this.minDimension / 12
if (this.getProp('compact')) {
this.canvas[0].style.top = this.input[0].style.marginTop = (this.minDimension) * this.lostHeightFactor - (this.getProp('label') === false ? 0 : this.gaugeWidth / 4) + 'px'
} else {
this.canvas[0].style.top = Math.min((this.minDimension) * this.lostHeightFactor - (this.getProp('label') === false ? 0 : this.margin * PXSCALE / 2), this.input.outerHeight() * .5) + 'px'
}
this.canvas[0].style.top = (this.minDimension) * this.lostHeightFactor - (this.getProp('label') === false ? 0 : this.gaugeWidth / 4) + 'px'
}
@ -163,131 +153,87 @@ module.exports = class Knob extends _sliders_base {
this.ctx.clearRect(0,0,this.width,this.height)
if (this.getProp('compact')) {
this.ctx.globalAlpha = 1
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.strokeStyle = this.colors.light
this.ctx.lineWidth = 7 * PXSCALE
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - this.gaugeWidth - this.margin * PXSCALE, min - 0.06, max + 0.06)
this.ctx.stroke()
this.ctx.lineWidth = this.gaugeWidth
this.ctx.globalAlpha = 0.3 + 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.strokeStyle = this.colors.bg
this.ctx.lineWidth = 5 * PXSCALE
this.ctx.beginPath()
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - this.gaugeWidth - this.margin * PXSCALE, min - 0.03, max + 0.03)
this.ctx.stroke()
if (this.getProp('pips')) {
this.ctx.globalAlpha = 1
this.ctx.strokeStyle = this.colors.track
this.ctx.lineWidth = 2 * PXSCALE
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.strokeStyle = this.colors.gauge
this.ctx.lineWidth = 2 * PXSCALE
this.ctx.beginPath()
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()
if (this.getProp('pips')) {
this.ctx.globalAlpha = 1
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 - this.margin * PXSCALE - 3.5 * PXSCALE,
r2 = this.minDimension / 2 - this.gaugeWidth - this.margin * PXSCALE + 3.5 * 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.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()
}
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.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 {
var r = Math.max(this.minDimension / 2 - (30 + this.margin) * PXSCALE, 2 * PXSCALE)
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.raised
this.ctx.strokeStyle = this.colors.raised
this.ctx.arc(this.width / 2, this.height / 2, r, 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()
this.ctx.globalAlpha = 1
this.ctx.lineWidth = 2 * PXSCALE
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.track
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (10 + this.margin) * PXSCALE, min, max)
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.strokeStyle = this.colors.gauge
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - (10 + this.margin) * PXSCALE, Math.min(o,d), Math.max(o,d))
this.ctx.stroke()
this.ctx.save()
this.ctx.translate(this.width / 2, this.height / 2)
this.ctx.rotate(d)
this.ctx.translate(-this.width / 2, -this.height / 2)
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.knob
this.ctx.arc(this.width / 2 + this.minDimension / 2 - (10 + this.margin) * PXSCALE, this.height / 2, 4 * PXSCALE, 0, Math.PI * 2)
this.ctx.fill()
this.ctx.globalAlpha = 0.3
this.ctx.fillStyle = this.colors.knob
this.ctx.arc(this.width / 2 + this.minDimension / 2 - (10 + this.margin) * PXSCALE, this.height / 2, 10 * PXSCALE, 0, Math.PI * 2)
this.ctx.fill()
this.ctx.restore()
}
// knob
this.ctx.lineWidth = PXSCALE
this.ctx.fillStyle = this.colors.raised
this.ctx.beginPath()
this.ctx.globalAlpha = 1
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - this.gaugeWidth * 2 - this.margin * PXSCALE, 0, Math.PI * 2)
this.ctx.fill()
this.ctx.strokeStyle = this.colors.track
this.ctx.stroke()
this.ctx.beginPath()
this.ctx.globalAlpha = 1
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - this.gaugeWidth * 2 - this.margin * PXSCALE - PXSCALE, 0, Math.PI * 2)
this.ctx.strokeStyle = this.colors.light
this.ctx.stroke()
// cursor
this.ctx.globalAlpha = 1
let r1 = this.minDimension / 2 - this.gaugeWidth * 2 - this.margin * PXSCALE,
r2 = this.minDimension / 2 - this.gaugeWidth * 3 - 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((r1/2) * Math.cos(a) + this.width / 2, this.height / 2 - (r1/2) * Math.sin(a))
this.ctx.lineWidth = 2 * PXSCALE
this.ctx.strokeStyle = this.colors.knob
this.ctx.stroke()
}
}