pads: add pips

This commit is contained in:
jean-emmanuel 2017-07-20 18:33:06 +02:00
parent e38c5dd45f
commit 687358ad03
3 changed files with 126 additions and 121 deletions

View file

@ -28,6 +28,7 @@ module.exports = class MultiXy extends _pads_base {
top:'auto',
width:'auto',
height:'auto',
pips: true,
color:'auto',
css:'',
@ -55,7 +56,6 @@ module.exports = class MultiXy extends _pads_base {
this.npoints = typeof this.getProp('points') == 'object' ? this.getProp('points').length : this.getProp('points')
this.labels = typeof this.getProp('points') == 'object'
this.pointSize = parseInt(this.getProp('pointSize'))
this.widget[0].style.setProperty("--point-size",this.pointSize + 'rem')
this.split = this.getProp('split')?
typeof this.getProp('split') == 'object' && this.getProp('split').length == 2 * this.npoints ?
@ -88,10 +88,12 @@ module.exports = class MultiXy extends _pads_base {
rangeY:this.getProp('rangeY'),
precision:this.precision,
logScaleX:this.getProp('logScaleX'),
logScaleY:this.getProp('logScaleY')
logScaleY:this.getProp('logScaleY'),
pointSize: this.getProp('pointSize'),
pips: this.getProp('pips') && i == this.npoints-1,
input:false
}})
this.pads[i].sendValue = ()=>{}
this.pads[i].draw = ()=>{}
this.wrapper.append(this.pads[i].widget)
this.handles[i] = $(`<div class="handle"></div>`)
@ -184,30 +186,17 @@ module.exports = class MultiXy extends _pads_base {
this.clear()
for (var i=0;i<this.npoints;i++) {
var x = Math.round(clip(this.pads[i].faders.x.percent,[0,100]) / 100 * (this.width - (this.pointSize * 2 + 2) * PXSCALE) + (this.pointSize + 1) * PXSCALE),
y = Math.round((100 - clip(this.pads[i].faders.y.percent,[0,100])) / 100 * (this.height - (this.pointSize * 2 + 2) * PXSCALE) + (this.pointSize + 1) * PXSCALE),
t = this.labels ? this.getProp('points')[i] : i
var margin = (this.pointSize + 1) * PXSCALE,
x = clip(this.pads[i].faders.x.percent,[0,100]) / 100 * (this.width - 2 * margin) + margin,
y = (100 - clip(this.pads[i].faders.y.percent,[0,100])) / 100 * (this.height - 2 * margin) + margin,
t = (this.labels ? this.getProp('points')[i] : i) + '',
length = this.fontSize * t.length
this.ctx.strokeStyle = this.colors.custom
this.ctx.fillStyle = this.colors.custom
this.ctx.lineWidth = PXSCALE * 2
this.ctx.globalAlpha = 1
this.ctx.fillStyle = this.colors.text
this.ctx.fillText(t, x, y)
this.ctx.globalAlpha = 0.3
this.ctx.beginPath()
this.ctx.arc(x, y,(this.pointSize - 2) * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
this.ctx.globalAlpha = 1
this.ctx.beginPath()
this.ctx.arc(x, y, (this.pointSize - 2) * PXSCALE, Math.PI * 2, false)
this.ctx.stroke()
this.ctx.globalAlpha = 1
this.ctx.fillStyle = this.colors.text
this.ctx.lineWidth = PXSCALE
this.ctx.fillText(t, x, y)
this.clearRect[i] = [x - this.pointSize * PXSCALE, y - this.pointSize * PXSCALE, this.pointSize * 2 * PXSCALE, this.pointSize * 2 * PXSCALE]
this.clearRect[i] = [x - length / 2, y - this.fontSize / 2, length, this.fontSize]
}

View file

@ -23,9 +23,14 @@ module.exports = class Xy extends _pads_base {
width:'auto',
height:'auto',
input: true,
pips: true,
color:'auto',
css:'',
_behaviour:'xy',
pointSize: 20,
_behaviour:'behaviour',
snap:false,
@ -73,7 +78,8 @@ module.exports = class Xy extends _pads_base {
range:this.getProp('rangeX'),
origin:'auto',
precision:this.precision,
logScale:this.getProp('logScaleX')
logScale:this.getProp('logScaleX'),
input:false
}, cancelDraw: true}),
y: new Fader({props:{
...faderDefaults,
@ -88,10 +94,15 @@ module.exports = class Xy extends _pads_base {
range:this.getProp('rangeY'),
origin:'auto',
precision:this.precision,
logScale:this.getProp('logScaleY')
logScale:this.getProp('logScaleY'),
input:false
}, cancelDraw: true}),
}
this.pointSize = parseInt(this.getProp('pointSize'))
this.faders.x.margin = this.faders.y.margin = this.pointSize + 1
this.value = [this.faders.x.value, this.faders.y.value]
this.wrapper.append(this.faders.x.widget)
@ -181,40 +192,58 @@ module.exports = class Xy extends _pads_base {
draw() {
var x = clip(this.faders.x.percent / 100 * this.width,[0,this.width]),
y = clip((1 - this.faders.y.percent / 100) * this.height,[0,this.height])
var pointSize = this.pointSize * PXSCALE,
margin = (pointSize + 1) * PXSCALE,
x = this.faders.x.percentToCoord(this.faders.x.percent),
y = this.faders.y.percentToCoord(this.faders.y.percent)
this.clear()
this.ctx.fillStyle = this.faders.x.colors.custom
this.ctx.lineWidth = PXSCALE
this.ctx.strokeStyle = this.faders.x.colors.custom
this.ctx.fillStyle = this.colors.custom
this.ctx.strokeStyle = this.colors.custom
if (this.getProp('pips')) {
this.ctx.globalAlpha = 0.1
this.ctx.beginPath()
this.ctx.rect(margin + 0.5, margin + 0.5, this.width - margin * 2 - 1, this.height - margin * 2 - 1)
this.ctx.stroke()
this.ctx.beginPath()
for (var pip of this.faders.x.rangeKeys.concat(this.faders.x.valueToPercent(this.faders.x.originValue))) {
if (pip == 0 || pip == 100) continue
var xpip = Math.round(2 * this.faders.x.percentToCoord(pip)) / 2
this.ctx.moveTo(xpip, margin + 0.5)
this.ctx.lineTo(xpip, this.height - margin - 0.5)
}
for (pip of this.faders.y.rangeKeys.concat(this.faders.y.valueToPercent(this.faders.y.originValue))) {
if (pip == 0 || pip == 100) continue
var ypip = Math.round(2 * this.faders.y.percentToCoord(pip)) / 2
this.ctx.moveTo(margin + 0.5, ypip)
this.ctx.lineTo(this.width - margin - 0.5, ypip)
}
this.ctx.stroke()
} else {
this.clearRect = [x - margin, y - margin, margin * 2, margin * 2]
}
this.ctx.globalAlpha = 0.3
this.ctx.beginPath()
this.ctx.arc(x, y, 10 * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
this.ctx.globalAlpha = 0.1
this.ctx.beginPath()
this.ctx.moveTo(0,y)
this.ctx.lineTo(this.width,y)
this.ctx.moveTo(x,0)
this.ctx.lineTo(x,this.height)
this.ctx.arc(x, y, pointSize, Math.PI * 2, false)
this.ctx.stroke()
this.ctx.globalAlpha = 1
this.ctx.globalAlpha = 0.7
this.ctx.beginPath()
this.ctx.arc(x, y, 4 * PXSCALE, Math.PI * 2, false)
this.ctx.fill()
this.ctx.arc(x, y, pointSize / 2, Math.PI * 2, false)
this.ctx.stroke()
this.clearRect = [
[x - 10 * PXSCALE,0, 20 * PXSCALE, this.height],
[0, y - 10 * PXSCALE, this.width, 20 * PXSCALE]
]
}
showValue() {

View file

@ -2,11 +2,66 @@
width:200rem;
height:230rem;
padding:1rem;
.label {
flex-shrink: 0;
z-index: 1;
}
.pad {
height:100%;
width: 100%;
overflow: hidden;
display: flex;
flex-direction: column;
> .input {
height: 25rem;
line-height: 25rem;
flex:initial!important;
display: block;
flex-shrink: 0!important;
background: transparent!important;
border: 0!important;
}
> .wrapper {
position: relative;
height: 100%;
width: 100%;
background:var(--color-track);
border: 1rem solid var(--color-bg);
> canvas {
width:100%;
height:100%;
position: absolute;
pointer-events: none;
z-index: 1;
}
.fader {
pointer-events: none;
position: absolute;
width:100%;
height:100%;
z-index: 0;
--color-knob:transparent;
--color-gauge:transparent;
box-shadow: none;
border: 0;
* {
background: transparent!important;
}
.wrapper {
border:none;
}
.input {
display: none;
}
}
}
}
}
.panel:not(.tab) > .xy-container,
@ -24,59 +79,6 @@
}
}
.pad {
height:100%;
width: 100%;
overflow: hidden;
display: flex;
flex-direction: column;
> .input {
height: 25rem;
line-height: 25rem;
flex:initial!important;
display: block;
flex-shrink: 0!important;
background: transparent!important;
border: 0!important;
}
> .wrapper {
position: relative;
height: 100%;
width: 100%;
background:var(--color-track);
border: 1rem solid var(--color-bg);
> canvas {
width:100%;
height:100%;
position: absolute;
pointer-events: none;
z-index: 1;
}
.fader {
pointer-events: none;
position: absolute;
width:100%;
height:100%;
z-index: 0;
--color-knob:transparent;
--color-gauge:transparent;
box-shadow: none;
border: 0;
* {
background: transparent!important;
}
.wrapper {
border:none;
}
.input {
display: none;
}
}
}
}
.rgb-container {
.pad {
> .wrapper {
@ -127,13 +129,10 @@
.multixy-container {
> .pad {
--point-size:10rem;
text-align: center;
font-weight: 500;
font-size: 12rem;
> .wrapper {
padding: calc(var(--point-size) + 1rem);
> canvas {
top:0;
@ -141,42 +140,30 @@
}
.handle {
position: absolute;
top: calc( var(--point-size) + 1rem);
left: calc( var(--point-size) + 1rem);
right: calc( var(--point-size) + 1rem);
bottom:calc( var(--point-size) + 1rem);
top: 0;
left: 0;
right: 0;
bottom:0;
cursor: -webkit-grab;
z-index: 1;
&.active {
pointer-events: none;
}
&:after {
content:"";
position: absolute;
top: calc( -1 * var(--point-size));
left: calc( -1 * var(--point-size));
right: calc( -1 * var(--point-size));
bottom:calc( -1 * var(--point-size));
}
}
> .pad {
pointer-events: none;
position: absolute;
width:calc(100% - 2 * var(--point-size) - 2rem);
height:calc(100% - 2 * var(--point-size) - 2rem);
.wrapper {
border:0;
background: transparent;
}
canvas {
border:0;
left:0;
}
.input {
display: none;
}
&:not(:nth-child(2)) {
opacity: 0;
}
}
}
}